You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by bd...@apache.org on 2020/03/09 13:53:20 UTC

[sling-org-apache-sling-repoinit-parser] branch master updated: SLING-9084 - simplify add/remove to/from group syntax and add test-99 and parsing errors tests

This is an automated email from the ASF dual-hosted git repository.

bdelacretaz pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-repoinit-parser.git


The following commit(s) were added to refs/heads/master by this push:
     new 30c5e5c  SLING-9084 - simplify add/remove to/from group syntax and add test-99 and parsing errors tests
30c5e5c is described below

commit 30c5e5cd1509737d4b4f6321f74eb1208cad7dbb
Author: Bertrand Delacretaz <bd...@apache.org>
AuthorDate: Mon Mar 9 14:53:03 2020 +0100

    SLING-9084 - simplify add/remove to/from group syntax and add test-99 and parsing errors tests
---
 src/main/javacc/RepoInitGrammar.jjt                | 42 +++++++++++++++-------
 .../repoinit/parser/test/ParsingErrorsTest.java    | 12 +++++++
 src/test/resources/testcases/test-64.txt           |  2 +-
 src/test/resources/testcases/test-65.txt           |  2 +-
 src/test/resources/testcases/test-66.txt           | 10 +++---
 src/test/resources/testcases/test-99-output.txt    |  4 ++-
 src/test/resources/testcases/test-99.txt           |  4 +++
 7 files changed, 55 insertions(+), 21 deletions(-)

diff --git a/src/main/javacc/RepoInitGrammar.jjt b/src/main/javacc/RepoInitGrammar.jjt
index 306d232..8ece527 100644
--- a/src/main/javacc/RepoInitGrammar.jjt
+++ b/src/main/javacc/RepoInitGrammar.jjt
@@ -57,7 +57,8 @@ TOKEN:
     < SET: "set" >
 |   < ACL: "ACL" >
 |   < ON: "on" >
-|   < IN: "in" >
+|   < TO: "to" >
+|   < FROM: "from" >
 |   < REMOVE: "remove" >
 |   < ALLOW: "allow" >
 |   < DENY: "deny" >
@@ -78,7 +79,6 @@ TOKEN:
 |   < REGISTER: "register" >
 |   < NAMESPACE: "namespace" >
 |   < PRIVILEGE: "privilege" >
-|   < MEMBERS: "members" >
 |   < WITH: "with" >
 |   < ABSTRACT: "abstract" >
 |   < PASSWORD: "password" >
@@ -147,7 +147,8 @@ List<Operation> parse() :
         | createUserStatement(result)
         | deleteUserStatement(result)
         | disableServiceUserStatement(result)
-        | groupMembershipStatement(result)
+        | addToGroupStatement(result)
+        | removeFromGroupStatement(result)
         | blankLine() 
     ) * 
     <EOF>
@@ -666,22 +667,37 @@ void disableServiceUserStatement(List<Operation> result) :
         result.add(new DisableServiceUser(user.image, msg == null ? null : msg.image));
     }
 }
-void groupMembershipStatement(List<Operation> result) :
+
+void addToGroupStatement(List<Operation> result) :
 {
     List <String> members;
     Token t;
     Token group = null;
 }
 {
-    (t=<ADD> | t=<REMOVE>) <MEMBERS>
-       ( members =  principalsList() )
-        <IN> <GROUP>
-        ( group = <STRING> )
+    <ADD>
+    members =  principalsList()
+    <TO> <GROUP>
+    group = <STRING>
+
     {
-        if(ADD == t.kind) {
-           result.add(new AddGroupMembers(members, group.image));
-        } else {
-           result.add(new RemoveGroupMembers(members, group.image));
-        }
+        result.add(new AddGroupMembers(members, group.image));
+    }
+}
+
+void removeFromGroupStatement(List<Operation> result) :
+{
+    List <String> members;
+    Token t;
+    Token group = null;
+}
+{
+    <REMOVE>
+    members =  principalsList()
+    <FROM> <GROUP>
+    group = <STRING>
+
+    {
+        result.add(new RemoveGroupMembers(members, group.image));
     }
 }
