Search in sources :

Example 1 with OIDProviderJSONResponseBuilder

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);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) OIDProviderConfigResponse(org.wso2.carbon.identity.discovery.OIDProviderConfigResponse) HttpServletResponse(javax.servlet.http.HttpServletResponse) Response(javax.ws.rs.core.Response) Field(java.lang.reflect.Field) HashMap(java.util.HashMap) OIDCDiscoveryEndPointException(org.wso2.carbon.identity.discovery.OIDCDiscoveryEndPointException) OIDProviderJSONResponseBuilder(org.wso2.carbon.identity.oauth.endpoint.oidcdiscovery.impl.OIDProviderJSONResponseBuilder) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) PowerMockIdentityBaseTest(org.wso2.carbon.identity.testutil.powermock.PowerMockIdentityBaseTest)

Aggregations

Field (java.lang.reflect.Field)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 HttpServletResponse (javax.servlet.http.HttpServletResponse)1 Response (javax.ws.rs.core.Response)1 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)1 BeforeTest (org.testng.annotations.BeforeTest)1 Test (org.testng.annotations.Test)1 OIDCDiscoveryEndPointException (org.wso2.carbon.identity.discovery.OIDCDiscoveryEndPointException)1 OIDProviderConfigResponse (org.wso2.carbon.identity.discovery.OIDProviderConfigResponse)1 OIDProviderJSONResponseBuilder (org.wso2.carbon.identity.oauth.endpoint.oidcdiscovery.impl.OIDProviderJSONResponseBuilder)1 PowerMockIdentityBaseTest (org.wso2.carbon.identity.testutil.powermock.PowerMockIdentityBaseTest)1