Search in sources :

Example 26 with Email

use of com.sanctionco.thunder.models.Email in project thunder by RohanNagar.

the class RequestValidatorTest method testValidatePasswordAndEmailDisabledHeaderCheck.

/* Disable header check */
@Test
void testValidatePasswordAndEmailDisabledHeaderCheck() {
    var propertyValidator = mock(PropertyValidator.class);
    var validator = new RequestValidator(EMAIL_VALIDATOR, propertyValidator, HASH_SERVICE, false);
    when(propertyValidator.isValidPropertiesMap(anyMap())).thenReturn(true);
    Email email = new Email("test@test.com", false, "token");
    User user = new User(email, "password");
    assertDoesNotThrow(() -> validator.validate(null, "test@test.com", false));
    assertDoesNotThrow(() -> validator.validate("", "test@test.com", false));
    assertDoesNotThrow(() -> validator.validate(null, "test@test.com", user));
    assertDoesNotThrow(() -> validator.validate("", "test@test.com", user));
}
Also used : Email(com.sanctionco.thunder.models.Email) User(com.sanctionco.thunder.models.User) Test(org.junit.jupiter.api.Test)

Example 27 with Email

use of com.sanctionco.thunder.models.Email in project thunder by RohanNagar.

the class ThunderClientFakeTest method ensureFakeClientPersists.

@Test
void ensureFakeClientPersists() {
    var client = ThunderClient.fake();
    var user = new User(Email.unverified(ADDRESS), PASSWORD, Collections.emptyMap());
    assertEquals(user, client.postUser(user).join());
    assertEquals(user, client.getUser(ADDRESS, PASSWORD).join());
    var userWithNewProperties = new User(new Email(user.getEmail().getAddress(), user.getEmail().isVerified(), user.getEmail().getVerificationToken()), user.getPassword(), Collections.singletonMap("prop1", "val1"));
    assertEquals(userWithNewProperties, client.updateUser(userWithNewProperties, PASSWORD).join());
    assertEquals(userWithNewProperties, client.getUser(ADDRESS, PASSWORD).join());
    // Assert correct initial verification state
    assertNull(client.getUser(ADDRESS, PASSWORD).join().getEmail().getVerificationToken());
    assertFalse(client.getUser(ADDRESS, PASSWORD).join().getEmail().isVerified());
    // Send email to set token
    assertNotNull(client.sendVerificationEmail(ADDRESS, PASSWORD).join().getEmail().getVerificationToken());
    var userWithToken = client.getUser(ADDRESS, PASSWORD).join();
    assertNotNull(userWithToken.getEmail().getVerificationToken());
    assertFalse(userWithToken.getEmail().isVerified());
    // Verify user
    assertTrue(client.verifyUser(ADDRESS, userWithToken.getEmail().getVerificationToken()).join().getEmail().isVerified());
    var verifiedUser = client.getUser(ADDRESS, PASSWORD).join();
    assertEquals(userWithToken.getEmail().getVerificationToken(), verifiedUser.getEmail().getVerificationToken());
    assertTrue(verifiedUser.getEmail().isVerified());
    // Reset verification
    assertFalse(client.resetVerificationStatus(ADDRESS, PASSWORD).join().getEmail().isVerified());
    var resetUser = client.getUser(ADDRESS, PASSWORD).join();
    assertNull(resetUser.getEmail().getVerificationToken());
    assertFalse(resetUser.getEmail().isVerified());
    assertEquals(resetUser, client.deleteUser(ADDRESS, PASSWORD).join());
    assertFailure(() -> client.getUser(ADDRESS, PASSWORD).get(), 404);
}
Also used : User(com.sanctionco.thunder.models.User) Email(com.sanctionco.thunder.models.Email) Test(org.junit.jupiter.api.Test)

Aggregations

Email (com.sanctionco.thunder.models.Email)27 User (com.sanctionco.thunder.models.User)26 Test (org.junit.jupiter.api.Test)20 RequestValidator (com.sanctionco.thunder.validation.RequestValidator)9 MetricRegistry (com.codahale.metrics.MetricRegistry)5 Metered (com.codahale.metrics.annotation.Metered)5 RequestValidationException (com.sanctionco.thunder.validation.RequestValidationException)5 Objects (java.util.Objects)5 Inject (javax.inject.Inject)5 POST (javax.ws.rs.POST)5 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)5 Logger (org.slf4j.Logger)5 LoggerFactory (org.slf4j.LoggerFactory)5 Counter (com.codahale.metrics.Counter)4 ThunderException (com.sanctionco.thunder.ThunderException)4 UsersDao (com.sanctionco.thunder.dao.UsersDao)4 EmailService (com.sanctionco.thunder.email.EmailService)4 SwaggerAnnotations (com.sanctionco.thunder.openapi.SwaggerAnnotations)4 MetricNameUtil (com.sanctionco.thunder.util.MetricNameUtil)4 Auth (io.dropwizard.auth.Auth)4