ranger-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From me...@apache.org
Subject ranger git commit: RANGER-2171 : Unit Test cases to cover policy operations from service admin user
Date Tue, 07 Aug 2018 10:48:42 GMT
Repository: ranger
Updated Branches:
  refs/heads/master c7d15b305 -> 8e4a02f9e


RANGER-2171 : Unit Test cases to cover policy operations from service admin user

Signed-off-by: Mehul Parikh <mehul@apache.org>


Project: http://git-wip-us.apache.org/repos/asf/ranger/repo
Commit: http://git-wip-us.apache.org/repos/asf/ranger/commit/8e4a02f9
Tree: http://git-wip-us.apache.org/repos/asf/ranger/tree/8e4a02f9
Diff: http://git-wip-us.apache.org/repos/asf/ranger/diff/8e4a02f9

Branch: refs/heads/master
Commit: 8e4a02f9e8c67ce057c358b94a272025b81113d9
Parents: c7d15b3
Author: Nikhil P <nikhil.purbhe@gmail.com>
Authored: Tue Aug 7 12:47:22 2018 +0530
Committer: Mehul Parikh <mehul@apache.org>
Committed: Tue Aug 7 13:51:08 2018 +0530

----------------------------------------------------------------------
 .../apache/ranger/biz/TestServiceDBStore.java   | 41 ++++++++++++++++
 .../org/apache/ranger/rest/TestServiceREST.java | 50 ++++++++++++++++++++
 2 files changed, 91 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ranger/blob/8e4a02f9/security-admin/src/test/java/org/apache/ranger/biz/TestServiceDBStore.java
----------------------------------------------------------------------
diff --git a/security-admin/src/test/java/org/apache/ranger/biz/TestServiceDBStore.java b/security-admin/src/test/java/org/apache/ranger/biz/TestServiceDBStore.java
index b0b0110..cb496ea 100644
--- a/security-admin/src/test/java/org/apache/ranger/biz/TestServiceDBStore.java
+++ b/security-admin/src/test/java/org/apache/ranger/biz/TestServiceDBStore.java
@@ -217,6 +217,7 @@ public class TestServiceDBStore {
 		configs.put("dfs.secondary.namenode.kerberos.principal", "");
 		configs.put("hadoop.rpc.protection", "Privacy");
 		configs.put("commonNameForCertificate", "");
+		configs.put("service.admin.users", "testServiceAdminUser1,testServiceAdminUser2");
 
 		RangerService rangerService = new RangerService();
 		rangerService.setId(Id);
@@ -2457,4 +2458,44 @@ public class TestServiceDBStore {
     	Mockito.when(serviceDefService.searchRangerServiceDefs(Mockito.any(SearchFilter.class))).thenReturn(svcDefList);
     	serviceDBStore.getMetricByType(type);
     }
+
+    @Test
+    public void test48IsServiceAdminUserTrue() throws Exception{
+    	String configName = "service.admin.users";
+    	boolean result=false;
+    	RangerService rService= rangerService();
+    	XXServiceConfigMapDao xxServiceConfigMapDao = Mockito.mock(XXServiceConfigMapDao.class);
+    	XXServiceConfigMap xxServiceConfigMap = new XXServiceConfigMap();
+    	xxServiceConfigMap.setConfigkey(configName);
+    	xxServiceConfigMap.setConfigvalue(rService.getConfigs().get(configName));
+
+    	Mockito.when(daoManager.getXXServiceConfigMap()).thenReturn(xxServiceConfigMapDao);
+    	Mockito.when(xxServiceConfigMapDao.findByServiceNameAndConfigKey(rService.getName(),
configName)).thenReturn(xxServiceConfigMap);
+
+    	result = serviceDBStore.isServiceAdminUser(rService.getName(),"testServiceAdminUser2");
+
+    	Assert.assertTrue(result);
+    	Mockito.verify(daoManager).getXXServiceConfigMap();
+    	Mockito.verify(xxServiceConfigMapDao).findByServiceNameAndConfigKey(rService.getName(),
configName);
+    }
+
+    @Test
+    public void test49IsServiceAdminUserFalse() throws Exception{
+    	String configName = "service.admin.users";
+    	boolean result=false;
+    	RangerService rService= rangerService();
+    	XXServiceConfigMapDao xxServiceConfigMapDao = Mockito.mock(XXServiceConfigMapDao.class);
+    	XXServiceConfigMap xxServiceConfigMap = new XXServiceConfigMap();
+    	xxServiceConfigMap.setConfigkey(configName);
+    	xxServiceConfigMap.setConfigvalue(rService.getConfigs().get(configName));
+
+    	Mockito.when(daoManager.getXXServiceConfigMap()).thenReturn(xxServiceConfigMapDao);
+    	Mockito.when(xxServiceConfigMapDao.findByServiceNameAndConfigKey(rService.getName(),
configName)).thenReturn(xxServiceConfigMap);
+
+    	result = serviceDBStore.isServiceAdminUser(rService.getName(),"testServiceAdminUser3");
+
+    	Assert.assertFalse(result);
+    	Mockito.verify(daoManager).getXXServiceConfigMap();
+    	Mockito.verify(xxServiceConfigMapDao).findByServiceNameAndConfigKey(rService.getName(),
configName);
+    }
 }

