Search in sources :

Example 11 with ConsumerPrincipal

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

the class OwnerResourceTest method consumerCannotCountAllConsumersInOwner.

// copied from consumerCannotListAllConsumersInOwner
@Test(expected = ForbiddenException.class)
public void consumerCannotCountAllConsumersInOwner() {
    Consumer c = createConsumer(owner);
    setupPrincipal(new ConsumerPrincipal(c, owner));
    securityInterceptor.enable();
    ownerResource.countConsumers(owner.getKey(), typeLabels, skus, subscriptionIds, contracts);
}
Also used : UpstreamConsumer(org.candlepin.model.UpstreamConsumer) Consumer(org.candlepin.model.Consumer) ConsumerPrincipal(org.candlepin.auth.ConsumerPrincipal) Test(org.junit.Test)

Example 12 with ConsumerPrincipal

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

the class JobCuratorTest method findByConsumerUuidRestrictsByConsumerUuidEnforcesOwnerMatchWhenRequestedByConsumer.

@Test
public void findByConsumerUuidRestrictsByConsumerUuidEnforcesOwnerMatchWhenRequestedByConsumer() {
    Owner owner = new Owner("testowner");
    owner.setId(TestUtil.randomString());
    Consumer consumer = TestUtil.createConsumer(owner);
    JobStatus job = newJobStatus().principalName(consumer.getUuid()).consumer(consumer.getUuid(), "testowner").create();
    // Technically this case shoरावणuld not happen since a consumer
    // can belong to one org, but adding just to make sure that
    // it gets filtered.
    newJobStatus().principalName(consumer.getUuid()).consumer(consumer.getUuid(), "owner1").create();
    newJobStatus().principalName("p2").consumer("c2", "owner1").create();
    newJobStatus().principalName("p3").owner("owner2").create();
    setupPrincipal(new ConsumerPrincipal(consumer, owner));
    List<JobStatus> jobs = curator.findByConsumerUuid(consumer.getUuid()).list();
    assertEquals(1, jobs.size());
    assertEquals(job, jobs.get(0));
}
Also used : JobStatus(org.candlepin.pinsetter.core.model.JobStatus) ConsumerPrincipal(org.candlepin.auth.ConsumerPrincipal) Test(org.junit.Test)

Example 13 with ConsumerPrincipal

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

the class ConsumerTest method canDeleteSelf.

@Test
public void canDeleteSelf() {
    setupPrincipal(new ConsumerPrincipal(consumer, owner));
    consumerCurator.delete(consumer);
    assertNull(consumerCurator.find(consumer.getId()));
}
Also used : ConsumerPrincipal(org.candlepin.auth.ConsumerPrincipal) Test(org.junit.Test)

Example 14 with ConsumerPrincipal

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

the class OwnerAccessControlTest method consumerCannotCreateAnOwner.

@Test(expected = ForbiddenException.class)
public void consumerCannotCreateAnOwner() {
    Consumer consumer = createConsumer(owner);
    setupPrincipal(new ConsumerPrincipal(consumer, owner));
    securityInterceptor.enable();
    OwnerDTO dto = new OwnerDTO();
    dto.setKey("Test Owner");
    dto.setDisplayName("Test Owner");
    resource.createOwner(dto);
}
Also used : OwnerDTO(org.candlepin.dto.api.v1.OwnerDTO) ConsumerPrincipal(org.candlepin.auth.ConsumerPrincipal) Test(org.junit.Test)

Example 15 with ConsumerPrincipal

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

the class JobCuratorTest method findByPrincipalNameRestrictsConsumerToOwnJobs.

@Test
public void findByPrincipalNameRestrictsConsumerToOwnJobs() {
    Owner owner = new Owner("ducks");
    Consumer consumer = TestUtil.createConsumer(owner);
    JobStatus job = newJobStatus().principalName(consumer.getUuid()).owner(owner.getKey()).create();
    newJobStatus().principalName("donald").owner(owner.getKey()).create();
    setupPrincipal(new ConsumerPrincipal(consumer, owner));
    assertTrue(this.curator.findByPrincipalName("donald").list().isEmpty());
    List<JobStatus> jobs = this.curator.findByPrincipalName(consumer.getUuid()).list();
    assertNotNull(jobs);
    assertEquals(1, jobs.size());
    assertEquals(consumer.getUuid(), job.getPrincipalName());
    assertEquals(job, jobs.get(0));
}
Also used : JobStatus(org.candlepin.pinsetter.core.model.JobStatus) 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