diff options
author | Instrumental <jcgmisc@stl.gathman.org> | 2018-03-26 12:04:27 -0700 |
---|---|---|
committer | Instrumental <jcgmisc@stl.gathman.org> | 2018-03-26 12:04:38 -0700 |
commit | 6d469611d86642bc0b74ce51af72cc36d2af962d (patch) | |
tree | 8a3d4ad886228e770a7d0d2515ef1dd4f794bbb5 /core/src/test | |
parent | 1b8ff51dcbeb503f2a641074f6ceebf65e73fd87 (diff) |
Remove Code from cadi, it is now in authz
Issue-ID: AAF-193
Change-Id: Ib7abdb15ba8a7445a3875cf8c6bb48b7d563f424
Signed-off-by: Instrumental <jcgmisc@stl.gathman.org>
Diffstat (limited to 'core/src/test')
25 files changed, 0 insertions, 3007 deletions
diff --git a/core/src/test/java/org/onap/aaf/cadi/JU_AES.java b/core/src/test/java/org/onap/aaf/cadi/JU_AES.java deleted file mode 100644 index 50c4f27..0000000 --- a/core/src/test/java/org/onap/aaf/cadi/JU_AES.java +++ /dev/null @@ -1,229 +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====================================================
- * *
- * * ECOMP is a trademark and service mark of AT&T Intellectual Property.
- * *
- ******************************************************************************/
-package org.onap.aaf.cadi;
-
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-
-import javax.crypto.CipherInputStream;
-import javax.crypto.CipherOutputStream;
-
-import org.junit.Test;
-import org.onap.aaf.cadi.AES;
-import org.onap.aaf.cadi.Symm;
-
-import junit.framework.Assert;
-
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.File;
-import java.io.OutputStream;
-
-import javax.crypto.CipherInputStream;
-import javax.crypto.CipherOutputStream;
-
-import org.junit.Test;
-import org.onap.aaf.cadi.AES;
-import org.onap.aaf.cadi.Symm;
-
-import junit.framework.Assert;
-
-public class JU_AES {
-
- @Test
- public void test() throws Exception {
- AES aes = new AES();
- String orig = "I'm a password, really";
- byte[] passin = orig.getBytes();
- byte[] encrypted = aes.encrypt(passin);
- byte[] b64enc = Symm.base64.encode(encrypted);
- System.out.println(new String(b64enc));
-
- encrypted = Symm.base64.decode(b64enc);
- passin = aes.decrypt(encrypted);
- Assert.assertEquals(orig, new String(passin));
- }
-
- @Test
- public void testAESFileStream() throws Exception {
- File fi = new File("test/AESKeyFile");
- AES aes = new AES(fi);
-
- String orig = "I'm a password, really";
- byte[] passin = orig.getBytes();
- byte[] encrypted = aes.encrypt(passin);
- byte[] b64enc = Symm.base64.encode(encrypted);
- System.out.println(new String(b64enc));
-
- encrypted = Symm.base64.decode(b64enc);
- passin = aes.decrypt(encrypted);
- Assert.assertEquals(orig, new String(passin));
-
- File temp = new File("tempFile");
- try {
- assertFalse(temp.exists());
- aes.save(temp);
- assertTrue(temp.exists());
- } catch (Exception e) {
- } finally {
- temp.delete();
- }
-
- }
-
- @Test
- public void testInputStream() throws Exception {
- AES aes = new AES();
- String orig = "I'm a password, really";
- ByteArrayInputStream bais = new ByteArrayInputStream(orig.getBytes());
- CipherInputStream cis = aes.inputStream(bais, true);
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- Symm.base64.encode(cis, baos);
- cis.close();
-
- byte[] b64encrypted;
- System.out.println(new String(b64encrypted=baos.toByteArray()));
-
- CipherInputStream cis1 = aes.inputStream(bais, false);
- ByteArrayOutputStream baos1 = new ByteArrayOutputStream();
- Symm.base64.encode(cis1, baos1);
- cis.close();
-
- byte[] b64encrypted1;
- System.out.println(new String(b64encrypted1=baos1.toByteArray()));
-
- baos.reset();
- CipherOutputStream cos = aes.outputStream(baos, false);
- Symm.base64.decode(new ByteArrayInputStream(b64encrypted),cos);
- cos.close();
- Assert.assertEquals(orig, new String(baos.toByteArray()));
-
- OutputStream stream = aes.outputStream(System.out, true);
- assertTrue(stream instanceof CipherOutputStream);
-
- }
-
- @Test
- public void testObtain() throws Exception {
- byte[] keygen = Symm.baseCrypt().keygen();
-
- Symm symm = Symm.obtain(new ByteArrayInputStream(keygen));
-
- String orig ="Another Password, please";
- String encrypted = symm.enpass(orig);
- System.out.println(encrypted);
- String decrypted = symm.depass(encrypted);
- System.out.println(decrypted);
- Assert.assertEquals(orig, decrypted);
- }
-
- @Test
- public void test1() throws Exception {
- AES aes = new AES();
- String orig = "I'm a password, really";
- byte[] passin = orig.getBytes();
- byte[] encrypted = aes.encrypt(passin);
- byte[] b64enc = Symm.base64.encode(encrypted);
- System.out.println(new String(b64enc));
-
- encrypted = Symm.base64.decode(b64enc);
- passin = aes.decrypt(encrypted);
- Assert.assertEquals(orig, new String(passin));
- }
-
- @Test
- public void testAESFileStream1() throws Exception {
- File fi = new File("test/AESKeyFile");
- AES aes = new AES(fi);
-
- String orig = "I'm a password, really";
- byte[] passin = orig.getBytes();
- byte[] encrypted = aes.encrypt(passin);
- byte[] b64enc = Symm.base64.encode(encrypted);
- System.out.println(new String(b64enc));
-
- encrypted = Symm.base64.decode(b64enc);
- passin = aes.decrypt(encrypted);
- Assert.assertEquals(orig, new String(passin));
-
- File temp = new File("tempFile");
- try {
- assertFalse(temp.exists());
- aes.save(temp);
- assertTrue(temp.exists());
- } catch (Exception e) {
- } finally {
- temp.delete();
- }
-
- }
-
- @Test
- public void testInputStream1() throws Exception {
- AES aes = new AES();
- String orig = "I'm a password, really";
- ByteArrayInputStream bais = new ByteArrayInputStream(orig.getBytes());
- CipherInputStream cis = aes.inputStream(bais, true);
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- Symm.base64.encode(cis, baos);
- cis.close();
-
- byte[] b64encrypted;
- System.out.println(new String(b64encrypted=baos.toByteArray()));
-
- CipherInputStream cis1 = aes.inputStream(bais, false);
- ByteArrayOutputStream baos1 = new ByteArrayOutputStream();
- Symm.base64.encode(cis1, baos1);
- cis.close();
-
- byte[] b64encrypted1;
- System.out.println(new String(b64encrypted1=baos1.toByteArray()));
-
- baos.reset();
- CipherOutputStream cos = aes.outputStream(baos, false);
- Symm.base64.decode(new ByteArrayInputStream(b64encrypted),cos);
- cos.close();
- Assert.assertEquals(orig, new String(baos.toByteArray()));
-
- OutputStream stream = aes.outputStream(System.out, true);
- assertTrue(stream instanceof CipherOutputStream);
-
- }
-
- @Test
- public void testObtain1() throws Exception {
- byte[] keygen = Symm.baseCrypt().keygen();
-
- Symm symm = Symm.obtain(new ByteArrayInputStream(keygen));
-
- String orig ="Another Password, please";
- String encrypted = symm.enpass(orig);
- System.out.println(encrypted);
- String decrypted = symm.depass(encrypted);
- System.out.println(decrypted);
- Assert.assertEquals(orig, decrypted);
- }
-}
diff --git a/core/src/test/java/org/onap/aaf/cadi/JU_CadiExceptionTest.java b/core/src/test/java/org/onap/aaf/cadi/JU_CadiExceptionTest.java deleted file mode 100644 index 2eae209..0000000 --- a/core/src/test/java/org/onap/aaf/cadi/JU_CadiExceptionTest.java +++ /dev/null @@ -1,125 +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====================================================
- * *
- * * ECOMP is a trademark and service mark of AT&T Intellectual Property.
- * *
- ******************************************************************************/
-package org.onap.aaf.cadi;
-
-import static org.junit.Assert.*;
-
-import org.junit.Test;
-
-import static org.hamcrest.CoreMatchers.is;
-import static org.junit.Assert.*;
-
-import org.junit.Test;
-
-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/core/src/test/java/org/onap/aaf/cadi/JU_CadiWrapTest.java b/core/src/test/java/org/onap/aaf/cadi/JU_CadiWrapTest.java deleted file mode 100644 index da81e0c..0000000 --- a/core/src/test/java/org/onap/aaf/cadi/JU_CadiWrapTest.java +++ /dev/null @@ -1,197 +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====================================================
- * *
- * * ECOMP is a trademark and service mark of AT&T Intellectual Property.
- * *
- ******************************************************************************/
-package org.onap.aaf.cadi;
-
-import static org.junit.Assert.*;
-
-import org.junit.Test;
-
-import static org.junit.Assert.*;
-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.Mockito;
-import org.mockito.MockitoAnnotations;
-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.taf.TafResp;
-
-public class JU_CadiWrapTest {
-
- @Mock
- private HttpServletRequest request;
-
- @Mock
- private TafResp tafResp;
-
- @Mock
- private Principal 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);
-
- 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);
-
-
- CachingLur<Permission> lur1 = new CachingLur<Permission>() {
-
- @Override
- public Permission createPerm(String p) {
- // TODO Auto-generated method stub
- return null;
- }
-
- @Override
- public boolean fish(Principal bait, Permission pond) {
- // TODO Auto-generated method stub
- return true;
- }
-
- @Override
- public void fishAll(Principal bait, List<Permission> permissions) {
- // TODO Auto-generated method stub
-
- }
-
- @Override
- public void destroy() {
- // TODO Auto-generated method stub
-
- }
-
- @Override
- public boolean handlesExclusively(Permission pond) {
- // TODO Auto-generated method stub
- return false;
- }
-
- @Override
- public boolean supports(String userName) {
- // TODO Auto-generated method stub
- return false;
- }
-
- @Override
- public void remove(String user) {
- // TODO Auto-generated method stub
-
- }
-
- @Override
- public Resp reload(User<Permission> user) {
- // TODO Auto-generated method stub
- return null;
- }
-
- @Override
- public void setDebug(String commaDelimIDsOrNull) {
- // TODO Auto-generated method stub
-
- }
-
- @Override
- public void clear(Principal p, StringBuilder sb) {
- // TODO Auto-generated method stub
-
- }
- };
-
- 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/core/src/test/java/org/onap/aaf/cadi/JU_PropAccessTest.java b/core/src/test/java/org/onap/aaf/cadi/JU_PropAccessTest.java deleted file mode 100644 index 9b18aa6..0000000 --- a/core/src/test/java/org/onap/aaf/cadi/JU_PropAccessTest.java +++ /dev/null @@ -1,75 +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====================================================
- * *
- * * ECOMP is a trademark and service mark of AT&T Intellectual Property.
- * *
- ******************************************************************************/
-package org.onap.aaf.cadi;
-
-
-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 java.io.IOException;
-import java.util.Properties;
-
-import org.junit.Before;
-import org.junit.Test;
-import org.onap.aaf.cadi.Access.Level;
-import org.onap.aaf.cadi.config.Config;
-
-public class JU_PropAccessTest {
-
- @Test
- public void test() {
- PropAccess prop = new PropAccess(new Object());
-
- prop = new PropAccess("cadi_name=user","cadi_loglevel=DEBUG","cadi_prop_files=test/cadi.properties");
-
- assertTrue(prop.getProperties().keySet().contains("cadi_name"));
- assertTrue(prop.getProperty("cadi_name").equals("user"));
-
- prop.setProperty("cadi_keyfile", "file");
- prop.setLogLevel(Level.DEBUG);
- assertEquals(prop.getProperty("cadi_keyfile"),"file");
- prop.log(Level.DEBUG);
- assertTrue(prop.getDME2Properties().keySet().contains("AFT_DME2_SSL_INCLUDE_PROTOCOLS"));
- }
-
- @Test
- public void testWithProperties() {
- Properties p = new Properties();
- p.put("cadi_name", "user");
- p.put("cadi_loglevel", "DEBUG");
-
- PropAccess prop = new PropAccess(p);
-
- assertTrue(prop.getProperties().keySet().contains("cadi_name"));
- assertTrue(prop.getProperty("cadi_name").equals("user"));
-
- prop.setProperty("cadi_keyfile", "file");
- prop.setLogLevel(Level.DEBUG);
- assertEquals(prop.getProperty("cadi_keyfile"),"file");
- prop.log(Level.DEBUG);
- assertTrue(prop.getDME2Properties().keySet().contains("AFT_DME2_SSL_INCLUDE_PROTOCOLS"));
- }
-}
diff --git a/core/src/test/java/org/onap/aaf/cadi/JU_UserTest.java b/core/src/test/java/org/onap/aaf/cadi/JU_UserTest.java deleted file mode 100644 index be2becd..0000000 --- a/core/src/test/java/org/onap/aaf/cadi/JU_UserTest.java +++ /dev/null @@ -1,161 +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====================================================
- * *
- * * ECOMP is a trademark and service mark of AT&T Intellectual Property.
- * *
- ******************************************************************************/
-package org.onap.aaf.cadi;
-
-import static org.junit.Assert.*;
-
-import org.junit.Test;
-
-
-import static org.hamcrest.CoreMatchers.is;
-import static org.junit.Assert.*;
-import static org.mockito.Mockito.when;
-
-import java.security.Principal;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import org.junit.Before;
-import org.junit.Test;
-import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
-import org.onap.aaf.cadi.lur.LocalPermission;
-
-public class JU_UserTest {
-
- @Mock
- private Principal principal;
-
- @Mock
- private LocalPermission permission;
-
- @Before
- public void setup() {
- MockitoAnnotations.initMocks(this);
-
- when(principal.getName()).thenReturn("Principal");
-
- when(permission.getKey()).thenReturn("NewKey");
- when(permission.match(permission)).thenReturn(true);
- }
-
- @Test
- public void testCountCheck() {
- User<Permission> user = new User<Permission>(principal);
- user.resetCount();
- assertThat(user.count, is(0));
- user.incCount();
- assertThat(user.count, is(1));
- }
-
- @Test
- public void testCountCheck1() {
- User<Permission> user = new User<Permission>(principal);
- user.resetCount();
- assertThat(user.count, is(0));
- user.incCount();
- assertThat(user.count, is(1));
- }
-
- @Test
- public void testPerm() throws InterruptedException {
- User<Permission> user = new User<Permission>(principal);
- assertThat(user.permExpires(), is(Long.MAX_VALUE));
- user.renewPerm();
- Thread.sleep(1);
- assertThat(user.permExpired(), is(true));
- user = new User<Permission>(principal,100);
- assertTrue(user.noPerms());
- user.add(permission);
- assertFalse(user.noPerms());
- user.setNoPerms();
- assertThat(user.permExpired(), is(false));
- assertFalse(user.permsUnloaded());
- user.perms = null;
- assertTrue(user.permsUnloaded());
- assertTrue(user.noPerms());
- }
-
- @Test
- public void testPerm1() throws InterruptedException {
- User<Permission> user = new User<Permission>(principal);
- assertThat(user.permExpires(), is(Long.MAX_VALUE));
- user.renewPerm();
- Thread.sleep(1);
- assertThat(user.permExpired(), is(true));
- user = new User<Permission>(principal,100);
- assertTrue(user.noPerms());
- user.add(permission);
- assertFalse(user.noPerms());
- user.setNoPerms();
- assertThat(user.permExpired(), is(false));
- assertFalse(user.permsUnloaded());
- user.perms = null;
- assertTrue(user.permsUnloaded());
- assertTrue(user.noPerms());
- }
-
- @Test
- public void testAddValuesToNewMap() {
- User<Permission> user = new User<Permission>(principal);
- Map<String, Permission> newMap = new HashMap<String,Permission>();
-
- assertFalse(user.contains(permission));
-
- user.add(newMap, permission);
- user.setMap(newMap);
-
- assertTrue(user.contains(permission));
-
- List<Permission> sink = new ArrayList<Permission>();
- user.copyPermsTo(sink);
-
- assertThat(sink.size(), is(1));
- assertTrue(sink.contains(permission));
-
- assertThat(user.toString(), is("Principal|:NewKey"));
- }
-
- @Test
- public void testAddValuesToNewMap1() {
- User<Permission> user = new User<Permission>(principal);
- Map<String, Permission> newMap = new HashMap<String,Permission>();
-
- assertFalse(user.contains(permission));
-
- user.add(newMap, permission);
- user.setMap(newMap);
-
- assertTrue(user.contains(permission));
-
- List<Permission> sink = new ArrayList<Permission>();
- user.copyPermsTo(sink);
-
- assertThat(sink.size(), is(1));
- assertTrue(sink.contains(permission));
-
- assertThat(user.toString(), is("Principal|:NewKey"));
- }
-}
diff --git a/core/src/test/java/org/onap/aaf/cadi/filter/JU_FCGetTest.java b/core/src/test/java/org/onap/aaf/cadi/filter/JU_FCGetTest.java deleted file mode 100644 index b0308a5..0000000 --- a/core/src/test/java/org/onap/aaf/cadi/filter/JU_FCGetTest.java +++ /dev/null @@ -1,99 +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====================================================
- * *
- * * ECOMP is a trademark and service mark of AT&T Intellectual Property.
- * *
- ******************************************************************************/
-package org.onap.aaf.cadi.filter;
-
-import static org.junit.Assert.assertEquals;
-import static org.mockito.Mockito.when;
-
-import javax.servlet.FilterConfig;
-import javax.servlet.ServletContext;
-
-import org.junit.Before;
-import org.junit.Test;
-import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
-import org.onap.aaf.cadi.PropAccess;
-
-public class JU_FCGetTest {
-
- @Mock
- private ServletContext context;
-
- @Mock
- private FilterConfig config;
-
- @Mock
- private PropAccess access = new PropAccess();
-
- @Before
- public void setUp() {
- MockitoAnnotations.initMocks(this);
- }
-
- @Test
- public void testGetStringFromDef() {
- PropAccess access = new PropAccess();
-
- FCGet fcGet = new FCGet(access, context, config);
-
- String user = fcGet.get("user", "DefaultUser", true);
-
- assertEquals(user, "DefaultUser");
- }
-
- @Test
- public void testGetStringFromContext() {
- PropAccess access = new PropAccess();
- when(context.getInitParameter("user")).thenReturn("ContextUser");
-
- FCGet fcGet = new FCGet(access, context, null);
-
- String user = fcGet.get("user", "DefaultUser", true);
-
- assertEquals(user,"ContextUser");
- }
-
- @Test
- public void testGetStringFromFilter() {
- PropAccess access = new PropAccess();
- when(config.getInitParameter("user")).thenReturn("FilterUser");
-
- FCGet fcGet = new FCGet(access, null, config);
-
- String user = fcGet.get("user", "DefaultUser", true);
-
- assertEquals(user,"FilterUser");
- }
-
- @Test
- public void testGetStringWithNullContextFilter() {
-
- when(access.getProperty("user", "DefaultUser")).thenReturn(null);
-
- FCGet fcGet = new FCGet(access, null, null);
-
- String user = fcGet.get("user", "DefaultUser", true);
-
- assertEquals(user,"DefaultUser");
- }
-}
diff --git a/core/src/test/java/org/onap/aaf/cadi/lur/JU_ConfigPrincipalTest.java b/core/src/test/java/org/onap/aaf/cadi/lur/JU_ConfigPrincipalTest.java deleted file mode 100644 index ec5d0a8..0000000 --- a/core/src/test/java/org/onap/aaf/cadi/lur/JU_ConfigPrincipalTest.java +++ /dev/null @@ -1,171 +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====================================================
- * *
- * * ECOMP is a trademark and service mark of AT&T Intellectual Property.
- * *
- ******************************************************************************/
-package org.onap.aaf.cadi.lur;
-
-import static org.junit.Assert.*;
-
-import java.io.IOException;
-
-import org.junit.Before;
-import org.junit.Test;
-
-public class JU_ConfigPrincipalTest {
-
- @Before
- public void setUp() throws Exception {
- }
-
- @Test
- public void testConfigPrincipalStringString() {
- ConfigPrincipal p = new ConfigPrincipal("User", "pass");
-
- assertEquals(p.getName(), "User");
- assertEquals(p.toString(), "User");
-
- }
-
- @Test
- public void testConfigPrincipalStringByteArray() throws IOException {
- byte[] bytes = "pass".getBytes();
- ConfigPrincipal p = new ConfigPrincipal("User", bytes);
-
- assertEquals(p.getName(), "User");
- assertEquals(p.getCred(), bytes);
- assertEquals(p.toString(), "User");
- assertTrue(p.getAsBasicAuthHeader().startsWith("Basic"));
- }
-
- @Test
- public void testConfigPrincipalStringString2() {
- ConfigPrincipal p = new ConfigPrincipal("Demo", "password");
-
- assertEquals(p.getName(), "Demo");
- assertEquals(p.toString(), "Demo");
-
- }
-
- @Test
- public void testConfigPrincipalStringByteArray2() throws IOException {
- byte[] bytes = "password".getBytes();
- ConfigPrincipal p = new ConfigPrincipal("Demo", bytes);
-
- assertEquals(p.getName(), "Demo");
- assertEquals(p.getCred(), bytes);
- assertEquals(p.toString(), "Demo");
- assertTrue(p.getAsBasicAuthHeader().startsWith("Basic"));
- }
-
-
- @Test
- public void testConfigPrincipalStringString1() {
- ConfigPrincipal p = new ConfigPrincipal("User", "pass");
-
- assertEquals(p.getName(), "User");
- assertEquals(p.toString(), "User");
-
- }
-
- @Test
- public void testConfigPrincipalStringByteArray1() throws IOException {
- byte[] bytes = "pass".getBytes();
- ConfigPrincipal p = new ConfigPrincipal("User", bytes);
-
- assertEquals(p.getName(), "User");
- assertEquals(p.getCred(), bytes);
- assertEquals(p.toString(), "User");
- assertTrue(p.getAsBasicAuthHeader().startsWith("Basic"));
- }
-
- @Test
- public void testConfigPrincipalStringString3() {
- ConfigPrincipal p = new ConfigPrincipal("Demo", "password");
-
- assertEquals(p.getName(), "Demo");
- assertEquals(p.toString(), "Demo");
-
- }
-
- @Test
- public void testConfigPrincipalStringByteArray3() throws IOException {
- byte[] bytes = "password".getBytes();
- ConfigPrincipal p = new ConfigPrincipal("Demo", bytes);
-
- assertEquals(p.getName(), "Demo");
- assertEquals(p.getCred(), bytes);
- assertEquals(p.toString(), "Demo");
- assertTrue(p.getAsBasicAuthHeader().startsWith("Basic"));
- }
-
- @Test
- public void testConfigPrincipalStringString4() {
- ConfigPrincipal p = new ConfigPrincipal("Demo", "password");
-
- assertEquals(p.getName(), "Demo");
- assertEquals(p.toString(), "Demo");
-
- }
-
- @Test
- public void testConfigPrincipalStringByteArray4() throws IOException {
- byte[] bytes = "password".getBytes();
- ConfigPrincipal p = new ConfigPrincipal("Demo", bytes);
-
- assertEquals(p.getName(), "Demo");
- assertEquals(p.getCred(), bytes);
- assertEquals(p.toString(), "Demo");
- assertTrue(p.getAsBasicAuthHeader().startsWith("Basic"));
- }
-
- @Test
- public void testConfigPrincipalStringByteArray5() throws IOException {
- byte[] bytes = "password".getBytes();
- ConfigPrincipal p = new ConfigPrincipal("Demo", bytes);
-
- assertEquals(p.getName(), "Demo");
- assertEquals(p.getCred(), bytes);
- assertEquals(p.toString(), "Demo");
- assertTrue(p.getAsBasicAuthHeader().startsWith("Basic"));
- }
-
- @Test
- public void testConfigPrincipalStringByteArray6() throws IOException {
- byte[] bytes = "password".getBytes();
- ConfigPrincipal p = new ConfigPrincipal("Demo", bytes);
-
- assertEquals(p.getName(), "Demo");
- assertEquals(p.getCred(), bytes);
- assertEquals(p.toString(), "Demo");
- assertTrue(p.getAsBasicAuthHeader().startsWith("Basic"));
- }
-
- @Test
- public void testConfigPrincipalStringByteArray7() throws IOException {
- byte[] bytes = "password".getBytes();
- ConfigPrincipal p = new ConfigPrincipal("Demo", bytes);
-
- assertEquals(p.getName(), "Demo");
- assertEquals(p.getCred(), bytes);
- assertEquals(p.toString(), "Demo");
- assertTrue(p.getAsBasicAuthHeader().startsWith("Basic"));
- }
-}
diff --git a/core/src/test/java/org/onap/aaf/cadi/lur/test/JU_LocalLur.java b/core/src/test/java/org/onap/aaf/cadi/lur/test/JU_LocalLur.java deleted file mode 100644 index b04d00d..0000000 --- a/core/src/test/java/org/onap/aaf/cadi/lur/test/JU_LocalLur.java +++ /dev/null @@ -1,104 +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====================================================
- * *
- * * ECOMP is a trademark and service mark of AT&T Intellectual Property.
- * *
- ******************************************************************************/
-package org.onap.aaf.cadi.lur.test;
-
-import static junit.framework.Assert.assertEquals;
-import static junit.framework.Assert.assertFalse;
-import static junit.framework.Assert.assertTrue;
-
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.security.Principal;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Set;
-import java.util.TreeSet;
-
-import org.junit.Test;
-import org.onap.aaf.cadi.Lur;
-import org.onap.aaf.cadi.Permission;
-import org.onap.aaf.cadi.PropAccess;
-import org.onap.aaf.cadi.Symm;
-import org.onap.aaf.cadi.CredVal.Type;
-import org.onap.aaf.cadi.config.UsersDump;
-import org.onap.aaf.cadi.lur.LocalLur;
-import org.onap.aaf.cadi.lur.LocalPermission;
-
-public class JU_LocalLur {
-
- @Test
- public void test() throws IOException {
- Symm symmetric = Symm.baseCrypt().obtain();
- LocalLur up;
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- baos.write(Symm.ENC.getBytes());
- symmetric.enpass("<pass>", baos);
- PropAccess ta = new PropAccess();
- Lur ml = up = new LocalLur(ta,"myname:groupA,groupB","admin:myname,yourname;suser:hisname,hername,m1234%"+baos.toString());
-
-
-// Permission admin = new LocalPermission("admin");
-// Permission suser = new LocalPermission("suser");
-//
-// // Check User fish
-// assertTrue(ml.fish(new JUPrincipal("myname"),admin));
-// assertTrue(ml.fish(new JUPrincipal("hisname"),admin));
-// assertFalse(ml.fish(new JUPrincipal("noname"),admin));
-// assertTrue(ml.fish(new JUPrincipal("itsname"),suser));
-// assertTrue(ml.fish(new JUPrincipal("hername"),suser));
-// assertFalse(ml.fish(new JUPrincipal("myname"),suser));
-//
-// // Check validate password
-// assertTrue(up.validate("m1234",Type.PASSWORD, "<pass>".getBytes()));
-// assertFalse(up.validate("m1234",Type.PASSWORD, "badPass".getBytes()));
-//
- // Check fishAll
- Set<String> set = new TreeSet<String>();
- List<Permission> perms = new ArrayList<Permission>();
- ml.fishAll(new JUPrincipal("myname"), perms);
- for(Permission p : perms) {
- set.add(p.getKey());
- }
-// assertEquals("[admin, groupA, groupB]",set.toString());
- UsersDump.write(System.out, up);
- System.out.flush();
-
- }
-
- // Simplistic Principal for testing purposes
- private static class JUPrincipal implements Principal {
- private String name;
- public JUPrincipal(String name) {
- this.name = name;
- }
-// @Override
- public String getName() {
- return name;
- }
- }
-
-
-
-
-
-}
diff --git a/core/src/test/java/org/onap/aaf/cadi/lur/test/JU_TestAccess.java b/core/src/test/java/org/onap/aaf/cadi/lur/test/JU_TestAccess.java deleted file mode 100644 index 1bdf765..0000000 --- a/core/src/test/java/org/onap/aaf/cadi/lur/test/JU_TestAccess.java +++ /dev/null @@ -1,91 +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====================================================
- * *
- * * ECOMP is a trademark and service mark of AT&T Intellectual Property.
- * *
- ******************************************************************************/
-package org.onap.aaf.cadi.lur.test;
-
-import java.io.IOException;
-import java.io.InputStream;
-
-import org.onap.aaf.cadi.Access;
-import org.onap.aaf.cadi.Symm;
-
-public class JU_TestAccess implements Access {
- private Symm symm;
-
- public JU_TestAccess() {
- symm = Symm.obtain(this);
- }
-
- public JU_TestAccess(Symm symmetric) {
- symm = symmetric;
- }
-
- public void log(Level level, Object... elements) {
- boolean first = true;
- for(int i=0;i<elements.length;++i) {
- if(first)first = false;
- else System.out.print(' ');
- System.out.print(elements[i].toString());
- }
- System.out.println();
- }
-
- public void log(Exception e, Object... elements) {
- e.printStackTrace();
- log(Level.ERROR,elements);
- }
-
- public void setLogLevel(Level level) {
-
- }
-
- public ClassLoader classLoader() {
- return ClassLoader.getSystemClassLoader();
- }
-
- public String getProperty(String string, String def) {
- String rv = System.getProperty(string);
- return rv==null?def:rv;
- }
-
- public void load(InputStream is) throws IOException {
-
- }
-
- public String decrypt(String encrypted, boolean anytext) throws IOException {
- return (encrypted!=null && (anytext==true || encrypted.startsWith(Symm.ENC)))
- ? symm.depass(encrypted)
- : encrypted;
- }
-
- @Override
- public boolean willLog(Level level) {
- return true;
- }
-
- @Override
- public void printf(Level level, String fmt, Object[] elements) {
- // TODO Auto-generated method stub
-
- }
-
-}
diff --git a/core/src/test/java/org/onap/aaf/cadi/taf/JU_NullTafRespTest.java b/core/src/test/java/org/onap/aaf/cadi/taf/JU_NullTafRespTest.java deleted file mode 100644 index d7f6560..0000000 --- a/core/src/test/java/org/onap/aaf/cadi/taf/JU_NullTafRespTest.java +++ /dev/null @@ -1,62 +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====================================================
- * *
- * * ECOMP is a trademark and service mark of AT&T Intellectual Property.
- * *
- ******************************************************************************/
-package org.onap.aaf.cadi.taf;
-
-import static org.junit.Assert.*;
-
-import java.io.IOException;
-
-import org.junit.Before;
-import org.junit.Test;
-import org.onap.aaf.cadi.Access;
-import org.onap.aaf.cadi.taf.TafResp.RESP;
-
-public class JU_NullTafRespTest {
-
- @Before
- public void setUp() throws Exception {
- }
-
- @Test
- public void test() throws IOException {
- TafResp singleton = NullTafResp.singleton();
- TafResp singleton1 = NullTafResp.singleton();
-
- assertEquals(singleton, singleton1);
-
- assertFalse(singleton.isValid());
-
- assertEquals(singleton.isAuthenticated(), RESP.NO_FURTHER_PROCESSING);
-
- assertEquals(singleton.desc(), "All Authentication denied");
-
- assertEquals(singleton.authenticate(), RESP.NO_FURTHER_PROCESSING);
-
- assertNull(singleton.getPrincipal());
-
- assertEquals(singleton.getAccess(), Access.NULL);
-
- assertEquals(singleton.isFailedAttempt(), true);
- }
-
-}
diff --git a/core/src/test/java/org/onap/aaf/cadi/test/JU_Base64.java b/core/src/test/java/org/onap/aaf/cadi/test/JU_Base64.java deleted file mode 100644 index 3596619..0000000 --- a/core/src/test/java/org/onap/aaf/cadi/test/JU_Base64.java +++ /dev/null @@ -1,368 +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====================================================
- * *
- * * ECOMP is a trademark and service mark of AT&T Intellectual Property.
- * *
- ******************************************************************************/
-package org.onap.aaf.cadi.test;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotSame;
-
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.security.SecureRandom;
-import org.junit.Test;
-import org.onap.aaf.cadi.Symm;
-import org.onap.aaf.cadi.config.Config;
-
-
-public class JU_Base64 {
- private static final String encoding = "Man is distinguished, not only by his reason, but by this singular " +
- "passion from other animals, which is a lust of the mind, that by a " +
- "perseverance of delight in the continued and indefatigable generation of " +
- "knowledge, exceeds the short vehemence of any carnal pleasure.";
-
- private static final String expected =
- "TWFuIGlzIGRpc3Rpbmd1aXNoZWQsIG5vdCBvbmx5IGJ5IGhpcyByZWFzb24sIGJ1dCBieSB0aGlz\n" +
- "IHNpbmd1bGFyIHBhc3Npb24gZnJvbSBvdGhlciBhbmltYWxzLCB3aGljaCBpcyBhIGx1c3Qgb2Yg\n" +
- "dGhlIG1pbmQsIHRoYXQgYnkgYSBwZXJzZXZlcmFuY2Ugb2YgZGVsaWdodCBpbiB0aGUgY29udGlu\n" +
- "dWVkIGFuZCBpbmRlZmF0aWdhYmxlIGdlbmVyYXRpb24gb2Yga25vd2xlZGdlLCBleGNlZWRzIHRo\n" +
- "ZSBzaG9ydCB2ZWhlbWVuY2Ugb2YgYW55IGNhcm5hbCBwbGVhc3VyZS4=";
-
-
- @Test
- public void test() throws Exception {
- // Test with different Padding
- encode("leas", "bGVhcw==");
- encode("leasu", "bGVhc3U=");
- encode("leasur", "bGVhc3Vy");
- encode("leasure", "bGVhc3VyZQ==");
- encode("leasure.","bGVhc3VyZS4=");
-
- // Test with line ends
- encode(encoding, expected);
-
- int ITER = 2000;
- System.out.println("Priming by Encoding Base64 " + ITER + " times");
- long start = System.nanoTime();
- for(int i=0;i<ITER;++i) {
- Symm.base64.encode(encoding);
- }
- Float ms = (System.nanoTime()-start)/1000000F;
- System.out.println("Total: " + ms + "ms");
- System.out.println("Avg: " + ms/ITER + "ms");
-
- System.out.println("Priming by Decoding Base64 " + ITER + " times");
- start = System.nanoTime();
- for(int i=0;i<ITER;++i) {
- Symm.base64.decode(expected);
- }
- ms = (System.nanoTime()-start)/1000000F;
- System.out.println("Total: " + ms + "ms");
- System.out.println("Avg: " + ms/ITER + "ms");
-
-
- ITER=30000;
- System.out.println("Encoding Base64 " + ITER + " times");
- start = System.nanoTime();
- for(int i=0;i<ITER;++i) {
- Symm.base64.encode(encoding);
- }
- ms = (System.nanoTime()-start)/1000000F;
- System.out.println("Total: " + ms + "ms");
- System.out.println("Avg: " + ms/ITER + "ms");
-
- System.out.println("Decoding Base64 " + ITER + " times");
- start = System.nanoTime();
- for(int i=0;i<ITER;++i) {
- Symm.base64.decode(expected);
- }
- ms = (System.nanoTime()-start)/1000000F;
- System.out.println("Total: " + ms + "ms");
- System.out.println("Avg: " + ms/ITER + "ms");
- }
-
- @Test
- public void symmetric() throws IOException {
- System.out.println("Validating Generated Key mechanisms works");
- String symmetric = new String(Symm.base64.keygen());
- System.out.println(symmetric);
- Symm bsym = Symm.obtain(symmetric);
- String result = bsym.encode(encoding);
- System.out.println("\nResult:");
- System.out.println(result);
- assertEquals(encoding, bsym.decode(result));
-
- int ITER = 20000;
- System.out.println("Generating keys " + ITER + " times");
- long start = System.nanoTime();
- for(int i=0;i<ITER;++i) {
- Symm.base64.keygen();
- }
- Float ms = (System.nanoTime()-start)/1000000F;
- System.out.println("Total: " + ms + "ms");
- System.out.println("Avg: " + ms/ITER + "ms");
-
- char[] manipulate = symmetric.toCharArray();
- int spot = new SecureRandom().nextInt(manipulate.length);
- manipulate[spot]|=0xFF;
- String newsymmetric = new String(manipulate);
- assertNotSame(newsymmetric, symmetric);
- try {
- bsym = Symm.obtain(newsymmetric);
- result = bsym.decode(result);
- assertEquals(encoding, result);
- } catch (IOException e) {
- // this is what we want to see if key wrong
- System.out.println(e.getMessage() + " (as expected)");
- }
- }
-
- private void encode(String toEncode, String expected) throws IOException {
- System.out.println("-------------------------------------------------");
- System.out.println(toEncode);
- System.out.println();
- System.out.println(expected);
- System.out.println();
- String result = Symm.base64.encode(toEncode);
- System.out.println(result);
- assertEquals(expected,result);
-
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- Symm.base64.decode(new ByteArrayInputStream(result.getBytes()), baos);
- result = baos.toString(Config.UTF_8);
- System.out.println(result);
- assertEquals(toEncode,result);
-
- }
-
- @Test
- public void test1() throws Exception {
- // Test with different Padding
- encode("leas", "bGVhcw==");
- encode("leasu", "bGVhc3U=");
- encode("leasur", "bGVhc3Vy");
- encode("leasure", "bGVhc3VyZQ==");
- encode("leasure.","bGVhc3VyZS4=");
-
- // Test with line ends
- encode(encoding, expected);
-
- int ITER = 2000;
- System.out.println("Priming by Encoding Base64 " + ITER + " times");
- long start = System.nanoTime();
- for(int i=0;i<ITER;++i) {
- Symm.base64.encode(encoding);
- }
- Float ms = (System.nanoTime()-start)/1000000F;
- System.out.println("Total: " + ms + "ms");
- System.out.println("Avg: " + ms/ITER + "ms");
-
- System.out.println("Priming by Decoding Base64 " + ITER + " times");
- start = System.nanoTime();
- for(int i=0;i<ITER;++i) {
- Symm.base64.decode(expected);
- }
- ms = (System.nanoTime()-start)/1000000F;
- System.out.println("Total: " + ms + "ms");
- System.out.println("Avg: " + ms/ITER + "ms");
-
-
- ITER=30000;
- System.out.println("Encoding Base64 " + ITER + " times");
- start = System.nanoTime();
- for(int i=0;i<ITER;++i) {
- Symm.base64.encode(encoding);
- }
- ms = (System.nanoTime()-start)/1000000F;
- System.out.println("Total: " + ms + "ms");
- System.out.println("Avg: " + ms/ITER + "ms");
-
- System.out.println("Decoding Base64 " + ITER + " times");
- start = System.nanoTime();
- for(int i=0;i<ITER;++i) {
- Symm.base64.decode(expected);
- }
- ms = (System.nanoTime()-start)/1000000F;
- System.out.println("Total: " + ms + "ms");
- System.out.println("Avg: " + ms/ITER + "ms");
- }
-
- @Test
- public void symmetric1() throws IOException {
- System.out.println("Validating Generated Key mechanisms works");
- String symmetric = new String(Symm.base64.keygen());
- System.out.println(symmetric);
- Symm bsym = Symm.obtain(symmetric);
- String result = bsym.encode(encoding);
- System.out.println("\nResult:");
- System.out.println(result);
- assertEquals(encoding, bsym.decode(result));
-
- int ITER = 20000;
- System.out.println("Generating keys " + ITER + " times");
- long start = System.nanoTime();
- for(int i=0;i<ITER;++i) {
- Symm.base64.keygen();
- }
- Float ms = (System.nanoTime()-start)/1000000F;
- System.out.println("Total: " + ms + "ms");
- System.out.println("Avg: " + ms/ITER + "ms");
-
- char[] manipulate = symmetric.toCharArray();
- int spot = new SecureRandom().nextInt(manipulate.length);
- manipulate[spot]|=0xFF;
- String newsymmetric = new String(manipulate);
- assertNotSame(newsymmetric, symmetric);
- try {
- bsym = Symm.obtain(newsymmetric);
- result = bsym.decode(result);
- assertEquals(encoding, result);
- } catch (IOException e) {
- // this is what we want to see if key wrong
- System.out.println(e.getMessage() + " (as expected)");
- }
- }
-
- private void encode1(String toEncode, String expected) throws IOException {
- System.out.println("-------------------------------------------------");
- System.out.println(toEncode);
- System.out.println();
- System.out.println(expected);
- System.out.println();
- String result = Symm.base64.encode(toEncode);
- System.out.println(result);
- assertEquals(expected,result);
-
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- Symm.base64.decode(new ByteArrayInputStream(result.getBytes()), baos);
- result = baos.toString(Config.UTF_8);
- System.out.println(result);
- assertEquals(toEncode,result);
-
- }
-
- @Test
- public void test2() throws Exception {
- // Test with different Padding
- encode("leas", "bGVhcw==");
- encode("leasu", "bGVhc3U=");
- encode("leasur", "bGVhc3Vy");
- encode("leasure", "bGVhc3VyZQ==");
- encode("leasure.","bGVhc3VyZS4=");
-
- // Test with line ends
- encode(encoding, expected);
-
- int ITER = 2000;
- System.out.println("Priming by Encoding Base64 " + ITER + " times");
- long start = System.nanoTime();
- for(int i=0;i<ITER;++i) {
- Symm.base64.encode(encoding);
- }
- Float ms = (System.nanoTime()-start)/1000000F;
- System.out.println("Total: " + ms + "ms");
- System.out.println("Avg: " + ms/ITER + "ms");
-
- System.out.println("Priming by Decoding Base64 " + ITER + " times");
- start = System.nanoTime();
- for(int i=0;i<ITER;++i) {
- Symm.base64.decode(expected);
- }
- ms = (System.nanoTime()-start)/1000000F;
- System.out.println("Total: " + ms + "ms");
- System.out.println("Avg: " + ms/ITER + "ms");
-
-
- ITER=30000;
- System.out.println("Encoding Base64 " + ITER + " times");
- start = System.nanoTime();
- for(int i=0;i<ITER;++i) {
- Symm.base64.encode(encoding);
- }
- ms = (System.nanoTime()-start)/1000000F;
- System.out.println("Total: " + ms + "ms");
- System.out.println("Avg: " + ms/ITER + "ms");
-
- System.out.println("Decoding Base64 " + ITER + " times");
- start = System.nanoTime();
- for(int i=0;i<ITER;++i) {
- Symm.base64.decode(expected);
- }
- ms = (System.nanoTime()-start)/1000000F;
- System.out.println("Total: " + ms + "ms");
- System.out.println("Avg: " + ms/ITER + "ms");
- }
-
- @Test
- public void symmetric2() throws IOException {
- System.out.println("Validating Generated Key mechanisms works");
- String symmetric = new String(Symm.base64.keygen());
- System.out.println(symmetric);
- Symm bsym = Symm.obtain(symmetric);
- String result = bsym.encode(encoding);
- System.out.println("\nResult:");
- System.out.println(result);
- assertEquals(encoding, bsym.decode(result));
-
- int ITER = 20000;
- System.out.println("Generating keys " + ITER + " times");
- long start = System.nanoTime();
- for(int i=0;i<ITER;++i) {
- Symm.base64.keygen();
- }
- Float ms = (System.nanoTime()-start)/1000000F;
- System.out.println("Total: " + ms + "ms");
- System.out.println("Avg: " + ms/ITER + "ms");
-
- char[] manipulate = symmetric.toCharArray();
- int spot = new SecureRandom().nextInt(manipulate.length);
- manipulate[spot]|=0xFF;
- String newsymmetric = new String(manipulate);
- assertNotSame(newsymmetric, symmetric);
- try {
- bsym = Symm.obtain(newsymmetric);
- result = bsym.decode(result);
- assertEquals(encoding, result);
- } catch (IOException e) {
- // this is what we want to see if key wrong
- System.out.println(e.getMessage() + " (as expected)");
- }
- }
-
- private void encode2(String toEncode, String expected) throws IOException {
- System.out.println("-------------------------------------------------");
- System.out.println(toEncode);
- System.out.println();
- System.out.println(expected);
- System.out.println();
- String result = Symm.base64.encode(toEncode);
- System.out.println(result);
- assertEquals(expected,result);
-
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- Symm.base64.decode(new ByteArrayInputStream(result.getBytes()), baos);
- result = baos.toString(Config.UTF_8);
- System.out.println(result);
- assertEquals(toEncode,result);
-
- }
-}
diff --git a/core/src/test/java/org/onap/aaf/cadi/test/JU_BufferedServletInputStream.java b/core/src/test/java/org/onap/aaf/cadi/test/JU_BufferedServletInputStream.java deleted file mode 100644 index e496076..0000000 --- a/core/src/test/java/org/onap/aaf/cadi/test/JU_BufferedServletInputStream.java +++ /dev/null @@ -1,190 +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====================================================
- * *
- * * ECOMP is a trademark and service mark of AT&T Intellectual Property.
- * *
- ******************************************************************************/
-package org.onap.aaf.cadi.test;
-
-import static junit.framework.Assert.assertEquals;
-
-import java.io.ByteArrayInputStream;
-import java.io.FileInputStream;
-import java.io.IOException;
-
-import org.junit.Test;
-import org.onap.aaf.cadi.BufferedServletInputStream;
-
-public class JU_BufferedServletInputStream {
-
- @Test
- public void testByteRead() throws Exception {
- FileInputStream fis = new FileInputStream("test/CBUSevent.xml");
- BufferedServletInputStream bsis = new BufferedServletInputStream(fis);
- try {
- bsis.mark(0);
- int c;
- byte aa[] = new byte[260];
- for(int i=0;i<aa.length;++i) {
- c = bsis.read();
- if(c>=0) {
- aa[i]=(byte)c;
- }
- }
- System.out.println(new String(aa));
-
- bsis.reset();
-
- byte bb[] = new byte[400];
- for(int i=0;i<bb.length;++i) {
- c = bsis.read();
- if(c>=0) {
- bb[i]=(byte)c;
- }
- }
- System.out.println(new String(bb));
-
- } finally {
- bsis.close();
- fis.close();
- }
- }
-
- @Test
- public void testByteArray() throws Exception {
- FileInputStream fis = new FileInputStream("test/CBUSevent.xml");
- BufferedServletInputStream bsis = new BufferedServletInputStream(fis);
- try {
- bsis.mark(0);
- byte aa[] = new byte[260];
- bsis.read(aa);
- System.out.println(new String(aa));
-
- bsis.reset();
-
- byte bb[] = new byte[400];
- bsis.read(bb);
- System.out.println(new String(bb));
-
- } finally {
- bsis.close();
- fis.close();
- }
- }
-
- @Test
- public void testDoubleRead() throws Exception {
- FileInputStream fis = new FileInputStream("test/CBUSevent.xml");
- BufferedServletInputStream bsis = new BufferedServletInputStream(fis);
- try {
- bsis.mark(0);
- byte aa[] = new byte[260];
- bsis.read(aa);
- System.out.println(new String(aa));
-
- bsis.reset();
-
- byte bb[] = new byte[400];
- bsis.read(bb);
- System.out.println(new String(bb));
-
- } finally {
- bsis.close();
- fis.close();
- }
- }
-
- @Test
- public void testByteArray2() throws Exception {
- FileInputStream fis = new FileInputStream("test/CBUSevent.xml");
- try {
- BufferedServletInputStream bsis = new BufferedServletInputStream(fis);
- byte[] content = null;
- byte aa[] = new byte[500];
- for(int i=0;i<2000;++i) {
- bsis.mark(0);
- bsis.read(aa,0,260);
- if(i==0)System.out.println(new String(aa));
-
- bsis.reset();
-
- bsis.read(aa,0,aa.length);
- if(i==0) {
- System.out.println(new String(aa));
- content = aa;
- aa = new byte[400];
- }
- bsis = new BufferedServletInputStream(new ByteArrayInputStream(content));
-
- }
-
- System.out.println(new String(aa));
-
- } finally {
- fis.close();
- }
- }
-
- // "Bug" 4/22/2013
- // Some XML code expects Buffered InputStream can never return 0... This isn't actually true, but we'll accommodate as far
- // as we can.
- // Here, we make sure we set and read the Buffered data, making sure the buffer is empty on the last test...
- @Test
- public void issue04_22_2013() throws IOException {
- String testString = "We want to read in and get out with a Buffered Stream seamlessly.";
- ByteArrayInputStream bais = new ByteArrayInputStream(testString.getBytes());
- BufferedServletInputStream bsis = new BufferedServletInputStream(bais);
- try {
- bsis.mark(0);
- byte aa[] = new byte[testString.length()]; // 65 count... important for our test (divisible by 5);
-
- int read;
- for(int i=0;i<aa.length;i+=5) {
- read = bsis.read(aa, i, 5);
- assertEquals(5,read);
- }
- System.out.println(new String(aa));
-
- bsis.reset();
-
- byte bb[] = new byte[aa.length];
- read = 0;
- for(int i=0;read>=0;i+=read) {
- read = bsis.read(bb,i,5);
- switch(i) {
- case 65:
- assertEquals(read,-1);
- break;
- default:
- assertEquals(read,5);
- }
- }
- System.out.println(new String(bb));
- assertEquals(testString,new String(aa));
- assertEquals(testString,new String(bb));
-
- } finally {
- bsis.close();
- bais.close();
- }
-
- }
-
-
-}
diff --git a/core/src/test/java/org/onap/aaf/cadi/test/JU_Capacitor.java b/core/src/test/java/org/onap/aaf/cadi/test/JU_Capacitor.java deleted file mode 100644 index 9d11fe4..0000000 --- a/core/src/test/java/org/onap/aaf/cadi/test/JU_Capacitor.java +++ /dev/null @@ -1,143 +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====================================================
- * *
- * * ECOMP is a trademark and service mark of AT&T Intellectual Property.
- * *
- ******************************************************************************/
-package org.onap.aaf.cadi.test;
-
-import static junit.framework.Assert.assertEquals;
-
-import org.junit.Test;
-import org.onap.aaf.cadi.Capacitor;
-
-public class JU_Capacitor {
- @Test
- public void testA() {
- Capacitor cap = new Capacitor();
-
- for(int iter=0;iter<200;++iter) {
- for(int i=0;i<20;++i) {
- cap.put((byte)('a'+i));
- }
- cap.setForRead();
- byte[] array = new byte[20];
- for(int i=0;i<20;++i) {
- array[i]=(byte)cap.read();
- }
- assertEquals("abcdefghijklmnopqrst",new String(array));
- assertEquals(-1,cap.read());
- cap.done();
- }
- }
-
- public final static String TEST_DATA =
- "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" +
- "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb" +
- "cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc" +
- "dddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd" +
- "eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee" +
- "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff";
- @Test
- public void testB() {
- Capacitor cap = new Capacitor();
- byte[] arrayA = TEST_DATA.getBytes();
- System.out.println(arrayA.length);
- for(int iter=0;iter<200;++iter) {
- for(int i=0;i<arrayA.length;++i) {
- cap.put(arrayA[i]);
- }
- cap.setForRead();
- assertEquals(TEST_DATA.length(),cap.available());
- byte[] arrayB = new byte[arrayA.length];
- for(int i=0;i<arrayB.length;++i) {
- arrayB[i]=(byte)cap.read();
- }
- assertEquals(TEST_DATA,new String(arrayB));
- assertEquals(-1,cap.read());
- cap.done();
- }
- }
-
- @Test
- public void testC() {
- Capacitor cap = new Capacitor();
- byte[] arrayA = TEST_DATA.getBytes();
- System.out.println(arrayA.length);
- for(int iter=0;iter<200;++iter) {
- cap.put(arrayA,0,arrayA.length);
- cap.setForRead();
- assertEquals(TEST_DATA.length(),cap.available());
- byte[] arrayB = new byte[arrayA.length];
- assertEquals(arrayA.length,cap.read(arrayB,0,arrayB.length));
- assertEquals(TEST_DATA,new String(arrayB));
- assertEquals(-1,cap.read());
- cap.done();
- }
- }
-
-
- @Test
- public void testD() {
- StringBuffer sb = new StringBuffer();
- for(int i=0;i<300;++i) {
- sb.append(TEST_DATA);
- sb.append("###FILLER##");
- }
- String td = sb.toString();
- Capacitor cap = new Capacitor();
- byte[] arrayA = td.getBytes();
- System.out.println(arrayA.length);
- for(int iter=0;iter<200;++iter) {
- cap.put(arrayA,0,arrayA.length);
- cap.setForRead();
- assertEquals(td.length(),cap.available());
- byte[] arrayB = new byte[arrayA.length];
- assertEquals(arrayA.length,cap.read(arrayB,0,arrayB.length));
- assertEquals(td,new String(arrayB));
- assertEquals(-1,cap.read());
- cap.done();
- }
- }
-
- @Test
- public void testE() {
- Capacitor cap = new Capacitor();
-
- String b = "This is some content that we want to read";
- byte[] a = b.getBytes();
- byte[] c = new byte[b.length()]; // we want to use this to test reading offsets, etc
-
- for(int i=0;i<a.length;i+=11) {
- cap.put(a, i, Math.min(11,a.length-i));
- }
- cap.reset();
- int read;
- for(int i=0;i<c.length;i+=read) {
- read = cap.read(c, i, Math.min(3,c.length-i));
- if(read<0) break;
- }
-
- assertEquals(b, new String(c));
-
-
- }
-
-
-}
diff --git a/core/src/test/java/org/onap/aaf/cadi/test/JU_Hash.java b/core/src/test/java/org/onap/aaf/cadi/test/JU_Hash.java deleted file mode 100644 index f79564d..0000000 --- a/core/src/test/java/org/onap/aaf/cadi/test/JU_Hash.java +++ /dev/null @@ -1,115 +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====================================================
- * *
- * * ECOMP is a trademark and service mark of AT&T Intellectual Property.
- * *
- ******************************************************************************/
-package org.onap.aaf.cadi.test;
-
-import org.junit.Test;
-import org.onap.aaf.cadi.CadiException;
-import org.onap.aaf.cadi.Hash;
-
-import junit.framework.Assert;
-
-public class JU_Hash {
-
- @Test
- public void test() throws CadiException {
- String init = "m82347@csp.att.com:kumquat8rie@#Tomatos3";
- String hashed = Hash.toHex(init.getBytes());
- System.out.println(hashed);
- byte[] ba = Hash.fromHex(hashed);
- String recon = new String(ba);
- System.out.println(recon);
- Assert.assertEquals(init, recon);
-
- init =hashed.substring(1);
- try {
- hashed = Hash.fromHex(init).toString();
- Assert.fail("Should have thrown Exception");
- } catch (CadiException e) {
-
- }
-
- init = hashed.replace('1', '~');
- try {
- hashed = Hash.fromHex(init).toString();
- Assert.fail("Should have thrown Exception");
- } catch (CadiException e) {
-
- }
- }
-
- @Test
- public void test1() throws CadiException {
- String init = "m8234337@csp.att.com:kumquat8rie@#Tomatos3";
- String hashed = Hash.toHex(init.getBytes());
- System.out.println(hashed);
- byte[] ba = Hash.fromHex(hashed);
- String recon = new String(ba);
- System.out.println(recon);
- Assert.assertEquals(init, recon);
-
- init =hashed.substring(1);
- try {
- hashed = Hash.fromHex(init).toString();
- Assert.fail("Should have thrown Exception");
- } catch (CadiException e) {
-
- }
-
- init = hashed.replace('1', '~');
- try {
- hashed = Hash.fromHex(init).toString();
- Assert.fail("Should have thrown Exception");
- } catch (CadiException e) {
-
- }
- }
-
-
- @Test
- public void test2() throws CadiException {
- String init = "m823475@csp.att.com:kumquat8rie@#Tomatos3";
- String hashed = Hash.toHex(init.getBytes());
- System.out.println(hashed);
- byte[] ba = Hash.fromHex(hashed);
- String recon = new String(ba);
- System.out.println(recon);
- Assert.assertEquals(init, recon);
-
- init =hashed.substring(1);
- try {
- hashed = Hash.fromHex(init).toString();
- Assert.fail("Should have thrown Exception");
- } catch (CadiException e) {
-
- }
-
- init = hashed.replace('1', '~');
- try {
- hashed = Hash.fromHex(init).toString();
- Assert.fail("Should have thrown Exception");
- } catch (CadiException e) {
-
- }
- }
-
-}
diff --git a/core/src/test/java/org/onap/aaf/cadi/test/JU_Passcode.java b/core/src/test/java/org/onap/aaf/cadi/test/JU_Passcode.java deleted file mode 100644 index f51b131..0000000 --- a/core/src/test/java/org/onap/aaf/cadi/test/JU_Passcode.java +++ /dev/null @@ -1,106 +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====================================================
- * *
- * * ECOMP is a trademark and service mark of AT&T Intellectual Property.
- * *
- ******************************************************************************/
-package org.onap.aaf.cadi.test;
-
-import java.io.ByteArrayOutputStream;
-import java.io.File;
-import java.io.FileInputStream;
-
-import org.junit.Test;
-import org.onap.aaf.cadi.CmdLine;
-import org.onap.aaf.cadi.Symm;
-
-import junit.framework.Assert;
-
-import java.io.ByteArrayOutputStream;
-import java.io.File;
-import java.io.FileInputStream;
-
-import org.junit.AfterClass;
-import org.junit.Test;
-import org.onap.aaf.cadi.CmdLine;
-import org.onap.aaf.cadi.Symm;
-
-import junit.framework.Assert;
-
-public class JU_Passcode {
- @Test
- public void test() throws Exception {
- int iterations = 0;
- long start = System.nanoTime();
- int gens= 800, en_de=2000;
- for(int j=0;j<gens;++j) {
- CmdLine.main(new String[] {"keygen","tempkey"});
-
- Symm symm;
- File fi = new File("tempkey");
- Assert.assertEquals(2074, fi.length());
- FileInputStream fis = new FileInputStream(fi);
-
- try {
- symm = Symm.obtain(fis);
- } finally {
- fis.close();
- fi.delete();
- }
- String samples[] = {"activevos","ThisIsATestPassword","I have spaces","I have 's, /s and &s and _s"};
- ByteArrayOutputStream baos;
- for(int i=0;i<en_de;++i) {
- String password = samples[i%samples.length];
- baos = new ByteArrayOutputStream();
- symm.enpass(password, baos);
- String pass = baos.toString();
- byte[] array = baos.toByteArray();
- for(int k=0;k<array.length;++k) {
- byte ch = array[k];
-// for(int k=0;k<pass.length();++k) {
-// char ch = pass.charAt(k);
- if(!(Character.isLetter(ch) || Character.isDigit(ch) || ch=='-' || ch=='_' || ch=='=')) {
- throw new Exception("Yikes, have a bad character..." + ch + '(' + (int)ch + ')');
- }
- }
- baos = new ByteArrayOutputStream();
- symm.depass(pass, baos);
- Assert.assertEquals(password,baos.toString());
- Assert.assertEquals(password,symm.depass(pass));
- ++iterations;
- }
- symm.enpass("activevos", System.out);
- System.out.println();
- }
- float ms = (System.nanoTime()-start)/1000000F;
- System.out.println("Ran " + iterations + " Encrypt/Decrypt cycles + " + gens + " keygens");
-
- System.out.println("Total: " + ms + "ms");
- System.out.println("Avg: " + ms/iterations + "ms");
- System.out.println("Avg Gen + " + en_de + " Encrypt/Decrypt cycles: " + ms/gens + "ms");
-
-
- }
-
- @AfterClass
- public static void tearDown() {
-
- }
-
-}
diff --git a/core/src/test/java/org/onap/aaf/cadi/test/JU_Test.java b/core/src/test/java/org/onap/aaf/cadi/test/JU_Test.java deleted file mode 100644 index 38eefe4..0000000 --- a/core/src/test/java/org/onap/aaf/cadi/test/JU_Test.java +++ /dev/null @@ -1,70 +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====================================================
- * *
- * * ECOMP is a trademark and service mark of AT&T Intellectual Property.
- * *
- ******************************************************************************/
-package org.onap.aaf.cadi.test;
-import java.net.InetAddress;
-import java.net.UnknownHostException;
-
-/**
- * A Class to run on command line to determine suitability of environment for certain TAFs.
- *
- * For instance, CSP supports services only in certain domains, and while dynamic host
- * lookups on the machine work in most cases, sometimes, names and IPs are unexpected (and
- * invalid) for CSP because of multiple NetworkInterfaces, etc
- *
- *
- */
-public class JU_Test {
-
- /**
- * @param args
- */
- public static void main(String[] args) {
- try {
- System.out.println("CADI/TAF test");
-
- String hostName = InetAddress.getLocalHost().getCanonicalHostName();
-
- System.out.println(" Your automatic hostname is reported as \"" + hostName + "\"\n");
- String[] two;
-
- for(String str : args) {
- two = str.split("=");
- if(two.length==2) {
- if("hostname".equals(two[0])) {
- hostName = two[1];
- System.out.println(" You have overlaid the automatic hostname with \"" + hostName + "\"\n");
- }
- }
- }
- if(hostName.endsWith("vpn.cingular.net"))
- System.out.println(" This service appears to be an AT&T VPN address. These VPNs are typically\n" +
- " (and appropriately) firewalled against incoming traffic, and likely cannot be accessed.\n" +
- " For best results, choose a machine that is not firewalled on the ports you choose.\n");
-
- } catch (UnknownHostException e) {
- e.printStackTrace();
- }
-
- }
-
-}
diff --git a/core/src/test/java/org/onap/aaf/cadi/test/JU_UserChainManip.java b/core/src/test/java/org/onap/aaf/cadi/test/JU_UserChainManip.java deleted file mode 100644 index 397b4b1..0000000 --- a/core/src/test/java/org/onap/aaf/cadi/test/JU_UserChainManip.java +++ /dev/null @@ -1,47 +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====================================================
- * *
- * * ECOMP is a trademark and service mark of AT&T Intellectual Property.
- * *
- ******************************************************************************/
-package org.onap.aaf.cadi.test;
-
-import static org.junit.Assert.*;
-
-import org.junit.Test;
-import org.onap.aaf.cadi.util.UserChainManip;
-
-public class JU_UserChainManip {
-
- @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"));
- }
-
-}
diff --git a/core/src/test/java/org/onap/aaf/cadi/test/JU_Vars.java b/core/src/test/java/org/onap/aaf/cadi/test/JU_Vars.java deleted file mode 100644 index 47209cd..0000000 --- a/core/src/test/java/org/onap/aaf/cadi/test/JU_Vars.java +++ /dev/null @@ -1,125 +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====================================================
- * *
- * * ECOMP is a trademark and service mark of AT&T Intellectual Property.
- * *
- ******************************************************************************/
-package org.onap.aaf.cadi.test;
-
-import static org.junit.Assert.assertEquals;
-
-import org.junit.AfterClass;
-import org.junit.Test;
-import org.onap.aaf.cadi.util.Vars;
-
-public class JU_Vars {
-
- @AfterClass
- public static void tearDownAfterClass() throws Exception {
- }
-
- @Test
- public void test() {
- StringBuilder holder = new StringBuilder();
- String str,bstr;
- assertEquals(str = "set %1 to %2",Vars.convert(holder,str, "a","b"));
- assertEquals("set a to b",holder.toString());
- assertEquals(str,Vars.convert(null,str, "a","b"));
- holder.setLength(0);
- assertEquals(str,Vars.convert(holder,bstr="set %s to %s", "a","b"));
- assertEquals("set a to b",holder.toString());
- assertEquals(str,Vars.convert(null,bstr, "a","b"));
-
- holder.setLength(0);
- assertEquals(str = "%1=%2",Vars.convert(holder,str, "a","b"));
- assertEquals("a=b",holder.toString());
- assertEquals(str,Vars.convert(null,str, "a","b"));
- holder.setLength(0);
- assertEquals(str,Vars.convert(holder,bstr="%s=%s", "a","b"));
- assertEquals("a=b",holder.toString());
- assertEquals(str,Vars.convert(null,bstr, "a","b"));
-
- holder.setLength(0);
- assertEquals(str = "%1%2",Vars.convert(holder,str, "a","b"));
- assertEquals("ab",holder.toString());
- assertEquals(str ,Vars.convert(null,str, "a","b"));
- holder.setLength(0);
- assertEquals(str,Vars.convert(holder,bstr="%s%s", "a","b"));
- assertEquals("ab",holder.toString());
- assertEquals(str ,Vars.convert(null,bstr, "a","b"));
-
-
- holder.setLength(0);
- assertEquals(str = " %1=%2 ",Vars.convert(holder,str, "a","b"));
- assertEquals(" a=b ",holder.toString());
- assertEquals(str ,Vars.convert(null,str, "a","b"));
- holder.setLength(0);
- assertEquals(str,Vars.convert(holder,bstr = " %s=%s ", "a","b"));
- assertEquals(" a=b ",holder.toString());
- assertEquals(str ,Vars.convert(null,bstr, "a","b"));
-
- holder.setLength(0);
- assertEquals(str = " %1%2%10 ",Vars.convert(holder,str, "a","b","c","d","e","f","g","h","i","j"));
- assertEquals(" abj ",holder.toString());
- assertEquals(str,Vars.convert(null,str, "a","b","c","d","e","f","g","h","i","j"));
- holder.setLength(0);
- assertEquals(str=" %1%2%3 ",Vars.convert(holder,bstr = " %s%s%s ", "a","b","c","d","e","f","g","h","i","j"));
- assertEquals(" abc ",holder.toString());
- assertEquals(str,Vars.convert(null,bstr, "a","b","c","d","e","f","g","h","i","j"));
-
-
- holder.setLength(0);
- assertEquals(str = "set %1 to %2",Vars.convert(holder,str, "Something much","larger"));
- assertEquals("set Something much to larger",holder.toString());
- assertEquals(str,Vars.convert(null,str,"Something much","larger"));
- holder.setLength(0);
- assertEquals(str,Vars.convert(holder,bstr="set %s to %s", "Something much","larger"));
- assertEquals("set Something much to larger",holder.toString());
- assertEquals(str,Vars.convert(null,bstr, "Something much","larger"));
-
- holder.setLength(0);
- assertEquals(str = "Text without Vars",Vars.convert(holder,str));
- assertEquals(str,holder.toString());
- assertEquals(str = "Text without Vars",Vars.convert(null,str));
-
-
- holder.setLength(0);
- assertEquals(str = "Not %1 Enough %2 Vars %3",Vars.convert(holder,str, "a","b"));
- assertEquals("Not a Enough b Vars ",holder.toString());
- assertEquals(str ,Vars.convert(null,str, "a","b"));
- holder.setLength(0);
- assertEquals(str,Vars.convert(holder,bstr="Not %s Enough %s Vars %s", "a","b"));
- assertEquals("Not a Enough b Vars ",holder.toString());
- assertEquals(str ,Vars.convert(null,bstr, "a","b"));
-
- holder.setLength(0);
- assertEquals(str = "!@#$%^*()-+?/,:;.",Vars.convert(holder,str, "a","b"));
- assertEquals(str,holder.toString());
- assertEquals(str ,Vars.convert(null,str, "a","b"));
-
- holder.setLength(0);
- bstr = "%s !@#$%^*()-+?/,:;.";
- str = "%1 !@#$%^*()-+?/,:;.";
- assertEquals(str,Vars.convert(holder,bstr, "Not Acceptable"));
- assertEquals("Not Acceptable !@#$%^*()-+?/,:;.",holder.toString());
- assertEquals(str ,Vars.convert(null,bstr, "Not Acceptable"));
-
- }
-
-}
diff --git a/core/src/test/java/org/onap/aaf/cadi/util/JU_NetMask.java b/core/src/test/java/org/onap/aaf/cadi/util/JU_NetMask.java deleted file mode 100644 index afed731..0000000 --- a/core/src/test/java/org/onap/aaf/cadi/util/JU_NetMask.java +++ /dev/null @@ -1,65 +0,0 @@ -/*******************************************************************************
- * * 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====================================================
- * *
- * * ECOMP is a trademark and service mark of AT&T Intellectual Property.
- * *
- ******************************************************************************/
-package org.onap.aaf.cadi.util;
-
-import static org.junit.Assert.assertEquals;
-
-import org.junit.Test;
-
-public class JU_NetMask {
-
- @Test
- public void deriveTest() {
- String test = "test";
- assertEquals(NetMask.derive(test.getBytes()), 0);
- }
-
- @Test
- public void deriveTest2() {
- String test = "1.2.3.4";
- assertEquals(NetMask.derive(test.getBytes()), 0);
- }
-
- @Test
- public void deriveTest3() {
- String test = "1.2.4";
- assertEquals(NetMask.derive(test.getBytes()), 0);
- }
-
- @Test
- public void deriveTest4() {
- String test = "1.3.4";
- assertEquals(NetMask.derive(test.getBytes()), 0);
- }
-
- @Test
- public void deriveTest5() {
- String test = "2.3.4";
- assertEquals(NetMask.derive(test.getBytes()), 0);
- }
-
- @Test
- public void deriveTest6() {
- String test = "3.4";
- assertEquals(NetMask.derive(test.getBytes()), 0);
- }
-}
diff --git a/core/src/test/java/org/onap/aaf/cadi/util/JU_Split.java b/core/src/test/java/org/onap/aaf/cadi/util/JU_Split.java deleted file mode 100644 index 14f670f..0000000 --- a/core/src/test/java/org/onap/aaf/cadi/util/JU_Split.java +++ /dev/null @@ -1,64 +0,0 @@ -/*******************************************************************************
- * * 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====================================================
- * *
- * * ECOMP is a trademark and service mark of AT&T Intellectual Property.
- * *
- ******************************************************************************/
-package org.onap.aaf.cadi.util;
-
-import static org.junit.Assert.assertEquals;
-
-import org.junit.Test;
-
-public class JU_Split {
-
- @Test
- public void split() {
- assertEquals(Split.split('c', "testctc").length,3);
- }
-
- @Test
- public void splitTrim() {
- assertEquals(Split.splitTrim('c', "testctc").length,3);
- }
-
- @Test
- public void splitTrimWithSize() {
- assertEquals(Split.splitTrim('c', "testcctc",2).length,2);
- }
-
- @Test
- public void splitTrim1() {
- assertEquals(Split.splitTrim('c', "testctc").length,3);
- }
-
- @Test
- public void splitTrimWithSize1() {
- assertEquals(Split.splitTrim('c', "testcctc",2).length,2);
- }
-
- @Test
- public void splitTrim2() {
- assertEquals(Split.splitTrim('c', "testctc").length,3);
- }
-
- @Test
- public void splitTrimWithSize2() {
- assertEquals(Split.splitTrim('c', "testcctc",2).length,2);
- }
-}
diff --git a/core/src/test/java/org/onap/aaf/cadi/util/JU_TheConsole.java b/core/src/test/java/org/onap/aaf/cadi/util/JU_TheConsole.java deleted file mode 100644 index be7022d..0000000 --- a/core/src/test/java/org/onap/aaf/cadi/util/JU_TheConsole.java +++ /dev/null @@ -1,37 +0,0 @@ -/*******************************************************************************
- * * 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====================================================
- * *
- * * ECOMP is a trademark and service mark of AT&T Intellectual Property.
- * *
- ******************************************************************************/
-package org.onap.aaf.cadi.util;
-
-import static org.junit.Assert.assertEquals;
-
-import org.junit.Test;
-
-public class JU_TheConsole {
-
- @Test
- public void implemented(){
- assertEquals(TheConsole.implemented(),false);
- }
-
-
- }
-
diff --git a/core/src/test/java/org/onap/aaf/cadi/util/JU_UserChainManip.java b/core/src/test/java/org/onap/aaf/cadi/util/JU_UserChainManip.java deleted file mode 100644 index a3339d5..0000000 --- a/core/src/test/java/org/onap/aaf/cadi/util/JU_UserChainManip.java +++ /dev/null @@ -1,51 +0,0 @@ -/*******************************************************************************
- * * 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====================================================
- * *
- * * ECOMP is a trademark and service mark of AT&T Intellectual Property.
- * *
- ******************************************************************************/
-package org.onap.aaf.cadi.util;
-
-import static org.junit.Assert.assertEquals;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.junit.Test;
-import org.onap.aaf.cadi.UserChain;
-
-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");
- }
-
-
- @Test
- public void idToNS(){
- assertEquals(UserChainManip.idToNS(null), "");
- }
-
- @Test
- public void idToNS1(){
- assertEquals(UserChainManip.idToNS("t@st"), "st");
- }
-
-}
diff --git a/core/src/test/java/org/onap/aaf/cadi/util/JU_Vars.java b/core/src/test/java/org/onap/aaf/cadi/util/JU_Vars.java deleted file mode 100644 index 6a2b4c0..0000000 --- a/core/src/test/java/org/onap/aaf/cadi/util/JU_Vars.java +++ /dev/null @@ -1,57 +0,0 @@ -/*******************************************************************************
- * * 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====================================================
- * *
- * * ECOMP is a trademark and service mark of AT&T Intellectual Property.
- * *
- ******************************************************************************/
-package org.onap.aaf.cadi.util;
-
-import static org.junit.Assert.assertEquals;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.junit.Test;
-
-public class JU_Vars {
-
- @Test
- public void convert() {
- String test = "test";
- List<String> list = new ArrayList<String>();
- list.add("method");
- assertEquals(Vars.convert(test, list), test);
- }
-
- @Test
- public void convertTest1() {
- String test = "te%t";
- List<String> list = new ArrayList<String>();
- list.add("method");
- assertEquals(Vars.convert("test", list), "test");
- }
-
- @Test
- public void convertTest2() {
- String test = "te%s%t";
- List<String> list = new ArrayList<String>();
- list.add("method");
- assertEquals(Vars.convert("test", list), "test");
- }
-
-}
diff --git a/core/src/test/java/org/onap/aaf/cadi/wsse/test/JU_WSSE_Read.java b/core/src/test/java/org/onap/aaf/cadi/wsse/test/JU_WSSE_Read.java deleted file mode 100644 index af45f55..0000000 --- a/core/src/test/java/org/onap/aaf/cadi/wsse/test/JU_WSSE_Read.java +++ /dev/null @@ -1,190 +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====================================================
- * *
- * * ECOMP is a trademark and service mark of AT&T Intellectual Property.
- * *
- ******************************************************************************/
-package org.onap.aaf.cadi.wsse.test;
-
-import static junit.framework.Assert.assertEquals;
-import static junit.framework.Assert.assertNotNull;
-import static junit.framework.Assert.assertNull;
-
-import java.io.ByteArrayInputStream;
-import java.io.File;
-import java.io.FileInputStream;
-
-import javax.xml.stream.XMLStreamException;
-
-import org.junit.Test;
-import org.onap.aaf.cadi.BasicCred;
-import org.onap.aaf.cadi.BufferedServletInputStream;
-import org.onap.aaf.cadi.wsse.WSSEParser;
-
-public class JU_WSSE_Read {
-
- @Test
- public void test() {
- try {
- final BasicCred bc = new BasicCred() {
-
- private String user;
- private byte[] password;
-
- public void setUser(String user) {
- this.user = user;
- }
-
- public void setCred(byte[] passwd) {
- this.password = passwd;
- }
-
- public String getUser() {
- return user;
- }
-
- public byte[] getCred() {
- return password;
- }
- };
-
- WSSEParser wp = new WSSEParser();
-
- FileInputStream fis;
- fis = new FileInputStream("test/example.xml");
- BufferedServletInputStream is = new BufferedServletInputStream(fis);
- try {
- is.mark(1536);
- try {
- assertNull(wp.parse(bc, is));
- } finally {
- is.reset();
- assertEquals(814,is.buffered());
- }
- String password = new String(bc.getCred());
- System.out.println("CadiWrap credentials are: " + bc.getUser() + ", " + password);
- assertEquals("some_user", bc.getUser());
- assertEquals("some_password", password);
-
- } finally {
- fis.close();
- }
-
- // CBUS (larger)
- fis = new FileInputStream("test/CBUSevent.xml");
- is = new BufferedServletInputStream(fis);
- try {
- is.mark(1536);
- try {
- assertNull(wp.parse(bc, is));
- } finally {
- is.reset();
- assertEquals(667,is.buffered());
- }
- String password = new String(bc.getCred());
- System.out.println("CadiWrap credentials are: " + bc.getUser() + ", " + password);
- assertEquals("none", bc.getUser());
- assertEquals("none", password);
-
- } finally {
- fis.close();
- }
-
- // Closed Stream
- fis = new FileInputStream("test/example.xml");
- fis.close();
- bc.setCred(null);
- bc.setUser(null);
- XMLStreamException ex = wp.parse(bc, fis);
- assertNotNull(ex);
- assertNull(bc.getUser());
- assertNull(bc.getCred());
-
-
- fis = new FileInputStream("test/exampleNoSecurity.xml");
- try {
- bc.setCred(null);
- bc.setUser(null);
- assertNull(wp.parse(bc, fis));
- assertNull(bc.getUser());
- assertNull(bc.getCred());
- } finally {
- fis.close();
- }
-
- fis = new FileInputStream("test/exampleBad1.xml");
- try {
- bc.setCred(null);
- bc.setUser(null);
- assertNull(wp.parse(bc, fis));
- assertNull(bc.getUser());
- assertNull(bc.getCred());
- } finally {
- fis.close();
- }
-
- XMLStreamException e = wp.parse(bc, new ByteArrayInputStream("Not XML".getBytes())); // empty
- assertNotNull(e);
-
- e = wp.parse(bc, new ByteArrayInputStream("".getBytes())); // empty
- assertNotNull(e);
-
-
- long start, count = 0L;
- int iter = 30000;
- File f = new File("test/CBUSevent.xml");
- fis = new FileInputStream(f);
- is = new BufferedServletInputStream(fis);
- is.mark(0);
- try {
- while(is.read()>=0);
- } finally {
- fis.close();
- }
-
- for(int i=0;i<iter;++i) {
- start = System.nanoTime();
- is.reset();
- try {
- assertNull(wp.parse(bc, is));
- } finally {
- count += System.nanoTime()-start;
- }
- }
- float ms = count/1000000f;
- System.out.println("Executed " + iter + " WSSE reads from Memory Stream in " + ms + "ms. " + ms/iter + "ms per trans");
-
- // SPECIFIC ISSUES
-
- fis = new FileInputStream("test/error2013_04_23.xml");
- try {
- bc.setCred(null);
- bc.setUser(null);
- assertNull(wp.parse(bc, fis));
- assertNull(bc.getUser());
- assertNull(bc.getCred());
- } finally {
- fis.close();
- }
- } catch(Exception e) {
- e.printStackTrace(System.err);
- }
- }
-
-}
diff --git a/core/src/test/java/org/onap/aaf/cadi/wsse/test/JU_XReader.java b/core/src/test/java/org/onap/aaf/cadi/wsse/test/JU_XReader.java deleted file mode 100644 index de8da8a..0000000 --- a/core/src/test/java/org/onap/aaf/cadi/wsse/test/JU_XReader.java +++ /dev/null @@ -1,65 +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====================================================
- * *
- * * ECOMP is a trademark and service mark of AT&T Intellectual Property.
- * *
- ******************************************************************************/
-package org.onap.aaf.cadi.wsse.test;
-
-import java.io.FileInputStream;
-
-import javax.xml.stream.events.XMLEvent;
-
-import org.junit.Test;
-import org.onap.aaf.cadi.wsse.XEvent;
-import org.onap.aaf.cadi.wsse.XReader;
-
-public class JU_XReader {
- @Test
- public void test() throws Exception {
- FileInputStream fis = new FileInputStream("test/CBUSevent.xml");
- try {
- XReader xr = new XReader(fis);
- while(xr.hasNext()) {
- XEvent xe = xr.nextEvent();
- switch(xe.getEventType()) {
- case XMLEvent.START_DOCUMENT:
- System.out.println("Start Document");
- break;
- case XMLEvent.START_ELEMENT:
- System.out.println("Start Event: " + xe.asStartElement().getName());
- break;
- case XMLEvent.END_ELEMENT:
- System.out.println("End Event: " + xe.asEndElement().getName());
- break;
- case XMLEvent.CHARACTERS:
- System.out.println("Characters: " + xe.asCharacters().getData());
- break;
- case XMLEvent.COMMENT:
- System.out.println("Comment: " + ((XEvent.Comment)xe).value);
- break;
- }
- }
- } finally {
- fis.close();
- }
-
- }
-
-}
|