diff options
Diffstat (limited to 'cadi')
-rw-r--r-- | cadi/aaf/src/main/java/org/onap/aaf/cadi/aaf/PermEval.java | 15 | ||||
-rw-r--r-- | cadi/aaf/src/test/java/org/onap/aaf/cadi/aaf/test/JU_PermEval.java | 19 |
2 files changed, 32 insertions, 2 deletions
diff --git a/cadi/aaf/src/main/java/org/onap/aaf/cadi/aaf/PermEval.java b/cadi/aaf/src/main/java/org/onap/aaf/cadi/aaf/PermEval.java index 2c7aa12b..7c843dbd 100644 --- a/cadi/aaf/src/main/java/org/onap/aaf/cadi/aaf/PermEval.java +++ b/cadi/aaf/src/main/java/org/onap/aaf/cadi/aaf/PermEval.java @@ -66,11 +66,22 @@ public class PermEval { if (sInst.charAt(0)==startChar) { // To compare key-to-key, both strings must be keys String[] skeys=Split.split(startChar,sInst); String[] pkeys=Split.split(startChar,pInst); - if (skeys.length!=pkeys.length) return false; + if (pkeys.length<skeys.length) { + return false; + } else if(pkeys.length > skeys.length && + (skeys.length==0 || !ASTERIX.equals(skeys[skeys.length-1]))) { + return false; + } boolean pass = true; for (int i=1;pass && i<skeys.length;++i) { // We start at 1, because the first one, being ":" is always "" - if (ASTERIX.equals(skeys[i]))continue; // Server data accepts all for this key spot + if (ASTERIX.equals(skeys[i])) { + if(i==skeys.length-1) { + // accept all after + return true; + } + continue; // Server data accepts all for this key spot + } pass = false; for (String sItem : Split.split(LIST_SEP,skeys[i])) { // allow for "," definition in Action if (pkeys[i].length()==0) { diff --git a/cadi/aaf/src/test/java/org/onap/aaf/cadi/aaf/test/JU_PermEval.java b/cadi/aaf/src/test/java/org/onap/aaf/cadi/aaf/test/JU_PermEval.java index 3e137c25..5d242005 100644 --- a/cadi/aaf/src/test/java/org/onap/aaf/cadi/aaf/test/JU_PermEval.java +++ b/cadi/aaf/src/test/java/org/onap/aaf/cadi/aaf/test/JU_PermEval.java @@ -211,5 +211,24 @@ public class JU_PermEval { @SuppressWarnings("unused") PermEval pe = new PermEval(); } + + @Test + public void pathTest() { + assertTrue(PermEval.evalInstance("/","/")); + assertFalse(PermEval.evalInstance("/","/hello")); + assertTrue(PermEval.evalInstance("/","/")); + assertTrue(PermEval.evalInstance("/onap/so/infra/*/*/*","/onap/so/infra/a/b/c")); + assertFalse(PermEval.evalInstance("/onap/so/infra/*","/onap/so/infra")); + assertTrue(PermEval.evalInstance("/onap/so/infra/*","/onap/so/infra/a/b/c")); + assertTrue(PermEval.evalInstance("/onap/so/infra*","/onap/so/infra")); + assertFalse(PermEval.evalInstance("/onap/so/infra*/hello","/onap/so/infra")); + assertFalse(PermEval.evalInstance("/onap/so/infra*/hello","/onap/so/infra23")); + assertTrue(PermEval.evalInstance("/onap/so/infra*/hello","/onap/so/infra23/hello")); + assertFalse(PermEval.evalInstance("/onap/so/*/hello","/onap/so/infra23")); + assertFalse(PermEval.evalInstance("/onap/so/*/","/onap/so/infra23")); + assertTrue(PermEval.evalInstance("/onap/so/*/","/onap/so/infra23/")); + } + + } |