Search in sources :

Example 21 with ProjectInstance

use of org.apache.kylin.metadata.project.ProjectInstance in project ranger by apache.

the class RangerKylinAuthorizerTest method readProjectKylinWithOperationPermission.

/**
 * zhangqiang read kylin_project success
 */
@Test
@WithMockUser(username = ZHANGQIANG, roles = { ROLE_USER })
public void readProjectKylinWithOperationPermission() {
    ProjectInstance project = name2Projects.get(KYLIN_PROJECT);
    boolean result = aclEvaluate.hasProjectReadPermission(project);
    Assert.assertTrue(result);
}
Also used : ProjectInstance(org.apache.kylin.metadata.project.ProjectInstance) WithMockUser(org.springframework.security.test.context.support.WithMockUser) Test(org.junit.Test)

Example 22 with ProjectInstance

use of org.apache.kylin.metadata.project.ProjectInstance in project ranger by apache.

the class RangerKylinAuthorizerTest method initKylinProjects.

/**
 * Help function: init kylin projects
 */
private static void initKylinProjects() {
    for (String projectName : PROJECTNAMES) {
        ProjectInstance projectInstance = getProjectInstance(projectName);
        name2Projects.put(projectName, projectInstance);
        uuid2Projects.put(projectInstance.getUuid(), projectInstance);
    }
}
Also used : ProjectInstance(org.apache.kylin.metadata.project.ProjectInstance) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString)

Example 23 with ProjectInstance

use of org.apache.kylin.metadata.project.ProjectInstance in project ranger by apache.

the class RangerKylinAuthorizerTest method mockKylinProjects.

/**
 * Help function: mock kylin projects, to match projectUuid and projectName
 */
private static void mockKylinProjects() {
    KylinConfig kylinConfig = KylinConfig.getInstanceFromEnv();
    ProjectManager projectManager = mock(ProjectManager.class);
    @SuppressWarnings({ "rawtypes", "unchecked" }) Map<Class, Object> managersCache = (Map<Class, Object>) ReflectionTestUtils.getField(kylinConfig, "managersCache");
    managersCache.put(ProjectManager.class, projectManager);
    Answer<ProjectInstance> answer = new Answer<ProjectInstance>() {

        @Override
        public ProjectInstance answer(InvocationOnMock invocation) throws Throwable {
            Object[] args = invocation.getArguments();
            if (args == null || args.length == 0) {
                return null;
            }
            String uuid = (String) args[0];
            return uuid2Projects.get(uuid);
        }
    };
    when(projectManager.getPrjByUuid(anyString())).thenAnswer(answer);
}
Also used : KylinConfig(org.apache.kylin.common.KylinConfig) ProjectInstance(org.apache.kylin.metadata.project.ProjectInstance) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) ProjectManager(org.apache.kylin.metadata.project.ProjectManager) Answer(org.mockito.stubbing.Answer) InvocationOnMock(org.mockito.invocation.InvocationOnMock) BeforeClass(org.junit.BeforeClass) AfterClass(org.junit.AfterClass) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 24 with ProjectInstance

use of org.apache.kylin.metadata.project.ProjectInstance in project ranger by apache.

the class RangerKylinAuthorizerTest method operationProjectKylinWithoutPermission.

/**
 * yuwen operation kylin_project failed
 */
@Test
@WithMockUser(username = YUWEN, roles = { ROLE_USER })
public void operationProjectKylinWithoutPermission() {
    ProjectInstance project = name2Projects.get(KYLIN_PROJECT);
    boolean result = aclEvaluate.hasProjectOperationPermission(project);
    Assert.assertFalse(result);
}
Also used : ProjectInstance(org.apache.kylin.metadata.project.ProjectInstance) WithMockUser(org.springframework.security.test.context.support.WithMockUser) Test(org.junit.Test)

Example 25 with ProjectInstance

use of org.apache.kylin.metadata.project.ProjectInstance in project ranger by apache.

the class RangerKylinAuthorizerTest method writeProjectAllWithAdminPermission.

/**
 * kylin write all projects success
 */
@Test
@WithMockUser(username = KYLIN, roles = { ROLE_USER })
public void writeProjectAllWithAdminPermission() {
    for (ProjectInstance project : uuid2Projects.values()) {
        boolean result = aclEvaluate.hasProjectWritePermission(project);
        Assert.assertTrue(result);
    }
}
Also used : ProjectInstance(org.apache.kylin.metadata.project.ProjectInstance) WithMockUser(org.springframework.security.test.context.support.WithMockUser) Test(org.junit.Test)

Aggregations

ProjectInstance (org.apache.kylin.metadata.project.ProjectInstance)35 Test (org.junit.Test)32 WithMockUser (org.springframework.security.test.context.support.WithMockUser)28 KylinConfig (org.apache.kylin.common.KylinConfig)2 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)2 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 ProjectManager (org.apache.kylin.metadata.project.ProjectManager)1 RangerAccessResult (org.apache.ranger.plugin.policyengine.RangerAccessResult)1 AfterClass (org.junit.AfterClass)1 BeforeClass (org.junit.BeforeClass)1 InvocationOnMock (org.mockito.invocation.InvocationOnMock)1 Answer (org.mockito.stubbing.Answer)1