Skip to content

Commit

Permalink
Change to assertThrows for obo authenticator tests
Browse files Browse the repository at this point in the history
Signed-off-by: Ryan Liang <[email protected]>
  • Loading branch information
RyanL1997 committed Aug 23, 2023
1 parent e56bf01 commit 15c8530
Showing 1 changed file with 21 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,51 +46,45 @@ public class OnBehalfOfAuthenticatorTest {
final static SecretKey secretKey = Keys.hmacShaKeyFor(signingKeyB64Encoded.getBytes(StandardCharsets.UTF_8));

@Test
public void testNoKey() throws Exception {

try {
final AuthCredentials credentials = extractCredentialsFromJwtHeader(
public void testNoKey() {
Exception exception = Assert.assertThrows(
RuntimeException.class,
() -> extractCredentialsFromJwtHeader(
null,
claimsEncryptionKey,
Jwts.builder().setIssuer(clusterName).setSubject("Leonard McCoy"),
false
);
Assert.fail("Expected a RuntimeException");
} catch (RuntimeException e) {
Assert.assertTrue(e.getMessage().contains("Unable to find on behalf of authenticator signing key"));
}
)
);
Assert.assertTrue(exception.getMessage().contains("Unable to find on behalf of authenticator signing key"));
}

@Test
public void testEmptyKey() throws Exception {

try {
final AuthCredentials credentials = extractCredentialsFromJwtHeader(
public void testEmptyKey() {
Exception exception = Assert.assertThrows(
RuntimeException.class,
() -> extractCredentialsFromJwtHeader(
null,
claimsEncryptionKey,
Jwts.builder().setIssuer(clusterName).setSubject("Leonard McCoy"),
false
);
Assert.fail("Expected a RuntimeException");
} catch (RuntimeException e) {
Assert.assertTrue(e.getMessage().contains("Unable to find on behalf of authenticator signing key"));
}
)
);
Assert.assertTrue(exception.getMessage().contains("Unable to find on behalf of authenticator signing key"));
}

@Test
public void testBadKey() throws Exception {

try {
final AuthCredentials credentials = extractCredentialsFromJwtHeader(
public void testBadKey() {
Exception exception = Assert.assertThrows(
RuntimeException.class,
() -> extractCredentialsFromJwtHeader(
BaseEncoding.base64().encode(new byte[] { 1, 3, 3, 4, 3, 6, 7, 8, 3, 10 }),
claimsEncryptionKey,
Jwts.builder().setIssuer(clusterName).setSubject("Leonard McCoy"),
false
);
Assert.fail("Expected a WeakKeyException");
} catch (RuntimeException e) {
Assert.assertTrue(e.getMessage().contains("The specified key byte array is 80 bits"));
}
)
);
Assert.assertTrue(exception.getMessage().contains("The specified key byte array is 80 bits"));
}

@Test
Expand Down

0 comments on commit 15c8530

Please sign in to comment.