Search in sources :

Example 16 with User

use of com.faforever.api.data.domain.User in project faf-java-api by FAForever.

the class UsersControllerTest method linkToSteamAlreadyLinkedAccount.

@Test
@WithAnonymousUser
public void linkToSteamAlreadyLinkedAccount() throws Exception {
    String steamId = "1234";
    assertThat(userRepository.getOne(1).getSteamId(), nullValue());
    User userThatOwnsSteamId = userRepository.getOne(2);
    assertThat(userThatOwnsSteamId.getSteamId(), is(steamId));
    String callbackUrl = "http://faforever.com";
    String token = fafTokenService.createToken(FafTokenType.LINK_TO_STEAM, Duration.ofSeconds(100), ImmutableMap.of(UserService.KEY_USER_ID, "1", UserService.KEY_STEAM_LINK_CALLBACK_URL, callbackUrl));
    when(steamService.parseSteamIdFromLoginRedirect(any())).thenReturn(steamId);
    when(steamService.ownsForgedAlliance(anyString())).thenReturn(true);
    mockMvc.perform(get(String.format("/users/linkToSteam?callbackUrl=%s&token=%s&openid.identity=http://steamcommunity.com/openid/id/%s", callbackUrl, token, steamId))).andExpect(status().isFound()).andExpect(redirectedUrlPattern(callbackUrl + "?errors=*" + ErrorCode.STEAM_ID_ALREADY_LINKED.getCode() + "*" + userThatOwnsSteamId.getLogin() + "*"));
    // We expect and error with code STEAM_ID_ALREADY_LINKED and that the error message contains the user that this steam account was linked to already which is MODERATOR with id 2
    assertThat(userRepository.getOne(1).getSteamId(), nullValue());
}
Also used : User(com.faforever.api.data.domain.User) WithAnonymousUser(org.springframework.security.test.context.support.WithAnonymousUser) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) WithAnonymousUser(org.springframework.security.test.context.support.WithAnonymousUser) AbstractIntegrationTest(com.faforever.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 17 with User

use of com.faforever.api.data.domain.User in project faf-java-api by FAForever.

the class UserServiceTest method linkToSteamNoGame.

@Test
public void linkToSteamNoGame() {
    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(false);
    when(userRepository.findOneBySteamIdIgnoreCase(STEAM_ID)).thenReturn(Optional.empty());
    User user = createUser(TEST_USERID, TEST_USERNAME, TEST_CURRENT_PASSWORD, TEST_CURRENT_EMAIL);
    when(userRepository.findById(5)).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_LINK_NO_FA_GAME));
    assertThat(result.getErrors().get(0).getArgs(), is(new Object[0]));
    verifyZeroInteractions(mauticService);
}
Also used : User(com.faforever.api.data.domain.User) SteamLinkResult(com.faforever.api.user.UserService.SteamLinkResult) Test(org.junit.Test)

Example 18 with User

use of com.faforever.api.data.domain.User in project faf-java-api by FAForever.

the class UsersControllerTest method changeEmailWithSuccess.

@Test
@WithUserDetails(AUTH_USER)
public void changeEmailWithSuccess() throws Exception {
    MultiValueMap<String, String> params = new HttpHeaders();
    params.add("currentPassword", AUTH_USER);
    params.add("newEmail", NEW_EMAIL);
    mockMvc.perform(post("/users/changeEmail").with(getOAuthToken(OAuthScope._WRITE_ACCOUNT_DATA)).params(params)).andExpect(status().isOk());
    User user = userRepository.findOneByLoginIgnoreCase(AUTH_USER).get();
    assertEquals(user.getEmail(), NEW_EMAIL);
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) User(com.faforever.api.data.domain.User) WithAnonymousUser(org.springframework.security.test.context.support.WithAnonymousUser) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) AbstractIntegrationTest(com.faforever.api.AbstractIntegrationTest) Test(org.junit.Test) WithUserDetails(org.springframework.security.test.context.support.WithUserDetails)

Example 19 with User

use of com.faforever.api.data.domain.User in project faf-java-api by FAForever.

the class UsersControllerTest method changePasswordWithSuccess.

@Test
@WithUserDetails(AUTH_USER)
public void changePasswordWithSuccess() throws Exception {
    MultiValueMap<String, String> params = new HttpHeaders();
    params.add("currentPassword", AUTH_USER);
    params.add("newPassword", NEW_PASSWORD);
    mockMvc.perform(post("/users/changePassword").with(getOAuthToken(OAuthScope._WRITE_ACCOUNT_DATA)).params(params)).andExpect(status().isOk());
    User user = userRepository.findOneByLoginIgnoreCase(AUTH_USER).get();
    assertEquals(user.getPassword(), "5c29a959abce4eda5f0e7a4e7ea53dce4fa0f0abbe8eaa63717e2fed5f193d31");
    verify(anopeUserRepository, times(1)).updatePassword(eq(AUTH_USER), anyString());
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) User(com.faforever.api.data.domain.User) WithAnonymousUser(org.springframework.security.test.context.support.WithAnonymousUser) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) AbstractIntegrationTest(com.faforever.api.AbstractIntegrationTest) Test(org.junit.Test) WithUserDetails(org.springframework.security.test.context.support.WithUserDetails)

Example 20 with User

use of com.faforever.api.data.domain.User in project faf-java-api by FAForever.

the class UserServiceTest method changeLoginUsernameReserved.

@Test
public void changeLoginUsernameReserved() {
    expectedException.expect(ApiExceptionWithCode.apiExceptionWithCode(ErrorCode.USERNAME_RESERVED));
    when(nameRecordRepository.getLastUsernameOwnerWithinMonths(any(), anyInt())).thenReturn(Optional.of(TEST_USERID + 1));
    User user = createUser(TEST_USERID, TEST_USERNAME, TEST_CURRENT_PASSWORD, TEST_CURRENT_EMAIL);
    instance.changeLogin(TEST_USERNAME_CHANGED, user, "127.0.0.1");
}
Also used : User(com.faforever.api.data.domain.User) 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