Search in sources :

Example 21 with ForbiddenException

use of org.candlepin.common.exceptions.ForbiddenException in project candlepin by candlepin.

the class OwnerContentResourceTest method updateLockedContent.

@Test(expected = ForbiddenException.class)
public void updateLockedContent() {
    Owner owner = this.createOwner("test_owner");
    Content content = this.createContent("test_content", "test_content", owner);
    ContentDTO cdto = TestUtil.createContentDTO("test_content", "updated_name");
    content.setLocked(true);
    this.contentCurator.merge(content);
    assertNotNull(this.ownerContentCurator.getContentById(owner, cdto.getId()));
    try {
        this.ownerContentResource.updateContent(owner.getKey(), cdto.getId(), cdto);
    } catch (ForbiddenException e) {
        Content entity = this.ownerContentCurator.getContentById(owner, cdto.getId());
        assertNotNull(entity);
        assertEquals(content, entity);
        assertNotEquals(cdto.getName(), entity.getName());
        throw e;
    }
}
Also used : ContentDTO(org.candlepin.dto.api.v1.ContentDTO) Owner(org.candlepin.model.Owner) ForbiddenException(org.candlepin.common.exceptions.ForbiddenException) Content(org.candlepin.model.Content) Test(org.junit.Test)

Example 22 with ForbiddenException

use of org.candlepin.common.exceptions.ForbiddenException in project candlepin by candlepin.

the class OwnerContentResourceTest method createContentWhenContentAlreadyExistsAndLocked.

@Test(expected = ForbiddenException.class)
public void createContentWhenContentAlreadyExistsAndLocked() {
    // Note:
    // The current behavior of createContent is to update content if content already exists
    // with the given RHID. So, our expected behavior in this test is to trigger an update.
    Owner owner = this.createOwner("test_owner");
    Content content = this.createContent("test_content", "test_content", owner);
    ContentDTO cdto = TestUtil.createContentDTO("test_content", "updated_name");
    cdto.setLabel("test-label");
    cdto.setType("test-test");
    cdto.setVendor("test-vendor");
    content.setLocked(true);
    this.contentCurator.merge(content);
    assertNotNull(this.ownerContentCurator.getContentById(owner, cdto.getId()));
    try {
        ContentDTO output = this.ownerContentResource.createContent(owner.getKey(), cdto);
    } catch (ForbiddenException e) {
        Content entity = this.ownerContentCurator.getContentById(owner, cdto.getId());
        assertNotNull(entity);
        assertEquals(content, entity);
        assertNotEquals(cdto.getName(), entity.getName());
        throw e;
    }
}
Also used : ContentDTO(org.candlepin.dto.api.v1.ContentDTO) Owner(org.candlepin.model.Owner) ForbiddenException(org.candlepin.common.exceptions.ForbiddenException) Content(org.candlepin.model.Content) Test(org.junit.Test)

Example 23 with ForbiddenException

use of org.candlepin.common.exceptions.ForbiddenException in project candlepin by candlepin.

the class ConsumerBindUtilTest method registerPassWithOneGoodKeyPool.

@Test
public void registerPassWithOneGoodKeyPool() throws Exception {
    List<ActivationKey> keys = new ArrayList<>();
    ActivationKey key1 = new ActivationKey("key1", owner);
    keys.add(key1);
    Product prod1 = TestUtil.createProduct();
    Pool pool1 = TestUtil.createPool(owner, prod1, 5);
    pool1.setId("pool1");
    key1.addPool(pool1, 10L);
    Product prod2 = TestUtil.createProduct();
    Pool pool2 = TestUtil.createPool(owner, prod2, 5);
    pool2.setId("pool2");
    key1.addPool(pool2, 10L);
    Product prod3 = TestUtil.createProduct();
    Pool pool3 = TestUtil.createPool(owner, prod3, 5);
    pool3.setId("pool3");
    key1.addPool(pool3, 5L);
    Consumer consumer = new Consumer("sys.example.com", null, null, system);
    when(entitler.bindByPoolQuantity(eq(consumer), eq(pool1.getId()), eq(10))).thenThrow(new ForbiddenException("fail"));
    when(entitler.bindByPoolQuantity(eq(consumer), eq(pool2.getId()), eq(10))).thenThrow(new ForbiddenException("fail"));
    consumerBindUtil.handleActivationKeys(consumer, keys, false);
}
Also used : ForbiddenException(org.candlepin.common.exceptions.ForbiddenException) Consumer(org.candlepin.model.Consumer) ArrayList(java.util.ArrayList) Product(org.candlepin.model.Product) ConsumerInstalledProduct(org.candlepin.model.ConsumerInstalledProduct) Pool(org.candlepin.model.Pool) ActivationKey(org.candlepin.model.activationkeys.ActivationKey) Test(org.junit.Test)

Example 24 with ForbiddenException

use of org.candlepin.common.exceptions.ForbiddenException in project candlepin by candlepin.

