summaryrefslogtreecommitdiffstats
path: root/authz-service
diff options
context:
space:
mode:
authorsg481n <sg481n@att.com>2017-10-02 22:04:57 +0000
committersg481n <sg481n@att.com>2017-10-02 22:06:40 +0000
commit23256c452e2c078768bbb71d0dc1525767c9c0f1 (patch)
treed757318952d6cece3c3d8d60b8afdcb341d57150 /authz-service
parent2783a8d9ef962f65f4a0d170525f9b2982e331a8 (diff)
Improve code coverage for aaf authz modules
Issue-ID: AAF-79 Change-Id: Id919d5f936c5eacfb2a25dcf0d582f56d7bcde6f Signed-off-by: sg481n <sg481n@att.com>
Diffstat (limited to 'authz-service')
-rw-r--r--authz-service/src/test/java/org/onap/aaf/authz/service/api/JU_API_Api.java4
-rw-r--r--authz-service/src/test/java/org/onap/aaf/authz/service/api/JU_API_Approval.java4
-rw-r--r--authz-service/src/test/java/org/onap/aaf/authz/service/api/JU_API_Creds.java4
-rw-r--r--authz-service/src/test/java/org/onap/aaf/authz/service/api/JU_API_Delegate.java4
-rw-r--r--authz-service/src/test/java/org/onap/aaf/authz/service/api/JU_API_History.java4
-rw-r--r--authz-service/src/test/java/org/onap/aaf/authz/service/api/JU_API_Mgmt.java4
-rw-r--r--authz-service/src/test/java/org/onap/aaf/authz/service/api/JU_API_NS.java4
-rw-r--r--authz-service/src/test/java/org/onap/aaf/authz/service/api/JU_API_Perms.java4
-rw-r--r--authz-service/src/test/java/org/onap/aaf/authz/service/api/JU_API_Roles.java4
-rw-r--r--authz-service/src/test/java/org/onap/aaf/authz/service/api/JU_API_User.java4
-rw-r--r--authz-service/src/test/java/org/onap/aaf/authz/service/api/JU_API_UserRole.java4
-rw-r--r--authz-service/src/test/java/org/onap/aaf/authz/service/validation/JU_Validator.java122
12 files changed, 116 insertions, 50 deletions
diff --git a/authz-service/src/test/java/org/onap/aaf/authz/service/api/JU_API_Api.java b/authz-service/src/test/java/org/onap/aaf/authz/service/api/JU_API_Api.java
index 08e8b4f7..f4158ce8 100644
--- a/authz-service/src/test/java/org/onap/aaf/authz/service/api/JU_API_Api.java
+++ b/authz-service/src/test/java/org/onap/aaf/authz/service/api/JU_API_Api.java
@@ -26,11 +26,13 @@ import static org.junit.Assert.*;
import org.junit.Before;
import org.junit.Test;
+import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.onap.aaf.authz.facade.AuthzFacade;
import org.onap.aaf.authz.service.AuthAPI;
import org.onap.aaf.authz.service.api.API_Api;
-
+import org.powermock.modules.junit4.PowerMockRunner;
+@RunWith(PowerMockRunner.class)
public class JU_API_Api {
API_Api api_Api;
@Mock
diff --git a/authz-service/src/test/java/org/onap/aaf/authz/service/api/JU_API_Approval.java b/authz-service/src/test/java/org/onap/aaf/authz/service/api/JU_API_Approval.java
index e210bbc2..d3bd5de4 100644
--- a/authz-service/src/test/java/org/onap/aaf/authz/service/api/JU_API_Approval.java
+++ b/authz-service/src/test/java/org/onap/aaf/authz/service/api/JU_API_Approval.java
@@ -26,11 +26,13 @@ import static org.junit.Assert.*;
import org.junit.Before;
import org.junit.Test;
+import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.onap.aaf.authz.facade.AuthzFacade;
import org.onap.aaf.authz.service.AuthAPI;
import org.onap.aaf.authz.service.api.API_Approval;
-
+import org.powermock.modules.junit4.PowerMockRunner;
+@RunWith(PowerMockRunner.class)
public class JU_API_Approval {
API_Approval api_Approval;
diff --git a/authz-service/src/test/java/org/onap/aaf/authz/service/api/JU_API_Creds.java b/authz-service/src/test/java/org/onap/aaf/authz/service/api/JU_API_Creds.java
index 442de9ef..d8ebc508 100644
--- a/authz-service/src/test/java/org/onap/aaf/authz/service/api/JU_API_Creds.java
+++ b/authz-service/src/test/java/org/onap/aaf/authz/service/api/JU_API_Creds.java
@@ -26,6 +26,7 @@ import static org.junit.Assert.*;
import org.junit.Before;
import org.junit.Test;
+import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.onap.aaf.authz.cadi.DirectAAFUserPass;
import org.onap.aaf.authz.facade.AuthzFacade;
@@ -33,7 +34,8 @@ import org.onap.aaf.authz.service.AuthAPI;
import org.onap.aaf.authz.service.api.API_Creds;
import org.onap.aaf.inno.env.Env;
-
+import org.powermock.modules.junit4.PowerMockRunner;
+@RunWith(PowerMockRunner.class)
public class JU_API_Creds {
API_Creds api_Creds;
diff --git a/authz-service/src/test/java/org/onap/aaf/authz/service/api/JU_API_Delegate.java b/authz-service/src/test/java/org/onap/aaf/authz/service/api/JU_API_Delegate.java
index 79c716a6..2be9bbcc 100644
--- a/authz-service/src/test/java/org/onap/aaf/authz/service/api/JU_API_Delegate.java
+++ b/authz-service/src/test/java/org/onap/aaf/authz/service/api/JU_API_Delegate.java
@@ -24,11 +24,13 @@ package org.onap.aaf.authz.service.api;
import org.junit.Before;
import org.junit.Test;
+import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.onap.aaf.authz.facade.AuthzFacade;
import org.onap.aaf.authz.service.AuthAPI;
import org.onap.aaf.authz.service.api.API_Delegate;
-
+import org.powermock.modules.junit4.PowerMockRunner;
+@RunWith(PowerMockRunner.class)
public class JU_API_Delegate {
API_Delegate api_Delegate;
@Mock
diff --git a/authz-service/src/test/java/org/onap/aaf/authz/service/api/JU_API_History.java b/authz-service/src/test/java/org/onap/aaf/authz/service/api/JU_API_History.java
index 99bc9bff..3f624bf9 100644
--- a/authz-service/src/test/java/org/onap/aaf/authz/service/api/JU_API_History.java
+++ b/authz-service/src/test/java/org/onap/aaf/authz/service/api/JU_API_History.java
@@ -26,11 +26,13 @@ import static org.junit.Assert.*;
import org.junit.Before;
import org.junit.Test;
+import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.onap.aaf.authz.facade.AuthzFacade;
import org.onap.aaf.authz.service.AuthAPI;
import org.onap.aaf.authz.service.api.API_History;
-
+import org.powermock.modules.junit4.PowerMockRunner;
+@RunWith(PowerMockRunner.class)
public class JU_API_History {
API_History api_History;
diff --git a/authz-service/src/test/java/org/onap/aaf/authz/service/api/JU_API_Mgmt.java b/authz-service/src/test/java/org/onap/aaf/authz/service/api/JU_API_Mgmt.java
index d99818c4..9fc2eefe 100644
--- a/authz-service/src/test/java/org/onap/aaf/authz/service/api/JU_API_Mgmt.java
+++ b/authz-service/src/test/java/org/onap/aaf/authz/service/api/JU_API_Mgmt.java
@@ -26,11 +26,13 @@ import static org.junit.Assert.*;
import org.junit.Before;
import org.junit.Test;
+import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.onap.aaf.authz.facade.AuthzFacade;
import org.onap.aaf.authz.service.AuthAPI;
import org.onap.aaf.authz.service.api.API_Mgmt;
-
+import org.powermock.modules.junit4.PowerMockRunner;
+@RunWith(PowerMockRunner.class)
public class JU_API_Mgmt {
API_Mgmt api_Mgmt;
diff --git a/authz-service/src/test/java/org/onap/aaf/authz/service/api/JU_API_NS.java b/authz-service/src/test/java/org/onap/aaf/authz/service/api/JU_API_NS.java
index d2cb4e2f..8509304e 100644
--- a/authz-service/src/test/java/org/onap/aaf/authz/service/api/JU_API_NS.java
+++ b/authz-service/src/test/java/org/onap/aaf/authz/service/api/JU_API_NS.java
@@ -25,11 +25,13 @@ package org.onap.aaf.authz.service.api;
import static org.junit.Assert.*;
import org.junit.Test;
+import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.onap.aaf.authz.facade.AuthzFacade;
import org.onap.aaf.authz.service.AuthAPI;
import org.onap.aaf.authz.service.api.API_NS;
-
+import org.powermock.modules.junit4.PowerMockRunner;
+@RunWith(PowerMockRunner.class)
public class JU_API_NS {
API_NS api_Ns;
@Mock
diff --git a/authz-service/src/test/java/org/onap/aaf/authz/service/api/JU_API_Perms.java b/authz-service/src/test/java/org/onap/aaf/authz/service/api/JU_API_Perms.java
index b1b3f5b5..15674f7b 100644
--- a/authz-service/src/test/java/org/onap/aaf/authz/service/api/JU_API_Perms.java
+++ b/authz-service/src/test/java/org/onap/aaf/authz/service/api/JU_API_Perms.java
@@ -26,11 +26,13 @@ import static org.junit.Assert.*;
import org.junit.Before;
import org.junit.Test;
+import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.onap.aaf.authz.facade.AuthzFacade;
import org.onap.aaf.authz.service.AuthAPI;
import org.onap.aaf.authz.service.api.API_Perms;
-
+import org.powermock.modules.junit4.PowerMockRunner;
+@RunWith(PowerMockRunner.class)
public class JU_API_Perms {
API_Perms api_Perms;
@Mock
diff --git a/authz-service/src/test/java/org/onap/aaf/authz/service/api/JU_API_Roles.java b/authz-service/src/test/java/org/onap/aaf/authz/service/api/JU_API_Roles.java
index f52f7f65..43cc8d50 100644
--- a/authz-service/src/test/java/org/onap/aaf/authz/service/api/JU_API_Roles.java
+++ b/authz-service/src/test/java/org/onap/aaf/authz/service/api/JU_API_Roles.java
@@ -26,11 +26,13 @@ import static org.junit.Assert.*;
import org.junit.Before;
import org.junit.Test;
+import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.onap.aaf.authz.facade.AuthzFacade;
import org.onap.aaf.authz.service.AuthAPI;
import org.onap.aaf.authz.service.api.API_Roles;
-
+import org.powermock.modules.junit4.PowerMockRunner;
+@RunWith(PowerMockRunner.class)
public class JU_API_Roles {
API_Roles api_Roles;
@Mock
diff --git a/authz-service/src/test/java/org/onap/aaf/authz/service/api/JU_API_User.java b/authz-service/src/test/java/org/onap/aaf/authz/service/api/JU_API_User.java
index 2348effe..29eee9f3 100644
--- a/authz-service/src/test/java/org/onap/aaf/authz/service/api/JU_API_User.java
+++ b/authz-service/src/test/java/org/onap/aaf/authz/service/api/JU_API_User.java
@@ -26,11 +26,13 @@ import static org.junit.Assert.*;
import org.junit.Before;
import org.junit.Test;
+import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.onap.aaf.authz.facade.AuthzFacade;
import org.onap.aaf.authz.service.AuthAPI;
import org.onap.aaf.authz.service.api.API_User;
-
+import org.powermock.modules.junit4.PowerMockRunner;
+@RunWith(PowerMockRunner.class)
public class JU_API_User {
API_User api_User;
@Mock
diff --git a/authz-service/src/test/java/org/onap/aaf/authz/service/api/JU_API_UserRole.java b/authz-service/src/test/java/org/onap/aaf/authz/service/api/JU_API_UserRole.java
index 16b8ba45..8adcb647 100644
--- a/authz-service/src/test/java/org/onap/aaf/authz/service/api/JU_API_UserRole.java
+++ b/authz-service/src/test/java/org/onap/aaf/authz/service/api/JU_API_UserRole.java
@@ -26,11 +26,13 @@ import static org.junit.Assert.*;
import org.junit.Before;
import org.junit.Test;
+import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.onap.aaf.authz.facade.AuthzFacade;
import org.onap.aaf.authz.service.AuthAPI;
import org.onap.aaf.authz.service.api.API_UserRole;
-
+import org.powermock.modules.junit4.PowerMockRunner;
+@RunWith(PowerMockRunner.class)
public class JU_API_UserRole {
API_UserRole api_UserRole;
@Mock
diff --git a/authz-service/src/test/java/org/onap/aaf/authz/service/validation/JU_Validator.java b/authz-service/src/test/java/org/onap/aaf/authz/service/validation/JU_Validator.java
index 1277b978..e0b49d40 100644
--- a/authz-service/src/test/java/org/onap/aaf/authz/service/validation/JU_Validator.java
+++ b/authz-service/src/test/java/org/onap/aaf/authz/service/validation/JU_Validator.java
@@ -22,32 +22,27 @@
******************************************************************************/
package org.onap.aaf.authz.service.validation;
-import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
+import java.util.HashSet;
+import java.util.Set;
+
import org.junit.Before;
import org.junit.Test;
-import org.onap.aaf.authz.cadi.DirectAAFLur.PermPermission;
-import org.onap.aaf.authz.env.AuthzTrans;
import org.onap.aaf.authz.layer.Result;
-import org.onap.aaf.authz.org.Organization;
-import org.onap.aaf.authz.service.validation.Validator;
-import org.onap.aaf.dao.aaf.cass.CredDAO;
-import org.onap.aaf.dao.aaf.cass.DelegateDAO;
-import org.onap.aaf.dao.aaf.cass.Namespace;
import org.onap.aaf.dao.aaf.cass.PermDAO;
import org.onap.aaf.dao.aaf.cass.RoleDAO;
-import org.onap.aaf.dao.aaf.cass.UserRoleDAO;
public class JU_Validator {
-
+
+ Validator validator;
+
@Before
- public void setUp(){
- Validator validator = new Validator();
+ public void setUp() {
+ validator = new Validator();
}
-
@Test
public void test() {
assertTrue(Validator.ACTION_CHARS.matcher("HowdyDoody").matches());
@@ -57,14 +52,14 @@ public class JU_Validator {
assertFalse(Validator.INST_CHARS.matcher("Howd?yDoody").matches());
assertTrue(Validator.INST_CHARS.matcher("_HowdyDoody").matches());
- //
+ //
assertTrue(Validator.ACTION_CHARS.matcher("*").matches());
assertTrue(Validator.INST_CHARS.matcher("*").matches());
assertFalse(Validator.ACTION_CHARS.matcher(":*").matches());
assertTrue(Validator.INST_CHARS.matcher(":*").matches());
assertFalse(Validator.ACTION_CHARS.matcher(":*:*").matches());
assertTrue(Validator.INST_CHARS.matcher(":*:*").matches());
-
+
assertFalse(Validator.ACTION_CHARS.matcher(":hello").matches());
assertTrue(Validator.INST_CHARS.matcher(":hello").matches());
assertFalse(Validator.INST_CHARS.matcher("hello:").matches());
@@ -91,7 +86,6 @@ public class JU_Validator {
assertFalse(Validator.INST_CHARS.matcher(":h:*:*h").matches());
assertTrue(Validator.INST_CHARS.matcher(":com.test.*:ns:*").matches());
-
assertFalse(Validator.ACTION_CHARS.matcher("1234+235gd").matches());
assertTrue(Validator.ACTION_CHARS.matcher("1234-235gd").matches());
assertTrue(Validator.ACTION_CHARS.matcher("1234-23_5gd").matches());
@@ -105,7 +99,7 @@ public class JU_Validator {
assertFalse(Validator.ACTION_CHARS.matcher("").matches());
assertFalse(Validator.ACTION_CHARS.matcher(" ").matches());
- // Allow % and = (Needed for Escaping & Base64 usages) jg
+ // Allow % and = (Needed for Escaping & Base64 usages) jg
assertTrue(Validator.ACTION_CHARS.matcher("1234%235g=d").matches());
assertFalse(Validator.ACTION_CHARS.matcher(":1234%235g=d").matches());
assertTrue(Validator.INST_CHARS.matcher("1234%235g=d").matches());
@@ -116,7 +110,7 @@ public class JU_Validator {
assertTrue(Validator.INST_CHARS.matcher(":1234%235g=d:==%20:*").matches());
assertTrue(Validator.INST_CHARS.matcher(":*:==%20:*").matches());
- // Allow / instead of : (more natural instance expression) jg
+ // Allow / instead of : (more natural instance expression) jg
assertFalse(Validator.INST_CHARS.matcher("1234/a").matches());
assertTrue(Validator.INST_CHARS.matcher("/1234/a").matches());
assertTrue(Validator.INST_CHARS.matcher("/1234/*/a/").matches());
@@ -125,7 +119,6 @@ public class JU_Validator {
assertFalse(Validator.ACTION_CHARS.matcher("/1234/*/a/").matches());
assertFalse(Validator.ACTION_CHARS.matcher("1234//a").matches());
-
assertFalse(Validator.INST_CHARS.matcher("1234+235gd").matches());
assertTrue(Validator.INST_CHARS.matcher("1234-235gd").matches());
assertTrue(Validator.INST_CHARS.matcher("1234-23_5gd").matches());
@@ -136,40 +129,91 @@ public class JU_Validator {
assertFalse(Validator.INST_CHARS.matcher("123#4-23@5g:d").matches());
assertFalse(Validator.INST_CHARS.matcher("").matches());
-
- for( char c=0x20;c<0x7F;++c) {
+ for (char c = 0x20; c < 0x7F; ++c) {
boolean b;
- switch(c) {
- case '?':
- case '|':
- case '*':
- continue; // test separately
- case '~':
- case ',':
- b = false;
- break;
- default:
- b=true;
+ switch (c) {
+ case '?':
+ case '|':
+ case '*':
+ continue; // test separately
+ case '~':
+ case ',':
+ b = false;
+ break;
+ default:
+ b = true;
}
}
-
+
assertFalse(Validator.ID_CHARS.matcher("abc").matches());
assertFalse(Validator.ID_CHARS.matcher("").matches());
assertTrue(Validator.ID_CHARS.matcher("abc@att.com").matches());
assertTrue(Validator.ID_CHARS.matcher("ab-me@att.com").matches());
assertTrue(Validator.ID_CHARS.matcher("ab-me_.x@att._-com").matches());
-
+
assertFalse(Validator.NAME_CHARS.matcher("ab-me_.x@att._-com").matches());
assertTrue(Validator.NAME_CHARS.matcher("ab-me").matches());
assertTrue(Validator.NAME_CHARS.matcher("ab-me_.xatt._-com").matches());
-
// 7/22/2016
- assertTrue(Validator.INST_CHARS.matcher(
- "/!com.att.*/role/write").matches());
- assertTrue(Validator.INST_CHARS.matcher(
- ":!com.att.*:role:write").matches());
+ assertTrue(Validator.INST_CHARS.matcher("/!com.att.*/role/write").matches());
+ assertTrue(Validator.INST_CHARS.matcher(":!com.att.*:role:write").matches());
+
+ }
+
+ @Test
+ public void permNotOk() {
+
+ Result<PermDAO.Data> rpd = Result.err(1, "ERR_Security");
+
+ validator.perm(rpd);
+ assertTrue(validator.errs().equals("ERR_Security\n"));
+
+ }
+
+ @Test
+ public void permOkNull() {
+
+ Result rpd = Result.ok();
+
+ validator.perm(rpd);
+ assertTrue(validator.errs().equals("Perm Data is null.\n"));
+
+ }
+
+ @Test
+ public void roleOkNull() {
+
+ Result rrd = Result.ok();
+
+ validator.role(rrd);
+ assertTrue(validator.errs().equals("Role Data is null.\n"));
+ }
+
+ @Test
+ public void roleOk() {
+ RoleDAO.Data to = new RoleDAO.Data();
+ to.ns = "namespace";
+ to.name = "name";
+ to.description = "description";
+ Set<String> permissions = new HashSet<String>();
+ permissions.add("perm1");
+ to.perms = permissions;
+
+ Result<RoleDAO.Data> rrd = Result.ok(to);
+
+ validator.role(rrd);
+ assertTrue(
+ validator.errs().equals("Perm [perm1] in Role [namespace.name] is not correctly separated with '|'\n"));
+ }
+
+ @Test
+ public void roleNotOk() {
+
+ Result rrd = Result.err(1, "ERR_Security");
+ validator.role(rrd);
+ assertTrue(validator.errs().equals("ERR_Security\n"));
}
}