use of org.wso2.carbon.identity.oauth.endpoint.oidcdiscovery.impl.OIDProviderJSONResponseBuilder in project identity-inbound-auth-oauth by wso2-extensions.
the class OIDCDiscoveryEndpointTest method testGetOIDProviderConfigurationTokenEndpoint.
@Test(dataProvider = "provideDataForGetOIDProviderConfigurationTokenEndpoint")
public void testGetOIDProviderConfigurationTokenEndpoint(String tokenEp, Map<String, Object> configMap, int expectedResponse) throws Exception {
ThreadLocal<Map<String, Object>> threadLocalProperties = new ThreadLocal() {
protected Map<String, Object> initialValue() {
return new HashMap();
}
};
threadLocalProperties.get().put(OAuthConstants.TENANT_NAME_FROM_CONTEXT, MultitenantConstants.SUPER_TENANT_DOMAIN_NAME);
Field threadLocalPropertiesField = identityUtilObj.getClass().getDeclaredField("threadLocalProperties");
Field modifiersField = Field.class.getDeclaredField("modifiers");
modifiersField.setAccessible(true);
modifiersField.setInt(threadLocalPropertiesField, threadLocalPropertiesField.getModifiers() & ~Modifier.FINAL);
threadLocalPropertiesField.setAccessible(true);
threadLocalPropertiesField.set(identityUtilObj, threadLocalProperties);
mockStatic(EndpointUtil.class);
when(EndpointUtil.getOIDCService()).thenReturn(defaultOIDCProcessor);
when(defaultOIDCProcessor.getResponse(any(HttpServletRequest.class), any(String.class))).thenReturn(oidProviderConfigResponse);
when(oidProviderConfigResponse.getConfigMap()).thenReturn(configMap);
when(defaultOIDCProcessor.handleError(any(OIDCDiscoveryEndPointException.class))).thenReturn(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
oidcDiscoveryEndpoint.setOidProviderResponseBuilder(new OIDProviderJSONResponseBuilder());
Response response = oidcDiscoveryEndpoint.getOIDProviderConfiguration(tokenEp, httpServletRequest);
Assert.assertEquals(expectedResponse, response.getStatus());
threadLocalProperties.get().remove(OAuthConstants.TENANT_NAME_FROM_CONTEXT);
}
Aggregations