|
17 | 17 |
|
18 | 18 | import static org.junit.jupiter.api.Assertions.assertEquals; |
19 | 19 | import static org.junit.jupiter.api.Assertions.assertNotNull; |
| 20 | +import static org.junit.jupiter.api.Assertions.assertThrows; |
20 | 21 | import static org.junit.jupiter.api.Assertions.assertTrue; |
21 | 22 |
|
22 | 23 | import com.fasterxml.jackson.databind.ObjectMapper; |
|
37 | 38 | import software.amazon.awssdk.services.signin.internal.DpopHeaderGenerator; |
38 | 39 |
|
39 | 40 | public class DpopHeaderGeneratorTest { |
40 | | - private static final String VALID_TEST_PEM = "-----BEGIN EC PRIVATE KEY-----\n" |
41 | | - + "MHcCAQEEICeY73qhQO/3o1QnrL5Nu3HMDB9h3kVW6imRdcHks0tboAoGCCqGSM49" |
42 | | - + "AwEHoUQDQgAEbefyxjd/UlGwAPF6hy0k4yCW7dSghc6yPd4To0sBqX0tPS/aoLrl" |
43 | | - + "QnPjfDslgD29p4+Pgwxj1s8cFHVeDKdKTQ==\n" |
44 | | - + "-----END EC PRIVATE KEY-----"; |
| 41 | + private static final String VALID_TEST_PEM = |
| 42 | + "-----BEGIN EC PRIVATE KEY-----\n" |
| 43 | + + "MHcCAQEEICeY73qhQO/3o1QnrL5Nu3HMDB9h3kVW6imRdcHks0tboAoGCCqGSM49" |
| 44 | + + "AwEHoUQDQgAEbefyxjd/UlGwAPF6hy0k4yCW7dSghc6yPd4To0sBqX0tPS/aoLrl" |
| 45 | + + "QnPjfDslgD29p4+Pgwxj1s8cFHVeDKdKTQ==\n" |
| 46 | + + "-----END EC PRIVATE KEY-----"; |
45 | 47 | private static final ObjectMapper MAPPER = new ObjectMapper(); |
46 | 48 |
|
47 | 49 | @Test |
@@ -84,6 +86,15 @@ public void testGenerateAndVerifyDPoPHeader() throws Exception { |
84 | 86 | assertTrue(verified, "DPoP ES256 signature should verify correctly"); |
85 | 87 | } |
86 | 88 |
|
| 89 | + @Test |
| 90 | + public void invalidKey_raisesException() { |
| 91 | + assertThrows(IllegalArgumentException.class, () -> { |
| 92 | + DpopHeaderGenerator.generateDPoPProofHeader( |
| 93 | + "INVALID-KEY", "https://example.com", |
| 94 | + Instant.now().getEpochSecond(), UUID.randomUUID().toString()); |
| 95 | + }); |
| 96 | + } |
| 97 | + |
87 | 98 | /** |
88 | 99 | * Verifies an ES256 signature given base64url-encoded JWT parts and the JWK public key. |
89 | 100 | */ |
|
0 commit comments