Search in sources :

Example 6 with User

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

the class UserServiceTest method resetPasswordByEmail.

@Test
@SuppressWarnings("unchecked")
public void resetPasswordByEmail() {
    properties.getPasswordReset().setPasswordResetUrlFormat(PASSWORD_RESET_URL_FORMAT);
    User user = createUser(TEST_USERID, TEST_USERNAME, TEST_CURRENT_PASSWORD, TEST_CURRENT_EMAIL);
    when(userRepository.findOneByEmailIgnoreCase(TEST_CURRENT_EMAIL)).thenReturn(Optional.of(user));
    instance.resetPassword(TEST_CURRENT_EMAIL, TEST_NEW_PASSWORD);
    verify(userRepository).findOneByEmailIgnoreCase(TEST_CURRENT_EMAIL);
    ArgumentCaptor<String> urlCaptor = ArgumentCaptor.forClass(String.class);
    verify(emailService).sendPasswordResetMail(eq(TEST_USERNAME), eq(TEST_CURRENT_EMAIL), urlCaptor.capture());
    assertThat(urlCaptor.getValue(), is(String.format(PASSWORD_RESET_URL_FORMAT, TOKEN_VALUE)));
    ArgumentCaptor<Map<String, String>> attributesMapCaptor = ArgumentCaptor.forClass(Map.class);
    verify(fafTokenService).createToken(eq(FafTokenType.PASSWORD_RESET), any(), attributesMapCaptor.capture());
    Map<String, String> tokenAttributes = attributesMapCaptor.getValue();
    assertThat(tokenAttributes.size(), is(2));
    assertThat(tokenAttributes.get(KEY_USER_ID), is(String.valueOf(TEST_USERID)));
    assertThat(tokenAttributes.get(KEY_PASSWORD), is(String.valueOf(TEST_NEW_PASSWORD)));
}
Also used : User(com.faforever.api.data.domain.User) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) Test(org.junit.Test)

Example 7 with User

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

the class UserServiceTest method resetPasswordByLogin.

@Test
@SuppressWarnings("unchecked")
public void resetPasswordByLogin() {
    properties.getPasswordReset().setPasswordResetUrlFormat(PASSWORD_RESET_URL_FORMAT);
    User user = createUser(TEST_USERID, TEST_USERNAME, TEST_CURRENT_PASSWORD, TEST_CURRENT_EMAIL);
    when(userRepository.findOneByLoginIgnoreCase(TEST_USERNAME)).thenReturn(Optional.of(user));
    instance.resetPassword(TEST_USERNAME, TEST_NEW_PASSWORD);
    verify(userRepository).findOneByLoginIgnoreCase(TEST_USERNAME);
    ArgumentCaptor<String> urlCaptor = ArgumentCaptor.forClass(String.class);
    verify(emailService).sendPasswordResetMail(eq(TEST_USERNAME), eq(TEST_CURRENT_EMAIL), urlCaptor.capture());
    assertThat(urlCaptor.getValue(), is(String.format(PASSWORD_RESET_URL_FORMAT, TOKEN_VALUE)));
    ArgumentCaptor<Map<String, String>> attributesMapCaptor = ArgumentCaptor.forClass(Map.class);
    verify(fafTokenService).createToken(eq(FafTokenType.PASSWORD_RESET), any(), attributesMapCaptor.capture());
    Map<String, String> tokenAttributes = attributesMapCaptor.getValue();
    assertThat(tokenAttributes.size(), is(2));
    assertThat(tokenAttributes.get(KEY_USER_ID), is(String.valueOf(TEST_USERID)));
    assertThat(tokenAttributes.get(KEY_PASSWORD), is(String.valueOf(TEST_NEW_PASSWORD)));
}
Also used : User(com.faforever.api.data.domain.User) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) Test(org.junit.Test)

Example 8 with User

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

the class UserServiceTest method changePassword.

@Test
public void changePassword() {
    User user = createUser(TEST_USERID, TEST_USERNAME, TEST_CURRENT_PASSWORD, TEST_CURRENT_EMAIL);
    instance.changePassword(TEST_CURRENT_PASSWORD, TEST_NEW_PASSWORD, user);
    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 9 with User

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

the class UserServiceTest method changeEmail.

@Test
public void changeEmail() {
    User user = createUser(TEST_USERID, TEST_USERNAME, TEST_CURRENT_PASSWORD, TEST_CURRENT_EMAIL);
    instance.changeEmail(TEST_CURRENT_PASSWORD, TEST_NEW_EMAIL, user, "127.0.0.1");
    verify(emailService).validateEmailAddress(TEST_NEW_EMAIL);
    ArgumentCaptor<User> captor = ArgumentCaptor.forClass(User.class);
    verify(userRepository).save(captor.capture());
    assertEquals(captor.getValue().getEmail(), TEST_NEW_EMAIL);
    verify(mauticService).createOrUpdateContact(eq(TEST_NEW_EMAIL), eq(String.valueOf(TEST_USERID)), eq(TEST_USERNAME), eq("127.0.0.1"), any(OffsetDateTime.class));
}
Also used : User(com.faforever.api.data.domain.User) OffsetDateTime(java.time.OffsetDateTime) Test(org.junit.Test)

Example 10 with User

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

the class UserServiceTest method changeLoginUsernameReservedBySelf.

@Test
public void changeLoginUsernameReservedBySelf() {
    when(nameRecordRepository.getLastUsernameOwnerWithinMonths(any(), anyInt())).thenReturn(Optional.of(TEST_USERID));
    User user = createUser(TEST_USERID, TEST_USERNAME, TEST_CURRENT_PASSWORD, TEST_CURRENT_EMAIL);
    instance.changeLogin(TEST_USERNAME_CHANGED, user, "127.0.0.1");
    verify(mauticService).createOrUpdateContact(eq(TEST_NEW_EMAIL), eq(String.valueOf(TEST_USERID)), eq(TEST_USERNAME_CHANGED), eq("127.0.0.1"), any(OffsetDateTime.class));
}
Also used : User(com.faforever.api.data.domain.User) OffsetDateTime(java.time.OffsetDateTime) 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