use of co.cask.cdap.proto.ProgramType in project cdap by caskdata.
the class ProgramLifecycleServiceAuthorizationTest method testProgramList.
@Test
public void testProgramList() throws Exception {
SecurityRequestContext.setUserId(ALICE.getName());
ApplicationId applicationId = NamespaceId.DEFAULT.app(AllProgramsApp.NAME);
Map<EntityId, Set<Action>> neededPrivileges = ImmutableMap.<EntityId, Set<Action>>builder().put(applicationId, EnumSet.of(Action.ADMIN)).put(NamespaceId.DEFAULT.artifact(AllProgramsApp.class.getSimpleName(), "1.0-SNAPSHOT"), EnumSet.of(Action.ADMIN)).put(NamespaceId.DEFAULT.dataset(AllProgramsApp.DATASET_NAME), EnumSet.of(Action.ADMIN)).put(NamespaceId.DEFAULT.dataset(AllProgramsApp.DATASET_NAME2), EnumSet.of(Action.ADMIN)).put(NamespaceId.DEFAULT.dataset(AllProgramsApp.DATASET_NAME3), EnumSet.of(Action.ADMIN)).put(NamespaceId.DEFAULT.dataset(AllProgramsApp.DS_WITH_SCHEMA_NAME), EnumSet.of(Action.ADMIN)).put(NamespaceId.DEFAULT.stream(AllProgramsApp.STREAM_NAME), EnumSet.of(Action.ADMIN)).build();
setUpPrivilegesAndExpectFailedDeploy(neededPrivileges);
// now we should be able to deploy
AppFabricTestHelper.deployApplication(Id.Namespace.DEFAULT, AllProgramsApp.class, null, cConf);
// no auto grant now, the list will be empty for all program types
for (ProgramType type : ProgramType.values()) {
if (!type.equals(ProgramType.CUSTOM_ACTION) && !type.equals(ProgramType.WEBAPP)) {
Assert.assertTrue(programLifecycleService.list(NamespaceId.DEFAULT, type).isEmpty());
}
}
// no auto grant now, need to have privileges on the program to be able to see the programs
authorizer.grant(Authorizable.fromEntityId(applicationId.program(ProgramType.FLOW, AllProgramsApp.NoOpFlow.NAME)), ALICE, Collections.singleton(Action.EXECUTE));
authorizer.grant(Authorizable.fromEntityId(applicationId.program(ProgramType.SERVICE, AllProgramsApp.NoOpService.NAME)), ALICE, Collections.singleton(Action.EXECUTE));
authorizer.grant(Authorizable.fromEntityId(applicationId.program(ProgramType.WORKER, AllProgramsApp.NoOpWorker.NAME)), ALICE, Collections.singleton(Action.EXECUTE));
authorizer.grant(Authorizable.fromEntityId(applicationId.program(ProgramType.SPARK, AllProgramsApp.NoOpSpark.NAME)), ALICE, Collections.singleton(Action.EXECUTE));
authorizer.grant(Authorizable.fromEntityId(applicationId.program(ProgramType.MAPREDUCE, AllProgramsApp.NoOpMR.NAME)), ALICE, Collections.singleton(Action.EXECUTE));
authorizer.grant(Authorizable.fromEntityId(applicationId.program(ProgramType.MAPREDUCE, AllProgramsApp.NoOpMR2.NAME)), ALICE, Collections.singleton(Action.EXECUTE));
authorizer.grant(Authorizable.fromEntityId(applicationId.program(ProgramType.WORKFLOW, AllProgramsApp.NoOpWorkflow.NAME)), ALICE, Collections.singleton(Action.EXECUTE));
for (ProgramType type : ProgramType.values()) {
if (!type.equals(ProgramType.CUSTOM_ACTION) && !type.equals(ProgramType.WEBAPP)) {
Assert.assertFalse(programLifecycleService.list(NamespaceId.DEFAULT, type).isEmpty());
SecurityRequestContext.setUserId("bob");
Assert.assertTrue(programLifecycleService.list(NamespaceId.DEFAULT, type).isEmpty());
SecurityRequestContext.setUserId("alice");
}
}
}
Aggregations