Search in sources :

Example 1 with SteamLinkResult

use of com.faforever.api.user.UserService.SteamLinkResult 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 SteamLinkResult

use of com.faforever.api.user.UserService.SteamLinkResult 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)

Example 3 with SteamLinkResult

use of com.faforever.api.user.UserService.SteamLinkResult 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 4 with SteamLinkResult

use of com.faforever.api.user.UserService.SteamLinkResult in project faf-java-api by FAForever.

the class UsersController method linkToSteam.

@ApiOperation("Processes the Steam redirect and creates the steam link in the user account.")
@RequestMapping(path = "/linkToSteam", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
public void linkToSteam(HttpServletRequest request, HttpServletResponse response, @RequestParam("token") String token) throws IOException {
    SteamLinkResult result = userService.linkToSteam(token, steamService.parseSteamIdFromLoginRedirect(request));
    if (!result.getErrors().isEmpty()) {
        UriComponentsBuilder uriBuilder = UriComponentsBuilder.fromHttpUrl(result.getCallbackUrl());
        String errorsJson = objectMapper.writeValueAsString(result.getErrors());
        uriBuilder.queryParam("errors", errorsJson);
        response.sendRedirect(uriBuilder.toUriString());
        return;
    }
    response.sendRedirect(result.getCallbackUrl());
}
Also used : SteamLinkResult(com.faforever.api.user.UserService.SteamLinkResult) UriComponentsBuilder(org.springframework.web.util.UriComponentsBuilder) ApiOperation(io.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

SteamLinkResult (com.faforever.api.user.UserService.SteamLinkResult)4 User (com.faforever.api.data.domain.User)3 Test (org.junit.Test)3 ApiOperation (io.swagger.annotations.ApiOperation)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1 UriComponentsBuilder (org.springframework.web.util.UriComponentsBuilder)1