Search in sources :

Example 16 with OAuth2ErrorRepresentation

use of org.keycloak.representations.idm.OAuth2ErrorRepresentation in project keycloak by keycloak.

the class UncaughtErrorPageTest method uncaughtErrorClientRegistration.

@Test
@UncaughtServerErrorExpected
public void uncaughtErrorClientRegistration() throws IOException {
    try (CloseableHttpClient client = HttpClientBuilder.create().build()) {
        HttpPost post = new HttpPost(suiteContext.getAuthServerInfo().getUriBuilder().path("/auth/realms/master/clients-registrations/openid-connect").build());
        post.setEntity(new StringEntity("{ invalid : invalid }"));
        post.setHeader("Content-Type", "application/json");
        CloseableHttpResponse response = client.execute(post);
        assertEquals(400, response.getStatusLine().getStatusCode());
        OAuth2ErrorRepresentation error = JsonSerialization.readValue(response.getEntity().getContent(), OAuth2ErrorRepresentation.class);
        assertEquals("unknown_error", error.getError());
        assertNull(error.getErrorDescription());
    }
}
Also used : CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) HttpPost(org.apache.http.client.methods.HttpPost) StringEntity(org.apache.http.entity.StringEntity) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) OAuth2ErrorRepresentation(org.keycloak.representations.idm.OAuth2ErrorRepresentation) Test(org.junit.Test) AbstractKeycloakTest(org.keycloak.testsuite.AbstractKeycloakTest) UncaughtServerErrorExpected(org.keycloak.testsuite.arquillian.annotation.UncaughtServerErrorExpected)

Example 17 with OAuth2ErrorRepresentation

use of org.keycloak.representations.idm.OAuth2ErrorRepresentation in project keycloak by keycloak.

the class UncaughtErrorPageTest method uncaughtErrorAdmin.

@Test
@UncaughtServerErrorExpected
public void uncaughtErrorAdmin() throws IOException {
    try (CloseableHttpClient client = HttpClientBuilder.create().build()) {
        String accessToken = adminClient.tokenManager().getAccessTokenString();
        HttpPost post = new HttpPost(suiteContext.getAuthServerInfo().getUriBuilder().path("/auth/admin/realms").build());
        post.setEntity(new StringEntity("{ invalid : invalid }"));
        post.setHeader("Authorization", "bearer " + accessToken);
        post.setHeader("Content-Type", "application/json");
        CloseableHttpResponse response = client.execute(post);
        assertEquals(400, response.getStatusLine().getStatusCode());
        OAuth2ErrorRepresentation error = JsonSerialization.readValue(response.getEntity().getContent(), OAuth2ErrorRepresentation.class);
        assertEquals("unknown_error", error.getError());
        assertNull(error.getErrorDescription());
    }
}
Also used : CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) HttpPost(org.apache.http.client.methods.HttpPost) StringEntity(org.apache.http.entity.StringEntity) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) OAuth2ErrorRepresentation(org.keycloak.representations.idm.OAuth2ErrorRepresentation) Test(org.junit.Test) AbstractKeycloakTest(org.keycloak.testsuite.AbstractKeycloakTest) UncaughtServerErrorExpected(org.keycloak.testsuite.arquillian.annotation.UncaughtServerErrorExpected)

Aggregations

OAuth2ErrorRepresentation (org.keycloak.representations.idm.OAuth2ErrorRepresentation)17 Test (org.junit.Test)8 AccessTokenResponse (org.keycloak.testsuite.util.OAuthClient.AccessTokenResponse)5 IOException (java.io.IOException)4 HttpPost (org.apache.http.client.methods.HttpPost)4 CloseableHttpClient (org.apache.http.impl.client.CloseableHttpClient)3 AbstractKeycloakTest (org.keycloak.testsuite.AbstractKeycloakTest)3 InputStream (java.io.InputStream)2 ArrayList (java.util.ArrayList)2 Objects (java.util.Objects)2 Response (javax.ws.rs.core.Response)2 HttpEntity (org.apache.http.HttpEntity)2 HttpResponse (org.apache.http.HttpResponse)2 NameValuePair (org.apache.http.NameValuePair)2 HttpClient (org.apache.http.client.HttpClient)2 UrlEncodedFormEntity (org.apache.http.client.entity.UrlEncodedFormEntity)2 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)2 StringEntity (org.apache.http.entity.StringEntity)2 BasicNameValuePair (org.apache.http.message.BasicNameValuePair)2 BadRequestException (org.jboss.resteasy.spi.BadRequestException)2