Skip to content

Commit 026f3c5

Browse files
authored
Add testParseJWKSWithEmptyKeysArray (#233)
Signed-off-by: Max Lambrecht <maxlambrecht@gmail.com>
1 parent 5ec9667 commit 026f3c5

1 file changed

Lines changed: 23 additions & 3 deletions

File tree

java-spiffe-core/src/test/java/io/spiffe/bundle/jwtbundle/JwtBundleTest.java

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
import java.io.IOException;
1313
import java.net.URISyntaxException;
14+
import java.nio.charset.StandardCharsets;
1415
import java.nio.file.Files;
1516
import java.nio.file.Path;
1617
import java.nio.file.Paths;
@@ -219,6 +220,25 @@ void testParseJsonWithRsaAndEcKeys_Success() throws URISyntaxException, IOExcept
219220
assertNotNull(jwtBundle.getJwtAuthorities().get("C6vs25welZOx6WksNYfbMfiw9l96pMnD"));
220221
}
221222

223+
@Test
224+
void testParseJWKSWithEmptyKeysArray_Success() {
225+
TrustDomain trustDomain = TrustDomain.parse("example.org");
226+
String jwksEmptyKeysJson = "{\"keys\": []}";
227+
byte[] bundleBytes = jwksEmptyKeysJson.getBytes(StandardCharsets.UTF_8);
228+
229+
230+
JwtBundle jwtBundle = null;
231+
try {
232+
jwtBundle = JwtBundle.parse(trustDomain, bundleBytes);
233+
} catch (JwtBundleException e) {
234+
fail("Parsing failed with exception: " + e.getMessage());
235+
}
236+
237+
assertNotNull(jwtBundle, "JwtBundle should not be null");
238+
assertEquals(trustDomain, jwtBundle.getTrustDomain(), "Trust domain should match");
239+
assertTrue(jwtBundle.getJwtAuthorities().isEmpty(), "JwtAuthorities should be empty");
240+
}
241+
222242
@Test
223243
void testParse_MissingKid_Fails() throws URISyntaxException, IOException {
224244
Path path = Paths.get(toUri("testdata/jwtbundle/jwks_missing_kid.json"));
@@ -269,7 +289,7 @@ void testgetBundleForTrustDomain_Success() {
269289
JwtBundle bundle = jwtBundle.getBundleForTrustDomain(TrustDomain.parse("example.org"));
270290
assertEquals(jwtBundle, bundle);
271291
} catch (BundleNotFoundException e) {
272-
fail(e);
292+
fail(e);
273293
}
274294
}
275295

@@ -305,8 +325,8 @@ void testJWTAuthoritiesCRUD() {
305325
} catch (AuthorityNotFoundException e) {
306326
fail(e);
307327
}
308-
assertEquals(key1, jwtAuthority1 );
309-
assertEquals(key2, jwtAuthority2 );
328+
assertEquals(key1, jwtAuthority1);
329+
assertEquals(key2, jwtAuthority2);
310330

311331
// Test RemoveJwtAuthority
312332
jwtBundle.removeJwtAuthority("key1");

0 commit comments

Comments
 (0)