use of co.cask.cdap.data2.dataset2.customds.CustomDatasetApp in project cdap by caskdata.
the class DatasetClassRewriterTest method testDatasetAccessRecorder.
@Test
public void testDatasetAccessRecorder() throws Exception {
ByteCodeClassLoader classLoader = new ByteCodeClassLoader(getClass().getClassLoader());
classLoader.addClass(rewrite(TopLevelExtendsDataset.class));
classLoader.addClass(rewrite(TopLevelDirectDataset.class));
classLoader.addClass(rewrite(TopLevelDataset.class));
classLoader.addClass(rewrite(DefaultTopLevelExtendsDataset.class));
classLoader.addClass(rewrite(CustomDatasetApp.InnerStaticInheritDataset.class));
classLoader.addClass(rewrite(CustomDatasetApp.InnerDataset.class));
InMemoryAccessRecorder accessRecorder = new InMemoryAccessRecorder();
TestAuthorizationEnforcer authEnforcer = new TestAuthorizationEnforcer(EnumSet.allOf(Action.class));
testDatasetAccessRecord(accessRecorder, createDataset(accessRecorder, authEnforcer, TopLevelDataset.class.getName(), classLoader));
accessRecorder.clear();
testDatasetAccessRecord(accessRecorder, createDataset(accessRecorder, authEnforcer, DefaultTopLevelExtendsDataset.class.getName(), classLoader));
accessRecorder.clear();
Dataset delegate = createDataset(accessRecorder, authEnforcer, TopLevelDataset.class.getName(), classLoader);
testDatasetAccessRecord(accessRecorder, createDataset(accessRecorder, authEnforcer, DelegatingDataset.class.getName(), classLoader, new Class<?>[] { CustomOperations.class }, new Object[] { delegate }));
accessRecorder.clear();
testDatasetAccessRecord(accessRecorder, createDataset(accessRecorder, authEnforcer, CustomDatasetApp.InnerStaticInheritDataset.class.getName(), classLoader));
accessRecorder.clear();
testDatasetAccessRecord(accessRecorder, createDataset(accessRecorder, authEnforcer, CustomDatasetApp.InnerDataset.class.getName(), classLoader, new Class<?>[] { CustomDatasetApp.class }, new Object[] { new CustomDatasetApp() }));
}
use of co.cask.cdap.data2.dataset2.customds.CustomDatasetApp in project cdap by caskdata.
the class DatasetClassRewriterTest method testDatasetAuthorization.
@Test
public void testDatasetAuthorization() throws Exception {
ByteCodeClassLoader classLoader = new ByteCodeClassLoader(getClass().getClassLoader());
classLoader.addClass(rewrite(TopLevelExtendsDataset.class));
classLoader.addClass(rewrite(TopLevelDirectDataset.class));
classLoader.addClass(rewrite(TopLevelDataset.class));
classLoader.addClass(rewrite(DefaultTopLevelExtendsDataset.class));
classLoader.addClass(rewrite(CustomDatasetApp.InnerStaticInheritDataset.class));
classLoader.addClass(rewrite(CustomDatasetApp.InnerDataset.class));
InMemoryAccessRecorder accessRecorder = new InMemoryAccessRecorder();
// Test no access
TestAuthorizationEnforcer authEnforcer = new TestAuthorizationEnforcer(EnumSet.noneOf(Action.class));
testNoAccess(createDataset(accessRecorder, authEnforcer, TopLevelDataset.class.getName(), classLoader));
testNoAccess(createDataset(accessRecorder, authEnforcer, DefaultTopLevelExtendsDataset.class.getName(), classLoader));
Dataset delegate = createDataset(accessRecorder, authEnforcer, TopLevelDataset.class.getName(), classLoader);
testNoAccess(createDataset(accessRecorder, authEnforcer, DelegatingDataset.class.getName(), classLoader, new Class<?>[] { CustomOperations.class }, new Object[] { delegate }));
testNoAccess(createDataset(accessRecorder, authEnforcer, CustomDatasetApp.InnerStaticInheritDataset.class.getName(), classLoader));
testNoAccess(createDataset(accessRecorder, authEnforcer, CustomDatasetApp.InnerDataset.class.getName(), classLoader, new Class<?>[] { CustomDatasetApp.class }, new Object[] { new CustomDatasetApp() }));
// Test read only access
authEnforcer = new TestAuthorizationEnforcer(EnumSet.of(Action.READ));
testReadOnlyAccess(createDataset(accessRecorder, authEnforcer, TopLevelDataset.class.getName(), classLoader));
testReadOnlyAccess(createDataset(accessRecorder, authEnforcer, DefaultTopLevelExtendsDataset.class.getName(), classLoader));
delegate = createDataset(accessRecorder, authEnforcer, TopLevelDataset.class.getName(), classLoader);
testReadOnlyAccess(createDataset(accessRecorder, authEnforcer, DelegatingDataset.class.getName(), classLoader, new Class<?>[] { CustomOperations.class }, new Object[] { delegate }));
testReadOnlyAccess(createDataset(accessRecorder, authEnforcer, CustomDatasetApp.InnerStaticInheritDataset.class.getName(), classLoader));
testReadOnlyAccess(createDataset(accessRecorder, authEnforcer, CustomDatasetApp.InnerDataset.class.getName(), classLoader, new Class<?>[] { CustomDatasetApp.class }, new Object[] { new CustomDatasetApp() }));
// Test write only access
authEnforcer = new TestAuthorizationEnforcer(EnumSet.of(Action.WRITE));
testWriteOnlyAccess(createDataset(accessRecorder, authEnforcer, TopLevelDataset.class.getName(), classLoader));
testWriteOnlyAccess(createDataset(accessRecorder, authEnforcer, DefaultTopLevelExtendsDataset.class.getName(), classLoader));
delegate = createDataset(accessRecorder, authEnforcer, TopLevelDataset.class.getName(), classLoader);
testWriteOnlyAccess(createDataset(accessRecorder, authEnforcer, DelegatingDataset.class.getName(), classLoader, new Class<?>[] { CustomOperations.class }, new Object[] { delegate }));
testWriteOnlyAccess(createDataset(accessRecorder, authEnforcer, CustomDatasetApp.InnerStaticInheritDataset.class.getName(), classLoader));
testWriteOnlyAccess(createDataset(accessRecorder, authEnforcer, CustomDatasetApp.InnerDataset.class.getName(), classLoader, new Class<?>[] { CustomDatasetApp.class }, new Object[] { new CustomDatasetApp() }));
}
Aggregations