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-320: show role grant group groupname should not throw an exception if group doesnt exist in db (Ke Jia via Dapeng Sun)
Date Sat, 11 Mar 2017 07:37:33 GMT
Repository: sentry
Updated Branches:
  refs/heads/sentry-ha-redesign 218be0c59 -> 0bec6c728


SENTRY-320: show role grant group groupname should not throw an exception if group doesnt
exist in db (Ke Jia via Dapeng Sun)


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

Branch: refs/heads/sentry-ha-redesign
Commit: 0bec6c728727638469b955589e9f167da4024ba7
Parents: 218be0c
Author: Alexander Kolbasov <akolb@cloudera.com>
Authored: Fri Mar 10 23:37:15 2017 -0800
Committer: Alexander Kolbasov <akolb@cloudera.com>
Committed: Fri Mar 10 23:37:15 2017 -0800

----------------------------------------------------------------------
 .../SentryPolicyServiceClientDefaultImpl.java   |  4 ++++
 .../e2e/dbprovider/TestDatabaseProvider.java    | 13 +++++++++--
 .../e2e/dbprovider/TestGrantUserToRole.java     | 24 ++++++++++++++++++++
 3 files changed, 39 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/sentry/blob/0bec6c72/sentry-provider/sentry-provider-db/src/main/java/org/apache/sentry/provider/db/service/thrift/SentryPolicyServiceClientDefaultImpl.java
----------------------------------------------------------------------
diff --git a/sentry-provider/sentry-provider-db/src/main/java/org/apache/sentry/provider/db/service/thrift/SentryPolicyServiceClientDefaultImpl.java
b/sentry-provider/sentry-provider-db/src/main/java/org/apache/sentry/provider/db/service/thrift/SentryPolicyServiceClientDefaultImpl.java
index 5bca574..9494b75 100644
--- a/sentry-provider/sentry-provider-db/src/main/java/org/apache/sentry/provider/db/service/thrift/SentryPolicyServiceClientDefaultImpl.java
+++ b/sentry-provider/sentry-provider-db/src/main/java/org/apache/sentry/provider/db/service/thrift/SentryPolicyServiceClientDefaultImpl.java
@@ -332,6 +332,10 @@ public class SentryPolicyServiceClientDefaultImpl implements SentryPolicyService
     TListSentryRolesResponse response;
     try {
       response = client.list_sentry_roles_by_group(request);
+      Status status = Status.fromCode(response.getStatus().getValue());
+      if (status == Status.NO_SUCH_OBJECT) {
+        return Collections.emptySet();
+      }
       Status.throwIfNotOk(response.getStatus());
       return response.getRoles();
     } catch (TException e) {

http://git-wip-us.apache.org/repos/asf/sentry/blob/0bec6c72/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 eff0b6c..63b00e2 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
@@ -2019,8 +2019,17 @@ public class TestDatabaseProvider extends AbstractTestWithStaticConfiguration
{
     expected.add(testRole1);
     assertTestRoles(resultSet, expected, false);
 
-    context.assertSentryException(statement, "SHOW ROLE GRANT GROUP Admin",
-        SentryNoSuchObjectException.class.getSimpleName());
+    ResultSet res = statement.executeQuery("SHOW ROLE GRANT GROUP Admin");
+
+    List<String> expectedResult = new ArrayList<String>();
+    List<String> returnedResult = new ArrayList<String>();
+
+    while (res.next()) {
+      returnedResult.add(res.getString(1).trim());
+    }
+    validateReturnedResult(expectedResult, returnedResult);
+    returnedResult.clear();
+    expectedResult.clear();
 
     statement.close();
     connection.close();

http://git-wip-us.apache.org/repos/asf/sentry/blob/0bec6c72/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/dbprovider/TestGrantUserToRole.java
----------------------------------------------------------------------
diff --git a/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/dbprovider/TestGrantUserToRole.java
b/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/dbprovider/TestGrantUserToRole.java
index 4ce30c1..5364937 100644
--- a/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/dbprovider/TestGrantUserToRole.java
+++ b/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/dbprovider/TestGrantUserToRole.java
@@ -24,6 +24,8 @@ import static org.junit.Assert.fail;
 import java.sql.Connection;
 import java.sql.ResultSet;
 import java.sql.Statement;
+import java.util.ArrayList;
+import java.util.List;
 import java.util.Set;
 
 import org.apache.sentry.tests.e2e.hive.AbstractTestWithStaticConfiguration;
@@ -144,6 +146,28 @@ public class TestGrantUserToRole extends AbstractTestWithStaticConfiguration
{
   }
 
   @Test
+  public void testShowGrantNotExistGroup() throws Exception {
+    Connection connection = context.createConnection(ADMIN1);
+    Statement statement = context.createStatement(connection);
+    //group1 does not exist in db;
+    ResultSet res = statement.executeQuery("SHOW ROLE GRANT GROUP group1");
+
+    List<String> expectedResult = new ArrayList<String>();
+    List<String> returnedResult = new ArrayList<String>();
+
+    while (res.next()) {
+      returnedResult.add(res.getString(1).trim());
+    }
+    validateReturnedResult(expectedResult, returnedResult);
+    returnedResult.clear();
+    expectedResult.clear();
+
+    statement.close();
+    connection.close();
+
+  }
+
+  @Test
   public void testAuthorizationForUsersWithRoles() throws Exception {
     Connection connection = context.createConnection(ADMIN1);
     Statement statement = context.createStatement(connection);


Mime
View raw message