use of fr.xephi.authme.data.auth.PlayerAuth in project AuthMeReloaded by AuthMe.
the class AsyncChangeEmailTest method shouldRejectAlreadyUsedEmail.
@Test
public void shouldRejectAlreadyUsedEmail() {
// given
String newEmail = "new@example.com";
given(player.getName()).willReturn("Username");
given(playerCache.isAuthenticated("username")).willReturn(true);
PlayerAuth auth = authWithMail("old@example.com");
given(playerCache.getAuth("username")).willReturn(auth);
given(validationService.validateEmail(newEmail)).willReturn(true);
given(validationService.isEmailFreeForRegistration(newEmail, player)).willReturn(false);
// when
process.changeEmail(player, "old@example.com", newEmail);
// then
verify(dataSource, never()).updateEmail(any(PlayerAuth.class));
verify(playerCache, never()).updatePlayer(any(PlayerAuth.class));
verify(service).send(player, MessageKey.EMAIL_ALREADY_USED_ERROR);
}
use of fr.xephi.authme.data.auth.PlayerAuth in project AuthMeReloaded by AuthMe.
the class AsyncChangeEmailTest method shouldShowErrorIfSaveFails.
@Test
public void shouldShowErrorIfSaveFails() {
// given
String newEmail = "new@mail.tld";
given(player.getName()).willReturn("Bobby");
given(playerCache.isAuthenticated("bobby")).willReturn(true);
PlayerAuth auth = authWithMail("old@mail.tld");
given(playerCache.getAuth("bobby")).willReturn(auth);
given(dataSource.updateEmail(auth)).willReturn(false);
given(validationService.validateEmail(newEmail)).willReturn(true);
given(validationService.isEmailFreeForRegistration(newEmail, player)).willReturn(true);
// when
process.changeEmail(player, "old@mail.tld", newEmail);
// then
verify(dataSource).updateEmail(auth);
verify(playerCache, never()).updatePlayer(auth);
verify(service).send(player, MessageKey.ERROR);
}
use of fr.xephi.authme.data.auth.PlayerAuth in project AuthMeReloaded by AuthMe.
the class AsyncChangeEmailTest method shouldShowAddEmailUsage.
@Test
public void shouldShowAddEmailUsage() {
// given
given(player.getName()).willReturn("Bobby");
given(playerCache.isAuthenticated("bobby")).willReturn(true);
PlayerAuth auth = authWithMail(null);
given(playerCache.getAuth("bobby")).willReturn(auth);
// when
process.changeEmail(player, "old@mail.tld", "new@mailt.tld");
// then
verify(dataSource, never()).updateEmail(any(PlayerAuth.class));
verify(playerCache, never()).updatePlayer(any(PlayerAuth.class));
verify(service).send(player, MessageKey.USAGE_ADD_EMAIL);
}
use of fr.xephi.authme.data.auth.PlayerAuth in project AuthMeReloaded by AuthMe.
the class AsyncChangeEmailTest method shouldRejectInvalidNewMail.
@Test
public void shouldRejectInvalidNewMail() {
// given
String newEmail = "bogus";
given(player.getName()).willReturn("Bobby");
given(playerCache.isAuthenticated("bobby")).willReturn(true);
PlayerAuth auth = authWithMail("old@mail.tld");
given(playerCache.getAuth("bobby")).willReturn(auth);
given(validationService.validateEmail(newEmail)).willReturn(false);
// when
process.changeEmail(player, "old@mail.tld", newEmail);
// then
verify(dataSource, never()).updateEmail(any(PlayerAuth.class));
verify(playerCache, never()).updatePlayer(any(PlayerAuth.class));
verify(service).send(player, MessageKey.INVALID_NEW_EMAIL);
}
use of fr.xephi.authme.data.auth.PlayerAuth in project AuthMeReloaded by AuthMe.
the class AbstractDataSourceIntegrationTest method shouldUpdateSession.
@Test
public void shouldUpdateSession() {
// given
DataSource dataSource = getDataSource();
PlayerAuth bobby = PlayerAuth.builder().name("bobby").realName("BOBBY").lastLogin(123L).ip("12.12.12.12").build();
// when
boolean response = dataSource.updateSession(bobby);
// then
assertThat(response, equalTo(true));
PlayerAuth result = dataSource.getAuth("bobby");
assertThat(result, hasAuthBasicData("bobby", "BOBBY", "your@email.com", "12.12.12.12"));
assertThat(result.getLastLogin(), equalTo(123L));
}
Aggregations