@@ -17,10 +17,10 @@ public class WebhookSignatureValidatorTest {
1717
1818 @ Test
1919 public void testHappyPath () {
20- String timestamp = "2021-10-04T17:30:43.42Z " ;
20+ String timestamp = "1633368643 " ;
2121 String reqBody = "hello world foo bar goodnight moon" ;
2222 byte [] secret = "super-secret-shhhh" .getBytes (StandardCharsets .UTF_8 );
23- String expectedSignature = "45bf0200a2cbc02ae2595fcf9ba4a2b262d836672c4a26fc3300cc54353587cd " ;
23+ String expectedSignature = "641ada412da02d7df7ca59e94a556b7f5683374db614565ad3d99da1a9a779fb " ;
2424
2525 WebhookSignatureValidator validator = new WebhookSignatureValidator (reallyLongTime );
2626 boolean result = validator .validate (reqBody , secret , expectedSignature , timestamp );
@@ -29,10 +29,22 @@ public void testHappyPath() {
2929
3030 @ Test
3131 public void testRequestTooOld () {
32- String timestamp = "2021-10-04T17:30:43.42Z " ;
32+ String timestamp = "1633368643 " ;
3333 String reqBody = "hello world foo bar goodnight moon" ;
3434 byte [] secret = "super-secret-shhhh" .getBytes (StandardCharsets .UTF_8 );
35- String expectedSignature = "45bf0200a2cbc02ae2595fcf9ba4a2b262d836672c4a26fc3300cc54353587cd" ;
35+ String expectedSignature = "641ada412da02d7df7ca59e94a556b7f5683374db614565ad3d99da1a9a779fb" ;
36+
37+ WebhookSignatureValidator validator = new WebhookSignatureValidator (Duration .ofMinutes (1 ));
38+ boolean result = validator .validate (reqBody , secret , expectedSignature , timestamp );
39+ assertFalse (result );
40+ }
41+
42+ @ Test
43+ public void testRequestTooFarInTheFuture () {
44+ String timestamp = "4789042243" ;
45+ String reqBody = "hello world foo bar goodnight moon" ;
46+ byte [] secret = "super-secret-shhhh" .getBytes (StandardCharsets .UTF_8 );
47+ String expectedSignature = "641ada412da02d7df7ca59e94a556b7f5683374db614565ad3d99da1a9a779fb" ;
3648
3749 WebhookSignatureValidator validator = new WebhookSignatureValidator (Duration .ofMinutes (1 ));
3850 boolean result = validator .validate (reqBody , secret , expectedSignature , timestamp );
@@ -41,7 +53,7 @@ public void testRequestTooOld() {
4153
4254 @ Test
4355 public void testSignatureMismatch () {
44- String timestamp = "2021-10-04T17:30:43.42Z " ;
56+ String timestamp = "1633368643 " ;
4557 String reqBody = "hello world foo bar goodnight moon" ;
4658 byte [] secret = "super-secret-shhhh" .getBytes (StandardCharsets .UTF_8 );
4759 String incorrectSignature = "e05aa9a373d652b6a38fdb0e093cca3eca3d6dd803a50dbe8b98b137fd20fe87" ;
0 commit comments