Search in sources :

Example 1 with HttpIdentityResponse

use of org.wso2.carbon.identity.application.authentication.framework.inbound.HttpIdentityResponse in project carbon-identity-framework by wso2.

the class SessionExtenderRequestFactoryTest method testHandleException.

@Test
public void testHandleException() {
    SessionExtenderClientException exception = mock(SessionExtenderClientException.class);
    when(exception.getErrorCode()).thenReturn(EXCEPTION_ERROR_CODE);
    when(exception.getErrorMessage()).thenReturn(EXCEPTION_MESSAGE);
    when(exception.getDescription()).thenReturn(EXCEPTION_DESCRIPTION);
    ThreadContext.put("Correlation-ID", TRACE_ID);
    HttpIdentityResponse.HttpIdentityResponseBuilder responseBuilder = sessionExtenderRequestFactory.handleException(exception, mockedHttpRequest, mockedHttpResponse);
    HttpIdentityResponse response = responseBuilder.build();
    assertEquals(response.getBody(), ERROR_RESPONSE_BODY);
    assertEquals(response.getStatusCode(), 400);
}
Also used : SessionExtenderClientException(org.wso2.carbon.identity.application.authentication.framework.session.extender.exception.SessionExtenderClientException) HttpIdentityResponse(org.wso2.carbon.identity.application.authentication.framework.inbound.HttpIdentityResponse) Test(org.testng.annotations.Test)

Example 2 with HttpIdentityResponse

use of org.wso2.carbon.identity.application.authentication.framework.inbound.HttpIdentityResponse in project carbon-identity-framework by wso2.

the class SessionExtenderResponseFactoryTest method testCreate.

@Test
public void testCreate() {
    SessionExtenderResponse sessionExtenderResponse = mock(SessionExtenderResponse.class);
    when(sessionExtenderResponse.getTraceId()).thenReturn(TRACE_ID);
    HttpIdentityResponse.HttpIdentityResponseBuilder responseBuilder = sessionExtenderResponseFactory.create(sessionExtenderResponse);
    HttpIdentityResponse response = responseBuilder.build();
    assertNull(response.getBody());
    assertNotNull(response.getHeaders().get("Trace-ID"));
}
Also used : HttpIdentityResponse(org.wso2.carbon.identity.application.authentication.framework.inbound.HttpIdentityResponse) Test(org.testng.annotations.Test)

Example 3 with HttpIdentityResponse

use of org.wso2.carbon.identity.application.authentication.framework.inbound.HttpIdentityResponse in project carbon-identity-framework by wso2.

the class SessionExtenderResponseFactoryTest method testHandleExceptions.

@Test(dataProvider = "handleExceptionProvider")
public void testHandleExceptions(FrameworkException exception, int expectedStatusCode) {
    ThreadContext.put("Correlation-ID", TRACE_ID);
    HttpIdentityResponse.HttpIdentityResponseBuilder responseBuilder = sessionExtenderResponseFactory.handleException(exception);
    HttpIdentityResponse response = responseBuilder.build();
    assertEquals(response.getBody(), ERROR_RESPONSE_BODY);
    assertEquals(response.getStatusCode(), expectedStatusCode);
}
Also used : HttpIdentityResponse(org.wso2.carbon.identity.application.authentication.framework.inbound.HttpIdentityResponse) Test(org.testng.annotations.Test)

Example 4 with HttpIdentityResponse

use of org.wso2.carbon.identity.application.authentication.framework.inbound.HttpIdentityResponse in project identity-inbound-auth-oauth by wso2-extensions.

the class HttpOIDCRegistrationResponseFactoryTest method testCreate.

@Test
public void testCreate() throws Exception {
    OIDCRegistrationResponseProfile registrationResponseProfile = new OIDCRegistrationResponseProfile();
    registrationResponseProfile.setClientId("client_id");
    registrationResponseProfile.setClientName("client_name");
    registrationResponseProfile.setRedirectUrls(Arrays.asList("http://example.com", "http://foo.com"));
    registrationResponseProfile.setGrantTypes(Arrays.asList("code", "implicit"));
    registrationResponseProfile.setClientSecret("cl1ent_s3cr3t");
    registrationResponseProfile.setClientSecretExpiresAt("dummyExpiry");
    RegistrationResponse mockResponse = new RegistrationResponse.DCRRegisterResponseBuilder().setRegistrationResponseProfile(registrationResponseProfile).build();
    HttpIdentityResponse identityResponse = testedResponseFactory.create(mockResponse).build();
    assertEquals(identityResponse.getStatusCode(), HttpServletResponse.SC_CREATED, "Invalid status code.");
    assertEquals(identityResponse.getHeaders().get(OAuthConstants.HTTP_RESP_HEADER_CACHE_CONTROL), OAuthConstants.HTTP_RESP_HEADER_VAL_CACHE_CONTROL_NO_STORE, "Invalid cache control header.");
    assertEquals(identityResponse.getHeaders().get(OAuthConstants.HTTP_RESP_HEADER_PRAGMA), OAuthConstants.HTTP_RESP_HEADER_VAL_PRAGMA_NO_CACHE, "Invalid pragma header.");
    assertEquals(identityResponse.getHeaders().get(HttpHeaders.CONTENT_TYPE), MediaType.APPLICATION_JSON, "Invalid content type header.");
}
Also used : OIDCRegistrationResponseProfile(org.wso2.carbon.identity.oidc.dcr.model.OIDCRegistrationResponseProfile) HttpIdentityResponse(org.wso2.carbon.identity.application.authentication.framework.inbound.HttpIdentityResponse) RegistrationResponse(org.wso2.carbon.identity.oauth.dcr.model.RegistrationResponse) OIDCRegistrationResponse(org.wso2.carbon.identity.oidc.dcr.model.OIDCRegistrationResponse) Test(org.testng.annotations.Test)

Aggregations

Test (org.testng.annotations.Test)4 HttpIdentityResponse (org.wso2.carbon.identity.application.authentication.framework.inbound.HttpIdentityResponse)4 SessionExtenderClientException (org.wso2.carbon.identity.application.authentication.framework.session.extender.exception.SessionExtenderClientException)1 RegistrationResponse (org.wso2.carbon.identity.oauth.dcr.model.RegistrationResponse)1 OIDCRegistrationResponse (org.wso2.carbon.identity.oidc.dcr.model.OIDCRegistrationResponse)1 OIDCRegistrationResponseProfile (org.wso2.carbon.identity.oidc.dcr.model.OIDCRegistrationResponseProfile)1