Skip to content

Commit 520bda7

Browse files
committed
Add more validation of arguments
1 parent f144118 commit 520bda7

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

services/signin/src/main/java/software/amazon/awssdk/services/signin/internal/DpopHeaderGenerator.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import software.amazon.awssdk.annotations.SdkInternalApi;
3030
import software.amazon.awssdk.protocols.jsoncore.JsonWriter;
3131
import software.amazon.awssdk.utils.Pair;
32+
import software.amazon.awssdk.utils.Validate;
3233

3334
/**
3435
* Utilities that implement rfc9449 - OAuth 2.0 Demonstrating Proof of Possession (DPoP)
@@ -65,6 +66,10 @@ private DpopHeaderGenerator() {
6566
* @return DPoP header value
6667
*/
6768
public static String generateDPoPProofHeader(String pemContent, String endpoint, long epochSeconds, String uuid) {
69+
Validate.notBlank(pemContent, "pemContent must be set.");
70+
Validate.notBlank(endpoint, "endpoint must be set.");
71+
Validate.notBlank(uuid, "uuid must be set.");
72+
6873
try {
6974
// Load EC public and private key from PEM
7075
Pair<ECPrivateKey, ECPublicKey> keys = EcKeyLoader.loadSec1Pem(pemContent);

services/signin/src/test/java/software/amazon/awssdk/services/signin/auth/internal/DpopHeaderGeneratorTest.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,27 @@ public void testGenerateAndVerifyDPoPHeader() throws Exception {
8686
assertTrue(verified, "DPoP ES256 signature should verify correctly");
8787
}
8888

89+
@Test
90+
public void missingArguments_raisesException() {
91+
assertThrows(IllegalArgumentException.class, () -> {
92+
DpopHeaderGenerator.generateDPoPProofHeader(
93+
"", "https://example.com",
94+
Instant.now().getEpochSecond(), UUID.randomUUID().toString());
95+
});
96+
97+
assertThrows(IllegalArgumentException.class, () -> {
98+
DpopHeaderGenerator.generateDPoPProofHeader(
99+
VALID_TEST_PEM, "",
100+
Instant.now().getEpochSecond(), UUID.randomUUID().toString());
101+
});
102+
103+
assertThrows(IllegalArgumentException.class, () -> {
104+
DpopHeaderGenerator.generateDPoPProofHeader(
105+
VALID_TEST_PEM, "https://example.com",
106+
Instant.now().getEpochSecond(), "");
107+
});
108+
}
109+
89110
@Test
90111
public void invalidKey_raisesException() {
91112
assertThrows(IllegalArgumentException.class, () -> {

0 commit comments

Comments
 (0)