Search in sources :

Example 6 with ConsumerPrincipal

use of org.candlepin.auth.ConsumerPrincipal in project candlepin by candlepin.

the class PoolResourceTest method consumerCannotListPoolsForAnotherOwner.

@Test(expected = NotFoundException.class)
public void consumerCannotListPoolsForAnotherOwner() {
    Principal p = setupPrincipal(new ConsumerPrincipal(foreignConsumer, owner2));
    securityInterceptor.enable();
    poolResource.list(owner1.getId(), null, null, false, null, p, null);
}
Also used : ConsumerPrincipal(org.candlepin.auth.ConsumerPrincipal) Principal(org.candlepin.auth.Principal) ConsumerPrincipal(org.candlepin.auth.ConsumerPrincipal) Test(org.junit.Test)

Example 7 with ConsumerPrincipal

use of org.candlepin.auth.ConsumerPrincipal in project candlepin by candlepin.

the class JobCuratorTest method findByUserFiltersByOwnerAccessAndUUIDWhenRequestedByConsumer.

@Test
public void findByUserFiltersByOwnerAccessAndUUIDWhenRequestedByConsumer() {
    Owner owner = new Owner("testowner");
    owner.setId(TestUtil.randomString());
    Consumer consumer = TestUtil.createConsumer(owner);
    JobStatus job = newJobStatus().principalName(consumer.getUuid()).owner(owner.getKey()).create();
    newJobStatus().principalName("p1").owner("owner1").create();
    newJobStatus().principalName("p2").owner("owner1").create();
    newJobStatus().principalName("p3").owner("owner2").create();
    setupPrincipal(new ConsumerPrincipal(consumer, owner));
    assertTrue(this.curator.findByOwnerKey("owner1").list().isEmpty());
    assertTrue(this.curator.findByOwnerKey("owner2").list().isEmpty());
    List<JobStatus> found = this.curator.findByOwnerKey("testowner").list();
    assertEquals(1, found.size());
    assertEquals(job, found.get(0));
}
Also used : JobStatus(org.candlepin.pinsetter.core.model.JobStatus) ConsumerPrincipal(org.candlepin.auth.ConsumerPrincipal) Test(org.junit.Test)

Example 8 with ConsumerPrincipal

use of org.candlepin.auth.ConsumerPrincipal in project candlepin by candlepin.

the class ConsumerResourceIntegrationTest method consumerShouldNotSeeAnotherConsumersEntitlements.

@Test(expected = NotFoundException.class)
public void consumerShouldNotSeeAnotherConsumersEntitlements() {
    Consumer evilConsumer = TestUtil.createConsumer(standardSystemType, owner);
    consumerCurator.create(evilConsumer);
    consumerResource.bind(consumer.getUuid(), pool.getId().toString(), null, 1, null, null, false, null, null);
    consumerResource.bind(consumer.getUuid(), pool.getId().toString(), null, 1, null, null, false, null, null);
    consumerResource.bind(evilConsumer.getUuid(), pool.getId().toString(), null, 1, null, null, false, null, null);
    setupPrincipal(new ConsumerPrincipal(evilConsumer, owner));
    securityInterceptor.enable();
    consumerResource.listEntitlements(consumer.getUuid(), null, true, "", new ArrayList<>(), null);
}
Also used : Consumer(org.candlepin.model.Consumer) ConsumerPrincipal(org.candlepin.auth.ConsumerPrincipal) Test(org.junit.Test)

Example 9 with ConsumerPrincipal

use of org.candlepin.auth.ConsumerPrincipal in project candlepin by candlepin.

the class ConsumerResourceIntegrationTest method testCanGetOwnedConsumersCerts.

@Test
public void testCanGetOwnedConsumersCerts() {
    consumerResource.bind(consumer.getUuid(), pool.getId().toString(), null, 1, null, null, false, null, null);
    consumerResource.bind(consumer.getUuid(), pool.getId().toString(), null, 1, null, null, false, null, null);
    consumerResource.bind(consumer.getUuid(), pool.getId().toString(), null, 1, null, null, false, null, null);
    setupPrincipal(new ConsumerPrincipal(consumer, owner));
    assertEquals(3, consumerResource.getEntitlementCertificates(consumer.getUuid(), null).size());
}
Also used : ConsumerPrincipal(org.candlepin.auth.ConsumerPrincipal) Test(org.junit.Test)

Example 10 with ConsumerPrincipal

use of org.candlepin.auth.ConsumerPrincipal in project candlepin by candlepin.

the class ConsumerResourceIntegrationTest method testConsumerCannotListAllConsumers.

@Test(expected = ForbiddenException.class)
public void testConsumerCannotListAllConsumers() {
    setupPrincipal(new ConsumerPrincipal(consumer, owner));
    securityInterceptor.enable();
    consumerResource.list(null, null, null, new ArrayList<>(), null, null, null);
}
Also used : ConsumerPrincipal(org.candlepin.auth.ConsumerPrincipal) Test(org.junit.Test)

Aggregations

ConsumerPrincipal (org.candlepin.auth.ConsumerPrincipal)27 Test (org.junit.Test)25 Consumer (org.candlepin.model.Consumer)11 Principal (org.candlepin.auth.Principal)9 UpstreamConsumer (org.candlepin.model.UpstreamConsumer)7 Date (java.util.Date)4 Method (java.lang.reflect.Method)3 UserPrincipal (org.candlepin.auth.UserPrincipal)3 PoolDTO (org.candlepin.dto.api.v1.PoolDTO)3 Pool (org.candlepin.model.Pool)3 JobStatus (org.candlepin.pinsetter.core.model.JobStatus)3 Product (org.candlepin.model.Product)2 ResourceInfo (javax.ws.rs.container.ResourceInfo)1 OwnerDTO (org.candlepin.dto.api.v1.OwnerDTO)1 IdentityCertificate (org.candlepin.model.IdentityCertificate)1 Owner (org.candlepin.model.Owner)1 Before (org.junit.Before)1