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());
}
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);
}
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);
}
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());
}
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");
}
Aggregations