use of org.wso2.carbon.identity.oauth2.bean.OAuthClientAuthnContext in project identity-inbound-auth-oauth by wso2-extensions.
the class BasicAuthClientAuthenticatorTest method testAuthenticateClient.
@Test(dataProvider = "testClientAuthnData")
public void testAuthenticateClient(String headerName, String headerValue, HashMap<String, List> bodyContent, Object oAuthClientAuthnContextObj, boolean isAuthenticated, boolean authenticationResult) throws Exception {
OAuthClientAuthnContext oAuthClientAuthnContext = (OAuthClientAuthnContext) oAuthClientAuthnContextObj;
HttpServletRequest httpServletRequest = PowerMockito.mock(HttpServletRequest.class);
PowerMockito.mockStatic(OAuth2Util.class);
PowerMockito.when(OAuth2Util.authenticateClient(Matchers.anyString(), Matchers.anyString())).thenReturn(isAuthenticated);
PowerMockito.when(httpServletRequest.getHeader(headerName)).thenReturn(headerValue);
assertEquals(basicAuthClientAuthenticator.authenticateClient(httpServletRequest, bodyContent, oAuthClientAuthnContext), authenticationResult, "Expected client authentication result was not " + "received");
}
use of org.wso2.carbon.identity.oauth2.bean.OAuthClientAuthnContext in project identity-inbound-auth-oauth by wso2-extensions.
the class BasicAuthClientAuthenticatorTest method testCanAuthenticate.
@Test(dataProvider = "testCanAuthenticateData")
public void testCanAuthenticate(String headerName, String headerValue, HashMap<String, List> bodyContent, boolean canHandle) throws Exception {
HttpServletRequest httpServletRequest = PowerMockito.mock(HttpServletRequest.class);
PowerMockito.when(httpServletRequest.getHeader(headerName)).thenReturn(headerValue);
assertEquals(basicAuthClientAuthenticator.canAuthenticate(httpServletRequest, bodyContent, new OAuthClientAuthnContext()), canHandle, "Expected can authenticate evaluation not received");
}
use of org.wso2.carbon.identity.oauth2.bean.OAuthClientAuthnContext in project identity-inbound-auth-oauth by wso2-extensions.
the class BasicAuthClientAuthenticatorTest method testGetClientId.
@Test(dataProvider = "testGetClientIdData")
public void testGetClientId(String headerName, String headerValue, HashMap<String, List> bodyContent, String clientId) throws Exception {
HttpServletRequest httpServletRequest = PowerMockito.mock(HttpServletRequest.class);
PowerMockito.when(httpServletRequest.getHeader(headerName)).thenReturn(headerValue);
assertEquals(basicAuthClientAuthenticator.getClientId(httpServletRequest, bodyContent, new OAuthClientAuthnContext()), clientId);
}
use of org.wso2.carbon.identity.oauth2.bean.OAuthClientAuthnContext in project identity-inbound-auth-oauth by wso2-extensions.
the class AccessTokenIssuerTest method testIssueValidateGrantError.
@Test(dataProvider = "invalidGrantErrorDataProvider")
public void testIssueValidateGrantError(boolean throwException, String exceptionMsg) throws Exception {
AuthorizationGrantHandler dummyGrantHandler = mock(AuthorizationGrantHandler.class);
when(dummyGrantHandler.isConfidentialClient()).thenReturn(false);
// Not a confidential client
when(dummyGrantHandler.isOfTypeApplicationUser()).thenReturn(true);
when(dummyGrantHandler.isAuthorizedClient(any(OAuthTokenReqMessageContext.class))).thenReturn(true);
if (throwException) {
// validate grant will throw an exception
when(dummyGrantHandler.validateGrant(any(OAuthTokenReqMessageContext.class))).thenThrow(new IdentityOAuth2Exception(exceptionMsg));
} else {
// validate grant will return false
when(dummyGrantHandler.validateGrant(any(OAuthTokenReqMessageContext.class))).thenReturn(false);
}
HashMap<String, AuthorizationGrantHandler> authorizationGrantHandlers = new HashMap<>();
authorizationGrantHandlers.put(DUMMY_GRANT_TYPE, dummyGrantHandler);
mockOAuth2ServerConfiguration(authorizationGrantHandlers);
OAuth2AccessTokenReqDTO reqDTO = new OAuth2AccessTokenReqDTO();
reqDTO.setGrantType(DUMMY_GRANT_TYPE);
OAuthClientAuthnContext oAuthClientAuthnContext = new OAuthClientAuthnContext();
oAuthClientAuthnContext.setClientId(SOME_CLIENT_ID);
reqDTO.setoAuthClientAuthnContext(oAuthClientAuthnContext);
OAuth2AccessTokenRespDTO tokenRespDTO = AccessTokenIssuer.getInstance().issue(reqDTO);
assertNotNull(tokenRespDTO);
assertTrue(tokenRespDTO.isError());
assertEquals(tokenRespDTO.getErrorCode(), OAuthError.TokenResponse.INVALID_GRANT);
assertEquals(tokenRespDTO.getErrorMsg(), exceptionMsg);
}
use of org.wso2.carbon.identity.oauth2.bean.OAuthClientAuthnContext in project identity-inbound-auth-oauth by wso2-extensions.
the class AccessTokenIssuerTest method testIssueWithOpenIdScopeFailure.
@Test
public void testIssueWithOpenIdScopeFailure() throws Exception {
OAuth2AccessTokenReqDTO reqDTO = new OAuth2AccessTokenReqDTO();
reqDTO.setGrantType(DUMMY_GRANT_TYPE);
reqDTO.setScope(SCOPES_WITH_OPENID);
setupOIDCScopeTest(DUMMY_GRANT_TYPE, false);
OAuthClientAuthnContext oAuthClientAuthnContext = new OAuthClientAuthnContext();
oAuthClientAuthnContext.setClientId(SOME_CLIENT_ID);
reqDTO.setoAuthClientAuthnContext(oAuthClientAuthnContext);
OAuth2AccessTokenRespDTO tokenRespDTO = AccessTokenIssuer.getInstance().issue(reqDTO);
assertNotNull(tokenRespDTO);
assertTrue(tokenRespDTO.isError());
assertEquals(tokenRespDTO.getErrorCode(), OAuth2ErrorCodes.SERVER_ERROR);
// ID Token should not be set
assertNull(tokenRespDTO.getIDToken());
}
Aggregations