use of com.arnaugarcia.uplace.domain.User in project uplace.es by Uplace.
the class UserServiceIntTest method assertThatUserCanResetPassword.
@Test
@Transactional
public void assertThatUserCanResetPassword() {
String oldPassword = user.getPassword();
Instant daysAgo = Instant.now().minus(2, ChronoUnit.HOURS);
String resetKey = RandomUtil.generateResetKey();
user.setActivated(true);
user.setResetDate(daysAgo);
user.setResetKey(resetKey);
userRepository.saveAndFlush(user);
Optional<User> maybeUser = userService.completePasswordReset("johndoe2", user.getResetKey());
assertThat(maybeUser).isPresent();
assertThat(maybeUser.orElse(null).getResetDate()).isNull();
assertThat(maybeUser.orElse(null).getResetKey()).isNull();
assertThat(maybeUser.orElse(null).getPassword()).isNotEqualTo(oldPassword);
userRepository.delete(user);
}
use of com.arnaugarcia.uplace.domain.User in project uplace.es by Uplace.
the class UserServiceIntTest method init.
@Before
public void init() {
user = new User();
user.setLogin("johndoe");
user.setPassword(RandomStringUtils.random(60));
user.setActivated(true);
user.setEmail("johndoe@localhost");
user.setFirstName("john");
user.setLastName("doe");
user.setImageUrl("http://placehold.it/50x50");
user.setLangKey("en");
}
use of com.arnaugarcia.uplace.domain.User in project uplace.es by Uplace.
the class UserServiceIntTest method assertThatResetKeyMustNotBeOlderThan24Hours.
@Test
@Transactional
public void assertThatResetKeyMustNotBeOlderThan24Hours() {
Instant daysAgo = Instant.now().minus(25, ChronoUnit.HOURS);
String resetKey = RandomUtil.generateResetKey();
user.setActivated(true);
user.setResetDate(daysAgo);
user.setResetKey(resetKey);
userRepository.saveAndFlush(user);
Optional<User> maybeUser = userService.completePasswordReset("johndoe2", user.getResetKey());
assertThat(maybeUser).isNotPresent();
userRepository.delete(user);
}
use of com.arnaugarcia.uplace.domain.User in project uplace.es by Uplace.
the class AccountResourceIntTest method testRegisterDuplicateEmail.
@Test
@Transactional
public void testRegisterDuplicateEmail() throws Exception {
// Good
ManagedUserVM validUser = new ManagedUserVM();
validUser.setLogin("john");
validUser.setPassword("password");
validUser.setFirstName("John");
validUser.setLastName("Doe");
validUser.setEmail("john@example.com");
validUser.setActivated(true);
validUser.setImageUrl("http://placehold.it/50x50");
validUser.setLangKey(Constants.DEFAULT_LANGUAGE);
validUser.setAuthorities(Collections.singleton(AuthoritiesConstants.USER));
// Duplicate email, different login
ManagedUserVM duplicatedUser = new ManagedUserVM();
duplicatedUser.setLogin("johnjr");
duplicatedUser.setPassword(validUser.getPassword());
duplicatedUser.setFirstName(validUser.getFirstName());
duplicatedUser.setLastName(validUser.getLastName());
duplicatedUser.setEmail(validUser.getEmail());
duplicatedUser.setActivated(validUser.isActivated());
duplicatedUser.setImageUrl(validUser.getImageUrl());
duplicatedUser.setLangKey(validUser.getLangKey());
duplicatedUser.setCreatedBy(validUser.getCreatedBy());
duplicatedUser.setCreatedDate(validUser.getCreatedDate());
duplicatedUser.setLastModifiedBy(validUser.getLastModifiedBy());
duplicatedUser.setLastModifiedDate(validUser.getLastModifiedDate());
duplicatedUser.setAuthorities(new HashSet<>(validUser.getAuthorities()));
// Good user
restMvc.perform(post("/api/register").contentType(TestUtil.APPLICATION_JSON_UTF8).content(TestUtil.convertObjectToJsonBytes(validUser))).andExpect(status().isCreated());
// Duplicate email
restMvc.perform(post("/api/register").contentType(TestUtil.APPLICATION_JSON_UTF8).content(TestUtil.convertObjectToJsonBytes(duplicatedUser))).andExpect(status().is4xxClientError());
// Duplicate email - with uppercase email address
ManagedUserVM userWithUpperCaseEmail = new ManagedUserVM();
userWithUpperCaseEmail.setId(validUser.getId());
userWithUpperCaseEmail.setLogin("johnjr");
userWithUpperCaseEmail.setPassword(validUser.getPassword());
userWithUpperCaseEmail.setFirstName(validUser.getFirstName());
userWithUpperCaseEmail.setLastName(validUser.getLastName());
userWithUpperCaseEmail.setEmail(validUser.getEmail().toUpperCase());
userWithUpperCaseEmail.setActivated(validUser.isActivated());
userWithUpperCaseEmail.setImageUrl(validUser.getImageUrl());
userWithUpperCaseEmail.setLangKey(validUser.getLangKey());
userWithUpperCaseEmail.setCreatedBy(validUser.getCreatedBy());
userWithUpperCaseEmail.setCreatedDate(validUser.getCreatedDate());
userWithUpperCaseEmail.setLastModifiedBy(validUser.getLastModifiedBy());
userWithUpperCaseEmail.setLastModifiedDate(validUser.getLastModifiedDate());
userWithUpperCaseEmail.setAuthorities(new HashSet<>(validUser.getAuthorities()));
restMvc.perform(post("/api/register").contentType(TestUtil.APPLICATION_JSON_UTF8).content(TestUtil.convertObjectToJsonBytes(userWithUpperCaseEmail))).andExpect(status().is4xxClientError());
Optional<User> userDup = userRepository.findOneByLogin("johnjr");
assertThat(userDup.isPresent()).isFalse();
}
use of com.arnaugarcia.uplace.domain.User in project uplace.es by Uplace.
the class AccountResourceIntTest method testFinishPasswordResetTooSmall.
@Test
@Transactional
public void testFinishPasswordResetTooSmall() throws Exception {
User user = new User();
user.setPassword(RandomStringUtils.random(60));
user.setLogin("finish-password-reset-too-small");
user.setEmail("finish-password-reset-too-small@example.com");
user.setResetDate(Instant.now().plusSeconds(60));
user.setResetKey("reset key too small");
userRepository.saveAndFlush(user);
KeyAndPasswordVM keyAndPassword = new KeyAndPasswordVM();
keyAndPassword.setKey(user.getResetKey());
keyAndPassword.setNewPassword("foo");
restMvc.perform(post("/api/account/reset-password/finish").contentType(TestUtil.APPLICATION_JSON_UTF8).content(TestUtil.convertObjectToJsonBytes(keyAndPassword))).andExpect(status().isBadRequest());
User updatedUser = userRepository.findOneByLogin(user.getLogin()).orElse(null);
assertThat(passwordEncoder.matches(keyAndPassword.getNewPassword(), updatedUser.getPassword())).isFalse();
}
Aggregations