diff --git a/src/test/java/org/apache/sling/repoinit/parser/test/ParsingErrorsTest.java b/src/test/java/org/apache/sling/repoinit/parser/test/ParsingErrorsTest.java
index fd70828..ddbf056 100644
--- a/src/test/java/org/apache/sling/repoinit/parser/test/ParsingErrorsTest.java
+++ b/src/test/java/org/apache/sling/repoinit/parser/test/ParsingErrorsTest.java
@@ -94,6 +94,18 @@ public class ParsingErrorsTest {
             add(new Object[] { "set ACL on home(alice#hashNotAllowed) \n remove * for u \n end", ParseException.class });
             add(new Object[] { "set ACL on home(alice,commaNotAllowed) \n remove * for u \n end", ParseException.class });
             add(new Object[] { "set ACL on home(alice,comma,not,allowed) \n remove * for u \n end", ParseException.class });
+
+            // SLING-9084 - add/remove group members
+            add(new Object[] { "add to group missingUsernames", ParseException.class });
+            add(new Object[] { "add missingGroupName, another to group", ParseException.class });
+            add(new Object[] { "add bob, alice to group only, one, allowed", ParseException.class });
+            add(new Object[] { "remove from group missingUsernames", ParseException.class });
+            add(new Object[] { "remove missingGroup from group", ParseException.class });
+            add(new Object[] { "remove bob, alice from group only, one, really", ParseException.class });
+            add(new Object[] { "add bob, alice from group shouldBeToNotFrom", ParseException.class });
+            add(new Object[] { "remove bob, alice to group shouldBeFromNotTo", ParseException.class });
+            add(new Object[] { "add bob, alice group missingTo", ParseException.class });
+            add(new Object[] { "remove bob, alice group missingFrom", ParseException.class });
         }};
         return result;
     }
diff --git a/src/test/resources/testcases/test-64.txt b/src/test/resources/testcases/test-64.txt
index dd2df1b..0c90940 100644
--- a/src/test/resources/testcases/test-64.txt
+++ b/src/test/resources/testcases/test-64.txt
@@ -1,2 +1,2 @@
 # Test "add members" statements
-add members user1,user2 in group grpA
\ No newline at end of file
+add user1,user2 to group grpA
\ No newline at end of file
diff --git a/src/test/resources/testcases/test-65.txt b/src/test/resources/testcases/test-65.txt
index 9626931..1cfd534 100644
--- a/src/test/resources/testcases/test-65.txt
+++ b/src/test/resources/testcases/test-65.txt
@@ -1,2 +1,2 @@
 # Test "remove members" statements
-remove members user3,user5 in group grpB
\ No newline at end of file
+remove user3,user5 from group grpB
\ No newline at end of file
diff --git a/src/test/resources/testcases/test-66.txt b/src/test/resources/testcases/test-66.txt
index c60b1e0..3cb0bb4 100644
--- a/src/test/resources/testcases/test-66.txt
+++ b/src/test/resources/testcases/test-66.txt
@@ -1,6 +1,6 @@
 # Test add and remove together statements
-add members user1,user2 in group grpA
-add members user3 in group grpB
-add members user4,user5 in group grpB
-remove members user1 in group grpA
-remove members user3,user5 in group grpB
\ No newline at end of file
+add user1,user2 to group grpA
+add user3 to group grpB
+add user4,user5 to group grpB
+remove user1 from group grpA
+remove user3,user5 from group grpB
\ No newline at end of file
diff --git a/src/test/resources/testcases/test-99-output.txt b/src/test/resources/testcases/test-99-output.txt
index a556865..dbe14ee 100644
--- a/src/test/resources/testcases/test-99-output.txt
+++ b/src/test/resources/testcases/test-99-output.txt
@@ -52,4 +52,6 @@ SetAclPaths on :home:alice#
 SetAclPrincipals for bob 
   AclLine ALLOW {paths=[:home:alice#, /another/path, :home:larry#], privileges=[jcr:two]}
 SetAclPaths on :home:alice#/sub/folder/of/their/homes 
-  AclLine ALLOW {principals=[fred], privileges=[jcr:three]}  
\ No newline at end of file
+  AclLine ALLOW {principals=[fred], privileges=[jcr:three]}
+AddGroupMembers user1 user2 in group grpA
+RemoveGroupMembers user3 user5 in group grpB
\ No newline at end of file
diff --git a/src/test/resources/testcases/test-99.txt b/src/test/resources/testcases/test-99.txt
index 5863fb0..594f454 100644
--- a/src/test/resources/testcases/test-99.txt
+++ b/src/test/resources/testcases/test-99.txt
@@ -96,3 +96,7 @@ end
 set ACL on home(alice)/sub/folder/of/their/homes
   allow jcr:three for fred
 end
+
+# Add/remove principals to group, since V1.5.2
+add user1,user2 to group grpA
+remove user3,user5 from group grpB