Search in sources :

Example 31 with Consumer

use of org.candlepin.model.Consumer in project candlepin by candlepin.

the class VerifyAuthorizationFilterTest method testAccessToConsumer.

@Test
public void testAccessToConsumer() throws Exception {
    mockReq = MockHttpRequest.create("POST", "http://localhost/candlepin/fake/123");
    ResteasyProviderFactory.pushContext(HttpRequest.class, mockReq);
    mockReq.setAttribute(ResteasyProviderFactory.class.getName(), ResteasyProviderFactory.getInstance());
    Consumer c = createConsumer(createOwner());
    methodInjector.setArguments(new Object[] { c.getUuid() });
    X500Principal dn = new X500Principal("CN=" + c.getUuid() + ", C=US, L=Raleigh");
    // create mock certs to trigger SSLAuth provider
    X509Certificate[] certs = new X509Certificate[1];
    X509Certificate cert = mock(X509Certificate.class);
    when(cert.getSubjectX500Principal()).thenReturn(dn);
    certs[0] = cert;
    mockReq.setAttribute("javax.servlet.request.X509Certificate", certs);
    Principal p = sslAuth.getPrincipal(mockReq);
    when(mockSecurityContext.getUserPrincipal()).thenReturn(p);
    interceptor.filter(mockRequestContext);
}
Also used : Consumer(org.candlepin.model.Consumer) X500Principal(javax.security.auth.x500.X500Principal) ResteasyProviderFactory(org.jboss.resteasy.spi.ResteasyProviderFactory) X509Certificate(java.security.cert.X509Certificate) X500Principal(javax.security.auth.x500.X500Principal) Principal(org.candlepin.auth.Principal) Test(org.junit.Test)

Example 32 with Consumer

use of org.candlepin.model.Consumer in project candlepin by candlepin.

the class OwnerResourceTest method testConsumerRoleCannotGetOwner.

@Test(expected = ForbiddenException.class)
public void testConsumerRoleCannotGetOwner() {
    Consumer c = createConsumer(owner);
    setupPrincipal(new ConsumerPrincipal(c, owner));
    securityInterceptor.enable();
    ownerResource.getOwner(owner.getKey());
}
Also used : UpstreamConsumer(org.candlepin.model.UpstreamConsumer) Consumer(org.candlepin.model.Consumer) ConsumerPrincipal(org.candlepin.auth.ConsumerPrincipal) Test(org.junit.Test)

Example 33 with Consumer

use of org.candlepin.model.Consumer in project candlepin by candlepin.

the class OwnerResourceTest method testComplexDeleteOwner.

@Test
public void testComplexDeleteOwner() throws Exception {
    // Create some consumers:
    Consumer c1 = createConsumer(owner);
    Consumer c2 = createConsumer(owner);
    // Create a pool for this owner:
    Pool pool = TestUtil.createPool(owner, product);
    poolCurator.create(pool);
    // Give those consumers entitlements:
    Map<String, Integer> pQs = new HashMap<>();
    pQs.put(pool.getId(), 1);
    poolManager.entitleByPools(c1, pQs);
    assertEquals(2, consumerCurator.listByOwner(owner).list().size());
    assertEquals(1, poolCurator.listByOwner(owner).list().size());
    assertEquals(1, entitlementCurator.listByOwner(owner).list().size());
    // Generate an ueber certificate for the Owner. This will need to
    // be cleaned up along with the owner deletion.
    UeberCertificate uCert = ueberCertGenerator.generate(owner.getKey(), setupAdminPrincipal("test"));
    assertNotNull(uCert);
    ownerResource.deleteOwner(owner.getKey(), true, false);
    assertEquals(0, consumerCurator.listByOwner(owner).list().size());
    assertNull(consumerCurator.findByUuid(c1.getUuid()));
    assertNull(consumerCurator.findByUuid(c2.getUuid()));
    assertEquals(0, poolCurator.listByOwner(owner).list().size());
    assertEquals(0, entitlementCurator.listByOwner(owner).list().size());
    assertNull(ueberCertCurator.findForOwner(owner));
}
Also used : UpstreamConsumer(org.candlepin.model.UpstreamConsumer) Consumer(org.candlepin.model.Consumer) UeberCertificate(org.candlepin.model.UeberCertificate) HashMap(java.util.HashMap) Pool(org.candlepin.model.Pool) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Example 34 with Consumer

use of org.candlepin.model.Consumer in project candlepin by candlepin.

the class OwnerResourceTest method createConsumerCreatedEvent.

private Event createConsumerCreatedEvent(Owner o) {
    // Rather than run through an entire call to ConsumerResource, we'll
    // fake the
    // events in the db:
    setupPrincipal(o, Access.ALL);
    Consumer consumer = createConsumer(o);
    Event e1 = eventFactory.consumerCreated(consumer);
    eventCurator.create(e1);
    return e1;
}
Also used : UpstreamConsumer(org.candlepin.model.UpstreamConsumer) Consumer(org.candlepin.model.Consumer) Event(org.candlepin.audit.Event)

Example 35 with Consumer

use of org.candlepin.model.Consumer in project candlepin by candlepin.

the class ConsumerBindUtilTest method registerFailWithKeyServiceLevelNotExist.

@Test(expected = BadRequestException.class)
public void registerFailWithKeyServiceLevelNotExist() throws Exception {
    List<ActivationKey> keys = new ArrayList<>();
    ActivationKey key1 = new ActivationKey("key1", owner);
    keys.add(key1);
    key1.setServiceLevel("I don't exist");
    Consumer consumer = new Consumer("sys.example.com", null, null, system);
    doThrow(new BadRequestException("exception")).when(serviceLevelValidator).validate(eq(owner.getId()), eq(key1.getServiceLevel()));
    consumerBindUtil.handleActivationKeys(consumer, keys, false);
}
Also used : Consumer(org.candlepin.model.Consumer) ArrayList(java.util.ArrayList) BadRequestException(org.candlepin.common.exceptions.BadRequestException) ActivationKey(org.candlepin.model.activationkeys.ActivationKey) Test(org.junit.Test)

Aggregations

Consumer (org.candlepin.model.Consumer)470 Test (org.junit.Test)345 Entitlement (org.candlepin.model.Entitlement)162 Owner (org.candlepin.model.Owner)126 Pool (org.candlepin.model.Pool)114 Product (org.candlepin.model.Product)112 Date (java.util.Date)102 ConsumerType (org.candlepin.model.ConsumerType)94 LinkedList (java.util.LinkedList)73 ArrayList (java.util.ArrayList)71 HashSet (java.util.HashSet)69 ConsumerInstalledProduct (org.candlepin.model.ConsumerInstalledProduct)69 HashMap (java.util.HashMap)48 ApiOperation (io.swagger.annotations.ApiOperation)43 Produces (javax.ws.rs.Produces)43 ConsumerDTO (org.candlepin.dto.api.v1.ConsumerDTO)40 ApiResponses (io.swagger.annotations.ApiResponses)38 GuestId (org.candlepin.model.GuestId)37 Path (javax.ws.rs.Path)36 List (java.util.List)35