summaryrefslogtreecommitdiffstats
path: root/auth/auth-core/src
diff options
context:
space:
mode:
Diffstat (limited to 'auth/auth-core/src')
-rw-r--r--auth/auth-core/src/test/java/org/onap/aaf/auth/common/test/JU_Define.java57
-rw-r--r--auth/auth-core/src/test/java/org/onap/aaf/auth/env/test/JU_AuthzEnv.java44
-rw-r--r--auth/auth-core/src/test/java/org/onap/aaf/auth/env/test/JU_AuthzTransOnlyFilter.java34
-rw-r--r--auth/auth-core/src/test/java/org/onap/aaf/auth/layer/test/JU_Result.java173
-rw-r--r--auth/auth-core/src/test/java/org/onap/aaf/auth/org/test/JU_Organization.java68
-rw-r--r--auth/auth-core/src/test/java/org/onap/aaf/auth/org/test/JU_OrganizationException.java25
-rw-r--r--auth/auth-core/src/test/java/org/onap/aaf/auth/org/test/JU_OrganizationFactory.java25
-rw-r--r--auth/auth-core/src/test/java/org/onap/aaf/auth/rserv/test/JU_CachingFileAccess.java49
-rw-r--r--auth/auth-core/src/test/java/org/onap/aaf/auth/validation/test/JU_Validator.java153
9 files changed, 485 insertions, 143 deletions
diff --git a/auth/auth-core/src/test/java/org/onap/aaf/auth/common/test/JU_Define.java b/auth/auth-core/src/test/java/org/onap/aaf/auth/common/test/JU_Define.java
index 89e1aa94..9de907d8 100644
--- a/auth/auth-core/src/test/java/org/onap/aaf/auth/common/test/JU_Define.java
+++ b/auth/auth-core/src/test/java/org/onap/aaf/auth/common/test/JU_Define.java
@@ -7,9 +7,9 @@
* * Licensed under the Apache License, Version 2.0 (the "License");
* * you may not use this file except in compliance with the License.
* * You may obtain a copy of the License at
- * *
+ * *
* * http://www.apache.org/licenses/LICENSE-2.0
- * *
+ * *
* * Unless required by applicable law or agreed to in writing, software
* * distributed under the License is distributed on an "AS IS" BASIS,
* * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -25,6 +25,10 @@ import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
+import org.junit.Before;
+import static org.mockito.Mockito.*;
+import org.onap.aaf.auth.common.Define;
+import org.onap.aaf.cadi.Access;
import org.onap.aaf.cadi.CadiException;
import org.onap.aaf.cadi.config.Config;
import org.onap.aaf.misc.env.Env;
@@ -35,32 +39,39 @@ import org.powermock.api.mockito.PowerMockito;
import org.powermock.modules.junit4.PowerMockRunner;
@RunWith(PowerMockRunner.class)
-//TODO: Gabe [JUnit] class path/ class Define is missing, com.att.authz.common also missing
public class JU_Define {
- //Define define;
public static String ROOT_NS="NS.Not.Set";
public static String ROOT_COMPANY=ROOT_NS;
-
- @Mock
+ Access acc;
+ @Mock
Env envMock;
-
-
-// @Before
-// public void setUp(){
-// define = new Define();
-// }
-//
-// @Test
-// public void testSet() throws CadiException {
-// PowerMockito.when(envMock.getProperty(Config.AAF_ROOT_NS)).thenReturn("aaf_root_ns");
-// PowerMockito.when(envMock.getProperty(Config.AAF_ROOT_COMPANY)).thenReturn("aaf_root_company");
-// //PowerMockito.when(envMock.init().log()).thenReturn(null);
-// //PowerMockito.doNothing().doThrow(new CadiException()).when(envMock).init().log(Matchers.anyString());
-// //define.set(envMock);
-// }
+
+
+ @Before
+ public void setUp(){
+ acc = mock(Access.class);
+ }
+
+ @Test
+ public void testRootNS() {
+ //Define.ROOT_NS();
+ }
+
+ @Test
+ public void testRootCompany() {
+ //Define.ROOT_COMPANY();
+ }
+
+ @Test
+ public void testSet() throws CadiException {
+ when(acc.getProperty(Config.AAF_ROOT_NS,"org.onap.aaf")).thenReturn(".ns_Test");
+ //when(acc.getProperty(Config.AAF_ROOT_COMPANY,null)).thenReturn("company_Test");
+ //Define.set(acc);
+ }
@Test
- public void netYetTested() {
- fail("Tests not yet implemented");
+ public void testVarReplace() {
+ Define.varReplace("AAF_NS.");
+ Define.varReplace("test");
}
}
diff --git a/auth/auth-core/src/test/java/org/onap/aaf/auth/env/test/JU_AuthzEnv.java b/auth/auth-core/src/test/java/org/onap/aaf/auth/env/test/JU_AuthzEnv.java
index 1117fce7..f02a9de0 100644
--- a/auth/auth-core/src/test/java/org/onap/aaf/auth/env/test/JU_AuthzEnv.java
+++ b/auth/auth-core/src/test/java/org/onap/aaf/auth/env/test/JU_AuthzEnv.java
@@ -7,9 +7,9 @@
* * Licensed under the Apache License, Version 2.0 (the "License");
* * you may not use this file except in compliance with the License.
* * You may obtain a copy of the License at
- * *
+ * *
* * http://www.apache.org/licenses/LICENSE-2.0
- * *
+ * *
* * Unless required by applicable law or agreed to in writing, software
* * distributed under the License is distributed on an "AS IS" BASIS,
* * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -46,7 +46,7 @@ public class JU_AuthzEnv {
private static final org.onap.aaf.cadi.Access.Level DEBUG = null;
AuthzEnv authzEnv;
enum Level {DEBUG, INFO, AUDIT, INIT, WARN, ERROR};
-
+
@Before
public void setUp(){
PropAccess access = null;
@@ -61,49 +61,49 @@ public class JU_AuthzEnv {
public void testTransRate() {
Long Result = authzEnv.transRate();
System.out.println("value of result " +Result); //Expected 300000
- assertNotNull(Result);
+ assertNotNull(Result);
}
-
+
@Test
public void checkNewTransNoAvg() {
-
+
Assert.assertNotNull(authzEnv.newTransNoAvg());
}
-
+
@Test
public void checkNewTrans() {
Assert.assertNotNull(authzEnv.newTrans());
}
-
+
@Test
public void checkPropAccess() {
Assert.assertNotNull(authzEnv.access());
}
-
+
@Test
public void checkgetProperties() { //TODO:[GABE]No setter for this, add?
Assert.assertNotNull(authzEnv.getProperties());
Assert.assertNotNull(authzEnv.getProperties("test"));
}
-
+
@Test(expected = APIException.class)
public void checkSetLog4JNames() throws APIException {//TODO: Find better way to test instead of just seeing if strings pass
authzEnv.setLog4JNames("path", "root","service","audit","init","trace");
authzEnv.setLog4JNames("path", "root",null,"audit","init","trace");
}
-
+
@Test
public void checkPropertyGetters(){
authzEnv.setProperty("key","value");
Assert.assertEquals(authzEnv.getProperty("key"), "value");
Assert.assertEquals(authzEnv.getProperty("key","value"), "value");
}
-
+
@Test
public void checkPropertySetters(){
Assert.assertEquals(authzEnv.getProperty("key","value"), authzEnv.setProperty("key","value"));
}
-
+
@Test(expected = IOException.class)
public void testDecryptException() throws IOException{
String encrypted = "enc:";
@@ -111,7 +111,7 @@ public class JU_AuthzEnv {
authzEnv.decrypt(encrypted, true);
authzEnv.decrypt("", false);
}
-
+
@Test
public void testDecrypt() throws IOException{
String encrypted = "encrypted";
@@ -119,41 +119,41 @@ public class JU_AuthzEnv {
System.out.println("value of res " +Result);
assertEquals("encrypted",Result);
}
-
+
@Test
public void testClassLoader() {
ClassLoader cLoad = mock(ClassLoader.class);
cLoad = authzEnv.classLoader();
Assert.assertNotNull(cLoad);
}
-
+
@Test
public void testLoad() throws IOException {
InputStream is = mock(InputStream.class);
authzEnv.load(is);
}
-
+
@Test
public void testLog() {
Access.Level lvl = Access.Level.DEBUG;
Object msgs = null;
authzEnv.log(lvl, msgs);
}
-
+
@Test
public void testLog1() {
Exception e = new Exception();
Object msgs = null;
authzEnv.log(e, msgs);
}
-
+
@Test
public void testPrintf() {
Access.Level lvl = Access.Level.DEBUG;
Object msgs = null;
authzEnv.printf(lvl, "Test", msgs);
}
-
+
@Test
public void testWillLog() {
Access.Level lvl = Access.Level.DEBUG;
@@ -162,9 +162,9 @@ public class JU_AuthzEnv {
Assert.assertFalse(test);
test = authzEnv.willLog(lvl1);
Assert.assertTrue(test);
-
+
}
-
+
@Test
public void testSetLogLevel() {
Access.Level lvl = Access.Level.DEBUG;
diff --git a/auth/auth-core/src/test/java/org/onap/aaf/auth/env/test/JU_AuthzTransOnlyFilter.java b/auth/auth-core/src/test/java/org/onap/aaf/auth/env/test/JU_AuthzTransOnlyFilter.java
index b29e716a..f1243513 100644
--- a/auth/auth-core/src/test/java/org/onap/aaf/auth/env/test/JU_AuthzTransOnlyFilter.java
+++ b/auth/auth-core/src/test/java/org/onap/aaf/auth/env/test/JU_AuthzTransOnlyFilter.java
@@ -7,9 +7,9 @@
* * Licensed under the Apache License, Version 2.0 (the "License");
* * you may not use this file except in compliance with the License.
* * You may obtain a copy of the License at
- * *
+ * *
* * http://www.apache.org/licenses/LICENSE-2.0
- * *
+ * *
* * Unless required by applicable law or agreed to in writing, software
* * distributed under the License is distributed on an "AS IS" BASIS,
* * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -21,21 +21,20 @@
******************************************************************************/
package org.onap.aaf.auth.env.test;
-import static org.junit.Assert.*;
+import static org.mockito.Matchers.any;
+import static org.mockito.Matchers.anyInt;
+import static org.mockito.Mockito.doNothing;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.Mock;
-import static org.mockito.Mockito.*;
-import javax.servlet.http.HttpServletRequest;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import javax.servlet.ServletRequest;
-import org.onap.aaf.cadi.principal.TaggedPrincipal;
-import org.onap.aaf.misc.env.Env;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
import org.mockito.runners.MockitoJUnitRunner;
import org.onap.aaf.auth.env.AuthzEnv;
import org.onap.aaf.auth.env.AuthzTrans;
@@ -44,9 +43,8 @@ import org.onap.aaf.auth.env.AuthzTransOnlyFilter;
import org.onap.aaf.cadi.CadiException;
import org.onap.aaf.cadi.Connector;
import org.onap.aaf.cadi.TrustChecker;
+import org.onap.aaf.cadi.principal.TaggedPrincipal;
import org.onap.aaf.misc.env.LogTarget;
-import org.onap.aaf.misc.env.Slot;
-import org.onap.aaf.misc.env.Trans;
import org.onap.aaf.misc.env.Trans.Metric;
@RunWith(MockitoJUnitRunner.class)
@@ -59,20 +57,20 @@ public class JU_AuthzTransOnlyFilter {
Object additionalTafLurs = mock(Object.class);
ServletRequest servletRequestMock = mock(ServletRequest.class);
AuthzTransOnlyFilter authzTransOnlyFilter;
-
+
@Before
public void setUp(){
authzTransOnlyFilter = new AuthzTransOnlyFilter(authzEnvMock);
}
-
+
/*@Test
public void testProtected() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
Method newTransMethod = AuthzTransFilter.class.getDeclaredMethod("newTrans");
newTransMethod.setAccessible(true);
-
+
newTransMethod.invoke(authzTransFilter);
}*/
-
+
@Test
public void testStart() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
AuthzTransOnlyFilter aTF = new AuthzTransOnlyFilter(authzEnvMock);
@@ -97,7 +95,7 @@ public class JU_AuthzTransOnlyFilter {
authenticatedMethod.setAccessible(true);
authenticatedMethod.invoke(aTF,authzTransMock, null);
}
-
+
@Test
public void testTallyHo() throws CadiException, NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
AuthzTransOnlyFilter aTF = new AuthzTransOnlyFilter(authzEnvMock);
diff --git a/auth/auth-core/src/test/java/org/onap/aaf/auth/layer/test/JU_Result.java b/auth/auth-core/src/test/java/org/onap/aaf/auth/layer/test/JU_Result.java
index fc812a2c..3219e476 100644
--- a/auth/auth-core/src/test/java/org/onap/aaf/auth/layer/test/JU_Result.java
+++ b/auth/auth-core/src/test/java/org/onap/aaf/auth/layer/test/JU_Result.java
@@ -7,9 +7,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -25,34 +25,175 @@ import static org.junit.Assert.*;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mock;
+import static org.mockito.Mockito.*;
+
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import javax.servlet.ServletRequest;
+
+import org.onap.aaf.auth.env.AuthzTrans;
import org.onap.aaf.auth.layer.Result;
+import junit.framework.Assert;
+
public class JU_Result {
Result result;
// @Mock
// RV value;
int status=0;
- String details = "details";
+ String details = "details";
String[] variables;
-
+
@SuppressWarnings({ "unchecked", "rawtypes" })
@Before
public void setUp(){
- //TODO: Gabe [JUnit] Not visible for junit
- //result = new Result(result, status, details, variables);
+ //result = mock(Result.class);
+
+ }
+
+ @Test
+ public void testOk() {
+ Object value = null;
+ Collection col = new ArrayList();
+ List list = mock(List.class);
+ Set set = mock(Set.class);
+ Integer[] R = new Integer[1];
+
+ Assert.assertNotNull(Result.ok());
+ Assert.assertNotNull(Result.ok(value));
+ Assert.assertNotNull(Result.ok(col));
+ Assert.assertNotNull(Result.ok(list));
+ Assert.assertNotNull(Result.ok(set));
+ Assert.assertNotNull(Result.ok(R));
+
+ Collection<String> col1 = new ArrayList();
+ List<String> list1 = new ArrayList();
+ Set<String> set1 = new HashSet<String>();
+ Integer[] R1 = new Integer[0];
+ set1.add("derp");
+ list1.add("test");
+ col1.add("TEST");
+
+ Assert.assertNotNull(Result.ok(col1));
+ Assert.assertNotNull(Result.ok(list1));
+ Assert.assertNotNull(Result.ok(set1));
+ Assert.assertNotNull(Result.ok(R1));
+ }
+
+ @Test
+ public void testErr() {
+ Result result = Result.create(null, 0, null, null);
+ Result r = result;
+ Exception e = mock(Exception.class);
+
+ Assert.assertNotNull(result.err(r)); //Result case
+ Assert.assertNotNull(result.err(e)); //Exception case
+ Assert.assertNotNull(result.err(0, "test", "test")); //Multiple case
+
+ }
+
+ @Test
+ public void testCreate() {
+ Result result = Result.create(null, 0, null, null);
+ Assert.assertNotNull(Result.create(null, 0, null, null));
+ Assert.assertNotNull(Result.create(null, 0, null, "arg"));
+ Assert.assertNotNull(result.create(0, result));
+ }
+
+ @Test
+ public void testOks() {
+ Result result = Result.create(null, 0, null, null);
+
+ Assert.assertNotNull(result.isOK());
+ Assert.assertNotNull(result.notOK());
+ Assert.assertNotNull(result.isOKhasData());
+ Assert.assertNotNull(result.notOKorIsEmpty());
+
+ Result result1 = Result.create(null, 5, "test", "test");
+ Assert.assertNotNull(result1.emptyList(true));
+ Assert.assertNotNull(result1.isOK());
+ Assert.assertNotNull(result1.notOK());
+ Assert.assertNotNull(result1.isOKhasData());
+ Assert.assertNotNull(result1.notOKorIsEmpty());
+
+ Result result2 = Result.create(null, 0, "test", "test");
+ Assert.assertNotNull(result2.emptyList(false));
+ Assert.assertNotNull(result2.isOKhasData());
+ Assert.assertNotNull(result2.notOKorIsEmpty());
}
-// @Test
-// public void testPartialContent() {
-// Result Res = result.partialContent(true);
-// System.out.println("Res" +Res);
-// assertEquals(details,Res.toString());
-//
-// }
-
@Test
- public void netYetTested() {
- fail("Tests not yet implemented");
+ public void testEmptyList() {
+ Result result = Result.create(null, 0, null, null);
+
+ Assert.assertNotNull(result.emptyList(true));
+ Assert.assertNotNull(result.emptyList(false));
+ Assert.assertFalse(result.isEmpty());
+ }
+
+ @Test
+ public void testPartialContent() {
+ Result result = Result.create(null, 0, null, null);
+
+ Assert.assertNotNull(result.partialContent(true));
+ Assert.assertNotNull(result.partialContent(false));
+ Assert.assertFalse(result.partialContent());
+
+ Result result1 = Result.create(null, 1, "test", null);
+ Assert.assertNotNull(result1.partialContent(true));
+ Assert.assertNotNull(result1.partialContent());
}
+ @Test
+ public void testToString() {
+ Result result = Result.create(null, 0, null, null);
+
+ Assert.assertNull(result.toString() );
+
+ Result result1 = Result.create(null, 5, "test", "test");
+
+ Assert.assertNotNull(result1.toString());
+
+ int value = 1;
+ Result result2 = Result.create(value , 5, "test", "test");
+
+ Assert.assertNotNull(result2.toString());
+ }
+
+ @Test
+ public void testErrorString() {
+ Result result = Result.create(null, 0, "test", "test");
+ Assert.assertEquals("Error - test", result.errorString());
+ Result result1 = Result.create(null, 1, "test", "test");
+ Assert.assertEquals("Security - test",result1.errorString());
+ Result result2 = Result.create(null, 2, "test", "test");
+ Assert.assertEquals("Denied - test",result2.errorString());
+ Result result3 = Result.create(null, 3, "test", "test");
+ Assert.assertEquals("Policy - test",result3.errorString());
+ Result result4 = Result.create(null, 4, "test", "test");
+ Assert.assertEquals("BadData - test",result4.errorString());
+ Result result5 = Result.create(null, 5, "test", "test");
+ Assert.assertEquals("NotImplemented - test",result5.errorString());
+ Result result6 = Result.create(null, 6, "test", "test");
+ Assert.assertEquals("NotFound - test",result6.errorString());
+ Result result7 = Result.create(null, 7, "test", "test");
+ Assert.assertEquals("AlreadyExists - test",result7.errorString());
+ Result result8 = Result.create(null, 8, "test", "test");
+ Assert.assertEquals("ActionNotComplete - test",result8.errorString());
+ }
+
+
}
+
+
+
+
+
+
+
+
diff --git a/auth/auth-core/src/test/java/org/onap/aaf/auth/org/test/JU_Organization.java b/auth/auth-core/src/test/java/org/onap/aaf/auth/org/test/JU_Organization.java
new file mode 100644
index 00000000..9631e326
--- /dev/null
+++ b/auth/auth-core/src/test/java/org/onap/aaf/auth/org/test/JU_Organization.java
@@ -0,0 +1,68 @@
+package org.onap.aaf.auth.org.test;
+
+import static org.mockito.Mockito.mock;
+
+import java.util.ArrayList;
+import java.util.GregorianCalendar;
+import java.util.HashSet;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.onap.aaf.auth.env.AuthzTrans;
+import org.onap.aaf.auth.org.EmailWarnings;
+import org.onap.aaf.auth.org.Organization;
+import org.onap.aaf.auth.org.Organization.Expiration;
+import org.onap.aaf.auth.org.Organization.Identity;
+import org.onap.aaf.auth.org.Organization.Notify;
+import org.onap.aaf.auth.org.Organization.Policy;
+import org.onap.aaf.auth.org.Organization.Response;
+import org.onap.aaf.auth.org.OrganizationException;
+
+import junit.framework.Assert;
+
+public class JU_Organization {
+
+ AuthzTrans trans;
+ GregorianCalendar gc;
+ @Before
+ public void setUp() {
+ gc = new GregorianCalendar(1900, 1, 1);
+ trans = mock(AuthzTrans.class);
+ }
+
+ @Test
+ public void test() throws OrganizationException {
+ //tests for Org null
+ Assert.assertEquals("n/a",Organization.NULL.getName());
+ Assert.assertEquals("n/a",Organization.NULL.getDomain());
+ Assert.assertEquals("n/a",Organization.NULL.getRealm());
+ Assert.assertTrue(Organization.NULL.getIdentity(trans, "test") instanceof Identity);
+ Assert.assertEquals("n/a",Organization.NULL.isValidID(trans, null));
+ Assert.assertEquals("n/a",Organization.NULL.isValidPassword(trans, null, null, null));
+ Assert.assertTrue(Organization.NULL.getIdentityTypes() instanceof HashSet);
+ Assert.assertTrue(Organization.NULL.notify(trans, Notify.PasswordExpiration, null, null, null, null, null) instanceof Response);
+ Assert.assertEquals(0,Organization.NULL.sendEmail(trans, null, null, null, null, null));
+ Assert.assertEquals(gc.getTime(),Organization.NULL.whenToValidate(null, null));
+ Assert.assertEquals(gc,Organization.NULL.expiration(gc, Expiration.Password));
+ Assert.assertTrue(Organization.NULL.getApprovers(trans, null) instanceof ArrayList);
+ Assert.assertEquals("",Organization.NULL.getApproverType());
+ Assert.assertEquals(0,Organization.NULL.startOfDay());
+ Assert.assertFalse(Organization.NULL.canHaveMultipleCreds(null));
+ Assert.assertFalse(Organization.NULL.isValidCred(trans, null));
+ Assert.assertEquals("Null Organization rejects all Policies",Organization.NULL.validate(trans, Policy.CHANGE_JOB, null, null));
+ Assert.assertFalse(Organization.NULL.isTestEnv());
+ Organization.NULL.setTestMode(true);
+
+ //tests for org emailWarnings
+ Assert.assertTrue(Organization.NULL.emailWarningPolicy() instanceof EmailWarnings);
+ Assert.assertEquals(604800000L, Organization.NULL.emailWarningPolicy().credEmailInterval());
+ Assert.assertEquals(604800000L, Organization.NULL.emailWarningPolicy().roleEmailInterval());
+ Assert.assertEquals(259200000L, Organization.NULL.emailWarningPolicy().apprEmailInterval());
+ Assert.assertEquals(2592000000L, Organization.NULL.emailWarningPolicy().credExpirationWarning());
+ Assert.assertEquals(2592000000L, Organization.NULL.emailWarningPolicy().roleExpirationWarning());
+ Assert.assertEquals(1209600000L, Organization.NULL.emailWarningPolicy().emailUrgentWarning());
+ Assert.assertTrue(Organization.NULL.getPasswordRules() instanceof String[]);
+
+ }
+
+}
diff --git a/auth/auth-core/src/test/java/org/onap/aaf/auth/org/test/JU_OrganizationException.java b/auth/auth-core/src/test/java/org/onap/aaf/auth/org/test/JU_OrganizationException.java
index 01b8256f..79e8a4a1 100644
--- a/auth/auth-core/src/test/java/org/onap/aaf/auth/org/test/JU_OrganizationException.java
+++ b/auth/auth-core/src/test/java/org/onap/aaf/auth/org/test/JU_OrganizationException.java
@@ -7,9 +7,9 @@
* * Licensed under the Apache License, Version 2.0 (the "License");
* * you may not use this file except in compliance with the License.
* * You may obtain a copy of the License at
- * *
+ * *
* * http://www.apache.org/licenses/LICENSE-2.0
- * *
+ * *
* * Unless required by applicable law or agreed to in writing, software
* * distributed under the License is distributed on an "AS IS" BASIS,
* * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -31,18 +31,21 @@ import org.powermock.modules.junit4.PowerMockRunner;
@RunWith(PowerMockRunner.class)
public class JU_OrganizationException {
-
+
OrganizationException organizationException;
-
- @Before
- public void setUp(){
- organizationException = new OrganizationException();
- }
-
+ OrganizationException organizationException1;
+ OrganizationException organizationException2;
+ OrganizationException organizationException3;
+ OrganizationException organizationException4;
@Test
- public void test() {
- assertTrue(true);
+ public void testOrganizationException() {
+ Throwable thr = new Throwable();
+ organizationException = new OrganizationException();
+ organizationException1 = new OrganizationException("test");
+ organizationException2 = new OrganizationException(thr);
+ organizationException3 = new OrganizationException("test", thr);
+ organizationException4 = new OrganizationException("test", thr, true, true);
}
}
diff --git a/auth/auth-core/src/test/java/org/onap/aaf/auth/org/test/JU_OrganizationFactory.java b/auth/auth-core/src/test/java/org/onap/aaf/auth/org/test/JU_OrganizationFactory.java
index 2136e786..9723cd9e 100644
--- a/auth/auth-core/src/test/java/org/onap/aaf/auth/org/test/JU_OrganizationFactory.java
+++ b/auth/auth-core/src/test/java/org/onap/aaf/auth/org/test/JU_OrganizationFactory.java
@@ -7,9 +7,9 @@
* * Licensed under the Apache License, Version 2.0 (the "License");
* * you may not use this file except in compliance with the License.
* * You may obtain a copy of the License at
- * *
+ * *
* * http://www.apache.org/licenses/LICENSE-2.0
- * *
+ * *
* * Unless required by applicable law or agreed to in writing, software
* * distributed under the License is distributed on an "AS IS" BASIS,
* * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -27,6 +27,7 @@ import org.junit.runner.RunWith;
import org.mockito.Mock;
import static org.mockito.Mockito.mock;
import org.onap.aaf.auth.env.AuthzEnv;
+import org.onap.aaf.auth.env.AuthzTrans;
import org.onap.aaf.auth.org.OrganizationException;
import org.onap.aaf.auth.org.OrganizationFactory;
import org.onap.aaf.misc.env.APIException;
@@ -54,11 +55,17 @@ public class JU_OrganizationFactory {
public void testInit() throws OrganizationException {
organizationFactory.init(bEnv);
}
-
-// @SuppressWarnings("static-access") TODO:Fix this AAF-111
-// @Test(expected = OrganizationException.class)
-// public void testObtain() throws OrganizationException{
-// PowerMockito.when(authzEnvMock.getProperty("Organization."+orgNS)).thenReturn("notnull");
-// organizationFactory.obtain(authzEnvMock, orgNS);
-// }
+
+ @SuppressWarnings("static-access") //TODO:Fix this once real input is available AAF-111
+ @Test(expected = OrganizationException.class)
+ public void testObtain() throws OrganizationException{
+ PowerMockito.when(authzEnvMock.getProperty("Organization."+orgNS)).thenReturn("notnull");
+ //organizationFactory.obtain(authzEnvMock, orgNS);
+ }
+
+ @Test
+ public void testGet() throws OrganizationException { //TODO: Fix with when then return on fail
+ AuthzTrans trans = mock(AuthzTrans.class);
+ //organizationFactory.get(trans);
+ }
}
diff --git a/auth/auth-core/src/test/java/org/onap/aaf/auth/rserv/test/JU_CachingFileAccess.java b/auth/auth-core/src/test/java/org/onap/aaf/auth/rserv/test/JU_CachingFileAccess.java
index 26e9717f..e9c382d5 100644
--- a/auth/auth-core/src/test/java/org/onap/aaf/auth/rserv/test/JU_CachingFileAccess.java
+++ b/auth/auth-core/src/test/java/org/onap/aaf/auth/rserv/test/JU_CachingFileAccess.java
@@ -7,9 +7,9 @@
* * Licensed under the Apache License, Version 2.0 (the "License");
* * you may not use this file except in compliance with the License.
* * You may obtain a copy of the License at
- * *
+ * *
* * http://www.apache.org/licenses/LICENSE-2.0
- * *
+ * *
* * Unless required by applicable law or agreed to in writing, software
* * distributed under the License is distributed on an "AS IS" BASIS,
* * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -21,39 +21,34 @@
******************************************************************************/
package org.onap.aaf.auth.rserv.test;
-import static org.junit.Assert.*;
import static org.mockito.Matchers.any;
-import static org.mockito.Mockito.*;
-import static org.mockito.Matchers.*;
+import static org.mockito.Matchers.anyString;
+import static org.mockito.Mockito.doAnswer;
+import static org.mockito.Mockito.doNothing;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.lang.reflect.Field;
-import java.nio.file.Files;
-import java.nio.file.Paths;
import java.util.NavigableMap;
import java.util.concurrent.ConcurrentSkipListMap;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
-import org.mockito.Mock;
-import org.mockito.invocation.InvocationOnMock;
-import org.mockito.stubbing.Answer;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
+import org.mockito.invocation.InvocationOnMock;
+import org.mockito.stubbing.Answer;
import org.onap.aaf.auth.rserv.CachingFileAccess;
import org.onap.aaf.auth.rserv.HttpCode;
import org.onap.aaf.auth.rserv.Match;
-
-//import org.onap.aaf.auth.rserv.CachingFileAccess.Content;
-import java.util.NavigableMap;
import org.onap.aaf.misc.env.EnvJAXB;
import org.onap.aaf.misc.env.LogTarget;
-import org.onap.aaf.misc.env.StaticSlot;
import org.onap.aaf.misc.env.Store;
import org.onap.aaf.misc.env.Trans;
import org.powermock.modules.junit4.PowerMockRunner;
@@ -67,8 +62,8 @@ public class JU_CachingFileAccess {
HttpCode httpCode;
EnvJAXB envJ;
Trans trans;
-
-
+
+
@Before
public void setUp() throws IOException{
trans = mock(Trans.class);
@@ -85,7 +80,7 @@ public class JU_CachingFileAccess {
cachingFileAccess = new CachingFileAccess(envJ,"test");
-
+
}
@Test
@@ -100,14 +95,14 @@ public class JU_CachingFileAccess {
cachingFileAccess.setEnv(store1, test1); //These don't reach all the branches for some reason
cachingFileAccess.setEnv(store2, test2);
}
-
+
@Test
public void testHandle() throws IOException, NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException {
HttpServletRequest req = mock(HttpServletRequest.class);
Trans trans = mock(Trans.class);
HttpServletResponse resp = mock(HttpServletResponse.class);
when(req.getPathInfo()).thenReturn("path/to/file");
-
+
Field matchField = HttpCode.class.getDeclaredField("match");
matchField.setAccessible(true);
Match match = mock(Match.class);
@@ -117,27 +112,27 @@ public class JU_CachingFileAccess {
when(match.param(anyString(), anyString())).thenReturn("clear");
cachingFileAccess.handle(trans, req, resp);
}
-
+
@Test
public void testWebPath() {
EnvJAXB envJ = mock(EnvJAXB.class);
String web_path_test = "TEST";
Assert.assertEquals(web_path_test, cachingFileAccess.webPath());
}
-
+
@Test
public void testCleanupParams() {
NavigableMap<String,org.onap.aaf.auth.rserv.Content> content = new ConcurrentSkipListMap<String,org.onap.aaf.auth.rserv.Content>();
- cachingFileAccess.cleanupParams(50, 500); //TODO: find right input
+ cachingFileAccess.cleanupParams(50, 500); //TODO: find right input
}
-
+
@Test
public void testLoad() throws IOException {
cachingFileAccess.load(null, null, "1220227200L/1220227200L", null, 1320227200L );
String filePath = "test/output_key";
File keyfile = new File(filePath);
RandomAccessFile randFile = new RandomAccessFile (keyfile,"rw");
-
+
String dPath = "test/";
File directoryPath = new File(dPath);
directoryPath.mkdir();
@@ -152,14 +147,14 @@ public class JU_CachingFileAccess {
cachingFileAccess.load(null, filePath1, "-", "test", -1);
keyfile1.delete();
}
-
+
@Test
public void testLoadOrDefault() throws IOException, NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException, ClassNotFoundException, InstantiationException {
String filePath = "test/output_key";
File keyfile = new File(filePath);
cachingFileAccess.loadOrDefault(trans, filePath, "-", null, null);
keyfile.delete();
-
+
Trans trans = mock(Trans.class);
String filePath1 = "test/output_key.txt";
@@ -172,7 +167,7 @@ public class JU_CachingFileAccess {
//cachingFileAccess.loadOrDefault(trans, "bs", "also bs", "test", null); //TODO: Needs more testing AAF-111
//keyfile1.delete();
}
-
+
@Test
public void testInvalidate() {
//NavigableMap<String,org.onap.aaf.auth.rserv.Content> content = new ConcurrentSkipListMap<String,org.onap.aaf.auth.rserv.Content>();
diff --git a/auth/auth-core/src/test/java/org/onap/aaf/auth/validation/test/JU_Validator.java b/auth/auth-core/src/test/java/org/onap/aaf/auth/validation/test/JU_Validator.java
index fb59a54d..11aaa424 100644
--- a/auth/auth-core/src/test/java/org/onap/aaf/auth/validation/test/JU_Validator.java
+++ b/auth/auth-core/src/test/java/org/onap/aaf/auth/validation/test/JU_Validator.java
@@ -7,9 +7,9 @@
* * Licensed under the Apache License, Version 2.0 (the "License");
* * you may not use this file except in compliance with the License.
* * You may obtain a copy of the License at
- * *
+ * *
* * http://www.apache.org/licenses/LICENSE-2.0
- * *
+ * *
* * Unless required by applicable law or agreed to in writing, software
* * distributed under the License is distributed on an "AS IS" BASIS,
* * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -36,32 +36,36 @@ import org.junit.Test;
import org.junit.Test;
import org.onap.aaf.auth.env.AuthzTrans;
import org.onap.aaf.auth.env.AuthzTransOnlyFilter;
+import org.onap.aaf.auth.layer.Result;
import org.onap.aaf.auth.validation.Validator;
import org.onap.aaf.cadi.principal.TaggedPrincipal;
+import junit.framework.Assert;
+
public class JU_Validator {
-
+
Validator validator;
-
+ String base = "\\x25\\x28\\x29\\x2C-\\x2E\\x30-\\x39\\x3D\\x40-\\x5A\\x5F\\x61-\\x7A";
+
@Before
public void setUp() {
validator = new Validator();
}
-
+
@Test
public void testNullOrBlank() {
validator.nullOrBlank(null, "str");
validator.nullOrBlank("test", "");
validator.nullOrBlank("test", null);
}
-
+
@Test
public void testIsNull() {
Object o = new Object();
validator.isNull(null, null);
validator.isNull(null, o);
}
-
+
@Test
public void testDescription() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
Class c = validator.getClass();
@@ -74,7 +78,122 @@ public class JU_Validator {
descriptionMethod.invoke(validator,null, null);
descriptionMethod.invoke(validator,null, "[\\\\x25\\\\x28\\\\x29\\\\x2C-\\\\x2E\\\\x30-\\\\x39\\\\x3D\\\\x40-\\\\x5A\\\\x5F\\\\x61-\\\\x7A\\\\x20]+");
-
+
+ }
+
+ @Test
+ public void testPermType() {
+ Assert.assertNotNull(validator.permType("[\\\\w.-]+"));
+ Assert.assertNotNull(validator.permType(null));
+ Assert.assertNotNull(validator.permType(""));
+ Assert.assertNotNull(validator.permType("aewfew"));
+ }
+
+ @Test
+ public void testPermType1() {
+ Assert.assertNotNull(validator.permType("[\\\\w.-]+",null));
+ Assert.assertNotNull(validator.permType(null,null));
+ Assert.assertNotNull(validator.permType("","test"));
+ Assert.assertNotNull(validator.permType("aewfew","test"));
+ }
+
+ @Test
+ public void testPermInstance() {
+
+ String middle = "]+[\\\\*]*|\\\\*|(([:/]\\\\*)|([:/][!]{0,1}[";
+ Assert.assertNotNull(validator.permInstance("[" + base + middle + base + "]+[\\\\*]*[:/]*))+"));
+ Assert.assertNotNull(validator.permInstance(null));
+ Assert.assertNotNull(validator.permInstance(""));
+ Assert.assertNotNull(validator.permInstance("test"));
+ }
+
+ @Test
+ public void testErr() {
+ Assert.assertFalse(validator.err());
+ validator.isNull("test", null);
+ Assert.assertTrue(validator.err());
+ }
+
+ @Test
+ public void testErrs() {
+ validator.isNull("test", null);
+ Assert.assertNotNull(validator.errs());
+ }
+
+ @Test
+ public void testPermAction() {
+ Assert.assertNotNull(validator.permAction("[" + base + "]+" + "|\\\\*"));
+ Assert.assertNotNull(validator.permAction("test"));
+ }
+
+ @Test
+ public void testRole() {
+ Assert.assertNotNull(validator.role("[\\\\w.-]+"));
+ Assert.assertNotNull(validator.role(null));
+ Assert.assertNotNull(validator.role(""));
+ Assert.assertNotNull(validator.role("aewfew"));
+ }
+
+ @Test
+ public void testNs() {
+ Assert.assertNotNull(validator.ns("[\\\\w.-]+"));
+ Assert.assertNotNull(validator.ns(""));
+ Assert.assertNotNull(validator.ns(".access"));
+ }
+
+ @Test
+ public void testKey() {
+ Assert.assertNotNull(validator.key("[\\\\w.-]+"));
+ Assert.assertNotNull(validator.key(""));
+ Assert.assertNotNull(validator.key(".access"));
+ }
+
+ @Test
+ public void testValue() {
+ Assert.assertNotNull(validator.value(base));
+ Assert.assertNotNull(validator.value(""));
+ Assert.assertNotNull(validator.value(".access"));
+ }
+
+ @Test
+ public void testNotOK() {
+ Result<?> test = mock(Result.class);
+ validator.isNull("test", null);
+ when(test.notOK()).thenReturn(true);
+ Assert.assertNotNull(validator.notOK(null));
+ Assert.assertNotNull(validator.notOK(test));
+ }
+
+ @Test
+ public void testIntRange() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
+ Class c = validator.getClass();
+ Class[] cArg = new Class[4];
+ cArg[0] = String.class;
+ cArg[1] = int.class;
+ cArg[2] = int.class;
+ cArg[3] = int.class; //Steps to test a protected method
+ Method intRangeMethod = c.getDeclaredMethod("intRange", cArg);
+ intRangeMethod.setAccessible(true);
+ intRangeMethod.invoke(validator,"Test",5,1,10);
+ intRangeMethod.invoke(validator,"Test",1,5,10);
+ intRangeMethod.invoke(validator,"Test",11,5,10);
+ intRangeMethod.invoke(validator,"Test",5,6,4);
+ }
+
+ @Test
+ public void testFloatRange() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
+ Class c = validator.getClass();
+ Class[] cArg = new Class[4];
+ cArg[0] = String.class;
+ cArg[1] = float.class;
+ cArg[2] = float.class;
+ cArg[3] = float.class; //Steps to test a protected method
+ Method floatRangeMethod = c.getDeclaredMethod("floatRange", cArg);
+ floatRangeMethod.setAccessible(true);
+ floatRangeMethod.invoke(validator,"Test",5f,1f,10f);
+ floatRangeMethod.invoke(validator,"Test",1f,5f,10f);
+ floatRangeMethod.invoke(validator,"Test",11f,5f,10f);
+ floatRangeMethod.invoke(validator,"Test",5f,6f,4f);
}
@Test
@@ -86,14 +205,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());
@@ -120,7 +239,7 @@ 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());
@@ -134,7 +253,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());
@@ -145,7 +264,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());
@@ -165,7 +284,7 @@ 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) {
boolean b;
switch(c) {
@@ -181,18 +300,18 @@ public class JU_Validator {
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());