Skip to content

Commit

Permalink
correct HMAC padding, escape chars in tests
Browse files Browse the repository at this point in the history
Signed-off-by: Maciej Mierzwa <[email protected]>
  • Loading branch information
MaciejMierzwa committed Oct 4, 2023
1 parent 10fe305 commit da51bec
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public static String padSecret(String signingKey, JWSAlgorithm jwsAlgorithm) {
}
int requiredByteLength = ByteUtils.byteLength(requiredSecretLength);
// padding the signing key with 0s to meet the minimum required length
return StringUtils.rightPad(signingKey, requiredByteLength, "0");
return StringUtils.rightPad(signingKey, requiredByteLength, "\0");
}

public String createJwt(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -345,10 +345,10 @@ public void shouldUnescapeSamlEntitiesTest2() throws Exception {
Assert.assertNotNull("Expected authorization attribute in JSON: " + responseJson, authorization);

SignedJWT jwt = SignedJWT.parse(authorization.replaceAll("\\s*bearer\\s*", ""));
Assert.assertEquals("ABC\\User1", jwt.getJWTClaimsSet().getClaim("sub"));
Assert.assertEquals("ABC\\User1", samlAuthenticator.httpJwtAuthenticator.extractSubject(jwt.getJWTClaimsSet()));
Assert.assertEquals("[ABC\\Admin]", String.valueOf(jwt.getJWTClaimsSet().getClaim("roles")));
Assert.assertEquals("ABC\\Admin", samlAuthenticator.httpJwtAuthenticator.extractRoles(jwt.getJWTClaimsSet())[0]);
Assert.assertEquals("ABC\"User1", jwt.getJWTClaimsSet().getClaim("sub"));
Assert.assertEquals("ABC\"User1", samlAuthenticator.httpJwtAuthenticator.extractSubject(jwt.getJWTClaimsSet()));
Assert.assertEquals("[ABC\"Admin]", String.valueOf(jwt.getJWTClaimsSet().getClaim("roles")));
Assert.assertEquals("ABC\"Admin", samlAuthenticator.httpJwtAuthenticator.extractRoles(jwt.getJWTClaimsSet())[0]);
}

@Test
Expand Down Expand Up @@ -395,10 +395,10 @@ public void shouldNotEscapeSamlEntities() throws Exception {
Assert.assertNotNull("Expected authorization attribute in JSON: " + responseJson, authorization);

SignedJWT jwt = SignedJWT.parse(authorization.replaceAll("\\s*bearer\\s*", ""));
Assert.assertEquals("ABC\\User1", jwt.getJWTClaimsSet().getClaim("sub"));
Assert.assertEquals("ABC\\User1", samlAuthenticator.httpJwtAuthenticator.extractSubject(jwt.getJWTClaimsSet()));
Assert.assertEquals("[ABC\\Admin]", String.valueOf(jwt.getJWTClaimsSet().getClaim("roles")));
Assert.assertEquals("ABC\\Admin", samlAuthenticator.httpJwtAuthenticator.extractRoles(jwt.getJWTClaimsSet())[0]);
Assert.assertEquals("ABC/User1", jwt.getJWTClaimsSet().getClaim("sub"));
Assert.assertEquals("ABC/User1", samlAuthenticator.httpJwtAuthenticator.extractSubject(jwt.getJWTClaimsSet()));
Assert.assertEquals("[ABC/Admin]", String.valueOf(jwt.getJWTClaimsSet().getClaim("roles")));
Assert.assertEquals("ABC/Admin", samlAuthenticator.httpJwtAuthenticator.extractRoles(jwt.getJWTClaimsSet())[0]);
}

@Test
Expand Down Expand Up @@ -445,7 +445,7 @@ public void shouldNotTrimWhitespaceInJwtRoles() throws Exception {
Assert.assertNotNull("Expected authorization attribute in JSON: " + responseJson, authorization);

SignedJWT jwt = SignedJWT.parse(authorization.replaceAll("\\s*bearer\\s*", ""));
Assert.assertEquals("ABC\\Admin", samlAuthenticator.httpJwtAuthenticator.extractRoles(jwt.getJWTClaimsSet())[0]);
Assert.assertEquals("ABC/Admin", samlAuthenticator.httpJwtAuthenticator.extractRoles(jwt.getJWTClaimsSet())[0]);

}

Expand Down

0 comments on commit da51bec

Please sign in to comment.