You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sentry.apache.org by an...@apache.org on 2016/07/11 17:44:59 UTC

sentry git commit: SENTRY-1334: [column level privileges] test and add test for CTAS and Create View AS SELECT (cross databases cases) (Ke Jia, reviewed by Anne Yu)

Repository: sentry
Updated Branches:
  refs/heads/master 09a8dcb01 -> 8256776bc


SENTRY-1334: [column level privileges] test and add test for CTAS and Create View AS SELECT (cross databases cases) (Ke Jia, reviewed by Anne Yu)


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

Branch: refs/heads/master
Commit: 8256776bc6f0acb1644b8d058f7f8a1d08ba6402
Parents: 09a8dcb
Author: Anne Yu <an...@cloudera.com>
Authored: Mon Jul 11 11:19:54 2016 -0700
Committer: Anne Yu <an...@cloudera.com>
Committed: Mon Jul 11 11:20:57 2016 -0700

----------------------------------------------------------------------
 .../e2e/dbprovider/TestColumnEndToEnd.java      | 62 ++++++++++++++++++++
 1 file changed, 62 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/sentry/blob/8256776b/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/dbprovider/TestColumnEndToEnd.java
----------------------------------------------------------------------
diff --git a/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/dbprovider/TestColumnEndToEnd.java b/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/dbprovider/TestColumnEndToEnd.java
index 22d4cf8..8c15257 100644
--- a/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/dbprovider/TestColumnEndToEnd.java
+++ b/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/dbprovider/TestColumnEndToEnd.java
@@ -414,4 +414,66 @@ public class TestColumnEndToEnd extends AbstractTestWithStaticConfiguration {
     statement.close();
     connection.close();
   }
+
+  @Test
+  public void testCrossDbTableOperations() throws Exception {
+    //The privilege of user_role1 is used to test create table as select.
+    //The privilege of user_role2 is used to test create view as select.
+    Connection connection = context.createConnection(ADMIN1);
+    Statement statement = context.createStatement(connection);
+    statement.execute("CREATE database " + DB1);
+    statement.execute("CREATE database " + DB2);
+    statement.execute("use " + DB1);
+    statement.execute("CREATE ROLE user_role1");
+    statement.execute("CREATE ROLE user_role2");
+    statement.execute("CREATE TABLE tb1 (id int , name String)");
+    statement.execute("GRANT CREATE ON DATABASE db_1 TO ROLE user_role1");
+    statement.execute("GRANT CREATE ON DATABASE db_1 TO ROLE user_role2");
+    statement.execute("GRANT SELECT (id) ON TABLE tb1 TO ROLE user_role1");
+    statement.execute("GRANT SELECT  ON TABLE tb1 TO ROLE user_role2");
+    statement.execute("GRANT ROLE user_role1 TO GROUP " + USERGROUP1);
+    statement.execute("GRANT ROLE user_role2 TO GROUP " + USERGROUP2);
+    statement.execute("load data local inpath '" + dataFile.getPath() + "' into table db_1.tb1" );
+    statement.execute("use " + DB2);
+    statement.execute("CREATE TABLE tb2 (id int, num String)");
+    statement.execute("CREATE TABLE tb3 (id int, val String)");
+    statement.execute("GRANT SELECT (num) ON TABLE tb2 TO ROLE user_role1");
+    statement.execute("GRANT SELECT (val) ON TABLE tb3 TO ROLE user_role1");
+    statement.execute("GRANT SELECT  ON TABLE tb2 TO ROLE user_role2");
+    statement.execute("GRANT SELECT  ON TABLE tb3 TO ROLE user_role2");
+    statement.execute("GRANT ROLE user_role1 TO GROUP " + USERGROUP1);
+    statement.execute("GRANT ROLE user_role2 TO GROUP " + USERGROUP2);
+    statement.execute("load data local inpath '" + dataFile.getPath() + "' into table db_2.tb2" );
+    statement.execute("load data local inpath '" + dataFile.getPath() + "' into table db_2.tb3" );
+    statement.close();
+    connection.close();
+
+    connection =context.createConnection(USER1_1);
+    statement = context.createStatement(connection);
+    statement.execute("use " + DB1);
+    statement.execute("CREATE table db_1.t1 as select tb1.id, tb3.val, tb2.num from db_1.tb1,db_2.tb3,db_2.tb2");
+    statement.close();
+    connection.close();
+
+    connection =context.createConnection(USER2_1);
+    statement = context.createStatement(connection);
+    //The db_1.tb1 and db_2.tb3 is same with db_2.tb2.
+    ResultSet res = statement.executeQuery("select * from db_2.tb2 limit 2");
+    List<String> expectedResult = new ArrayList<String>();
+    List<String> returnedResult = new ArrayList<String>();
+    expectedResult.add("238");
+    expectedResult.add("86");
+    while(res.next()){
+      returnedResult.add(res.getString(1).trim());
+    }
+    validateReturnedResult(expectedResult, returnedResult);
+    expectedResult.clear();
+    returnedResult.clear();
+
+    statement.execute("use " + DB1);
+    statement.execute("CREATE VIEW db_1.v1 as select tb1.id, tb3.val, tb2.num from db_1.tb1,db_2.tb3,db_2.tb2");
+    statement.close();
+    connection.close();
+
+  }
 }