This repository was archived by the owner on Jul 7, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +12
-4
lines changed
src/test/java/com/cascadebot/shared Expand file tree Collapse file tree 1 file changed +12
-4
lines changed Original file line number Diff line number Diff line change 8
8
import static org .junit .jupiter .api .Assertions .*;
9
9
10
10
class HmacTests {
11
+
12
+ // Used https://www.freeformatter.com/hmac-generator.html to generate HMacs
13
+
11
14
@ Test
12
15
void hmacValidateTest () {
13
16
try {
14
- Auth auth = new Auth ("key1234" ); //Not out actual key
15
- String hmacText = auth .hmacEncrypt ("Test" );
16
- assertTrue (auth .verifyEncrypt ("Test" , hmacText ));
17
- assertFalse (auth .verifyEncrypt ("Test2" , hmacText ));
17
+ Auth auth = new Auth ("key1234" );
18
+
19
+ String hmacText = auth .hmacEncrypt ("Test" , 1L );
20
+ assertEquals (hmacText , "e60313610635674f2961c017ce6aae1aaa48e291061788addcac7b5ed428cc3ba6c5907b10a64d4a115a12a1ed168cb5eb68ee42b512e5c40b7fb1fb49a9a0a1" );
21
+
22
+ hmacText = auth .hmacEncrypt ("Test" , Long .MAX_VALUE );
23
+ assertEquals (hmacText , "3341b6ada4be6744d3fb7658ddc229050dee320ec04dd546708a82f3e34679a3f2da10fc3644316d2807296668c45fd81881bb00d32453f30b07b2c515c1629f" );
24
+
25
+ assertTrue (auth .verifyEncrypt ("Test" , "e60313610635674f2961c017ce6aae1aaa48e291061788addcac7b5ed428cc3ba6c5907b10a64d4a115a12a1ed168cb5eb68ee42b512e5c40b7fb1fb49a9a0a1" , 1L ));
18
26
} catch (NoSuchAlgorithmException | InvalidKeyException ignored ) {
19
27
}
20
28
}
You can’t perform that action at this time.
0 commit comments