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;
}
}
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;
}
}
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);
}
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);
}
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);
}
}
Aggregations