You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sentry.apache.org by co...@apache.org on 2017/11/16 09:57:06 UTC

[29/32] sentry git commit: SENTRY-2039: KeyValue is case sensitive and it causes incompatibility issues with external components (Sergio Pena, reviewed by Alexander Kolbasov, Na Li)

SENTRY-2039: KeyValue is case sensitive and it causes incompatibility issues with external components (Sergio Pena, reviewed by Alexander Kolbasov, Na Li)


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

Branch: refs/heads/akolb-cli
Commit: a001d43992eab3d543927580da1f7533a3279897
Parents: 598b203
Author: Sergio Pena <se...@cloudera.com>
Authored: Mon Nov 13 11:09:04 2017 -0600
Committer: Sergio Pena <se...@cloudera.com>
Committed: Mon Nov 13 11:09:04 2017 -0600

----------------------------------------------------------------------
 .../apache/sentry/core/common/utils/KeyValue.java    | 15 +++++++++++++--
 .../sentry/core/common/utils/TestKeyValue.java       |  7 +++++++
 .../sentry/policy/common/TestCommonPrivilege.java    | 15 ---------------
 3 files changed, 20 insertions(+), 17 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/sentry/blob/a001d439/sentry-core/sentry-core-common/src/main/java/org/apache/sentry/core/common/utils/KeyValue.java
----------------------------------------------------------------------
diff --git a/sentry-core/sentry-core-common/src/main/java/org/apache/sentry/core/common/utils/KeyValue.java b/sentry-core/sentry-core-common/src/main/java/org/apache/sentry/core/common/utils/KeyValue.java
index 4e944e5..500b98f 100644
--- a/sentry-core/sentry-core-common/src/main/java/org/apache/sentry/core/common/utils/KeyValue.java
+++ b/sentry-core/sentry-core-common/src/main/java/org/apache/sentry/core/common/utils/KeyValue.java
@@ -68,6 +68,17 @@ public class KeyValue {
     return result;
   }
 
+  /**
+   * Compares the specified object with this KeyValue for equality.
+   *
+   * Returns true if and only if the specified object is also a KeyValue and the corresponding
+   * key-value pair in the two KeyValue objects are equals. Key and value strings are compared
+   * for equality as case-insensitive (Two KeyValue objects are equal if (k1.equalsIgnoreCase(k2)
+   * && v1.equalsIgnoreCase(v1))).
+   *
+   * @param obj the object to be compared for equality with this KeyValue
+   * @return true if the specified object is equal to this KeyValue
+   */
   @Override
   public boolean equals(Object obj) {
     if (this == obj) {
@@ -84,14 +95,14 @@ public class KeyValue {
       if (other.key != null) {
         return false;
       }
-    } else if (!key.equals(other.key)) {
+    } else if (!key.equalsIgnoreCase(other.key)) {
       return false;
     }
     if (value == null) {
       if (other.value != null) {
         return false;
       }
-    } else if (!value.equals(other.value)) {
+    } else if (!value.equalsIgnoreCase(other.value)) {
       return false;
     }
     return true;

http://git-wip-us.apache.org/repos/asf/sentry/blob/a001d439/sentry-core/sentry-core-common/src/test/java/org/apache/sentry/core/common/utils/TestKeyValue.java
----------------------------------------------------------------------
diff --git a/sentry-core/sentry-core-common/src/test/java/org/apache/sentry/core/common/utils/TestKeyValue.java b/sentry-core/sentry-core-common/src/test/java/org/apache/sentry/core/common/utils/TestKeyValue.java
index ca44a24..0c5dfcc 100644
--- a/sentry-core/sentry-core-common/src/test/java/org/apache/sentry/core/common/utils/TestKeyValue.java
+++ b/sentry-core/sentry-core-common/src/test/java/org/apache/sentry/core/common/utils/TestKeyValue.java
@@ -55,6 +55,13 @@ public class TestKeyValue {
     doTest(kv1, kv2, kv3);
   }
 
+  @Test
+  public void testKeyValueCaseInsensitive() throws Exception {
+    KeyValue kv1 = new KeyValue("k1", "v1");
+    KeyValue kv2 = new KeyValue("K1", "V1");
+    Assert.assertEquals(kv1, kv2);
+  }
+
   private void doTest(KeyValue kv1, KeyValue kv2, KeyValue kv3) {
     Assert.assertEquals(kv1, kv2);
     Assert.assertFalse(kv1.equals(kv3));

http://git-wip-us.apache.org/repos/asf/sentry/blob/a001d439/sentry-policy/sentry-policy-common/src/test/java/org/apache/sentry/policy/common/TestCommonPrivilege.java
----------------------------------------------------------------------
diff --git a/sentry-policy/sentry-policy-common/src/test/java/org/apache/sentry/policy/common/TestCommonPrivilege.java b/sentry-policy/sentry-policy-common/src/test/java/org/apache/sentry/policy/common/TestCommonPrivilege.java
index 3f60b19..abaf61f 100644
--- a/sentry-policy/sentry-policy-common/src/test/java/org/apache/sentry/policy/common/TestCommonPrivilege.java
+++ b/sentry-policy/sentry-policy-common/src/test/java/org/apache/sentry/policy/common/TestCommonPrivilege.java
@@ -129,19 +129,4 @@ public class TestCommonPrivilege {
     assertFalse(privilegForSelect.implies(privilegForAll, testModel));
     assertFalse(privilegForInsert.implies(privilegForAll, testModel));
   }
-
-  @Test
-  public void testImplyStringCaseSensitive() throws Exception {
-    CommonPrivilege privileg1 = new CommonPrivilege("server=server1->db=db1->table=table1->column=col1->action=select");
-    CommonPrivilege privileg2 = new CommonPrivilege("server=server1->db=db1->table=table1->column=CoL1->action=select");
-    CommonPrivilege privileg3 = new CommonPrivilege("server=SERver1->db=Db1->table=TAbLe1->column=col1->action=select");
-    CommonPrivilege privileg4 = new CommonPrivilege("SERVER=server1->DB=db1->TABLE=table1->COLUMN=col1->ACTION=select");
-
-    // column is case sensitive
-    assertFalse(privileg1.implies(privileg2, testModel));
-    // server, db, table is case insensitive
-    assertTrue(privileg1.implies(privileg3, testModel));
-    // key in privilege is case insensitive
-    assertTrue(privileg1.implies(privileg4, testModel));
-  }
 }