use of com.faforever.api.data.domain.User in project faf-java-api by FAForever.
the class UserServiceTest method linkToSteamAlreadyLinked.
@Test
public void linkToSteamAlreadyLinked() {
when(fafTokenService.resolveToken(FafTokenType.LINK_TO_STEAM, TOKEN_VALUE)).thenReturn(ImmutableMap.of(KEY_USER_ID, "6", KEY_STEAM_LINK_CALLBACK_URL, "callbackUrl"));
when(steamService.ownsForgedAlliance(any())).thenReturn(true);
User otherUser = new User();
otherUser.setLogin("axel12");
when(userRepository.findOneBySteamIdIgnoreCase(STEAM_ID)).thenReturn(Optional.of(otherUser));
User user = createUser(TEST_USERID, TEST_USERNAME, TEST_CURRENT_PASSWORD, TEST_CURRENT_EMAIL);
when(userRepository.findById(6)).thenReturn(Optional.of(user));
SteamLinkResult result = instance.linkToSteam(TOKEN_VALUE, STEAM_ID);
assertThat(result.getCallbackUrl(), is("callbackUrl"));
assertThat(result.getErrors(), hasSize(1));
assertThat(result.getErrors().get(0).getErrorCode(), is(ErrorCode.STEAM_ID_ALREADY_LINKED));
assertThat(result.getErrors().get(0).getArgs(), hasItemInArray(otherUser.getLogin()));
verifyZeroInteractions(mauticService);
}
use of com.faforever.api.data.domain.User in project faf-java-api by FAForever.
the class UserServiceTest method changeLoginWithInvalidUsername.
@Test
public void changeLoginWithInvalidUsername() {
expectedException.expect(ApiExceptionWithCode.apiExceptionWithCode(ErrorCode.USERNAME_INVALID));
User user = createUser(TEST_USERID, TEST_USERNAME, TEST_CURRENT_PASSWORD, TEST_CURRENT_EMAIL);
instance.changeLogin("$%&", user, "127.0.0.1");
}
use of com.faforever.api.data.domain.User in project faf-java-api by FAForever.
the class UserServiceTest method changeEmailInvalidPassword.
@Test
public void changeEmailInvalidPassword() {
expectedException.expect(ApiExceptionWithCode.apiExceptionWithCode(ErrorCode.EMAIL_CHANGE_FAILED_WRONG_PASSWORD));
User user = createUser(TEST_USERID, TEST_USERNAME, "invalid password", TEST_CURRENT_EMAIL);
instance.changeEmail(TEST_CURRENT_PASSWORD, TEST_NEW_PASSWORD, user, "127.0.0.1");
}
use of com.faforever.api.data.domain.User in project faf-java-api by FAForever.
the class UserServiceTest method claimPasswordResetToken.
@Test
public void claimPasswordResetToken() {
when(fafTokenService.resolveToken(FafTokenType.PASSWORD_RESET, TOKEN_VALUE)).thenReturn(ImmutableMap.of(KEY_USER_ID, "5", KEY_PASSWORD, TEST_NEW_PASSWORD));
User user = createUser(TEST_USERID, TEST_USERNAME, TEST_CURRENT_PASSWORD, TEST_CURRENT_EMAIL);
when(userRepository.findById(5)).thenReturn(Optional.of(user));
instance.claimPasswordResetToken(TOKEN_VALUE);
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 linkToSteam.
@Test
public void linkToSteam() {
when(fafTokenService.resolveToken(FafTokenType.LINK_TO_STEAM, TOKEN_VALUE)).thenReturn(ImmutableMap.of(KEY_USER_ID, "5", KEY_STEAM_LINK_CALLBACK_URL, "callbackUrl"));
when(steamService.ownsForgedAlliance(any())).thenReturn(true);
User user = createUser(TEST_USERID, TEST_USERNAME, TEST_CURRENT_PASSWORD, TEST_CURRENT_EMAIL);
when(userRepository.findById(5)).thenReturn(Optional.of(user));
when(userRepository.findOneBySteamIdIgnoreCase(STEAM_ID)).thenReturn(Optional.empty());
SteamLinkResult result = instance.linkToSteam(TOKEN_VALUE, STEAM_ID);
assertThat(result.getCallbackUrl(), is("callbackUrl"));
assertThat(result.getErrors(), is(empty()));
assertThat(user.getSteamId(), is(STEAM_ID));
verifyZeroInteractions(mauticService);
}
Aggregations