Skip to content

Commit

Permalink
Add testParseJWKSWithEmptyKeysArray (#233)
Browse files Browse the repository at this point in the history
Signed-off-by: Max Lambrecht <[email protected]>
  • Loading branch information
maxlambrecht authored Oct 8, 2024
1 parent 5ec9667 commit 026f3c5
Showing 1 changed file with 23 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

import java.io.IOException;
import java.net.URISyntaxException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
Expand Down Expand Up @@ -219,6 +220,25 @@ void testParseJsonWithRsaAndEcKeys_Success() throws URISyntaxException, IOExcept
assertNotNull(jwtBundle.getJwtAuthorities().get("C6vs25welZOx6WksNYfbMfiw9l96pMnD"));
}

@Test
void testParseJWKSWithEmptyKeysArray_Success() {
TrustDomain trustDomain = TrustDomain.parse("example.org");
String jwksEmptyKeysJson = "{\"keys\": []}";
byte[] bundleBytes = jwksEmptyKeysJson.getBytes(StandardCharsets.UTF_8);


JwtBundle jwtBundle = null;
try {
jwtBundle = JwtBundle.parse(trustDomain, bundleBytes);
} catch (JwtBundleException e) {
fail("Parsing failed with exception: " + e.getMessage());
}

assertNotNull(jwtBundle, "JwtBundle should not be null");
assertEquals(trustDomain, jwtBundle.getTrustDomain(), "Trust domain should match");
assertTrue(jwtBundle.getJwtAuthorities().isEmpty(), "JwtAuthorities should be empty");
}

@Test
void testParse_MissingKid_Fails() throws URISyntaxException, IOException {
Path path = Paths.get(toUri("testdata/jwtbundle/jwks_missing_kid.json"));
Expand Down Expand Up @@ -269,7 +289,7 @@ void testgetBundleForTrustDomain_Success() {
JwtBundle bundle = jwtBundle.getBundleForTrustDomain(TrustDomain.parse("example.org"));
assertEquals(jwtBundle, bundle);
} catch (BundleNotFoundException e) {
fail(e);
fail(e);
}
}

Expand Down Expand Up @@ -305,8 +325,8 @@ void testJWTAuthoritiesCRUD() {
} catch (AuthorityNotFoundException e) {
fail(e);
}
assertEquals(key1, jwtAuthority1 );
assertEquals(key2, jwtAuthority2 );
assertEquals(key1, jwtAuthority1);
assertEquals(key2, jwtAuthority2);

// Test RemoveJwtAuthority
jwtBundle.removeJwtAuthority("key1");
Expand Down

0 comments on commit 026f3c5

Please sign in to comment.