1 package org.openecomp.sdc.security;
5 import static org.junit.Assert.assertEquals;
6 import static org.junit.Assert.assertFalse;
7 import static org.junit.Assert.assertTrue;
9 public class PasswordsTest {
12 public void hashPassword() throws Exception {
13 String hash = Passwords.hashPassword("hello1234");
14 assertTrue(Passwords.isExpectedPassword("hello1234", hash));
16 //test different salt-> result in different hash
17 String hash2 = Passwords.hashPassword("hello1234");
18 assertFalse(hash.equals(hash2));
20 String hash3 = Passwords.hashPassword("");
21 assertTrue(Passwords.isExpectedPassword("", hash3));
23 String hash4 = Passwords.hashPassword(null);
24 assertTrue(hash4 == null);
28 public void isExpectedPassword() throws Exception {
29 //region isExpectedPassword(String password, String salt, String hash)
30 assertTrue(Passwords.isExpectedPassword(null, null, null));
32 assertTrue(Passwords.isExpectedPassword("hello1234", "e0277df331f4ff8f74752ac4a8fbe03b", "6dfbad308cdf53c9ff2ee2dca811ee92f1b359586b33027580e2ff92578edbd0"));
34 assertFalse(Passwords.isExpectedPassword("hello1234", "c0000df331f4ff8f74752ac4a00be03c", "6dfbad308cdf53c9ff2ee2dca811ee92f1b359586b33027580e2ff92578edbd0"));
35 assertFalse(Passwords.isExpectedPassword("hello1234", null, "6dfbad308cdf53c9ff2ee2dca811ee92f1b359586b33027580e2ff92578edbd0"));
36 //exacly 1 param uninitialized
37 assertFalse(Passwords.isExpectedPassword("hello1234", "", null));
38 assertFalse(Passwords.isExpectedPassword(null, "", "hello1234"));
40 assertFalse(Passwords.isExpectedPassword("hello1234", null, "hello1234"));
43 //region isExpectedPassword(String password, String expectedHash)
44 assertTrue(Passwords.isExpectedPassword(null, null));
46 assertTrue(Passwords.isExpectedPassword("hello1234", "e0277df331f4ff8f74752ac4a8fbe03b:6dfbad308cdf53c9ff2ee2dca811ee92f1b359586b33027580e2ff92578edbd0"));
48 assertFalse(Passwords.isExpectedPassword("hello1234", "c0000df331f4ff8f74752ac4a00be03c:6dfbad308cdf53c9ff2ee2dca811ee92f1b359586b33027580e2ff92578edbd0"));
49 //exacly 1 param uninitialized
50 assertFalse(Passwords.isExpectedPassword("hello1234", null));
51 assertFalse(Passwords.isExpectedPassword(null, "hello1234"));
53 assertFalse(Passwords.isExpectedPassword("hello1234", "hello1234"));
58 public void hashtest() {
59 String password = "123456";
60 String hash = Passwords.hashPassword(password);
61 assertTrue(Passwords.isExpectedPassword(password, hash));
62 password = "1sdfgsgd23456";
63 hash = Passwords.hashPassword(password);
64 assertTrue(Passwords.isExpectedPassword(password, hash));
65 password = "1sdfgsgd2345((*&%$%6";
66 hash = Passwords.hashPassword(password);
67 assertTrue(Passwords.isExpectedPassword(password, hash));
69 hash = Passwords.hashPassword(password);
70 assertTrue(Passwords.isExpectedPassword(password, hash));
72 hash = Passwords.hashPassword(password);
73 assertTrue(Passwords.isExpectedPassword(password, hash));