use of io.gravitee.am.service.exception.EmailFormatInvalidException in project gravitee-access-management by gravitee-io.
the class ForgotPasswordSubmissionEndpointTest method shouldFailWhenEmailFormatInvalidException.
@Test
public void shouldFailWhenEmailFormatInvalidException() throws Exception {
Client client = new Client();
client.setId("client-id");
client.setClientId("client-id");
router.route().order(-1).handler(routingContext -> {
routingContext.put("client", client);
routingContext.next();
});
when(userService.forgotPassword(argThat(p -> p.getEmail().equals("email.test.com")), eq(client), any(User.class))).thenReturn(Completable.error(new EmailFormatInvalidException("email.test.com")));
testRequest(HttpMethod.POST, "/forgotPassword?client_id=client-id", req -> postEmail(req, "email.test.com"), resp -> {
String location = resp.headers().get("location");
assertNotNull(location);
assertTrue(location.endsWith("/forgotPassword?client_id=client-id&error=forgot_password_failed"));
}, HttpStatusCode.FOUND_302, "Found", null);
}
use of io.gravitee.am.service.exception.EmailFormatInvalidException in project gravitee-access-management by gravitee-io.
the class UserValidatorTest method validate_invalidEmail.
@Test
public void validate_invalidEmail() {
User user = getValidUser();
user.setEmail("invalid");
Throwable throwable = userValidator.validate(user).blockingGet();
assertNotNull(throwable);
assertTrue(throwable instanceof EmailFormatInvalidException);
}
use of io.gravitee.am.service.exception.EmailFormatInvalidException in project gravitee-access-management by gravitee-io.
the class RegisterSubmissionEndpointTest method shouldFail_emailFormatInvalidException.
@Test
public void shouldFail_emailFormatInvalidException() throws Exception {
Client client = new Client();
client.setId("client-id");
client.setClientId("client-id");
client.setRedirectUris(Collections.singletonList("http://localhost:9999/callback"));
router.route().order(-1).handler(routingContext -> {
routingContext.put("client", client);
routingContext.next();
});
when(userService.register(eq(client), any(), any())).thenReturn(Single.error(new EmailFormatInvalidException("test")));
testRequest(HttpMethod.POST, "/register?client_id=client-id", null, resp -> {
String location = resp.headers().get("location");
assertNotNull(location);
assertTrue(location.endsWith("/register?client_id=client-id&warning=invalid_email"));
}, HttpStatusCode.FOUND_302, "Found", null);
}
use of io.gravitee.am.service.exception.EmailFormatInvalidException in project gravitee-access-management by gravitee-io.
the class RegisterFailureHandler method handle.
@Override
public void handle(RoutingContext context) {
if (context.failed()) {
// prepare response
final MultiMap queryParams = RequestUtils.getCleanedQueryParams(context.request());
// if failure, return to the register page with an error
Throwable cause = context.failure();
if (cause instanceof InvalidUserException) {
queryParams.set(ConstantKeys.WARNING_PARAM_KEY, "invalid_user_information");
} else if (cause instanceof EmailFormatInvalidException) {
queryParams.set(ConstantKeys.WARNING_PARAM_KEY, "invalid_email");
} else {
logger.error("An error occurs while ending user registration", cause);
queryParams.set(ConstantKeys.ERROR_PARAM_KEY, "registration_failed");
}
redirectToPage(context, queryParams, cause);
}
}
Aggregations