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);
}
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());
}
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));
}
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;
}
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);
}
Aggregations