Search in sources :

Example 16 with PlayerAuth

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

the class PasswordRegisterExecutorTest method shouldCreatePlayerAuth.

@Test
public void shouldCreatePlayerAuth() {
    // given
    given(passwordSecurity.computeHash(anyString(), anyString())).willAnswer(invocation -> new HashedPassword(invocation.getArgument(0)));
    Player player = mockPlayerWithName("S1m0N");
    TestHelper.mockPlayerIp(player, "123.45.67.89");
    World world = mock(World.class);
    given(world.getName()).willReturn("someWorld");
    given(player.getLocation()).willReturn(new Location(world, 48, 96, 144, 1.1f, 0.28f));
    PasswordRegisterParams params = PasswordRegisterParams.of(player, "pass", "mail@example.org");
    // when
    PlayerAuth auth = executor.buildPlayerAuth(params);
    // then
    assertThat(auth, hasAuthBasicData("s1m0n", "S1m0N", "mail@example.org", "123.45.67.89"));
    assertThat(auth, hasAuthLocation(48, 96, 144, "someWorld", 1.1f, 0.28f));
    assertThat(auth.getPassword(), equalToHash("pass"));
}
Also used : Player(org.bukkit.entity.Player) World(org.bukkit.World) PlayerAuth(fr.xephi.authme.data.auth.PlayerAuth) HashedPassword(fr.xephi.authme.security.crypts.HashedPassword) AuthMeMatchers.hasAuthLocation(fr.xephi.authme.AuthMeMatchers.hasAuthLocation) Location(org.bukkit.Location) Test(org.junit.Test)

Example 17 with PlayerAuth

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

the class PlayerAuthBuilderHelperTest method shouldConstructPlayerAuth.

@Test
public void shouldConstructPlayerAuth() {
    // given
    Player player = mock(Player.class);
    given(player.getName()).willReturn("Noah");
    String ip = "192.168.34.47";
    TestHelper.mockPlayerIp(player, ip);
    World world = mock(World.class);
    given(world.getName()).willReturn("worldName");
    Location location = new Location(world, 123, 80, -99, 2.45f, 7.61f);
    given(player.getLocation()).willReturn(location);
    HashedPassword hashedPassword = new HashedPassword("myHash0001");
    String email = "test@example.org";
    // when
    PlayerAuth auth = PlayerAuthBuilderHelper.createPlayerAuth(player, hashedPassword, email);
    // then
    assertThat(auth, hasAuthBasicData("noah", "Noah", email, ip));
    assertThat(auth, hasAuthLocation(123, 80, -99, "worldName", 2.45f, 7.61f));
}
Also used : Player(org.bukkit.entity.Player) World(org.bukkit.World) PlayerAuth(fr.xephi.authme.data.auth.PlayerAuth) HashedPassword(fr.xephi.authme.security.crypts.HashedPassword) Location(org.bukkit.Location) AuthMeMatchers.hasAuthLocation(fr.xephi.authme.AuthMeMatchers.hasAuthLocation) Test(org.junit.Test)

Example 18 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 19 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 20 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)

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