use of org.candlepin.auth.Principal in project candlepin by candlepin.
the class OwnerResourceTest method ownerAdminCannotAccessAnotherOwnersPools.
@Test(expected = NotFoundException.class)
public void ownerAdminCannotAccessAnotherOwnersPools() {
Owner evilOwner = new Owner("evilowner");
ownerCurator.create(evilOwner);
Principal principal = setupPrincipal(evilOwner, 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);
securityInterceptor.enable();
// Filtering should just cause this to return no results:
ownerResource.listPools(owner.getKey(), null, null, null, null, true, null, null, new ArrayList<>(), false, false, null, null, principal, null);
}
use of org.candlepin.auth.Principal in project candlepin by candlepin.
the class PoolResourceTest method consumerCannotListPoolsForAnotherOwner.
@Test(expected = NotFoundException.class)
public void consumerCannotListPoolsForAnotherOwner() {
Principal p = setupPrincipal(new ConsumerPrincipal(foreignConsumer, owner2));
securityInterceptor.enable();
poolResource.list(owner1.getId(), null, null, false, null, p, null);
}
use of org.candlepin.auth.Principal in project candlepin by candlepin.
the class PoolResourceTest method ownerAdminCannotListAnotherOwnersPools.
@Test(expected = NotFoundException.class)
public void ownerAdminCannotListAnotherOwnersPools() {
List<PoolDTO> pools = poolResource.list(owner1.getId(), null, null, false, null, adminPrincipal, null);
assertEquals(2, pools.size());
Principal anotherPrincipal = setupPrincipal(owner2, Access.ALL);
securityInterceptor.enable();
poolResource.list(owner1.getId(), null, null, false, null, anotherPrincipal, null);
}
use of org.candlepin.auth.Principal in project candlepin by candlepin.
the class UserResourceTest method testListOwnersForMySystemsAdmin.
@Test
public void testListOwnersForMySystemsAdmin() {
User user = new User();
user.setUsername("dummyuser" + TestUtil.randomInt());
user.setPassword("password");
userResource.createUser(user);
Owner owner1 = createOwner();
Role owner1Role = new Role(owner1.getKey() + " role");
owner1Role.addPermission(new PermissionBlueprint(PermissionType.USERNAME_CONSUMERS, owner1, Access.ALL));
owner1Role.addUser(user);
roleCurator.create(owner1Role);
Set<Permission> perms = new HashSet<>();
perms.add(new UsernameConsumersPermission(user, owner1));
Principal userPrincipal = new UserPrincipal(user.getUsername(), perms, false);
Iterable<Owner> response = userResource.listUsersOwners(user.getUsername(), userPrincipal);
List<Owner> owners = new LinkedList<>();
for (Object entity : response) {
owners.add((Owner) entity);
}
assertEquals(1, owners.size());
assertEquals(owner1.getKey(), owners.get(0).getKey());
}
use of org.candlepin.auth.Principal in project candlepin by candlepin.
the class ExporterTest method exportConsumer.
@Test
public void exportConsumer() throws ExportCreationException, IOException {
config.setProperty(ConfigProperties.SYNC_WORK_DIR, "/tmp/");
config.setProperty(ConfigProperties.PREFIX_WEBURL, "localhost:8443/weburl");
config.setProperty(ConfigProperties.PREFIX_APIURL, "localhost:8443/apiurl");
Rules mrules = mock(Rules.class);
Consumer consumer = mock(Consumer.class);
Principal principal = mock(Principal.class);
when(mrules.getRules()).thenReturn("foobar");
when(pki.getSHA256WithRSAHash(any(InputStream.class))).thenReturn("signature".getBytes());
when(rc.getRules()).thenReturn(mrules);
when(pprov.get()).thenReturn(principal);
when(principal.getUsername()).thenReturn("testUser");
// specific to this test
IdentityCertificate idcert = new IdentityCertificate();
idcert.setSerial(new CertificateSerial(10L, new Date()));
idcert.setKey("euh0876puhapodifbvj094");
idcert.setCert("hpj-08ha-w4gpoknpon*)&^%#");
idcert.setCreated(new Date());
idcert.setUpdated(new Date());
when(consumer.getIdCert()).thenReturn(idcert);
ConsumerType ctype = new ConsumerType(ConsumerTypeEnum.CANDLEPIN);
ctype.setId("test-ctype");
KeyPair keyPair = createKeyPair();
when(consumer.getKeyPair()).thenReturn(keyPair);
when(pki.getPemEncoded(keyPair.getPrivateKey())).thenReturn("privateKey".getBytes());
when(pki.getPemEncoded(keyPair.getPublicKey())).thenReturn("publicKey".getBytes());
when(consumer.getUuid()).thenReturn("8auuid");
when(consumer.getName()).thenReturn("consumer_name");
when(consumer.getContentAccessMode()).thenReturn("access_mode");
when(consumer.getTypeId()).thenReturn(ctype.getId());
when(ctc.getConsumerType(eq(consumer))).thenReturn(ctype);
when(ctc.find(eq(ctype.getId()))).thenReturn(ctype);
CandlepinQuery cqmock = mock(CandlepinQuery.class);
when(cqmock.iterator()).thenReturn(Arrays.asList(new ConsumerType("system")).iterator());
when(ctc.listAll()).thenReturn(cqmock);
CandlepinQuery emptyIteratorMock = mock(CandlepinQuery.class);
when(emptyIteratorMock.iterate()).thenReturn(new MockResultIterator(Arrays.asList().iterator()));
when(cdnc.listAll()).thenReturn(emptyIteratorMock);
// FINALLY test this badboy
Exporter e = new Exporter(ctc, oc, me, ce, cte, re, ece, ecsa, pe, psa, pce, ec, ee, pki, config, exportRules, pprov, dvc, dve, cdnc, cdne, pc, su, exportExtensionAdapter, translator);
File export = e.getFullExport(consumer);
verifyContent(export, "export/consumer.json", new VerifyConsumer("consumer.json"));
}
Aggregations