Search in sources :

Example 36 with PlayerAuth

use of fr.xephi.authme.data.auth.PlayerAuth in project AuthMeReloaded by AuthMe.

the class AsynchronousUnregisterTest method shouldPerformUnregister.

@Test
public void shouldPerformUnregister() {
    // given
    Player player = mock(Player.class);
    String name = "Frank21";
    given(player.getName()).willReturn(name);
    given(player.isOnline()).willReturn(true);
    PlayerAuth auth = mock(PlayerAuth.class);
    given(playerCache.getAuth(name)).willReturn(auth);
    HashedPassword password = new HashedPassword("password", "in_auth_obj");
    given(auth.getPassword()).willReturn(password);
    String userPassword = "pass";
    given(passwordSecurity.comparePassword(userPassword, password, name)).willReturn(true);
    given(dataSource.removeAuth(name)).willReturn(true);
    given(service.getProperty(RegistrationSettings.FORCE)).willReturn(true);
    // when
    asynchronousUnregister.unregister(player, userPassword);
    // then
    verify(service).send(player, MessageKey.UNREGISTERED_SUCCESS);
    verify(passwordSecurity).comparePassword(userPassword, password, name);
    verify(dataSource).removeAuth(name);
    verify(playerCache).removePlayer(name);
    verify(teleportationService).teleportOnJoin(player);
    verify(bukkitService).scheduleSyncTaskFromOptionallyAsyncTask(any(Runnable.class));
    verifyCalledUnregisterEventFor(player);
    verify(commandManager).runCommandsOnUnregister(player);
}
Also used : Player(org.bukkit.entity.Player) PlayerAuth(fr.xephi.authme.data.auth.PlayerAuth) HashedPassword(fr.xephi.authme.security.crypts.HashedPassword) Test(org.junit.Test)

Example 37 with PlayerAuth

use of fr.xephi.authme.data.auth.PlayerAuth in project AuthMeReloaded by AuthMe.

the class AsynchronousUnregisterTest method shouldPerformUnregisterAndNotApplyBlindEffect.

@Test
public void shouldPerformUnregisterAndNotApplyBlindEffect() {
    // given
    Player player = mock(Player.class);
    String name = "Frank21";
    given(player.getName()).willReturn(name);
    given(player.isOnline()).willReturn(true);
    PlayerAuth auth = mock(PlayerAuth.class);
    given(playerCache.getAuth(name)).willReturn(auth);
    HashedPassword password = new HashedPassword("password", "in_auth_obj");
    given(auth.getPassword()).willReturn(password);
    String userPassword = "pass";
    given(passwordSecurity.comparePassword(userPassword, password, name)).willReturn(true);
    given(dataSource.removeAuth(name)).willReturn(true);
    given(service.getProperty(RegistrationSettings.FORCE)).willReturn(true);
    // when
    asynchronousUnregister.unregister(player, userPassword);
    // then
    verify(service).send(player, MessageKey.UNREGISTERED_SUCCESS);
    verify(passwordSecurity).comparePassword(userPassword, password, name);
    verify(dataSource).removeAuth(name);
    verify(playerCache).removePlayer(name);
    verify(teleportationService).teleportOnJoin(player);
    verify(bukkitService).scheduleSyncTaskFromOptionallyAsyncTask(any(Runnable.class));
    verifyCalledUnregisterEventFor(player);
    verify(commandManager).runCommandsOnUnregister(player);
}
Also used : Player(org.bukkit.entity.Player) PlayerAuth(fr.xephi.authme.data.auth.PlayerAuth) HashedPassword(fr.xephi.authme.security.crypts.HashedPassword) Test(org.junit.Test)

Example 38 with PlayerAuth

use of fr.xephi.authme.data.auth.PlayerAuth in project AuthMeReloaded by AuthMe.

the class AsynchronousUnregisterTest method shouldRejectWrongPassword.

@Test
public void shouldRejectWrongPassword() {
    // given
    Player player = mock(Player.class);
    String name = "Bobby";
    given(player.getName()).willReturn(name);
    PlayerAuth auth = mock(PlayerAuth.class);
    given(playerCache.getAuth(name)).willReturn(auth);
    HashedPassword password = new HashedPassword("password", "in_auth_obj");
    given(auth.getPassword()).willReturn(password);
    String userPassword = "pass";
    given(passwordSecurity.comparePassword(userPassword, password, name)).willReturn(false);
    // when
    asynchronousUnregister.unregister(player, userPassword);
    // then
    verify(service).send(player, MessageKey.WRONG_PASSWORD);
    verify(passwordSecurity).comparePassword(userPassword, password, name);
    verifyZeroInteractions(dataSource, limboService, teleportationService, bukkitService);
    verify(player, only()).getName();
}
Also used : Player(org.bukkit.entity.Player) PlayerAuth(fr.xephi.authme.data.auth.PlayerAuth) HashedPassword(fr.xephi.authme.security.crypts.HashedPassword) Test(org.junit.Test)

Example 39 with PlayerAuth

use of fr.xephi.authme.data.auth.PlayerAuth in project AuthMeReloaded by AuthMe.

the class AsyncAddEmailTest method shouldAddEmail.

@Test
public void shouldAddEmail() {
    // 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(true);
    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.EMAIL_ADDED_SUCCESS);
    verify(auth).setEmail(email);
    verify(playerCache).updatePlayer(auth);
}
Also used : PlayerAuth(fr.xephi.authme.data.auth.PlayerAuth) Test(org.junit.Test)

Example 40 with PlayerAuth

use of fr.xephi.authme.data.auth.PlayerAuth in project AuthMeReloaded by AuthMe.

the class AsyncAddEmailTest method shouldNotAddMailIfItIsInvalid.

@Test
public void shouldNotAddMailIfItIsInvalid() {
    // given
    String email = "invalid_mail";
    given(player.getName()).willReturn("my_Player");
    given(playerCache.isAuthenticated("my_player")).willReturn(true);
    PlayerAuth auth = mock(PlayerAuth.class);
    given(auth.getEmail()).willReturn(null);
    given(playerCache.getAuth("my_player")).willReturn(auth);
    given(validationService.validateEmail(email)).willReturn(false);
    // when
    asyncAddEmail.addEmail(player, email);
    // then
    verify(service).send(player, MessageKey.INVALID_EMAIL);
    verify(playerCache, never()).updatePlayer(any(PlayerAuth.class));
}
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