http://git-wip-us.apache.org/repos/asf/ranger/blob/8e4a02f9/security-admin/src/test/java/org/apache/ranger/rest/TestServiceREST.java
----------------------------------------------------------------------
diff --git a/security-admin/src/test/java/org/apache/ranger/rest/TestServiceREST.java b/security-admin/src/test/java/org/apache/ranger/rest/TestServiceREST.java
index e669c03..15ff20f 100644
--- a/security-admin/src/test/java/org/apache/ranger/rest/TestServiceREST.java
+++ b/security-admin/src/test/java/org/apache/ranger/rest/TestServiceREST.java
@@ -1021,6 +1021,56 @@ public class TestServiceREST {
 		Mockito.verify(svcStore).getServices(filter);
 	}
 
+
+	@Test
+	public void test27getPoliciesWithoutServiceAdmin() throws Exception {
+		HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
+		SearchFilter filter = new SearchFilter();
+		List<RangerPolicy> policies = new ArrayList<RangerPolicy>();
+		policies.add(rangerPolicy());
+		filter.setParam(SearchFilter.POLICY_NAME, "policyName");
+		filter.setParam(SearchFilter.SERVICE_NAME, "serviceName");
+		Mockito.when(searchUtil.getSearchFilter(request, policyService.sortFields)).thenReturn(filter);
+		Mockito.when(svcStore.getPolicies(filter)).thenReturn(policies);
+		RangerPolicyList dbRangerPolicy = serviceREST.getPolicies(request);
+		Assert.assertNotNull(dbRangerPolicy);
+		/*here we are not setting service admin role,hence we will not get any policy without the
service admin roles*/
+		Assert.assertEquals(dbRangerPolicy.getListSize(), 0);
+		Mockito.verify(searchUtil).getSearchFilter(request,
+				policyService.sortFields);
+	}
+
+	@Test
+	public void test28getPoliciesWithServiceAdmin() throws Exception {
+		HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
+		RangerService rs = rangerService();
+		SearchFilter filter = new SearchFilter();
+		XXService xs = Mockito.mock(XXService.class);
+		xs.setType(3L);
+		XXServiceDao xSDao = Mockito.mock(XXServiceDao.class);
+		List<RangerPolicy> policies = new ArrayList<RangerPolicy>();
+		RangerPolicy rPol=rangerPolicy();
+		policies.add(rPol);
+		filter.setParam(SearchFilter.POLICY_NAME, "policyName");
+		filter.setParam(SearchFilter.SERVICE_NAME, "serviceName");
+		Mockito.when(searchUtil.getSearchFilter(request, policyService.sortFields)).thenReturn(filter);
+		Mockito.when(svcStore.getPolicies(filter)).thenReturn(policies);
+		/*here we are setting serviceAdminRole, so we will get the required policy with serviceAdmi
role*/
+		Mockito.when(daoManager.getXXService()).thenReturn(xSDao);
+		Mockito.when(svcStore.isServiceAdminUser(rPol.getService(), null)).thenReturn(true);
+		Mockito.when(xSDao.findByName(rPol.getName())).thenReturn(xs);
+		RangerPolicyList dbRangerPolicy = serviceREST.getPolicies(request);
+		Assert.assertNotNull(dbRangerPolicy);
+		Assert.assertEquals(dbRangerPolicy.getListSize(), 1);
+		Mockito.verify(searchUtil).getSearchFilter(request,
+				policyService.sortFields);
+		Mockito.verify(svcStore).getPolicies(filter);
+		Mockito.verify(svcStore).isServiceAdminUser(rPol.getService(), null);
+		Mockito.verify(daoManager).getXXService();
+		Mockito.verify(xSDao).findByName(rPol.getName());
+	}
+
+
 	@Test
 	public void test30getPolicyFromEventTime() throws Exception {
 		HttpServletRequest request = Mockito.mock(HttpServletRequest.class);


Mime
View raw message