sentry-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ann...@apache.org
Subject incubator-sentry git commit: Sentry-1009: Improve TestDatabaseProvider to validate test object names instead of validating vague numbers. (Anne Yu, reviewed by Lenni Kuff>)
Date Sat, 23 Jan 2016 01:52:48 GMT
Repository: incubator-sentry
Updated Branches:
  refs/heads/master 0ce626c11 -> ef9b73884


Sentry-1009: Improve TestDatabaseProvider to validate test object names instead of validating
vague numbers. (Anne Yu, reviewed by Lenni Kuff>)


Project: http://git-wip-us.apache.org/repos/asf/incubator-sentry/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-sentry/commit/ef9b7388
Tree: http://git-wip-us.apache.org/repos/asf/incubator-sentry/tree/ef9b7388
Diff: http://git-wip-us.apache.org/repos/asf/incubator-sentry/diff/ef9b7388

Branch: refs/heads/master
Commit: ef9b73884896fe63ec8182cc0f7fa428389cf43d
Parents: 0ce626c
Author: Anne Yu <anneyu@apache.org>
Authored: Thu Jan 21 14:24:15 2016 -0800
Committer: Anne Yu <anneyu@apache.org>
Committed: Fri Jan 22 17:57:18 2016 -0800

----------------------------------------------------------------------
 .../e2e/dbprovider/TestDatabaseProvider.java    | 85 ++++++++++++++------
 1 file changed, 61 insertions(+), 24 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/ef9b7388/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/dbprovider/TestDatabaseProvider.java