the class ConsumerBindUtilTest method registerPassWithOneGoodKey.

@Test
public void registerPassWithOneGoodKey() throws Exception {
    List<ActivationKey> keys = new ArrayList<>();
    ActivationKey key1 = new ActivationKey("key1", owner);
    ActivationKey key2 = new ActivationKey("key2", owner);
    keys.add(key1);
    keys.add(key2);
    Product prod1 = TestUtil.createProduct();
    Pool pool1 = TestUtil.createPool(owner, prod1, 5);
    pool1.setId("pool1");
    key1.addPool(pool1, 10L);
    Product prod2 = TestUtil.createProduct();
    Pool pool2 = TestUtil.createPool(owner, prod2, 5);
    pool2.setId("pool2");
    key1.addPool(pool2, 10L);
    Product prod3 = TestUtil.createProduct();
    Pool pool3 = TestUtil.createPool(owner, prod3, 5);
    pool3.setId("pool3");
    key2.addPool(pool3, 5L);
    Consumer consumer = new Consumer("sys.example.com", null, null, system);
    when(entitler.bindByPoolQuantity(eq(consumer), eq(pool1.getId()), eq(10))).thenThrow(new ForbiddenException("fail"));
    when(entitler.bindByPoolQuantity(eq(consumer), eq(pool2.getId()), eq(10))).thenThrow(new ForbiddenException("fail"));
    consumerBindUtil.handleActivationKeys(consumer, keys, false);
}
Also used : ForbiddenException(org.candlepin.common.exceptions.ForbiddenException) Consumer(org.candlepin.model.Consumer) ArrayList(java.util.ArrayList) Product(org.candlepin.model.Product) ConsumerInstalledProduct(org.candlepin.model.ConsumerInstalledProduct) Pool(org.candlepin.model.Pool) ActivationKey(org.candlepin.model.activationkeys.ActivationKey) Test(org.junit.Test)

Example 25 with ForbiddenException

use of org.candlepin.common.exceptions.ForbiddenException in project candlepin by candlepin.

the class ManifestManagerTest method verifyCdnExistsBeforeGeneratingManifest.

@Test
public void verifyCdnExistsBeforeGeneratingManifest() throws Exception {
    Owner owner = TestUtil.createOwner();
    Consumer consumer = this.createMockConsumer(owner, true);
    Cdn cdn = new Cdn("test-cdn", "Test CDN", "");
    String webAppPrefix = "webapp-prefix";
    String apiUrl = "api-url";
    Map<String, String> extData = new HashMap<>();
    when(consumerCurator.verifyAndLookupConsumer(eq(consumer.getUuid()))).thenReturn(consumer);
    when(cdnCurator.lookupByLabel(eq(cdn.getLabel()))).thenReturn(null);
    try {
        manager.generateManifestAsync(consumer.getUuid(), owner.getKey(), cdn.getLabel(), webAppPrefix, apiUrl, extData);
        fail("Expected ForbiddenException not thrown");
    } catch (Exception e) {
        assertTrue(e instanceof ForbiddenException);
        String expectedMsg = String.format("A CDN with label %s does not exist on this system.", cdn.getLabel());
        assertEquals(e.getMessage(), expectedMsg);
    }
}
Also used : Owner(org.candlepin.model.Owner) ForbiddenException(org.candlepin.common.exceptions.ForbiddenException) Consumer(org.candlepin.model.Consumer) HashMap(java.util.HashMap) Cdn(org.candlepin.model.Cdn) NotFoundException(org.candlepin.common.exceptions.NotFoundException) ForbiddenException(org.candlepin.common.exceptions.ForbiddenException) BadRequestException(org.candlepin.common.exceptions.BadRequestException) Test(org.junit.Test)

Aggregations

ForbiddenException (org.candlepin.common.exceptions.ForbiddenException)37 Owner (org.candlepin.model.Owner)22 Consumer (org.candlepin.model.Consumer)19 Test (org.junit.Test)15 BadRequestException (org.candlepin.common.exceptions.BadRequestException)13 Product (org.candlepin.model.Product)13 ApiOperation (io.swagger.annotations.ApiOperation)12 Produces (javax.ws.rs.Produces)12 Pool (org.candlepin.model.Pool)12 ArrayList (java.util.ArrayList)11 Path (javax.ws.rs.Path)11 NotFoundException (org.candlepin.common.exceptions.NotFoundException)9 Transactional (com.google.inject.persist.Transactional)8 ApiResponses (io.swagger.annotations.ApiResponses)8 Content (org.candlepin.model.Content)7 HashMap (java.util.HashMap)6 Consumes (javax.ws.rs.Consumes)6 ConsumerInstalledProduct (org.candlepin.model.ConsumerInstalledProduct)6 ActivationKey (org.candlepin.model.activationkeys.ActivationKey)6 DELETE (javax.ws.rs.DELETE)5