use of org.candlepin.model.ConsumerType in project candlepin by candlepin.
the class SSLAuthTest method correctUserName.
/**
* Happy path - parses the username from the cert's DN correctly.
*
* @throws Exception
*/
@Test
public void correctUserName() throws Exception {
ConsumerType ctype = new ConsumerType(ConsumerTypeEnum.SYSTEM);
ctype.setId("test-ctype");
Owner owner = new Owner("test owner");
owner.setId(TestUtil.randomString());
Consumer consumer = new Consumer("machine_name", "test user", owner, ctype);
ConsumerPrincipal expected = new ConsumerPrincipal(consumer, owner);
String dn = "CN=453-44423-235";
mockCert(dn);
when(this.consumerCurator.getConsumer("453-44423-235")).thenReturn(consumer);
when(this.ownerCurator.findOwnerById(owner.getOwnerId())).thenReturn(owner);
assertEquals(expected, this.auth.getPrincipal(httpRequest));
}
use of org.candlepin.model.ConsumerType in project candlepin by candlepin.
the class ConsumerPrincipalTest method equalsDifferentConsumer.
@Test
public void equalsDifferentConsumer() {
ConsumerType ctype = new ConsumerType(ConsumerType.ConsumerTypeEnum.SYSTEM);
ctype.setId("test-ctype");
Consumer c = new Consumer("Test Consumer", "test-consumer", new Owner("o1"), ctype);
ConsumerPrincipal cp = new ConsumerPrincipal(c, o);
assertFalse(principal.equals(cp));
}
use of org.candlepin.model.ConsumerType in project candlepin by candlepin.
the class ConsumerContentOverrideResourceTest method setUp.
@Before
public void setUp() {
ConsumerType ctype = new ConsumerType("test-consumer-type");
ctype.setId("test-ctype");
consumer = new Consumer("test-consumer", "test-user", new Owner("Test Owner"), ctype);
MultivaluedMap<String, String> mvm = new MultivaluedMapImpl<>();
mvm.add("consumer_uuid", consumer.getUuid());
context = mock(UriInfo.class);
when(context.getPathParameters()).thenReturn(mvm);
when(consumerCurator.verifyAndLookupConsumer(eq(consumer.getUuid()))).thenReturn(consumer);
when(overrideRules.canOverrideForConsumer(any(String.class))).thenReturn(true);
i18n = I18nFactory.getI18n(getClass(), Locale.US, I18nFactory.FALLBACK);
contentOverrideValidator = new ContentOverrideValidator(i18n, overrideRules);
resource = new ConsumerContentOverrideResource(consumerContentOverrideCurator, consumerCurator, contentOverrideValidator, i18n);
when(principal.canAccess(any(Object.class), any(SubResource.class), any(Access.class))).thenReturn(true);
}
use of org.candlepin.model.ConsumerType in project candlepin by candlepin.
the class ConsumerResourceCreationTest method registerFailsWithKeyWhenAutobindOnKeyAndDisabledOnOwner.
@Test
public void registerFailsWithKeyWhenAutobindOnKeyAndDisabledOnOwner() {
ConsumerType ctype = new ConsumerType(ConsumerTypeEnum.SYSTEM);
ConsumerTypeDTO ctypeDTO = this.modelTranslator.translate(ctype, ConsumerTypeDTO.class);
this.mockConsumerType(ctype);
// Disable autobind for the owner.
owner.setAutobindDisabled(true);
// Create a key that has autobind disabled.
ActivationKey key = new ActivationKey("autobind-disabled-key", owner);
key.setAutoAttach(true);
when(activationKeyCurator.lookupForOwner(key.getName(), owner)).thenReturn(key);
// No auth should be required for registering with keys:
Principal p = new NoAuthPrincipal();
ConsumerDTO consumer = TestUtil.createConsumerDTO("sys.example.com", null, null, ctypeDTO);
resource.create(consumer, p, null, owner.getKey(), key.getName(), true);
}
use of org.candlepin.model.ConsumerType in project candlepin by candlepin.
the class ConsumerResourceIntegrationTest method testReadOnlyUsersCanGenerateExports.
@Test
public void testReadOnlyUsersCanGenerateExports() {
// add an identity certificate for the export
IdentityCertificate idCert = TestUtil.createIdCert();
// needs to be null to persist
idCert.setId(null);
certSerialCurator.create(idCert.getSerial());
identityCertificateCurator.create(idCert);
consumer.setIdCert(idCert);
consumer.setType(consumerTypeCurator.create(new ConsumerType(ConsumerTypeEnum.CANDLEPIN)));
consumerCurator.update(consumer);
setupPrincipal(owner, Access.READ_ONLY);
securityInterceptor.enable();
consumerResource.exportData(mock(HttpServletResponse.class), consumer.getUuid(), null, null, null, new ArrayList<>());
// if no exception, we're good
}
Aggregations