Search in sources :

Example 1 with User

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);
}
Also used : User(com.faforever.api.data.domain.User) SteamLinkResult(com.faforever.api.user.UserService.SteamLinkResult) Test(org.junit.Test)

Example 2 with User

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");
}
Also used : User(com.faforever.api.data.domain.User) Test(org.junit.Test)

Example 3 with User

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");
}
Also used : User(com.faforever.api.data.domain.User) Test(org.junit.Test)

Example 4 with User

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);
}
Also used : User(com.faforever.api.data.domain.User) Test(org.junit.Test)

Example 5 with User

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);
}
Also used : User(com.faforever.api.data.domain.User) SteamLinkResult(com.faforever.api.user.UserService.SteamLinkResult) Test(org.junit.Test)

Aggregations

User (com.faforever.api.data.domain.User)28 Test (org.junit.Test)22 OffsetDateTime (java.time.OffsetDateTime)4 AbstractIntegrationTest (com.faforever.api.AbstractIntegrationTest)3 ApiException (com.faforever.api.error.ApiException)3 Error (com.faforever.api.error.Error)3 SteamLinkResult (com.faforever.api.user.UserService.SteamLinkResult)3 ImmutableMap (com.google.common.collect.ImmutableMap)3 Map (java.util.Map)3 SneakyThrows (lombok.SneakyThrows)3 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)3 WithAnonymousUser (org.springframework.security.test.context.support.WithAnonymousUser)3 GlobalRating (com.faforever.api.data.domain.GlobalRating)2 Ladder1v1Rating (com.faforever.api.data.domain.Ladder1v1Rating)2 ArrayList (java.util.ArrayList)2 HttpHeaders (org.springframework.http.HttpHeaders)2 WithUserDetails (org.springframework.security.test.context.support.WithUserDetails)2 FafApiProperties (com.faforever.api.config.FafApiProperties)1 NameRecord (com.faforever.api.data.domain.NameRecord)1 Before (org.junit.Before)1