----------------------------------------------------------------------
diff --git a/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/dbprovider/TestDatabaseProvider.java
b/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/dbprovider/TestDatabaseProvider.java
index 98de57d..06967bd 100644
--- a/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/dbprovider/TestDatabaseProvider.java
+++ b/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/dbprovider/TestDatabaseProvider.java
@@ -46,8 +46,12 @@ import org.junit.Ignore;
 import org.junit.Test;
 
 import com.google.common.io.Resources;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 public class TestDatabaseProvider extends AbstractTestWithStaticConfiguration {
+  private static final Logger LOGGER = LoggerFactory
+      .getLogger(TestDatabaseProvider.class);
 
   @BeforeClass
   public static void setupTestStaticConfiguration() throws Exception{
@@ -56,8 +60,6 @@ public class TestDatabaseProvider extends AbstractTestWithStaticConfiguration
{
     AbstractTestWithStaticConfiguration.setupAdmin();
   }
 
-
-
   @Test
   public void testBasic() throws Exception {
     Connection connection = context.createConnection(ADMIN1);
@@ -1184,6 +1186,20 @@ public class TestDatabaseProvider extends AbstractTestWithStaticConfiguration
{
     assertThat(count, is(expected));
   }
 
+  private void assertTestRoles(ResultSet resultSet, List<String> expected, boolean
isAdmin) throws SQLException{
+    List<String> returned = new ArrayList<>();
+    while(resultSet.next()) {
+      String role = resultSet.getString(1);
+      if (role.startsWith("role") || (isAdmin && role.startsWith("admin_role")))
{
+        LOGGER.info("Found role " + role);
+        returned.add(role);
+      } else {
+        LOGGER.error("Found an incorrect role so ignore it from validation: " + role);
+      }
+    }
+    validateReturnedResult(expected, returned);
+  }
+
   /**
    * Create and Drop role by admin
    * @throws Exception
@@ -1194,10 +1210,16 @@ public class TestDatabaseProvider extends AbstractTestWithStaticConfiguration
{
     Statement statement = context.createStatement(connection);
     statement.execute("CREATE ROLE role1");
     ResultSet resultSet = statement.executeQuery("SHOW roles");
-    assertResultSize(resultSet, 2);
+    List<String> expected = new ArrayList<String>();
+    expected.add("role1");
+    expected.add("admin_role");
+    assertTestRoles(resultSet, expected, true);
+
     statement.execute("DROP ROLE role1");
     resultSet = statement.executeQuery("SHOW roles");
-    assertResultSize(resultSet, 1);
+    expected.clear();
+    expected.add("admin_role");
+    assertTestRoles(resultSet, expected, true);
   }
 
   /**
@@ -1343,7 +1365,10 @@ public class TestDatabaseProvider extends AbstractTestWithStaticConfiguration
{
     Connection connection = context.createConnection(ADMIN1);
     Statement statement = context.createStatement(connection);
     ResultSet resultSet = statement.executeQuery("SHOW ROLES");
-    assertResultSize(resultSet, 1);
+    List<String> expected = new ArrayList<>();
+    expected.add("admin_role");
+    assertTestRoles(resultSet, expected, true);
+
     statement.execute("CREATE ROLE role1");
     statement.execute("CREATE ROLE role2");
     resultSet = statement.executeQuery("SHOW ROLES");
@@ -1351,13 +1376,9 @@ public class TestDatabaseProvider extends AbstractTestWithStaticConfiguration
{
     assertThat(resultSetMetaData.getColumnCount(), is(1));
     assertThat(resultSetMetaData.getColumnName(1), equalToIgnoringCase("role"));
 
-    Set<String> roles = new HashSet<String>();
-    while ( resultSet.next()) {
-      roles.add(resultSet.getString(1));
-    }
-    assertThat(roles.size(), is(3));
-    assertTrue(roles.contains("role1"));
-    assertTrue(roles.contains("role2"));
+    expected.add("role1");
+    expected.add("role2");
+    assertTestRoles(resultSet, expected, true);
     statement.close();
     connection.close();
   }
@@ -1872,7 +1893,7 @@ public class TestDatabaseProvider extends AbstractTestWithStaticConfiguration
{
   public void testShowAllCurrentRoles() throws Exception {
     Connection connection = context.createConnection(ADMIN1);
     Statement statement = context.createStatement(connection);
-    String testRole1 = "testRole1", testRole2 = "testRole2";
+    String testRole1 = "role1", testRole2 = "role2";
     statement.execute("CREATE ROLE " + testRole1);
     statement.execute("CREATE ROLE " + testRole2);
     statement.execute("GRANT ROLE " + testRole1 + " TO GROUP " + ADMINGROUP);
@@ -1881,11 +1902,17 @@ public class TestDatabaseProvider extends AbstractTestWithStaticConfiguration
{
     statement.execute("GRANT ROLE " + testRole2 + " TO GROUP " + USERGROUP1);
 
     ResultSet resultSet = statement.executeQuery("SHOW CURRENT ROLES");
-    assertResultSize(resultSet, 3);
+    List<String> expected = new ArrayList<>();
+    expected.add("admin_role");
+    expected.add(testRole1);
+    expected.add(testRole2);
+    assertTestRoles(resultSet, expected, true);
 
     statement.execute("SET ROLE " + testRole1);
     resultSet = statement.executeQuery("SHOW CURRENT ROLES");
-    assertResultSize(resultSet, 1);
+    expected.clear();
+    expected.add(testRole1);
+    assertTestRoles(resultSet, expected, true);
 
     statement.close();
     connection.close();
@@ -1901,11 +1928,16 @@ public class TestDatabaseProvider extends AbstractTestWithStaticConfiguration
{
     statement = context.createStatement(connection);
 
     resultSet = statement.executeQuery("SHOW CURRENT ROLES");
-    assertResultSize(resultSet, 2);
+    expected.clear();
+    expected.add(testRole1);
+    expected.add(testRole2);
+    assertTestRoles(resultSet, expected, false);
 
     statement.execute("SET ROLE " + testRole2);
     resultSet = statement.executeQuery("SHOW CURRENT ROLES");
-    assertResultSize(resultSet, 1);
+    expected.clear();
+    expected.add(testRole2);
+    assertTestRoles(resultSet, expected, false);
 
     statement.close();
     connection.close();
@@ -1915,7 +1947,7 @@ public class TestDatabaseProvider extends AbstractTestWithStaticConfiguration
{
   public void testSetRole() throws Exception {
     Connection connection = context.createConnection(ADMIN1);
     Statement statement = context.createStatement(connection);
-    String testRole0 = "testRole1", testRole1 = "testRole2";
+    String testRole0 = "role1", testRole1 = "role2";
     statement.execute("CREATE ROLE " + testRole0);
     statement.execute("CREATE ROLE " + testRole1);
 
@@ -1974,16 +2006,21 @@ public class TestDatabaseProvider extends AbstractTestWithStaticConfiguration
{
   }
 
   @Test
-  public void caseSensitiveGroupNames() throws Exception {
+  public void testCaseSensitiveGroupNames() throws Exception {
     Connection connection = context.createConnection(ADMIN1);
     Statement statement = context.createStatement(connection);
-    String testRole1 = "testRole1";
+    ResultSet resultSet;
+    resultSet = statement.executeQuery("SHOW ROLE GRANT GROUP " + ADMINGROUP);
+    List<String> expected = new ArrayList<>();
+    assertTestRoles(resultSet, expected, false);
+
+    String testRole1 = "role1";
     statement.execute("CREATE ROLE " + testRole1);
     statement.execute("GRANT ROLE " + testRole1 + " TO GROUP " + ADMINGROUP);
-
-    ResultSet resultSet;
     resultSet = statement.executeQuery("SHOW ROLE GRANT GROUP " + ADMINGROUP);
-    assertResultSize(resultSet, 2);
+    expected.clear();
+    expected.add(testRole1);
+    assertTestRoles(resultSet, expected, false);
 
     context.assertSentryException(statement, "SHOW ROLE GRANT GROUP Admin",
         SentryNoSuchObjectException.class.getSimpleName());
@@ -2004,7 +2041,7 @@ public class TestDatabaseProvider extends AbstractTestWithStaticConfiguration
{
     statement.execute("CREATE DATABASE " + DB1);
     statement.execute("USE " + DB1);
     statement.execute("DROP TABLE IF EXISTS t1");
-    statement.execute("CREATE TABLE t1 (c1 string)");
+    statement.execute("CREATE TABLE t1 (c1 string,c2 string,c3 string,c4 string,c5 string)");
     statement.execute("CREATE ROLE user_role");
     statement.execute("GRANT ALL ON TABLE t1 TO ROLE user_role");
 


Mime
View raw message