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/02/20 11:11:38 UTC
[sling-org-apache-sling-repoinit-parser] branch master updated:
SLING-8757 - parser changes for home(...) function
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 0a718c1 SLING-8757 - parser changes for home(...) function
0a718c1 is described below
commit 0a718c1587b982f60aabcab755290a5ed3eeb4d7
Author: Bertrand Delacretaz <bd...@apache.org>
AuthorDate: Wed Oct 9 14:19:58 2019 +0200
SLING-8757 - parser changes for home(...) function
---
src/main/javacc/RepoInitGrammar.jjt | 45 ++++++++++++++++++++--
.../repoinit/parser/test/ParsingErrorsTest.java | 7 ++++
src/test/resources/testcases/test-34-output.txt | 14 +++++++
src/test/resources/testcases/test-34.txt | 29 ++++++++++++++
src/test/resources/testcases/test-99-output.txt | 6 +++
src/test/resources/testcases/test-99.txt | 13 +++++++
6 files changed, 111 insertions(+), 3 deletions(-)
diff --git a/src/main/javacc/RepoInitGrammar.jjt b/src/main/javacc/RepoInitGrammar.jjt
index 0695780..bda1db2 100644
--- a/src/main/javacc/RepoInitGrammar.jjt
+++ b/src/main/javacc/RepoInitGrammar.jjt
@@ -214,14 +214,53 @@ List<String> namespacedItemsList() :
{ return priv; }
}
-List<String> pathsList() :
+String usernameList() :
{
+ List<String> names = new ArrayList<String>();
Token t = null;
+}
+{
+ ( t = <STRING> ) { names.add(t.image); }
+ ( <COMMA> t = <STRING> { names.add(t.image); }) *
+
+ {
+ return String.join(",", names);
+ }
+}
+
+String pathExpression() :
+{
+ Token t = null;
+ Token tf = null;
+ String usernames = null;
+ final StringBuilder sb = new StringBuilder();
+}
+{
+ (
+ tf = <STRING> <LPAREN> usernames = usernameList() <RPAREN> ( t = <PATH_STRING> ) ?
+ | ( t = <PATH_STRING>
+ | t = <PATH_REPOSITORY> )
+ )
+ {
+ if(tf != null) {
+ sb.append(':').append(tf.image).append(':').append(usernames).append('#');
+ }
+ if(t != null) {
+ sb.append(t.image);
+ }
+ }
+
+ { return sb.toString(); }
+}
+
+List<String> pathsList() :
+{
+ String pathExpr = null;
List<String> paths = new ArrayList<String>();
}
{
- ( t = <PATH_STRING> | t = <PATH_REPOSITORY> ) { paths.add(t.image); }
- ( <COMMA> ( t = <PATH_STRING> | t = <PATH_REPOSITORY> ) { paths.add(t.image); } )*
+ ( pathExpr = pathExpression() ) { paths.add(pathExpr); }
+ ( <COMMA> ( pathExpr = pathExpression() ) { paths.add(pathExpr); } )*
{ return paths; }
}
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 759cdce..cb8ba9e 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
@@ -85,6 +85,13 @@ public class ParsingErrorsTest {
// path must come before password if used
add(new Object[] { "create user E with password PWD with path P", ParseException.class });
+
+ // SLING-8757 - functions at the beginning of paths
+ add(new Object[] { "set ACL on home(missingRParen \n remove * for u \n end", ParseException.class });
+ add(new Object[] { "set ACL on spaceAfterFunctionName(user) \n remove * for u \n end", ParseException.class });
+ add(new Object[] { "set ACL on one(name)two(onlyOneFunctionAllowed) \n remove * for u \n end", ParseException.class });
+ add(new Object[] { "set ACL on home(alice:colonNotAllowed) \n remove * for u \n end", ParseException.class });
+ add(new Object[] { "set ACL on home(alice#hashNotAllowed) \n remove * for u \n end", ParseException.class });
}};
return result;
}
diff --git a/src/test/resources/testcases/test-34-output.txt b/src/test/resources/testcases/test-34-output.txt
new file mode 100644
index 0000000..63787b2
--- /dev/null
+++ b/src/test/resources/testcases/test-34-output.txt
@@ -0,0 +1,14 @@
+SetAclPaths on :home:alice#
+ AclLine ALLOW {principals=[alice, bob, carol], privileges=[jcr:one]}
+SetAclPaths on :home:jack# /tmp/a :functionNamesAreFree:bobby#
+ AclLine ALLOW {principals=[alice], privileges=[jcr:two]}
+SetAclPrincipals for fred
+ AclLine ALLOW {paths=[/one, :home:Alice123#, /tmp], privileges=[jcr:three]}
+SetAclPaths on /a/b :home:jack,jill# /tmp/a :square:bobby#
+ AclLine ALLOW {principals=[alice], privileges=[jcr:four]}
+SetAclPrincipals for austin
+ AclLine ALLOW {paths=[/one, :home:Alice123,11bob42#, /tmp], privileges=[jcr:five]}
+SetAclPaths on :home:spaces,are,ok#
+ AclLine ALLOW {principals=[spaceman], privileges=[jcr:six]}
+SetAclPaths on :home:alice,bob#/sub/folder /anotherPath :home:fred#/root
+ AclLine ALLOW {principals=[mercury], privileges=[jcr:seven]}
\ No newline at end of file
diff --git a/src/test/resources/testcases/test-34.txt b/src/test/resources/testcases/test-34.txt
new file mode 100644
index 0000000..41dc2f3
--- /dev/null
+++ b/src/test/resources/testcases/test-34.txt
@@ -0,0 +1,29 @@
+# Test functions at the beginning of path names, for SLING-8757
+
+set ACL on home(alice)
+ allow jcr:one for alice, bob, carol
+end
+
+set ACL on home(jack),/tmp/a,functionNamesAreFree(bobby)
+ allow jcr:two for alice
+end
+
+set ACL for fred
+ allow jcr:three on /one,home(Alice123),/tmp
+end
+
+set ACL on /a/b,home(jack,jill),/tmp/a,square(bobby)
+ allow jcr:four for alice
+end
+
+set ACL for austin
+ allow jcr:five on /one,home(Alice123,11bob42),/tmp
+end
+
+set ACL on home(spaces, are, ok)
+ allow jcr:six for spaceman
+end
+
+set ACL on home(alice, bob)/sub/folder, /anotherPath, home(fred)/root
+ allow jcr:seven for mercury
+end
diff --git a/src/test/resources/testcases/test-99-output.txt b/src/test/resources/testcases/test-99-output.txt
index f5136a9..f23f2fd 100644
--- a/src/test/resources/testcases/test-99-output.txt
+++ b/src/test/resources/testcases/test-99-output.txt
@@ -47,3 +47,9 @@ DisableServiceUser svc1 : This is the message
CreateGroup since124_A
CreateGroup since124_B with path /path_B
DeleteGroup since124_C
+SetAclPaths on :home:alice#
+ AclLine ALLOW {principals=[alice, bob, carol], privileges=[jcr:one]}
+SetAclPrincipals for bob
+ AclLine ALLOW {paths=[:home:alice,fredTheSecond,markTheThird#, /another/path, :home:larry#], privileges=[jcr:two]}
+SetAclPaths on :home:alice,bob#/sub/folder/of/their/homes
+ AclLine ALLOW {principals=[fred], privileges=[jcr:three]}
\ 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 7aa0d8b..08d71eb 100644
--- a/src/test/resources/testcases/test-99.txt
+++ b/src/test/resources/testcases/test-99.txt
@@ -83,3 +83,16 @@ disable service user svc1 : "This is the message"
create group since124_A
create group since124_B with path /path_B
delete group since124_C
+
+# Home function maps to user and group home folders
+set ACL on home(alice)
+ allow jcr:one for alice, bob, carol
+end
+
+set ACL for bob
+ allow jcr:two on home(alice, fredTheSecond, markTheThird), /another/path, home(larry)
+end
+
+set ACL on home(alice,bob)/sub/folder/of/their/homes
+ allow jcr:three for fred
+end