Search in sources :

Example 1 with ExpressionEvaluationException

use of io.gravitee.el.exceptions.ExpressionEvaluationException in project gravitee-management-rest-api by gravitee-io.

the class OAuth2AuthenticationResourceTest method shouldNotConnectNewUserWhenWrongELGroupsMapping.

@Test
public void shouldNotConnectNewUserWhenWrongELGroupsMapping() throws Exception {
    // -- MOCK
    // mock environment
    mockDefaultEnvironment();
    mockWrongELGroupsMapping();
    // mock oauth2 exchange authorisation code for access token
    mockExchangeAuthorizationCodeForAccessToken();
    // mock oauth2 user info call
    mockUserInfo(okJson(IOUtils.toString(read("/oauth2/json/user_info_response_body.json"), Charset.defaultCharset())));
    when(userService.createOrUpdateUserFromSocialIdentityProvider(any(), any())).thenThrow(new ExpressionEvaluationException("error"));
    // -- CALL
    AbstractAuthenticationResource.Payload payload = createPayload("the_client_id", "http://localhost/callback", "CoDe", "StAtE");
    Response response = orgTarget().request().post(json(payload));
    // -- VERIFY
    verify(userService, times(1)).createOrUpdateUserFromSocialIdentityProvider(any(), any());
    verify(userService, times(0)).connect(anyString());
    assertEquals(HttpStatusCode.INTERNAL_SERVER_ERROR_500, response.getStatus());
    // verify jwt token
    verifyJwtTokenIsNotPresent(response);
}
Also used : Response(javax.ws.rs.core.Response) ExpressionEvaluationException(io.gravitee.el.exceptions.ExpressionEvaluationException) Test(org.junit.Test) AbstractResourceTest(io.gravitee.rest.api.management.rest.resource.AbstractResourceTest)

Example 2 with ExpressionEvaluationException

use of io.gravitee.el.exceptions.ExpressionEvaluationException in project gravitee-management-rest-api by gravitee-io.

the class OAuth2AuthenticationResourceTest method shouldNotConnectNewUserWhenWrongELGroupsMapping.

@Test
public void shouldNotConnectNewUserWhenWrongELGroupsMapping() throws Exception {
    // -- MOCK
    // mock environment
    mockDefaultEnvironment();
    // mock oauth2 exchange authorisation code for access token
    mockExchangeAuthorizationCodeForAccessToken();
    // mock oauth2 user info call
    mockUserInfo(okJson(IOUtils.toString(read("/oauth2/json/user_info_response_body.json"), Charset.defaultCharset())));
    // mock DB find user by name
    when(userService.createOrUpdateUserFromSocialIdentityProvider(eq(identityProvider), anyString())).thenThrow(new ExpressionEvaluationException("cannot convert from java.lang.String to boolean"));
    // -- CALL
    final MultivaluedMap<String, String> payload = createPayload("the_client_id", "http://localhost/callback", "CoDe");
    Response response = target().request().post(form(payload));
    // -- VERIFY
    verify(userService, times(1)).createOrUpdateUserFromSocialIdentityProvider(eq(identityProvider), anyString());
    verify(userService, times(0)).connect(anyString());
    assertEquals(HttpStatusCode.INTERNAL_SERVER_ERROR_500, response.getStatus());
    // verify jwt token
    verifyJwtTokenIsNotPresent(response);
}
Also used : ExpressionEvaluationException(io.gravitee.el.exceptions.ExpressionEvaluationException) AbstractResourceTest(io.gravitee.rest.api.portal.rest.resource.AbstractResourceTest) Test(org.junit.Test)

Aggregations

ExpressionEvaluationException (io.gravitee.el.exceptions.ExpressionEvaluationException)2 Test (org.junit.Test)2 AbstractResourceTest (io.gravitee.rest.api.management.rest.resource.AbstractResourceTest)1 AbstractResourceTest (io.gravitee.rest.api.portal.rest.resource.AbstractResourceTest)1 Response (javax.ws.rs.core.Response)1