Search in sources :

Example 16 with ConsumerPrincipal

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

the class OwnerResourceTest method consumerListPoolsGetCalculatedAttributes.

@Test
public void consumerListPoolsGetCalculatedAttributes() {
    Product p = this.createProduct(owner);
    Pool pool1 = TestUtil.createPool(owner, p);
    poolCurator.create(pool1);
    Consumer c = this.createConsumer(owner);
    Principal principal = setupPrincipal(new ConsumerPrincipal(c, owner));
    securityInterceptor.enable();
    List<PoolDTO> pools = ownerResource.listPools(owner.getKey(), c.getUuid(), null, p.getId(), null, true, null, null, new ArrayList<>(), false, false, null, null, principal, null);
    assertEquals(1, pools.size());
    PoolDTO returnedPool = pools.get(0);
    assertNotNull(returnedPool.getCalculatedAttributes());
}
Also used : UpstreamConsumer(org.candlepin.model.UpstreamConsumer) Consumer(org.candlepin.model.Consumer) Product(org.candlepin.model.Product) PoolDTO(org.candlepin.dto.api.v1.PoolDTO) Pool(org.candlepin.model.Pool) ConsumerPrincipal(org.candlepin.auth.ConsumerPrincipal) ConsumerPrincipal(org.candlepin.auth.ConsumerPrincipal) UserPrincipal(org.candlepin.auth.UserPrincipal) Principal(org.candlepin.auth.Principal) Test(org.junit.Test)

Example 17 with ConsumerPrincipal

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

the class OwnerResourceTest method testUnmappedGuestConsumerCanListPoolsForFuture.

@Test
public void testUnmappedGuestConsumerCanListPoolsForFuture() {
    Consumer c = this.createConsumer(owner);
    c.setFact("virt.is_guest", "true");
    c.setFact("virt.uuid", "system_uuid");
    consumerCurator.merge(c);
    Principal principal = setupPrincipal(new ConsumerPrincipal(c, owner));
    securityInterceptor.enable();
    Date now = new Date();
    Product p = this.createProduct(owner);
    Pool pool1 = TestUtil.createPool(owner, p);
    pool1.setAttribute(Pool.Attributes.VIRT_ONLY, "true");
    pool1.setAttribute(Pool.Attributes.DERIVED_POOL, "true");
    pool1.setAttribute(Pool.Attributes.PHYSICAL_ONLY, "false");
    pool1.setAttribute(Pool.Attributes.UNMAPPED_GUESTS_ONLY, "true");
    pool1.setStartDate(now);
    pool1.setEndDate(new Date(now.getTime() + 1000L * 60 * 60 * 24 * 365));
    Pool pool2 = TestUtil.createPool(owner, p);
    pool2.setAttribute(Pool.Attributes.VIRT_ONLY, "true");
    pool2.setAttribute(Pool.Attributes.DERIVED_POOL, "true");
    pool2.setAttribute(Pool.Attributes.PHYSICAL_ONLY, "false");
    pool2.setAttribute(Pool.Attributes.UNMAPPED_GUESTS_ONLY, "true");
    pool2.setStartDate(new Date(now.getTime() + 2 * 1000L * 60 * 60 * 24 * 365));
    pool2.setEndDate(new Date(now.getTime() + 3 * 1000L * 60 * 60 * 24 * 365));
    poolCurator.create(pool1);
    poolCurator.create(pool2);
    List<PoolDTO> nowList = ownerResource.listPools(owner.getKey(), c.getUuid(), null, null, null, false, new Date(), null, new ArrayList<>(), false, false, null, null, principal, null);
    assertEquals(1, nowList.size());
    assert (nowList.get(0).getId().equals(pool1.getId()));
    Date activeOn = new Date(pool2.getStartDate().getTime() + 1000L * 60 * 60 * 24);
    List<PoolDTO> futureList = ownerResource.listPools(owner.getKey(), c.getUuid(), null, null, null, false, activeOn, null, new ArrayList<>(), false, false, null, null, principal, null);
    assertEquals(1, futureList.size());
    assert (futureList.get(0).getId().equals(pool2.getId()));
}
Also used : UpstreamConsumer(org.candlepin.model.UpstreamConsumer) Consumer(org.candlepin.model.Consumer) Product(org.candlepin.model.Product) PoolDTO(org.candlepin.dto.api.v1.PoolDTO) ConsumerPrincipal(org.candlepin.auth.ConsumerPrincipal) Pool(org.candlepin.model.Pool) ConsumerPrincipal(org.candlepin.auth.ConsumerPrincipal) UserPrincipal(org.candlepin.auth.UserPrincipal) Principal(org.candlepin.auth.Principal) Date(java.util.Date) Test(org.junit.Test)

Example 18 with ConsumerPrincipal

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

the class OwnerResourceTest method testConsumerRoleCannotAccessOwnerAtomFeed.

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

Example 19 with ConsumerPrincipal

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

the class OwnerResourceTest method consumerCannotListAllConsumersInOwner.

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

Example 20 with ConsumerPrincipal

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

the class OwnerResourceTest method testConsumerCanListPools.

@Test
public void testConsumerCanListPools() {
    Consumer c = createConsumer(owner);
    Principal principal = setupPrincipal(new ConsumerPrincipal(c, owner));
    securityInterceptor.enable();
    ownerResource.listPools(owner.getKey(), null, null, null, null, false, null, null, new ArrayList<>(), false, false, null, null, principal, null);
}
Also used : UpstreamConsumer(org.candlepin.model.UpstreamConsumer) Consumer(org.candlepin.model.Consumer) ConsumerPrincipal(org.candlepin.auth.ConsumerPrincipal) ConsumerPrincipal(org.candlepin.auth.ConsumerPrincipal) UserPrincipal(org.candlepin.auth.UserPrincipal) Principal(org.candlepin.auth.Principal) 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