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);
}
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);
}
Aggregations