Skip to content

Commit

Permalink
Add unit tests for the validations.
Browse files Browse the repository at this point in the history
  • Loading branch information
mpmadhavig committed Jun 26, 2024
1 parent fadc560 commit 909bbae
Showing 1 changed file with 36 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -850,6 +850,34 @@ private void testValidateTokenAuthenticationWithInvalidAuthentication() throws E
}
}

@DataProvider(name = "getTokenAuthMethodAndTokenReuseConfigData")
public Object[][] getTokenAuthMethodAndTokenReuseConfigData() {

return new Object[][]{
// Client auth method, Expected result.
{"private_key_jwt", null, true},
{null, true, true},
{"", true, true},
{" ", true, true},
{"dummy_method", true, true},
{"private_key_jwt", true, false},
{null, null, false},
{"dummy_method", null, false}};
}

@Test(description = "Test invalid reuse token config & client auth method combination.",
dataProvider = "getTokenAuthMethodAndTokenReuseConfigData")
private void testInvalidReuseTokenRequestAndClientAuthMethod(String tokenEndpointAuthMethod,
Boolean tokenEndpointReusePvtKeyJWT,
boolean expectedResult) throws Exception {

OAuthAdminServiceImpl oAuthAdminService = new OAuthAdminServiceImpl();

Assert.assertEquals(invokePrivateMethod(oAuthAdminService,
"isInvalidTokenEPReusePvtKeyJWTRequest", new Class[]{String.class, Boolean.class},
tokenEndpointAuthMethod, tokenEndpointReusePvtKeyJWT), expectedResult);
}

@Test(description = "Test validating signature algorithm")
private void testValidateSignatureAlgorithm() throws Exception {

Expand Down Expand Up @@ -1059,4 +1087,12 @@ private Object invokePrivateMethod(Object object, String methodName, Object... p
method.setAccessible(true);
return method.invoke(object, params);
}

private Object invokePrivateMethod(Object object, String methodName, Class<?>[] paramTypes, Object... params)
throws Exception {

Method method = object.getClass().getDeclaredMethod(methodName, paramTypes);
method.setAccessible(true);
return method.invoke(object, params);
}
}

0 comments on commit 909bbae

Please sign in to comment.