use of co.cask.cdap.security.impersonation.OwnerStore in project cdap by caskdata.
the class DefaultOwnerStoreTest method createInjector.
@BeforeClass
public static void createInjector() {
Injector injector = Guice.createInjector(new ConfigModule(), new DataSetsModules().getInMemoryModules(), new LocationRuntimeModule().getInMemoryModules(), new TransactionInMemoryModule(), new SystemDatasetRuntimeModule().getInMemoryModules(), new NamespaceClientRuntimeModule().getInMemoryModules(), new AuthorizationTestModule(), new AuthorizationEnforcementModule().getInMemoryModules(), new AuthenticationContextModules().getMasterModule());
TransactionManager txManager = injector.getInstance(TransactionManager.class);
txManager.startAndWait();
ownerStore = injector.getInstance(OwnerStore.class);
}
use of co.cask.cdap.security.impersonation.OwnerStore in project cdap by caskdata.
the class InMemoryOwnerStoreTest method createInjector.
@BeforeClass
public static void createInjector() {
Injector injector = Guice.createInjector(new AbstractModule() {
@Override
protected void configure() {
bind(OwnerStore.class).to(InMemoryOwnerStore.class);
}
});
ownerStore = injector.getInstance(OwnerStore.class);
}
use of co.cask.cdap.security.impersonation.OwnerStore in project cdap by caskdata.
the class OwnerStoreTest method test.
@Test
public void test() throws Exception {
OwnerStore ownerStore = getOwnerStore();
StreamId streamId = NamespaceId.DEFAULT.stream("fooStream");
// No owner info should exist for above stream
Assert.assertNull(ownerStore.getOwner(streamId));
// delete behavior is idempotent, so won't throw NotFoundException
ownerStore.delete(streamId);
// Storing an owner for the first time should work
KerberosPrincipalId kerberosPrincipalId = new KerberosPrincipalId("alice/somehost@SOMEKDC.NET");
ownerStore.add(streamId, kerberosPrincipalId);
// owner principal should exists
Assert.assertTrue(ownerStore.exists(streamId));
// Should be able to get the principal back
Assert.assertEquals(kerberosPrincipalId, ownerStore.getOwner(streamId));
// Should not be able to update the owner principal
try {
ownerStore.add(streamId, new KerberosPrincipalId("bob@SOMEKDC.NET"));
Assert.fail();
} catch (AlreadyExistsException e) {
// expected
}
// Should not be able to update the owner principal
try {
ownerStore.add(streamId, new KerberosPrincipalId("somePrincipal"));
Assert.fail();
} catch (AlreadyExistsException e) {
// expected
}
// trying to update with invalid principal should fail early on with IllegalArgumentException
try {
ownerStore.add(streamId, new KerberosPrincipalId("b@ob@SOMEKDC.NET"));
Assert.fail();
} catch (IllegalArgumentException e) {
// expected
}
// Trying to store owner information for unsupported type should fail
try {
ownerStore.add(NamespaceId.DEFAULT.topic("anotherStream"), new KerberosPrincipalId("somePrincipal"));
Assert.fail();
} catch (IllegalArgumentException e) {
// expected
}
// delete the owner information
ownerStore.delete(streamId);
Assert.assertFalse(ownerStore.exists(streamId));
Assert.assertNull(ownerStore.getOwner(streamId));
}
Aggregations