use of com.faforever.api.data.domain.User in project faf-java-api by FAForever.
the class UserServiceTest method resetPasswordByEmail.
@Test
@SuppressWarnings("unchecked")
public void resetPasswordByEmail() {
properties.getPasswordReset().setPasswordResetUrlFormat(PASSWORD_RESET_URL_FORMAT);
User user = createUser(TEST_USERID, TEST_USERNAME, TEST_CURRENT_PASSWORD, TEST_CURRENT_EMAIL);
when(userRepository.findOneByEmailIgnoreCase(TEST_CURRENT_EMAIL)).thenReturn(Optional.of(user));
instance.resetPassword(TEST_CURRENT_EMAIL, TEST_NEW_PASSWORD);
verify(userRepository).findOneByEmailIgnoreCase(TEST_CURRENT_EMAIL);
ArgumentCaptor<String> urlCaptor = ArgumentCaptor.forClass(String.class);
verify(emailService).sendPasswordResetMail(eq(TEST_USERNAME), eq(TEST_CURRENT_EMAIL), urlCaptor.capture());
assertThat(urlCaptor.getValue(), is(String.format(PASSWORD_RESET_URL_FORMAT, TOKEN_VALUE)));
ArgumentCaptor<Map<String, String>> attributesMapCaptor = ArgumentCaptor.forClass(Map.class);
verify(fafTokenService).createToken(eq(FafTokenType.PASSWORD_RESET), any(), attributesMapCaptor.capture());
Map<String, String> tokenAttributes = attributesMapCaptor.getValue();
assertThat(tokenAttributes.size(), is(2));
assertThat(tokenAttributes.get(KEY_USER_ID), is(String.valueOf(TEST_USERID)));
assertThat(tokenAttributes.get(KEY_PASSWORD), is(String.valueOf(TEST_NEW_PASSWORD)));
}
use of com.faforever.api.data.domain.User in project faf-java-api by FAForever.
the class UserServiceTest method resetPasswordByLogin.
@Test
@SuppressWarnings("unchecked")
public void resetPasswordByLogin() {
properties.getPasswordReset().setPasswordResetUrlFormat(PASSWORD_RESET_URL_FORMAT);
User user = createUser(TEST_USERID, TEST_USERNAME, TEST_CURRENT_PASSWORD, TEST_CURRENT_EMAIL);
when(userRepository.findOneByLoginIgnoreCase(TEST_USERNAME)).thenReturn(Optional.of(user));
instance.resetPassword(TEST_USERNAME, TEST_NEW_PASSWORD);
verify(userRepository).findOneByLoginIgnoreCase(TEST_USERNAME);
ArgumentCaptor<String> urlCaptor = ArgumentCaptor.forClass(String.class);
verify(emailService).sendPasswordResetMail(eq(TEST_USERNAME), eq(TEST_CURRENT_EMAIL), urlCaptor.capture());
assertThat(urlCaptor.getValue(), is(String.format(PASSWORD_RESET_URL_FORMAT, TOKEN_VALUE)));
ArgumentCaptor<Map<String, String>> attributesMapCaptor = ArgumentCaptor.forClass(Map.class);
verify(fafTokenService).createToken(eq(FafTokenType.PASSWORD_RESET), any(), attributesMapCaptor.capture());
Map<String, String> tokenAttributes = attributesMapCaptor.getValue();
assertThat(tokenAttributes.size(), is(2));
assertThat(tokenAttributes.get(KEY_USER_ID), is(String.valueOf(TEST_USERID)));
assertThat(tokenAttributes.get(KEY_PASSWORD), is(String.valueOf(TEST_NEW_PASSWORD)));
}
use of com.faforever.api.data.domain.User in project faf-java-api by FAForever.
the class UserServiceTest method changePassword.
@Test
public void changePassword() {
User user = createUser(TEST_USERID, TEST_USERNAME, TEST_CURRENT_PASSWORD, TEST_CURRENT_EMAIL);
instance.changePassword(TEST_CURRENT_PASSWORD, TEST_NEW_PASSWORD, user);
ArgumentCaptor<User> captor = ArgumentCaptor.forClass(User.class);
verify(userRepository).save(captor.capture());
assertEquals(captor.getValue().getPassword(), fafPasswordEncoder.encode(TEST_NEW_PASSWORD));
verify(anopeUserRepository).updatePassword(TEST_USERNAME, Hashing.md5().hashString(TEST_NEW_PASSWORD, StandardCharsets.UTF_8).toString());
verifyZeroInteractions(mauticService);
}
use of com.faforever.api.data.domain.User in project faf-java-api by FAForever.
the class UserServiceTest method changeEmail.
@Test
public void changeEmail() {
User user = createUser(TEST_USERID, TEST_USERNAME, TEST_CURRENT_PASSWORD, TEST_CURRENT_EMAIL);
instance.changeEmail(TEST_CURRENT_PASSWORD, TEST_NEW_EMAIL, user, "127.0.0.1");
verify(emailService).validateEmailAddress(TEST_NEW_EMAIL);
ArgumentCaptor<User> captor = ArgumentCaptor.forClass(User.class);
verify(userRepository).save(captor.capture());
assertEquals(captor.getValue().getEmail(), TEST_NEW_EMAIL);
verify(mauticService).createOrUpdateContact(eq(TEST_NEW_EMAIL), eq(String.valueOf(TEST_USERID)), eq(TEST_USERNAME), eq("127.0.0.1"), any(OffsetDateTime.class));
}
use of com.faforever.api.data.domain.User in project faf-java-api by FAForever.
the class UserServiceTest method changeLoginUsernameReservedBySelf.
@Test
public void changeLoginUsernameReservedBySelf() {
when(nameRecordRepository.getLastUsernameOwnerWithinMonths(any(), anyInt())).thenReturn(Optional.of(TEST_USERID));
User user = createUser(TEST_USERID, TEST_USERNAME, TEST_CURRENT_PASSWORD, TEST_CURRENT_EMAIL);
instance.changeLogin(TEST_USERNAME_CHANGED, user, "127.0.0.1");
verify(mauticService).createOrUpdateContact(eq(TEST_NEW_EMAIL), eq(String.valueOf(TEST_USERID)), eq(TEST_USERNAME_CHANGED), eq("127.0.0.1"), any(OffsetDateTime.class));
}
Aggregations