Search in sources :

Example 76 with PlayerAuth

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);
}
Also used : PlayerAuth(fr.xephi.authme.data.auth.PlayerAuth) Test(org.junit.Test)

Example 77 with PlayerAuth

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);
}
Also used : PlayerAuth(fr.xephi.authme.data.auth.PlayerAuth) Test(org.junit.Test)

Example 78 with PlayerAuth

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;
}
Also used : PlayerAuth(fr.xephi.authme.data.auth.PlayerAuth)

Example 79 with PlayerAuth

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);
}
Also used : Player(org.bukkit.entity.Player) PlayerLoginEvent(org.bukkit.event.player.PlayerLoginEvent) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) PlayerAuth(fr.xephi.authme.data.auth.PlayerAuth) Test(org.junit.Test)

Example 80 with PlayerAuth

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);
}
Also used : PlayerAuth(fr.xephi.authme.data.auth.PlayerAuth) Test(org.junit.Test)

Aggregations

PlayerAuth (fr.xephi.authme.data.auth.PlayerAuth)102 Test (org.junit.Test)65 Player (org.bukkit.entity.Player)33 HashedPassword (fr.xephi.authme.security.crypts.HashedPassword)21 CommandSender (org.bukkit.command.CommandSender)16 Location (org.bukkit.Location)14 LimboPlayer (fr.xephi.authme.data.limbo.LimboPlayer)9 IOException (java.io.IOException)7 World (org.bukkit.World)7 BufferedReader (java.io.BufferedReader)6 FileReader (java.io.FileReader)6 ArrayList (java.util.ArrayList)5 ValidationResult (fr.xephi.authme.service.ValidationService.ValidationResult)4 Connection (java.sql.Connection)4 Matchers.containsString (org.hamcrest.Matchers.containsString)4 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)4 AuthMeMatchers.hasAuthLocation (fr.xephi.authme.AuthMeMatchers.hasAuthLocation)3 File (java.io.File)3 PreparedStatement (java.sql.PreparedStatement)3 ResultSet (java.sql.ResultSet)3