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