sentry-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ak...@apache.org
Subject 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)
Date Sat, 11 Mar 2017 02:03:01 GMT
Repository: sentry
Updated Branches:
  refs/heads/sentry-ha-redesign 86f67e606 -> b2121119b


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/b2121119
Tree: http://git-wip-us.apache.org/repos/asf/sentry/tree/b2121119
Diff: http://git-wip-us.apache.org/repos/asf/sentry/diff/b2121119

Branch: refs/heads/sentry-ha-redesign
Commit: b2121119bee5b7b6d70080c5bf07ab77405d75da
Parents: 86f67e6
Author: Alexander Kolbasov <akolb@cloudera.com>
Authored: Fri Mar 10 18:02:50 2017 -0800
Committer: Alexander Kolbasov <akolb@cloudera.com>
Committed: Fri Mar 10 18:02:50 2017 -0800

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


http://git-wip-us.apache.org/repos/asf/sentry/blob/b2121119/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();
+
+  }
 }


Mime
View raw message