aboutsummaryrefslogtreecommitdiffstats
path: root/security-utils/src/test/java/org
diff options
context:
space:
mode:
authorMichael Lando <ml636r@att.com>2018-03-04 14:53:33 +0200
committerMichael Lando <ml636r@att.com>2018-03-07 13:19:05 +0000
commita5445100050e49e83f73424198d73cd72d672a4d (patch)
treecacf4df817df31be23e4e790d1dda857bdae061e /security-utils/src/test/java/org
parent51157f92c21976cba4914c378aaa3cba49826931 (diff)
Sync Integ to Master
Change-Id: I71e3acc26fa612127756ac04073a522b9cc6cd74 Issue-ID: SDC-977 Signed-off-by: Gitelman, Tal (tg851x) <tg851x@intl.att.com>
Diffstat (limited to 'security-utils/src/test/java/org')
-rw-r--r--security-utils/src/test/java/org/openecomp/sdc/security/PasswordTest.java48
-rw-r--r--security-utils/src/test/java/org/openecomp/sdc/security/PasswordsTest.java75
-rw-r--r--security-utils/src/test/java/org/openecomp/sdc/security/SecurityUtilTest.java27
3 files changed, 102 insertions, 48 deletions
diff --git a/security-utils/src/test/java/org/openecomp/sdc/security/PasswordTest.java b/security-utils/src/test/java/org/openecomp/sdc/security/PasswordTest.java
deleted file mode 100644
index 895806d1b5..0000000000
--- a/security-utils/src/test/java/org/openecomp/sdc/security/PasswordTest.java
+++ /dev/null
@@ -1,48 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * SDC
- * ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-package org.openecomp.sdc.security;
-
-import static org.junit.Assert.assertTrue;
-
-import org.junit.Test;
-
-public class PasswordTest {
-
- @Test
- public void hashtest() {
- String password = "123456";
- String hash = Passwords.hashPassword(password);
- assertTrue(Passwords.isExpectedPassword(password, hash));
- password = "1sdfgsgd23456";
- hash = Passwords.hashPassword(password);
- assertTrue(Passwords.isExpectedPassword(password, hash));
- password = "1sdfgsgd2345((*&%$%6";
- hash = Passwords.hashPassword(password);
- assertTrue(Passwords.isExpectedPassword(password, hash));
- password = "";
- hash = Passwords.hashPassword(password);
- assertTrue(Passwords.isExpectedPassword(password, hash));
- password = " ";
- hash = Passwords.hashPassword(password);
- assertTrue(Passwords.isExpectedPassword(password, hash));
- }
-
-}
diff --git a/security-utils/src/test/java/org/openecomp/sdc/security/PasswordsTest.java b/security-utils/src/test/java/org/openecomp/sdc/security/PasswordsTest.java
new file mode 100644
index 0000000000..26f04735e5
--- /dev/null
+++ b/security-utils/src/test/java/org/openecomp/sdc/security/PasswordsTest.java
@@ -0,0 +1,75 @@
+package org.openecomp.sdc.security;
+
+import org.junit.Test;
+
+import static org.junit.Assert.*;
+
+public class PasswordsTest {
+
+ @Test
+ public void hashPassword() throws Exception {
+ String hash = Passwords.hashPassword("hello1234");
+ assertEquals(true, Passwords.isExpectedPassword("hello1234", hash));
+
+ //test different salt-> result in different hash
+ String hash2 = Passwords.hashPassword("hello1234");
+ assertEquals(false, hash.equals(hash2));
+
+ String hash3 = Passwords.hashPassword("");
+ assertEquals(true, Passwords.isExpectedPassword("", hash3));
+
+ String hash4 = Passwords.hashPassword(null);
+ assertEquals(true, hash4 == null );
+ }
+
+ @Test
+ public void isExpectedPassword() throws Exception {
+ //region isExpectedPassword(String password, String salt, String hash)
+ assertEquals(true, Passwords.isExpectedPassword(null, null , null));
+ //valid hash
+ assertEquals(true, Passwords.isExpectedPassword("hello1234", "e0277df331f4ff8f74752ac4a8fbe03b","6dfbad308cdf53c9ff2ee2dca811ee92f1b359586b33027580e2ff92578edbd0"));
+ //invalid salt
+ assertEquals(false, Passwords.isExpectedPassword("hello1234", "c0000df331f4ff8f74752ac4a00be03c","6dfbad308cdf53c9ff2ee2dca811ee92f1b359586b33027580e2ff92578edbd0"));
+ assertEquals(false, Passwords.isExpectedPassword("hello1234", null,"6dfbad308cdf53c9ff2ee2dca811ee92f1b359586b33027580e2ff92578edbd0"));
+ //exacly 1 param uninitialized
+ assertEquals(false,Passwords.isExpectedPassword("hello1234", "",null));
+ assertEquals(false,Passwords.isExpectedPassword( null, "" , "hello1234"));
+ //no salt & no hash
+ assertEquals(false, Passwords.isExpectedPassword("hello1234", null ,"hello1234"));
+ //endregion
+
+ //region isExpectedPassword(String password, String expectedHash)
+ assertEquals(true, Passwords.isExpectedPassword(null, null));
+ //valid hash
+ assertEquals(true, Passwords.isExpectedPassword("hello1234", "e0277df331f4ff8f74752ac4a8fbe03b:6dfbad308cdf53c9ff2ee2dca811ee92f1b359586b33027580e2ff92578edbd0"));
+ //invalid salt
+ assertEquals(false, Passwords.isExpectedPassword("hello1234", "c0000df331f4ff8f74752ac4a00be03c:6dfbad308cdf53c9ff2ee2dca811ee92f1b359586b33027580e2ff92578edbd0"));
+ //exacly 1 param uninitialized
+ assertEquals(false,Passwords.isExpectedPassword("hello1234", null));
+ assertEquals(false,Passwords.isExpectedPassword( null,"hello1234"));
+ //no salt & no hash
+ assertEquals(false, Passwords.isExpectedPassword("hello1234", "hello1234"));
+ //endregion
+ }
+
+ @Test
+ public void hashtest() {
+ String password = "123456";
+ String hash = Passwords.hashPassword(password);
+ assertTrue(Passwords.isExpectedPassword(password, hash));
+ password = "1sdfgsgd23456";
+ hash = Passwords.hashPassword(password);
+ assertTrue(Passwords.isExpectedPassword(password, hash));
+ password = "1sdfgsgd2345((*&%$%6";
+ hash = Passwords.hashPassword(password);
+ assertTrue(Passwords.isExpectedPassword(password, hash));
+ password = "";
+ hash = Passwords.hashPassword(password);
+ assertTrue(Passwords.isExpectedPassword(password, hash));
+ password = " ";
+ hash = Passwords.hashPassword(password);
+ assertTrue(Passwords.isExpectedPassword(password, hash));
+ }
+
+
+} \ No newline at end of file
diff --git a/security-utils/src/test/java/org/openecomp/sdc/security/SecurityUtilTest.java b/security-utils/src/test/java/org/openecomp/sdc/security/SecurityUtilTest.java
new file mode 100644
index 0000000000..e23c864b77
--- /dev/null
+++ b/security-utils/src/test/java/org/openecomp/sdc/security/SecurityUtilTest.java
@@ -0,0 +1,27 @@
+package org.openecomp.sdc.security;
+
+import org.junit.Test;
+import java.util.Base64;
+import static org.junit.Assert.*;
+
+public class SecurityUtilTest {
+
+ @Test
+ public void encryptDecryptAES128() throws Exception {
+ String data = "decrypt SUCCESS!!";
+ String encrypted = SecurityUtil.INSTANCE.encrypt(data).left().value();
+ assertNotEquals( data, encrypted );
+ byte[] decryptMsg = Base64.getDecoder().decode(encrypted);
+ assertEquals( SecurityUtil.INSTANCE.decrypt( decryptMsg , false ).left().value() ,data );
+ assertEquals( SecurityUtil.INSTANCE.decrypt( encrypted.getBytes() , true ).left().value() ,data );
+ }
+
+ @Test
+ public void obfuscateKey() throws Exception {
+ String key = "abcdefghij123456";
+ String expectedkey = "********ij123456";
+ String obfuscated = SecurityUtil.INSTANCE.obfuscateKey( key );
+ System.out.println( obfuscated );
+ assertEquals( obfuscated , expectedkey );
+ }
+} \ No newline at end of file