Search in sources :

Example 41 with Principal

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

the class OwnerResourceTest method testOwnerAdminCanGetPools.

@Test
public void testOwnerAdminCanGetPools() {
    Principal principal = setupPrincipal(owner, Access.ALL);
    Product p = this.createProduct(owner);
    Pool pool1 = TestUtil.createPool(owner, p);
    Pool pool2 = TestUtil.createPool(owner, p);
    poolCurator.create(pool1);
    poolCurator.create(pool2);
    List<PoolDTO> pools = ownerResource.listPools(owner.getKey(), null, null, null, null, true, null, null, new ArrayList<>(), false, false, null, null, principal, null);
    assertEquals(2, pools.size());
}
Also used : Product(org.candlepin.model.Product) PoolDTO(org.candlepin.dto.api.v1.PoolDTO) Pool(org.candlepin.model.Pool) ConsumerPrincipal(org.candlepin.auth.ConsumerPrincipal) UserPrincipal(org.candlepin.auth.UserPrincipal) Principal(org.candlepin.auth.Principal) Test(org.junit.Test)

Example 42 with Principal

use of org.candlepin.auth.Principal 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 43 with Principal

use of org.candlepin.auth.Principal 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 44 with Principal

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

the class OwnerResourceTest method testCanFilterPoolsByAttribute.

@Test
public void testCanFilterPoolsByAttribute() throws Exception {
    Principal principal = setupPrincipal(owner, Access.ALL);
    Product p = this.createProduct(owner);
    Pool pool1 = TestUtil.createPool(owner, p);
    pool1.setAttribute(Product.Attributes.VIRT_ONLY, "true");
    poolCurator.create(pool1);
    Product p2 = this.createProduct(owner);
    p2.setAttribute(Product.Attributes.CORES, "12");
    productCurator.merge(p2);
    Pool pool2 = TestUtil.createPool(owner, p2);
    poolCurator.create(pool2);
    List<KeyValueParameter> params = new ArrayList<>();
    params.add(createKeyValueParam("cores", "12"));
    List<PoolDTO> pools = ownerResource.listPools(owner.getKey(), null, null, null, null, true, null, null, params, false, false, null, null, principal, null);
    assertEquals(1, pools.size());
    assertModelEqualsDTO(pool2, pools.get(0));
    params.clear();
    params.add(createKeyValueParam("virt_only", "true"));
    pools = ownerResource.listPools(owner.getKey(), null, null, null, null, true, null, null, params, false, false, null, null, principal, null);
    assertEquals(1, pools.size());
    assertModelEqualsDTO(pool1, pools.get(0));
}
Also used : ArrayList(java.util.ArrayList) Product(org.candlepin.model.Product) KeyValueParameter(org.candlepin.resteasy.parameter.KeyValueParameter) PoolDTO(org.candlepin.dto.api.v1.PoolDTO) Pool(org.candlepin.model.Pool) ConsumerPrincipal(org.candlepin.auth.ConsumerPrincipal) UserPrincipal(org.candlepin.auth.UserPrincipal) Principal(org.candlepin.auth.Principal) Test(org.junit.Test)

Example 45 with Principal

use of org.candlepin.auth.Principal 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

Principal (org.candlepin.auth.Principal)74 Test (org.junit.Test)54 UserPrincipal (org.candlepin.auth.UserPrincipal)40 NoAuthPrincipal (org.candlepin.auth.NoAuthPrincipal)20 ConsumerPrincipal (org.candlepin.auth.ConsumerPrincipal)17 ConsumerDTO (org.candlepin.dto.api.v1.ConsumerDTO)15 Consumer (org.candlepin.model.Consumer)15 Owner (org.candlepin.model.Owner)15 TrustedUserPrincipal (org.candlepin.auth.TrustedUserPrincipal)14 Date (java.util.Date)12 ConsumerType (org.candlepin.model.ConsumerType)11 HashSet (java.util.HashSet)10 Pool (org.candlepin.model.Pool)10 JobDetail (org.quartz.JobDetail)10 Method (java.lang.reflect.Method)9 Permission (org.candlepin.auth.permissions.Permission)9 JobDataMap (org.quartz.JobDataMap)9 CandlepinQuery (org.candlepin.model.CandlepinQuery)8 File (java.io.File)7 FileInputStream (java.io.FileInputStream)7