summaryrefslogtreecommitdiffstats
path: root/cadi
diff options
context:
space:
mode:
Diffstat (limited to 'cadi')
-rw-r--r--cadi/cass/pom.xml119
-rw-r--r--cadi/core/src/test/java/org/onap/aaf/cadi/test/JU_AES.java374
-rw-r--r--cadi/core/src/test/java/org/onap/aaf/cadi/test/JU_CadiExceptionTest.java121
-rw-r--r--cadi/core/src/test/java/org/onap/aaf/cadi/test/JU_CadiWrapTest.java155
-rw-r--r--cadi/core/src/test/java/org/onap/aaf/cadi/test/config/JU_MultiGet.java68
-rw-r--r--cadi/core/src/test/java/org/onap/aaf/cadi/test/config/JU_SecurityInfoC.java109
-rw-r--r--cadi/core/src/test/java/org/onap/aaf/cadi/test/util/JU_UserChainManip.java57
7 files changed, 457 insertions, 546 deletions
diff --git a/cadi/cass/pom.xml b/cadi/cass/pom.xml
index e40827e2..ae4d06af 100644
--- a/cadi/cass/pom.xml
+++ b/cadi/cass/pom.xml
@@ -129,69 +129,64 @@
</configuration>
</plugin>
<plugin>
- <groupId>org.jacoco</groupId>
- <artifactId>jacoco-maven-plugin</artifactId>
- <version>${jacoco.version}</version>
- <configuration>
- <excludes>
- <exclude>**/gen/**</exclude>
- <exclude>**/generated-sources/**</exclude>
- <exclude>**/yang-gen/**</exclude>
- <exclude>**/pax/**</exclude>
- </excludes>
- </configuration>
- <executions>
-
- <execution>
- <id>pre-unit-test</id>
- <goals>
- <goal>prepare-agent</goal>
- </goals>
- <configuration>
- <destFile>${project.build.directory}/code-coverage/jacoco-ut.exec</destFile>
- <propertyName>surefireArgLine</propertyName>
- </configuration>
- </execution>
-
-
- <execution>
- <id>post-unit-test</id>
- <phase>test</phase>
- <goals>
- <goal>report</goal>
- </goals>
- <configuration>
- <dataFile>${project.build.directory}/code-coverage/jacoco-ut.exec</dataFile>
- <outputDirectory>${project.reporting.outputDirectory}/jacoco-ut</outputDirectory>
- </configuration>
- </execution>
- <execution>
- <id>pre-integration-test</id>
- <phase>pre-integration-test</phase>
- <goals>
- <goal>prepare-agent</goal>
- </goals>
- <configuration>
- <destFile>${project.build.directory}/code-coverage/jacoco-it.exec</destFile>
-
- <propertyName>failsafeArgLine</propertyName>
- </configuration>
- </execution>
+ <groupId>org.jacoco</groupId>
+ <artifactId>jacoco-maven-plugin</artifactId>
+ <version>${jacoco.version}</version>
+ <configuration>
+ <excludes>
+ <exclude>**/gen/**</exclude>
+ <exclude>**/generated-sources/**</exclude>
+ <exclude>**/yang-gen/**</exclude>
+ <exclude>**/pax/**</exclude>
+ </excludes>
+ </configuration>
+ <executions>
+ <execution>
+ <id>pre-unit-test</id>
+ <goals>
+ <goal>prepare-agent</goal>
+ </goals>
+ <configuration>
+ <destFile>${project.build.directory}/code-coverage/jacoco-ut.exec</destFile>
+ <propertyName>surefireArgLine</propertyName>
+ </configuration>
+ </execution>
+ <execution>
+ <id>post-unit-test</id>
+ <phase>test</phase>
+ <goals>
+ <goal>report</goal>
+ </goals>
+ <configuration>
+ <dataFile>${project.build.directory}/code-coverage/jacoco-ut.exec</dataFile>
+ <outputDirectory>${project.reporting.outputDirectory}/jacoco-ut</outputDirectory>
+ </configuration>
+ </execution>
+ <execution>
+ <id>pre-integration-test</id>
+ <phase>pre-integration-test</phase>
+ <goals>
+ <goal>prepare-agent</goal>
+ </goals>
+ <configuration>
+ <destFile>${project.build.directory}/code-coverage/jacoco-it.exec</destFile>
-
- <execution>
- <id>post-integration-test</id>
- <phase>post-integration-test</phase>
- <goals>
- <goal>report</goal>
- </goals>
- <configuration>
- <dataFile>${project.build.directory}/code-coverage/jacoco-it.exec</dataFile>
- <outputDirectory>${project.reporting.outputDirectory}/jacoco-it</outputDirectory>
- </configuration>
- </execution>
- </executions>
- </plugin>
+ <propertyName>failsafeArgLine</propertyName>
+ </configuration>
+ </execution>
+ <execution>
+ <id>post-integration-test</id>
+ <phase>post-integration-test</phase>
+ <goals>
+ <goal>report</goal>
+ </goals>
+ <configuration>
+ <dataFile>${project.build.directory}/code-coverage/jacoco-it.exec</dataFile>
+ <outputDirectory>${project.reporting.outputDirectory}/jacoco-it</outputDirectory>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
</plugins>
</build>
diff --git a/cadi/core/src/test/java/org/onap/aaf/cadi/test/JU_AES.java b/cadi/core/src/test/java/org/onap/aaf/cadi/test/JU_AES.java
index 4fb92429..fc960be8 100644
--- a/cadi/core/src/test/java/org/onap/aaf/cadi/test/JU_AES.java
+++ b/cadi/core/src/test/java/org/onap/aaf/cadi/test/JU_AES.java
@@ -1,180 +1,194 @@
-/*******************************************************************************
- * ============LICENSE_START====================================================
- * * org.onap.aaf
- * * ===========================================================================
- * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
- * * ===========================================================================
- * * 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.
- * * See the License for the specific language governing permissions and
- * * limitations under the License.
- * * ============LICENSE_END====================================================
- * *
- * *
- ******************************************************************************/
-package org.onap.aaf.cadi.test;
-
-import static org.junit.Assert.*;
-
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.File;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.lang.reflect.Field;
-import java.nio.file.Files;
-import java.nio.file.Paths;
-
-import javax.crypto.CipherInputStream;
-import javax.crypto.CipherOutputStream;
-import javax.crypto.SecretKey;
-
-import org.junit.Test;
-import org.onap.aaf.cadi.AES;
-import org.onap.aaf.cadi.CadiException;
-import org.onap.aaf.cadi.Symm;
-import org.junit.Before;
-
-public class JU_AES {
- private AES aes;
- private ByteArrayInputStream baisEncrypt;
- private ByteArrayInputStream baisDecrypt;
- private ByteArrayOutputStream baosEncrypt;
- private ByteArrayOutputStream baosDecrypt;
-
- @Before
- public void setup() throws Exception {
- byte[] keyBytes = new byte[AES.AES_KEY_SIZE/8];
- char[] codeset = Symm.base64.codeset;
- int offset = (Math.abs(codeset[0])+47)%(codeset.length-keyBytes.length);
- for(int i=0;i<keyBytes.length;++i) {
- keyBytes[i] = (byte)codeset[i+offset];
- }
- aes = new AES(keyBytes,0,keyBytes.length);
- }
-
- @Test
- public void newKeyTest() throws Exception {
- SecretKey secretKey = AES.newKey();
- assertEquals(secretKey.getAlgorithm(), AES.class.getSimpleName());
- }
-
- @Test
- public void encryptDecrpytFromBytes() throws Exception {
- String orig = "I'm a password, really";
- byte[] encrypted = aes.encrypt(orig.getBytes());
- byte[] decrypted = aes.decrypt(encrypted);
- assertEquals(orig, new String(decrypted));
-
- Field aeskeySpec_field = AES.class.getDeclaredField("aeskeySpec");
- aeskeySpec_field.setAccessible(true);
- aeskeySpec_field.set(aes, null);
-
- try {
- aes.encrypt(orig.getBytes());
- fail("Should have thrown an exception");
- } catch (CadiException e) {
- }
- try {
- aes.decrypt(encrypted);
- fail("Should have thrown an exception");
- } catch (CadiException e) {
- }
- }
-
- @Test
- public void saveToFileTest() throws Exception {
- String filePath = "test/output_key";
- File keyfile = new File(filePath);
- aes.save(keyfile);
- assertTrue(Files.isReadable(Paths.get(filePath)));
- assertFalse(Files.isWritable(Paths.get(filePath)));
- assertFalse(Files.isExecutable(Paths.get(filePath)));
- keyfile.delete();
- }
-
- @Test
- public void encryptDecryptFromInputStream() throws Exception {
- String orig = "I'm a password, really";
- byte[] b64encrypted;
- String output;
-
- CipherInputStream cisEncrypt;
- CipherInputStream cisDecrypt;
-
- // Test CipherInputStream
- baisEncrypt = new ByteArrayInputStream(orig.getBytes());
- cisEncrypt = aes.inputStream(baisEncrypt, true);
- baosEncrypt = new ByteArrayOutputStream();
- transferFromInputStreamToOutputStream(cisEncrypt, baosEncrypt);
- cisEncrypt.close();
-
- b64encrypted = baosEncrypt.toByteArray();
-
- baisDecrypt = new ByteArrayInputStream(b64encrypted);
- cisDecrypt = aes.inputStream(baisDecrypt, false);
- baosDecrypt = new ByteArrayOutputStream();
- transferFromInputStreamToOutputStream(cisDecrypt, baosDecrypt);
- cisDecrypt.close();
-
- output = new String(baosDecrypt.toByteArray());
- assertEquals(orig, output);
-
- Field aeskeySpec_field = AES.class.getDeclaredField("aeskeySpec");
- aeskeySpec_field.setAccessible(true);
- aeskeySpec_field.set(aes, null);
-
- assertNull(aes.inputStream(baisEncrypt, true));
- }
-
- @Test
- public void encryptDecryptFromOutputStream() throws Exception {
- String orig = "I'm a password, really";
- byte[] b64encrypted;
- String output;
-
- CipherOutputStream cosEncrypt;
- CipherOutputStream cosDecrypt;
-
- // Test CipherOutputStream
- baisEncrypt = new ByteArrayInputStream(orig.getBytes());
- baosEncrypt = new ByteArrayOutputStream();
- cosEncrypt = aes.outputStream(baosEncrypt, true);
- transferFromInputStreamToOutputStream(baisEncrypt, cosEncrypt);
- cosEncrypt.close();
-
- b64encrypted = baosEncrypt.toByteArray();
-
- baosDecrypt = new ByteArrayOutputStream();
- cosDecrypt = aes.outputStream(baosDecrypt, false);
- baisDecrypt = new ByteArrayInputStream(b64encrypted);
- transferFromInputStreamToOutputStream(baisDecrypt, cosDecrypt);
- cosDecrypt.close();
-
- output = new String(baosDecrypt.toByteArray());
- assertEquals(orig, output);
-
- Field aeskeySpec_field = AES.class.getDeclaredField("aeskeySpec");
- aeskeySpec_field.setAccessible(true);
- aeskeySpec_field.set(aes, null);
-
- assertNull(aes.outputStream(baosEncrypt, true));
- }
-
- public void transferFromInputStreamToOutputStream(InputStream is, OutputStream os) throws IOException {
- byte[] buffer = new byte[200];
- int len;
- while ((len = is.read(buffer)) != -1) {
- os.write(buffer, 0, len);
- }
- }
-
-}
+/*******************************************************************************
+ * ============LICENSE_START====================================================
+ * * org.onap.aaf
+ * * ===========================================================================
+ * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
+ * * ===========================================================================
+ * * 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.
+ * * See the License for the specific language governing permissions and
+ * * limitations under the License.
+ * * ============LICENSE_END====================================================
+ * *
+ * *
+ ******************************************************************************/
+package org.onap.aaf.cadi.test;
+
+import static org.hamcrest.CoreMatchers.*;
+import static org.junit.Assert.*;
+import org.junit.*;
+
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.PrintStream;
+import java.lang.reflect.Field;
+import java.nio.file.Files;
+import java.nio.file.Paths;
+
+import javax.crypto.CipherInputStream;
+import javax.crypto.CipherOutputStream;
+import javax.crypto.SecretKey;
+
+import org.onap.aaf.cadi.AES;
+import org.onap.aaf.cadi.CadiException;
+import org.onap.aaf.cadi.Symm;
+
+public class JU_AES {
+ private AES aes;
+ private ByteArrayInputStream baisEncrypt;
+ private ByteArrayInputStream baisDecrypt;
+ private ByteArrayOutputStream baosEncrypt;
+ private ByteArrayOutputStream baosDecrypt;
+
+ private ByteArrayOutputStream errStream;
+
+ @Before
+ public void setup() throws Exception {
+ byte[] keyBytes = new byte[AES.AES_KEY_SIZE/8];
+ char[] codeset = Symm.base64.codeset;
+ int offset = (Math.abs(codeset[0]) + 47) % (codeset.length - keyBytes.length);
+ for(int i = 0; i < keyBytes.length; ++i) {
+ keyBytes[i] = (byte)codeset[i+offset];
+ }
+ aes = new AES(keyBytes, 0, keyBytes.length);
+
+ errStream = new ByteArrayOutputStream();
+ System.setErr(new PrintStream(errStream));
+ }
+
+ @After
+ public void tearDown() {
+ System.setErr(System.err);
+ }
+
+ @Test
+ public void newKeyTest() throws Exception {
+ SecretKey secretKey = AES.newKey();
+ assertThat(secretKey.getAlgorithm(), is(AES.class.getSimpleName()));
+ }
+
+ @Test
+ public void encryptDecrpytFromBytes() throws Exception {
+ String orig = "I'm a password, really";
+ byte[] encrypted = aes.encrypt(orig.getBytes());
+ byte[] decrypted = aes.decrypt(encrypted);
+ assertThat(new String(decrypted), is(orig));
+
+ Field aeskeySpec_field = AES.class.getDeclaredField("aeskeySpec");
+ aeskeySpec_field.setAccessible(true);
+ aeskeySpec_field.set(aes, null);
+
+ try {
+ aes.encrypt(orig.getBytes());
+ fail("Should have thrown an exception");
+ } catch (CadiException e) {
+ }
+ try {
+ aes.decrypt(encrypted);
+ fail("Should have thrown an exception");
+ } catch (CadiException e) {
+ }
+ }
+
+ @Test
+ public void saveToFileTest() throws Exception {
+ String filePath = "test/output_key";
+ File keyfile = new File(filePath);
+ aes.save(keyfile);
+ assertTrue(Files.isReadable(Paths.get(filePath)));
+ assertFalse(Files.isWritable(Paths.get(filePath)));
+ assertFalse(Files.isExecutable(Paths.get(filePath)));
+ keyfile.delete();
+ }
+
+ @Test
+ public void encryptDecryptFromInputStream() throws Exception {
+ String orig = "I'm a password, really";
+ byte[] b64encrypted;
+ String output;
+
+ CipherInputStream cisEncrypt;
+ CipherInputStream cisDecrypt;
+
+ // Test CipherInputStream
+ baisEncrypt = new ByteArrayInputStream(orig.getBytes());
+ cisEncrypt = aes.inputStream(baisEncrypt, true);
+ baosEncrypt = new ByteArrayOutputStream();
+ transferFromInputStreamToOutputStream(cisEncrypt, baosEncrypt);
+ cisEncrypt.close();
+
+ b64encrypted = baosEncrypt.toByteArray();
+
+ baisDecrypt = new ByteArrayInputStream(b64encrypted);
+ cisDecrypt = aes.inputStream(baisDecrypt, false);
+ baosDecrypt = new ByteArrayOutputStream();
+ transferFromInputStreamToOutputStream(cisDecrypt, baosDecrypt);
+ cisDecrypt.close();
+
+ output = new String(baosDecrypt.toByteArray());
+ assertThat(output, is(orig));
+
+ Field aeskeySpec_field = AES.class.getDeclaredField("aeskeySpec");
+ aeskeySpec_field.setAccessible(true);
+ aeskeySpec_field.set(aes, null);
+
+ assertNull(aes.inputStream(baisEncrypt, true));
+ assertThat(errStream.toString(), is("Error creating Aes CipherInputStream\n"));
+ }
+
+ @Test
+ public void encryptDecryptFromOutputStream() throws Exception {
+ String orig = "I'm a password, really";
+ byte[] b64encrypted;
+ String output;
+
+ CipherOutputStream cosEncrypt;
+ CipherOutputStream cosDecrypt;
+
+ // Test CipherOutputStream
+ baisEncrypt = new ByteArrayInputStream(orig.getBytes());
+ baosEncrypt = new ByteArrayOutputStream();
+ cosEncrypt = aes.outputStream(baosEncrypt, true);
+ transferFromInputStreamToOutputStream(baisEncrypt, cosEncrypt);
+ cosEncrypt.close();
+
+ b64encrypted = baosEncrypt.toByteArray();
+
+ baosDecrypt = new ByteArrayOutputStream();
+ cosDecrypt = aes.outputStream(baosDecrypt, false);
+ baisDecrypt = new ByteArrayInputStream(b64encrypted);
+ transferFromInputStreamToOutputStream(baisDecrypt, cosDecrypt);
+ cosDecrypt.close();
+
+ output = new String(baosDecrypt.toByteArray());
+ assertThat(output, is(orig));
+
+ Field aeskeySpec_field = AES.class.getDeclaredField("aeskeySpec");
+ aeskeySpec_field.setAccessible(true);
+ aeskeySpec_field.set(aes, null);
+
+ assertNull(aes.outputStream(baosEncrypt, true));
+ assertThat(errStream.toString(), is("Error creating Aes CipherOutputStream\n"));
+ }
+
+ public void transferFromInputStreamToOutputStream(InputStream is, OutputStream os) throws IOException {
+ byte[] buffer = new byte[200];
+ int len;
+ while ((len = is.read(buffer)) != -1) {
+ os.write(buffer, 0, len);
+ }
+ }
+
+}
diff --git a/cadi/core/src/test/java/org/onap/aaf/cadi/test/JU_CadiExceptionTest.java b/cadi/core/src/test/java/org/onap/aaf/cadi/test/JU_CadiExceptionTest.java
deleted file mode 100644
index 03b20375..00000000
--- a/cadi/core/src/test/java/org/onap/aaf/cadi/test/JU_CadiExceptionTest.java
+++ /dev/null
@@ -1,121 +0,0 @@
-/*******************************************************************************
- * ============LICENSE_START====================================================
- * * org.onap.aaf
- * * ===========================================================================
- * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
- * * ===========================================================================
- * * 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.
- * * See the License for the specific language governing permissions and
- * * limitations under the License.
- * * ============LICENSE_END====================================================
- * *
- * *
- ******************************************************************************/
-package org.onap.aaf.cadi.test;
-
-import static org.junit.Assert.*;
-
-import org.junit.Test;
-import org.onap.aaf.cadi.CadiException;
-
-import static org.hamcrest.CoreMatchers.is;
-
-public class JU_CadiExceptionTest {
- @Test
- public void testCadiException() {
- CadiException exception = new CadiException();
-
- assertNotNull(exception);
- }
-
- @Test
- public void testCadiExceptionString() {
- CadiException exception = new CadiException("New Exception");
- assertNotNull(exception);
- assertThat(exception.getMessage(), is("New Exception"));
- }
-
- @Test
- public void testCadiExceptionThrowable() {
- CadiException exception = new CadiException(new Throwable("New Exception"));
- assertNotNull(exception);
- assertThat(exception.getMessage(), is("java.lang.Throwable: New Exception"));
- }
-
- @Test
- public void testCadiExceptionStringThrowable() {
- CadiException exception = new CadiException("New Exception",new Throwable("New Exception"));
- assertNotNull(exception);
- assertThat(exception.getMessage(), is("New Exception"));
-
- }
-
- @Test
- public void testCadiException1() {
- CadiException exception = new CadiException();
-
- assertNotNull(exception);
- }
-
- @Test
- public void testCadiExceptionString1() {
- CadiException exception = new CadiException("New Exception");
- assertNotNull(exception);
- assertThat(exception.getMessage(), is("New Exception"));
- }
-
- @Test
- public void testCadiExceptionThrowable1() {
- CadiException exception = new CadiException(new Throwable("New Exception"));
- assertNotNull(exception);
- assertThat(exception.getMessage(), is("java.lang.Throwable: New Exception"));
- }
-
- @Test
- public void testCadiExceptionStringThrowable1() {
- CadiException exception = new CadiException("New Exception",new Throwable("New Exception"));
- assertNotNull(exception);
- assertThat(exception.getMessage(), is("New Exception"));
-
- }
-
- @Test
- public void testCadiException2() {
- CadiException exception = new CadiException();
-
- assertNotNull(exception);
- }
-
- @Test
- public void testCadiExceptionString2() {
- CadiException exception = new CadiException("New Exception");
- assertNotNull(exception);
- assertThat(exception.getMessage(), is("New Exception"));
- }
-
- @Test
- public void testCadiExceptionThrowable2() {
- CadiException exception = new CadiException(new Throwable("New Exception"));
- assertNotNull(exception);
- assertThat(exception.getMessage(), is("java.lang.Throwable: New Exception"));
- }
-
- @Test
- public void testCadiExceptionStringThrowable2() {
- CadiException exception = new CadiException("New Exception",new Throwable("New Exception"));
- assertNotNull(exception);
- assertThat(exception.getMessage(), is("New Exception"));
-
- }
-
-
-
-}
diff --git a/cadi/core/src/test/java/org/onap/aaf/cadi/test/JU_CadiWrapTest.java b/cadi/core/src/test/java/org/onap/aaf/cadi/test/JU_CadiWrapTest.java
deleted file mode 100644
index 14b2999a..00000000
--- a/cadi/core/src/test/java/org/onap/aaf/cadi/test/JU_CadiWrapTest.java
+++ /dev/null
@@ -1,155 +0,0 @@
-/*******************************************************************************
- * ============LICENSE_START====================================================
- * * org.onap.aaf
- * * ===========================================================================
- * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
- * * ===========================================================================
- * * 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.
- * * See the License for the specific language governing permissions and
- * * limitations under the License.
- * * ============LICENSE_END====================================================
- * *
- * *
- ******************************************************************************/
-package org.onap.aaf.cadi.test;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
-import static org.mockito.Matchers.isA;
-import static org.mockito.Mockito.when;
-
-import java.security.Principal;
-import java.util.List;
-
-import javax.servlet.http.HttpServletRequest;
-
-import org.junit.Before;
-import org.junit.Test;
-import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
-import org.onap.aaf.cadi.Access;
-import org.onap.aaf.cadi.CachingLur;
-import org.onap.aaf.cadi.CadiException;
-import org.onap.aaf.cadi.CadiWrap;
-import org.onap.aaf.cadi.Lur;
-import org.onap.aaf.cadi.Permission;
-import org.onap.aaf.cadi.PropAccess;
-import org.onap.aaf.cadi.User;
-import org.onap.aaf.cadi.CachedPrincipal.Resp;
-import org.onap.aaf.cadi.filter.MapPermConverter;
-import org.onap.aaf.cadi.lur.EpiLur;
-import org.onap.aaf.cadi.principal.TaggedPrincipal;
-import org.onap.aaf.cadi.taf.TafResp;
-
-public class JU_CadiWrapTest {
-
- @Mock
- private HttpServletRequest request;
-
- @Mock
- private TafResp tafResp;
-
- @Mock
- private TaggedPrincipal principle;
-
- @Mock
- private Lur lur;
-
- @Before
- public void setUp() throws Exception {
- MockitoAnnotations.initMocks(this);
- }
-
- @Test
- public void testInstantiate() throws CadiException {
- Access a = new PropAccess();
- when(tafResp.getAccess()).thenReturn(a);
-
- lur.fishAll(isA(Principal.class), isA(List.class));
-
- EpiLur lur1 = new EpiLur(lur);
-
- CadiWrap wrap = new CadiWrap(request, tafResp, lur1);
-
- assertNull(wrap.getUserPrincipal());
- assertNull(wrap.getRemoteUser());
- assertNull(wrap.getUser());
- assertEquals(wrap.getPermissions(principle).size(), 0);
- assertTrue(wrap.access() instanceof PropAccess);
-
- byte[] arr = {'1','2'};
- wrap.setCred(arr);
-
- assertEquals(arr, wrap.getCred());
-
- wrap.setUser("User1");
- assertEquals("User1", wrap.getUser());
-
- wrap.invalidate("1");
-
- assertFalse(wrap.isUserInRole(null));
-
- wrap.set(tafResp, lur);
-
- wrap.invalidate("2");
-
- wrap.isUserInRole("User1");
- }
-
- @Test
- public void testInstantiateWithPermConverter() throws CadiException {
- Access a = new PropAccess();
- when(tafResp.getAccess()).thenReturn(a);
- when(tafResp.getPrincipal()).thenReturn(principle);
-
- // Anonymous object for testing purposes
- CachingLur<Permission> lur1 = new CachingLur<Permission>() {
- @Override public Permission createPerm(String p) { return null; }
- @Override public boolean fish(Principal bait, Permission pond) { return true; }
- @Override public void fishAll(Principal bait, List<Permission> permissions) { }
- @Override public void destroy() { }
- @Override public boolean handlesExclusively(Permission pond) { return false; }
- @Override public boolean handles(Principal principal) { return false; }
- @Override public void remove(String user) { }
- @Override public Resp reload(User<Permission> user) { return null; }
- @Override public void setDebug(String commaDelimIDsOrNull) { }
- @Override public void clear(Principal p, StringBuilder sb) { }
- };
-
- MapPermConverter pc = new MapPermConverter();
-
- CadiWrap wrap = new CadiWrap(request, tafResp, lur1, pc);
-
- assertNotNull(wrap.getUserPrincipal());
- assertNull(wrap.getRemoteUser());
- assertNull(wrap.getUser());
-
- byte[] arr = {'1','2'};
- wrap.setCred(arr);
-
- assertEquals(arr, wrap.getCred());
-
- wrap.setUser("User1");
- assertEquals("User1", wrap.getUser());
-
- wrap.invalidate("1");
- wrap.setPermConverter(new MapPermConverter());
-
- assertTrue(wrap.getLur() instanceof CachingLur);
- assertTrue(wrap.isUserInRole("User1"));
-
- wrap.set(tafResp, lur);
- assertFalse(wrap.isUserInRole("Perm1"));
- }
-}
diff --git a/cadi/core/src/test/java/org/onap/aaf/cadi/test/config/JU_MultiGet.java b/cadi/core/src/test/java/org/onap/aaf/cadi/test/config/JU_MultiGet.java
new file mode 100644
index 00000000..e678421c
--- /dev/null
+++ b/cadi/core/src/test/java/org/onap/aaf/cadi/test/config/JU_MultiGet.java
@@ -0,0 +1,68 @@
+/*******************************************************************************
+ * * org.onap.aaf
+ * * ===========================================================================
+ * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
+ * * ===========================================================================
+ * * 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.
+ * * See the License for the specific language governing permissions and
+ * * limitations under the License.
+ * * ============LICENSE_END====================================================
+ * *
+ * *
+ ******************************************************************************/
+
+package org.onap.aaf.cadi.test.config;
+
+import static org.junit.Assert.*;
+import static org.hamcrest.CoreMatchers.*;
+import org.junit.*;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.PrintStream;
+
+import org.onap.aaf.cadi.PropAccess;
+import org.onap.aaf.cadi.config.Get;
+import org.onap.aaf.cadi.config.MultiGet;
+
+public class JU_MultiGet {
+
+ private String defaultVal = "some default value";
+
+ private ByteArrayOutputStream outStream;
+
+ private MultiGet multiGet;
+ private Get.AccessGet accessGet;
+ private PropAccess access;
+
+ @Before
+ public void setup() throws IOException {
+ outStream = new ByteArrayOutputStream();
+ System.setOut(new PrintStream(outStream));
+
+ access = new PropAccess();
+ access.setProperty("tag", "value");
+ accessGet = new Get.AccessGet(access);
+ multiGet = new MultiGet(accessGet, Get.NULL);
+ }
+
+ @After
+ public void tearDown() {
+ System.setOut(System.out);
+ }
+
+ @Test
+ public void getTest() {
+ assertThat(multiGet.get("tag", defaultVal, false), is("value"));
+ assertThat(multiGet.get("not_a_tag", defaultVal, false), is(defaultVal));
+ }
+
+}
diff --git a/cadi/core/src/test/java/org/onap/aaf/cadi/test/config/JU_SecurityInfoC.java b/cadi/core/src/test/java/org/onap/aaf/cadi/test/config/JU_SecurityInfoC.java
new file mode 100644
index 00000000..948bfad4
--- /dev/null
+++ b/cadi/core/src/test/java/org/onap/aaf/cadi/test/config/JU_SecurityInfoC.java
@@ -0,0 +1,109 @@
+/*******************************************************************************
+ * ============LICENSE_START====================================================
+ * * org.onap.aaf
+ * * ===========================================================================
+ * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
+ * * ===========================================================================
+ * * 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.
+ * * See the License for the specific language governing permissions and
+ * * limitations under the License.
+ * * ============LICENSE_END====================================================
+ * *
+ * *
+ ******************************************************************************/
+package org.onap.aaf.cadi.test.config;
+
+import static org.hamcrest.CoreMatchers.*;
+import static org.junit.Assert.*;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.PrintStream;
+import java.net.HttpURLConnection;
+import java.net.MalformedURLException;
+import java.net.URL;
+
+import org.junit.*;
+import org.onap.aaf.cadi.CadiException;
+import org.onap.aaf.cadi.PropAccess;
+import org.onap.aaf.cadi.SecuritySetter;
+import org.onap.aaf.cadi.config.SecurityInfoC;
+
+public class JU_SecurityInfoC {
+
+ ByteArrayOutputStream outStream;
+ ByteArrayOutputStream errStream;
+
+ @Before
+ public void setup() {
+ outStream = new ByteArrayOutputStream();
+ errStream = new ByteArrayOutputStream();
+
+ System.setOut(new PrintStream(outStream));
+ System.setErr(new PrintStream(errStream));
+ }
+
+ @After
+ public void tearDown() {
+ System.setOut(System.out);
+ System.setErr(System.err);
+ }
+
+ @Test
+ public void instanceTest() throws CadiException, MalformedURLException {
+ SecurityInfoC<HttpURLConnection> si = SecurityInfoC.instance(new PropAccess(), HttpURLConnection.class);
+ assertThat(si.defSS.getID(), is(SecurityInfoC.DEF_ID));
+ try {
+ si.defSS.setSecurity(new HttpURLConnectionStub());
+ fail("Should have thrown an exception");
+ } catch (CadiException e) {
+ assertTrue(e instanceof CadiException);
+ assertThat(e.getMessage(), is("No Client Credentials set."));
+ }
+ assertThat(si.defSS.setLastResponse(0), is(0));
+
+ // Try it again for coverage
+ SecurityInfoC<HttpURLConnection> siClone = SecurityInfoC.instance(new PropAccess(), HttpURLConnection.class);
+ assertThat(siClone, is(si));
+ }
+
+ @Test
+ public void setTest() throws MalformedURLException, CadiException {
+ SecurityInfoC<HttpURLConnection> si = SecurityInfoC.instance(new PropAccess(), HttpURLConnection.class);
+ SecuritySetter<HttpURLConnection> ss = new SecuritySetterStub<HttpURLConnection>();
+ assertThat(si.set(ss), is(si));
+ assertThat(si.defSS.getID(), is("Example ID"));
+ try {
+ si.defSS.setSecurity(new HttpURLConnectionStub());
+ fail("Should have thrown an exception");
+ } catch (CadiException e) {
+ assertTrue(e instanceof CadiException);
+ assertThat(e.getMessage(), is("Example exception"));
+ }
+ assertThat(si.defSS.setLastResponse(0), is(0));
+ assertThat(si.defSS.setLastResponse(1), is(1));
+ assertThat(si.defSS.setLastResponse(-1), is(-1));
+ }
+
+ private class HttpURLConnectionStub extends HttpURLConnection {
+ public HttpURLConnectionStub() throws MalformedURLException { super(new URL("http://www.example.com")); }
+ @Override public void disconnect() { }
+ @Override public boolean usingProxy() { return false; }
+ @Override public void connect() throws IOException { }
+ }
+
+ private class SecuritySetterStub<CT> implements SecuritySetter<CT> {
+ public String getID() { return "Example ID"; }
+ public void setSecurity(CT client) throws CadiException { throw new CadiException("Example exception"); }
+ public int setLastResponse(int respCode) { return respCode; }
+ }
+
+}
diff --git a/cadi/core/src/test/java/org/onap/aaf/cadi/test/util/JU_UserChainManip.java b/cadi/core/src/test/java/org/onap/aaf/cadi/test/util/JU_UserChainManip.java
index d335edae..949d034b 100644
--- a/cadi/core/src/test/java/org/onap/aaf/cadi/test/util/JU_UserChainManip.java
+++ b/cadi/core/src/test/java/org/onap/aaf/cadi/test/util/JU_UserChainManip.java
@@ -6,9 +6,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.
@@ -20,12 +20,10 @@
******************************************************************************/
package org.onap.aaf.cadi.test.util;
-import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.*;
+import static org.hamcrest.CoreMatchers.*;
+import org.junit.*;
-import java.util.ArrayList;
-import java.util.List;
-
-import org.junit.Test;
import org.onap.aaf.cadi.UserChain;
import org.onap.aaf.cadi.util.UserChainManip;
@@ -34,33 +32,36 @@ public class JU_UserChainManip {
@Test
public void build(){
UserChain.Protocol baseAuth=UserChain.Protocol.BasicAuth;
- assertEquals(UserChainManip.build(new StringBuilder(""), "app", "id", baseAuth, true).toString(), "app:id:BasicAuth:AS");
- }
-
+ StringBuilder sb = UserChainManip.build(new StringBuilder(""), "app", "id", baseAuth, true);
+ assertThat(sb.toString(), is("app:id:BasicAuth:AS"));
- @Test
- public void idToNS(){
- assertEquals(UserChainManip.idToNS(null), "");
+ // for coverage
+ sb = UserChainManip.build(sb, "app", "id", baseAuth, true);
+ assertThat(sb.toString(), is("app:id:BasicAuth:AS,app:id:BasicAuth"));
+
+ sb = UserChainManip.build(new StringBuilder(""), "app", "id", baseAuth, false);
+ assertThat(sb.toString(), is("app:id:BasicAuth"));
}
-
+
@Test
- public void idToNS1(){
- assertEquals(UserChainManip.idToNS("t@st"), "st");
+ public void idToNSTEST() {
+ assertThat(UserChainManip.idToNS(null), is(""));
+ assertThat(UserChainManip.idToNS(""), is(""));
+ assertThat(UserChainManip.idToNS("something"), is(""));
+ assertThat(UserChainManip.idToNS("something@@"), is(""));
+ assertThat(UserChainManip.idToNS("something@@."), is(""));
+ assertThat(UserChainManip.idToNS("something@com"), is("com"));
+ assertThat(UserChainManip.idToNS("something@random.com"), is("com.random"));
+ assertThat(UserChainManip.idToNS("@random.com"), is("com.random"));
+ assertThat(UserChainManip.idToNS("something@random.com."), is("com.random"));
+ assertThat(UserChainManip.idToNS("something@..random...com..."), is("com.random"));
+ assertThat(UserChainManip.idToNS("something@this.random.com"), is("com.random.this"));
}
@Test
- public void test() {
- assertEquals("",UserChainManip.idToNS(null));
- assertEquals("",UserChainManip.idToNS(""));
- assertEquals("",UserChainManip.idToNS("something"));
- assertEquals("",UserChainManip.idToNS("something@@"));
- assertEquals("",UserChainManip.idToNS("something@@."));
- assertEquals("com",UserChainManip.idToNS("something@com"));
- assertEquals("com.random",UserChainManip.idToNS("something@random.com"));
- assertEquals("com.random",UserChainManip.idToNS("@random.com"));
- assertEquals("com.random",UserChainManip.idToNS("something@random.com."));
- assertEquals("com.random",UserChainManip.idToNS("something@..random...com..."));
- assertEquals("com.random.this",UserChainManip.idToNS("something@this.random.com"));
+ public void coverageTest() {
+ @SuppressWarnings("unused")
+ UserChainManip ucm = new UserChainManip();
}
}