mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2025-03-10 22:01:00 +01:00
Fix PassEncryptTest
This commit is contained in:
parent
0b7b270f78
commit
286a5aa0e4
@ -11,7 +11,7 @@ import java.util.List;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.stream.IntStream;
|
import java.util.stream.IntStream;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertFalse;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -23,30 +23,14 @@ public class PassEncryptTest {
|
|||||||
private final Map<String, String> passwordMap = new HashMap<>();
|
private final Map<String, String> passwordMap = new HashMap<>();
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() throws Exception {
|
||||||
IntStream.range(0, 50).forEach(i -> passwords.add(RandomData.randomString(RandomData.randomInt(1, 100))));
|
IntStream.range(0, 50).forEach(i -> passwords.add(RandomData.randomString(RandomData.randomInt(1, 100))));
|
||||||
}
|
|
||||||
|
|
||||||
@Before
|
|
||||||
@Test
|
|
||||||
public void testHashing() throws Exception {
|
|
||||||
for (String password : passwords) {
|
for (String password : passwords) {
|
||||||
passwordMap.put(password, PassEncryptUtil.createHash(password));
|
passwordMap.put(password, PassEncryptUtil.createHash(password));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testConsistency() throws Exception {
|
|
||||||
for (Map.Entry<String, String> entry : passwordMap.entrySet()) {
|
|
||||||
String password = entry.getKey();
|
|
||||||
String expHash = entry.getValue();
|
|
||||||
|
|
||||||
String secondHashRun = PassEncryptUtil.createHash(password);
|
|
||||||
|
|
||||||
assertEquals(expHash, secondHashRun);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testVerification() throws Exception {
|
public void testVerification() throws Exception {
|
||||||
for (Map.Entry<String, String> entry : passwordMap.entrySet()) {
|
for (Map.Entry<String, String> entry : passwordMap.entrySet()) {
|
||||||
@ -54,6 +38,7 @@ public class PassEncryptTest {
|
|||||||
String hash = entry.getValue();
|
String hash = entry.getValue();
|
||||||
|
|
||||||
assertTrue(PassEncryptUtil.verifyPassword(password, hash));
|
assertTrue(PassEncryptUtil.verifyPassword(password, hash));
|
||||||
|
assertFalse(PassEncryptUtil.verifyPassword(RandomData.randomString(RandomData.randomInt(1, 100)), hash));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user