use of com.sanctionco.thunder.models.Email in project thunder by RohanNagar.
the class ThunderClientFake method sendVerificationEmail.
@Override
public CompletableFuture<User> sendVerificationEmail(String email, String password) {
// This does not actually send an email, but it does update the verification token of the user.
var user = inMemoryStore.get(email);
if (user == null) {
return fail(404);
}
if (requirePasswordHeader && !user.getPassword().equals(password)) {
return fail(401);
}
var updated = new User(new Email(user.getEmail().getAddress(), user.getEmail().isVerified(), UUID.randomUUID().toString()), user.getPassword(), user.getProperties());
inMemoryStore.put(email, updated);
return CompletableFuture.completedFuture(updated);
}
use of com.sanctionco.thunder.models.Email in project thunder by RohanNagar.
the class ThunderClientFakeTest method ensureVerifyWorksWithResponseType.
@Test
void ensureVerifyWorksWithResponseType() {
var client = ThunderClient.fake();
var user = new User(Email.unverified(ADDRESS), PASSWORD, Collections.emptyMap());
client.postUser(user).join();
var token = client.sendVerificationEmail(ADDRESS, PASSWORD).join().getEmail().getVerificationToken();
assertEquals("Verified", client.verifyUser(ADDRESS, token, ResponseType.HTML).join());
var expectedUserString = new User(new Email(ADDRESS, true, token), PASSWORD, Collections.emptyMap()).toString();
assertEquals(expectedUserString, client.verifyUser(ADDRESS, token, ResponseType.JSON).join());
}
use of com.sanctionco.thunder.models.Email in project thunder by RohanNagar.
the class VerificationResourceTest method email_disabledPasswordHeaderCheckWithNullPasswordSucceeds.
@Test
void email_disabledPasswordHeaderCheckWithNullPasswordSucceeds() {
when(usersDao.findByEmail(anyString())).thenReturn(CompletableFuture.completedFuture(unverifiedMockUser));
when(usersDao.update(anyString(), any(User.class))).thenReturn(CompletableFuture.completedFuture(unverifiedMockUser));
when(emailService.sendVerificationEmail(any(Email.class), anyString())).thenReturn(CompletableFuture.completedFuture(true));
var requestValidator = new RequestValidator(EMAIL_VALIDATOR, propertyValidator, hashService, false);
var resource = new VerificationResource(usersDao, OPTIONS, requestValidator, emailService, METRICS);
var asyncResponse = mock(AsyncResponse.class);
var captor = ArgumentCaptor.forClass(Response.class);
resource.sendEmail(uriInfo, asyncResponse, key, "test@test.com", null);
verify(asyncResponse, timeout(100).times(1)).resume(captor.capture());
User result = (User) captor.getValue().getEntity();
assertAll("Assert successful send email", () -> assertEquals(captor.getValue().getStatusInfo(), Response.Status.OK), () -> assertEquals(unverifiedMockUser, result));
}
use of com.sanctionco.thunder.models.Email in project thunder by RohanNagar.
the class RequestValidatorTest method testValidateNullPassword.
@Test
void testValidateNullPassword() {
var propertyValidator = mock(PropertyValidator.class);
var validator = new RequestValidator(EMAIL_VALIDATOR, propertyValidator, HASH_SERVICE, true);
when(propertyValidator.isValidPropertiesMap(anyMap())).thenReturn(true);
Email email = new Email("test@test.com", false, "token");
User user = new User(email, "password");
RequestValidationException e = assertThrows(RequestValidationException.class, () -> validator.validate(null, "test@test.com", user));
assertEquals("Credentials are required to access this resource.", e.getMessage());
assertEquals(RequestValidationException.Error.INVALID_PARAMETERS, e.getError());
}
use of com.sanctionco.thunder.models.Email in project thunder by RohanNagar.
the class RequestValidatorTest method testValidateSuccess.
@Test
void testValidateSuccess() {
var propertyValidator = mock(PropertyValidator.class);
var validator = new RequestValidator(EMAIL_VALIDATOR, propertyValidator, HASH_SERVICE, true);
when(propertyValidator.isValidPropertiesMap(anyMap())).thenReturn(true);
Email email = new Email("test@test.com", false, "token");
User user = new User(email, "password");
assertDoesNotThrow(() -> validator.validate("password", "test@test.com", user));
}
Aggregations