Search in sources :

Example 36 with ConsumerType

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));
}
Also used : Owner(org.candlepin.model.Owner) Consumer(org.candlepin.model.Consumer) Matchers.anyString(org.mockito.Matchers.anyString) ConsumerType(org.candlepin.model.ConsumerType) Test(org.junit.Test)

Example 37 with ConsumerType

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));
}
Also used : Owner(org.candlepin.model.Owner) Consumer(org.candlepin.model.Consumer) ConsumerType(org.candlepin.model.ConsumerType) Test(org.junit.Test)

Example 38 with ConsumerType

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);
}
Also used : SubResource(org.candlepin.auth.SubResource) Owner(org.candlepin.model.Owner) Consumer(org.candlepin.model.Consumer) Access(org.candlepin.auth.Access) MultivaluedMapImpl(org.jboss.resteasy.specimpl.MultivaluedMapImpl) ContentOverrideValidator(org.candlepin.util.ContentOverrideValidator) ConsumerType(org.candlepin.model.ConsumerType) UriInfo(javax.ws.rs.core.UriInfo) Before(org.junit.Before)

Example 39 with ConsumerType

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);
}
Also used : NoAuthPrincipal(org.candlepin.auth.NoAuthPrincipal) ConsumerDTO(org.candlepin.dto.api.v1.ConsumerDTO) ConsumerType(org.candlepin.model.ConsumerType) ActivationKey(org.candlepin.model.activationkeys.ActivationKey) ConsumerTypeDTO(org.candlepin.dto.api.v1.ConsumerTypeDTO) TrustedUserPrincipal(org.candlepin.auth.TrustedUserPrincipal) UserPrincipal(org.candlepin.auth.UserPrincipal) Principal(org.candlepin.auth.Principal) NoAuthPrincipal(org.candlepin.auth.NoAuthPrincipal) Test(org.junit.Test)

Example 40 with ConsumerType

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
}
Also used : HttpServletResponse(javax.servlet.http.HttpServletResponse) ConsumerType(org.candlepin.model.ConsumerType) IdentityCertificate(org.candlepin.model.IdentityCertificate) Test(org.junit.Test)

Aggregations

ConsumerType (org.candlepin.model.ConsumerType)169 Consumer (org.candlepin.model.Consumer)92 Test (org.junit.Test)71 Owner (org.candlepin.model.Owner)53 Pool (org.candlepin.model.Pool)47 Entitlement (org.candlepin.model.Entitlement)33 ArrayList (java.util.ArrayList)29 Date (java.util.Date)27 HashMap (java.util.HashMap)24 HashSet (java.util.HashSet)24 ValidationResult (org.candlepin.policy.ValidationResult)22 ApiOperation (io.swagger.annotations.ApiOperation)21 Produces (javax.ws.rs.Produces)21 Before (org.junit.Before)20 ApiResponses (io.swagger.annotations.ApiResponses)19 Path (javax.ws.rs.Path)18 LinkedList (java.util.LinkedList)16 BadRequestException (org.candlepin.common.exceptions.BadRequestException)16 DeletedConsumer (org.candlepin.model.DeletedConsumer)16 Matchers.anyString (org.mockito.Matchers.anyString)16