cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jji...@apache.org
Subject [3/6] cassandra git commit: Accept role names containing forward-slash
Date Thu, 07 Dec 2017 21:22:00 GMT
Accept role names containing forward-slash

Patch by Kurt Greaves; Reviewed by Jeremiah Jordan for CASSANDRA-14088


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

Branch: refs/heads/trunk
Commit: f9de26a79de02e61624994e67e64f2c93fb5a35b
Parents: b885e9c
Author: kurt <kurt@instaclustr.com>
Authored: Mon Dec 4 03:35:07 2017 +0000
Committer: Jeff Jirsa <jjirsa@apple.com>
Committed: Thu Dec 7 13:19:58 2017 -0800

----------------------------------------------------------------------
 CHANGES.txt                                     |  1 +
 .../org/apache/cassandra/auth/RoleResource.java |  4 ++--
 .../miscellaneous/RoleSyntaxTest.java           | 23 ++++++++++++++++++++
 3 files changed, 26 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/f9de26a7/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index b275397..4a415eb 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -1,4 +1,5 @@
 3.0.16
+ * Accept role names containing forward-slash (CASSANDRA-14088)
  * Optimize CRC check chance probability calculations (CASSANDRA-14094)
  * Fix cleanup on keyspace with no replicas (CASSANDRA-13526)
  * Fix updating base table rows with TTL not removing materialized view entries (CASSANDRA-14071)

http://git-wip-us.apache.org/repos/asf/cassandra/blob/f9de26a7/src/java/org/apache/cassandra/auth/RoleResource.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/auth/RoleResource.java b/src/java/org/apache/cassandra/auth/RoleResource.java
index e994233..89665f4 100644
--- a/src/java/org/apache/cassandra/auth/RoleResource.java
+++ b/src/java/org/apache/cassandra/auth/RoleResource.java
@@ -96,9 +96,9 @@ public class RoleResource implements IResource, Comparable<RoleResource>
      */
     public static RoleResource fromName(String name)
     {
-        String[] parts = StringUtils.split(name, '/');
+        String[] parts = StringUtils.split(name, "/", 2);
 
-        if (!parts[0].equals(ROOT_NAME) || parts.length > 2)
+        if (!parts[0].equals(ROOT_NAME))
             throw new IllegalArgumentException(String.format("%s is not a valid role resource
name", name));
 
         if (parts.length == 1)

http://git-wip-us.apache.org/repos/asf/cassandra/blob/f9de26a7/test/unit/org/apache/cassandra/cql3/validation/miscellaneous/RoleSyntaxTest.java
----------------------------------------------------------------------
diff --git a/test/unit/org/apache/cassandra/cql3/validation/miscellaneous/RoleSyntaxTest.java
b/test/unit/org/apache/cassandra/cql3/validation/miscellaneous/RoleSyntaxTest.java
index 0cb1de2..f72e3dc 100644
--- a/test/unit/org/apache/cassandra/cql3/validation/miscellaneous/RoleSyntaxTest.java
+++ b/test/unit/org/apache/cassandra/cql3/validation/miscellaneous/RoleSyntaxTest.java
@@ -17,8 +17,10 @@
  */
 package org.apache.cassandra.cql3.validation.miscellaneous;
 
+import org.junit.Assert;
 import org.junit.Test;
 
+import org.apache.cassandra.auth.RoleResource;
 import org.apache.cassandra.cql3.CQLTester;
 
 public class RoleSyntaxTest extends CQLTester
@@ -158,4 +160,25 @@ public class RoleSyntaxTest extends CQLTester
         assertValidSyntax("LIST ROLES OF \"r1\"");
         assertValidSyntax("LIST ROLES OF $$ r '1' $$");
     }
+
+    @Test
+    public void roleNameTest()
+    {
+        // we used to split on all "/" which meant role names containing a / would trigger
an exception in RoleResource.fromName()
+        RoleResource t1 = RoleResource.role("ki/ng");
+        RoleResource t2 = RoleResource.role("emperor");
+        RoleResource t3 = RoleResource.role("aeou/!@*%");
+        RoleResource t4 = RoleResource.role("do$\\$P#?:");
+        RoleResource t5 = RoleResource.root();
+        RoleResource r1 = RoleResource.fromName("roles/ki/ng");
+        RoleResource r2 = RoleResource.fromName("roles/emperor");
+        RoleResource r3 = RoleResource.fromName("roles/aeou/!@*%");
+        RoleResource r4 = RoleResource.fromName("roles/do$\\$P#?:");
+        RoleResource r5 = RoleResource.fromName("roles");
+        Assert.assertEquals(t1, r1);
+        Assert.assertEquals(t2, r2);
+        Assert.assertEquals(t3, r3);
+        Assert.assertEquals(t4, r4);
+        Assert.assertEquals(t5, r5);
+    }
 }


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cassandra.apache.org
For additional commands, e-mail: commits-help@cassandra.apache.org


Mime
View raw message