Search in sources :

Example 1 with EmailFormatInvalidException

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);
}
Also used : ErrorHandler(io.gravitee.am.gateway.handler.common.vertx.web.handler.ErrorHandler) APPLICATION_X_WWW_FORM_URLENCODED(io.vertx.core.http.HttpHeaders.APPLICATION_X_WWW_FORM_URLENCODED) ArgumentMatchers(org.mockito.ArgumentMatchers) Client(io.gravitee.am.model.oidc.Client) Mock(org.mockito.Mock) EmailFormatInvalidException(io.gravitee.am.service.exception.EmailFormatInvalidException) Completable(io.reactivex.Completable) RunWith(org.junit.runner.RunWith) UserService(io.gravitee.am.gateway.handler.root.service.user.UserService) Domain(io.gravitee.am.model.Domain) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) BodyHandler(io.vertx.reactivex.ext.web.handler.BodyHandler) EnforceUserIdentityException(io.gravitee.am.service.exception.EnforceUserIdentityException) UserNotFoundException(io.gravitee.am.service.exception.UserNotFoundException) HttpStatusCode(io.gravitee.common.http.HttpStatusCode) CONTENT_TYPE(io.vertx.core.http.HttpHeaders.CONTENT_TYPE) User(io.gravitee.am.identityprovider.api.User) HttpMethod(io.vertx.core.http.HttpMethod) RxWebTestBase(io.gravitee.am.gateway.handler.common.vertx.RxWebTestBase) AccountSettings(io.gravitee.am.model.account.AccountSettings) MockitoJUnitRunner(org.mockito.junit.MockitoJUnitRunner) Mockito.reset(org.mockito.Mockito.reset) Buffer(io.vertx.reactivex.core.buffer.Buffer) User(io.gravitee.am.identityprovider.api.User) EmailFormatInvalidException(io.gravitee.am.service.exception.EmailFormatInvalidException) Client(io.gravitee.am.model.oidc.Client) Test(org.junit.Test)

Example 2 with EmailFormatInvalidException

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);
}
Also used : User(io.gravitee.am.model.User) EmailFormatInvalidException(io.gravitee.am.service.exception.EmailFormatInvalidException) Test(org.junit.Test)

Example 3 with 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);
}
Also used : EmailFormatInvalidException(io.gravitee.am.service.exception.EmailFormatInvalidException) Client(io.gravitee.am.model.oidc.Client) Test(org.junit.Test)

Example 4 with EmailFormatInvalidException

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);
    }
}
Also used : MultiMap(io.vertx.reactivex.core.MultiMap) EmailFormatInvalidException(io.gravitee.am.service.exception.EmailFormatInvalidException) InvalidUserException(io.gravitee.am.service.exception.InvalidUserException)

Aggregations

EmailFormatInvalidException (io.gravitee.am.service.exception.EmailFormatInvalidException)4 Test (org.junit.Test)3 Client (io.gravitee.am.model.oidc.Client)2 RxWebTestBase (io.gravitee.am.gateway.handler.common.vertx.RxWebTestBase)1 ErrorHandler (io.gravitee.am.gateway.handler.common.vertx.web.handler.ErrorHandler)1 UserService (io.gravitee.am.gateway.handler.root.service.user.UserService)1 User (io.gravitee.am.identityprovider.api.User)1 Domain (io.gravitee.am.model.Domain)1 User (io.gravitee.am.model.User)1 AccountSettings (io.gravitee.am.model.account.AccountSettings)1 EnforceUserIdentityException (io.gravitee.am.service.exception.EnforceUserIdentityException)1 InvalidUserException (io.gravitee.am.service.exception.InvalidUserException)1 UserNotFoundException (io.gravitee.am.service.exception.UserNotFoundException)1 HttpStatusCode (io.gravitee.common.http.HttpStatusCode)1 Completable (io.reactivex.Completable)1 APPLICATION_X_WWW_FORM_URLENCODED (io.vertx.core.http.HttpHeaders.APPLICATION_X_WWW_FORM_URLENCODED)1 CONTENT_TYPE (io.vertx.core.http.HttpHeaders.CONTENT_TYPE)1 HttpMethod (io.vertx.core.http.HttpMethod)1 MultiMap (io.vertx.reactivex.core.MultiMap)1 Buffer (io.vertx.reactivex.core.buffer.Buffer)1