use of fr.xephi.authme.data.auth.PlayerAuth in project AuthMeReloaded by AuthMe.
the class AsyncChangeEmailTest method shouldRejectInvalidOldEmail.
@Test
public void shouldRejectInvalidOldEmail() {
// given
String newEmail = "new@mail.tld";
given(player.getName()).willReturn("Bobby");
given(playerCache.isAuthenticated("bobby")).willReturn(true);
PlayerAuth auth = authWithMail("other@address.email");
given(playerCache.getAuth("bobby")).willReturn(auth);
given(validationService.validateEmail(newEmail)).willReturn(true);
// 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_OLD_EMAIL);
}
use of fr.xephi.authme.data.auth.PlayerAuth in project AuthMeReloaded by AuthMe.
the class AsyncChangeEmailTest method shouldAddEmail.
@Test
public void shouldAddEmail() {
// 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(true);
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).updatePlayer(auth);
verify(service).send(player, MessageKey.EMAIL_CHANGED_SUCCESS);
}
use of fr.xephi.authme.data.auth.PlayerAuth in project AuthMeReloaded by AuthMe.
the class AsyncChangeEmailTest method authWithMail.
private static PlayerAuth authWithMail(String email) {
PlayerAuth auth = mock(PlayerAuth.class);
when(auth.getEmail()).thenReturn(email);
return auth;
}
use of fr.xephi.authme.data.auth.PlayerAuth in project AuthMeReloaded by AuthMe.
the class PlayerListenerTest method shouldPerformAllJoinVerificationsSuccessfully.
@Test
public void shouldPerformAllJoinVerificationsSuccessfully() throws FailedVerificationException {
// given
String name = "someone";
Player player = mockPlayerWithName(name);
String ip = "12.34.56.78";
PlayerLoginEvent event = spy(new PlayerLoginEvent(player, "", mockAddrWithIp(ip)));
given(validationService.isUnrestricted(name)).willReturn(false);
given(onJoinVerifier.refusePlayerForFullServer(event)).willReturn(false);
PlayerAuth auth = PlayerAuth.builder().name(name).build();
given(dataSource.getAuth(name)).willReturn(auth);
// when
listener.onPlayerLogin(event);
// then
verify(validationService).isUnrestricted(name);
verify(onJoinVerifier).refusePlayerForFullServer(event);
verify(onJoinVerifier).checkSingleSession(name);
verify(onJoinVerifier).checkIsValidName(name);
verify(onJoinVerifier).checkAntibot(player, true);
verify(onJoinVerifier).checkKickNonRegistered(true);
verify(onJoinVerifier).checkNameCasing(player, auth);
verify(onJoinVerifier).checkPlayerCountry(true, ip);
verify(teleportationService).teleportOnJoin(player);
verifyNoModifyingCalls(event);
}
use of fr.xephi.authme.data.auth.PlayerAuth in project AuthMeReloaded by AuthMe.
the class AsyncAddEmailTest method shouldReturnErrorWhenMailCannotBeSaved.
@Test
public void shouldReturnErrorWhenMailCannotBeSaved() {
// given
String email = "my.mail@example.org";
given(player.getName()).willReturn("testEr");
given(playerCache.isAuthenticated("tester")).willReturn(true);
PlayerAuth auth = mock(PlayerAuth.class);
given(auth.getEmail()).willReturn(null);
given(playerCache.getAuth("tester")).willReturn(auth);
given(dataSource.updateEmail(any(PlayerAuth.class))).willReturn(false);
given(validationService.validateEmail(email)).willReturn(true);
given(validationService.isEmailFreeForRegistration(email, player)).willReturn(true);
// when
asyncAddEmail.addEmail(player, email);
// then
verify(dataSource).updateEmail(auth);
verify(service).send(player, MessageKey.ERROR);
}
Aggregations