Repository navigation
Expand file tree
/
Copy pathHashTest.java
More file actions
101 lines (85 loc) · 2.78 KB
/
Copy pathHashTest.java
File metadata and controls
101 lines (85 loc) · 2.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
package utils;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
import org.junit.jupiter.api.Test;
class HashTest {
@Test
void generateUserSolutionKeyOnly_returnsNonNull() {
assertNotNull(Hash.generateUserSolutionKeyOnly("baseKey", "userSalt"));
}
@Test
void generateUserSolutionKeyOnly_consistentForSameInputs() {
String first = Hash.generateUserSolutionKeyOnly("key1", "salt1");
String second = Hash.generateUserSolutionKeyOnly("key1", "salt1");
assertEquals(first, second);
}
@Test
void generateUserSolutionKeyOnly_differentForDifferentKeys() {
String first = Hash.generateUserSolutionKeyOnly("key1", "salt1");
String second = Hash.generateUserSolutionKeyOnly("key2", "salt1");
assertNotEquals(first, second);
}
@Test
void generateUserSolutionKeyOnly_differentForDifferentSalts() {
String first = Hash.generateUserSolutionKeyOnly("key1", "salt1");
String second = Hash.generateUserSolutionKeyOnly("key1", "salt2");
assertNotEquals(first, second);
}
@Test
void generateUserSolutionKeyOnly_producesHexOutput() {
String result = Hash.generateUserSolutionKeyOnly("key", "salt");
assertTrue(result.matches("[0-9A-F]+"));
}
@Test
void generateUserSolution_containsHtmlMarkup() {
String result = Hash.generateUserSolution("key", "salt");
assertTrue(result.contains("<textarea"));
assertTrue(result.contains("theKey"));
}
@Test
void generateUserSolution_containsSolutionKey() {
String key = Hash.generateUserSolutionKeyOnly("key", "salt");
String html = Hash.generateUserSolution("key", "salt");
assertTrue(html.contains(key));
}
@Test
void randomKeyBytes_returns16Bytes() {
byte[] bytes = Hash.randomKeyBytes();
assertEquals(16, bytes.length);
}
@Test
void randomKeyBytes_differentEachCall() {
byte[] first = Hash.randomKeyBytes();
byte[] second = Hash.randomKeyBytes();
boolean allSame = true;
for (int i = 0; i < first.length; i++) {
if (first[i] != second[i]) {
allSame = false;
break;
}
}
assertNotEquals(true, allSame);
}
@Test
void randomString_returnsNonEmpty() {
String result = Hash.randomString();
assertNotNull(result);
assertNotEquals("", result);
}
@Test
void randomString_differentEachCall() {
String first = Hash.randomString();
String second = Hash.randomString();
assertNotEquals(first, second);
}
@Test
void getCurrentKey_returnsNonNull() {
assertNotNull(Hash.getCurrentKey());
}
@Test
void getCurrentKey_returns16Bytes() {
assertEquals(16, Hash.getCurrentKey().length);
}
}