Search in sources :

Example 96 with PlayerAuth

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

the class AsynchronousUnregisterTest method shouldNotTeleportOfflinePlayer.

@Test
public void shouldNotTeleportOfflinePlayer() {
    // given
    Player player = mock(Player.class);
    String name = "Frank21";
    given(player.getName()).willReturn(name);
    given(player.isOnline()).willReturn(false);
    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);
    // when
    asynchronousUnregister.unregister(player, userPassword);
    // then
    verify(passwordSecurity).comparePassword(userPassword, password, name);
    verify(dataSource).removeAuth(name);
    verify(playerCache).removePlayer(name);
    verifyZeroInteractions(teleportationService);
    verifyCalledUnregisterEventFor(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 97 with PlayerAuth

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

the class AsynchronousUnregisterTest method shouldNotApplyUnregisteredEffectsForNotForcedRegistration.

@Test
public void shouldNotApplyUnregisteredEffectsForNotForcedRegistration() {
    // given
    Player player = mock(Player.class);
    String name = "__FranK";
    given(player.getName()).willReturn(name);
    given(player.isOnline()).willReturn(true);
    String userPassword = "141$$5ad";
    HashedPassword password = new HashedPassword("ttt123");
    PlayerAuth auth = PlayerAuth.builder().name(name).password(password).build();
    given(playerCache.getAuth(name)).willReturn(auth);
    given(passwordSecurity.comparePassword(userPassword, password, name)).willReturn(true);
    given(dataSource.removeAuth(name)).willReturn(true);
    given(service.getProperty(RegistrationSettings.FORCE)).willReturn(false);
    // 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);
    verifyZeroInteractions(teleportationService, limboService);
    verify(bukkitService, never()).runTask(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 98 with PlayerAuth

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

the class TeleportationServiceTest method shouldTeleportAccordingToPlayerAuthAndPlayerWorldAsFallback.

@Test
public void shouldTeleportAccordingToPlayerAuthAndPlayerWorldAsFallback() {
    // given
    given(settings.getProperty(RestrictionSettings.TELEPORT_UNAUTHED_TO_SPAWN)).willReturn(true);
    given(settings.getProperty(RestrictionSettings.SAVE_QUIT_LOCATION)).willReturn(true);
    PlayerAuth auth = createAuthWithLocation();
    auth.setWorld("myWorld");
    given(bukkitService.getWorld("myWorld")).willReturn(null);
    Player player = mock(Player.class);
    given(player.isOnline()).willReturn(true);
    World world = mock(World.class);
    given(player.getWorld()).willReturn(world);
    LimboPlayer limbo = mock(LimboPlayer.class);
    Location limboLocation = mockLocation();
    given(limbo.getLocation()).willReturn(limboLocation);
    // when
    teleportationService.teleportOnLogin(player, auth, limbo);
    runSyncDelayedTask(bukkitService);
    // then
    ArgumentCaptor<Location> locationCaptor = ArgumentCaptor.forClass(Location.class);
    verify(player).teleport(locationCaptor.capture());
    assertCorrectLocation(locationCaptor.getValue(), auth, world);
}
Also used : Player(org.bukkit.entity.Player) LimboPlayer(fr.xephi.authme.data.limbo.LimboPlayer) PlayerAuth(fr.xephi.authme.data.auth.PlayerAuth) World(org.bukkit.World) LimboPlayer(fr.xephi.authme.data.limbo.LimboPlayer) Location(org.bukkit.Location) Test(org.junit.Test)

Example 99 with PlayerAuth

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

the class TeleportationServiceTest method shouldNotTeleportToSpawnForOtherCaseInWorld.

@Test
public // Check that the worlds for "force spawn loc after login" are case-sensitive
void shouldNotTeleportToSpawnForOtherCaseInWorld() {
    // given
    given(settings.getProperty(RestrictionSettings.FORCE_SPAWN_LOCATION_AFTER_LOGIN)).willReturn(true);
    given(settings.getProperty(RestrictionSettings.TELEPORT_UNAUTHED_TO_SPAWN)).willReturn(false);
    Player player = mock(Player.class);
    Location spawn = mockLocation();
    PlayerAuth auth = mock(PlayerAuth.class);
    LimboPlayer limbo = mock(LimboPlayer.class);
    Location limboLocation = mockLocation();
    // different case
    given(limboLocation.getWorld().getName()).willReturn("Forced1");
    given(limbo.getLocation()).willReturn(limboLocation);
    // when
    teleportationService.teleportOnLogin(player, auth, limbo);
    // then
    verify(player, never()).teleport(spawn);
    verifyZeroInteractions(bukkitService, spawnLoader);
}
Also used : Player(org.bukkit.entity.Player) LimboPlayer(fr.xephi.authme.data.limbo.LimboPlayer) PlayerAuth(fr.xephi.authme.data.auth.PlayerAuth) LimboPlayer(fr.xephi.authme.data.limbo.LimboPlayer) Location(org.bukkit.Location) Test(org.junit.Test)

Example 100 with PlayerAuth

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

the class MigrationServiceTest method shouldMigratePlaintextHashes.

@Test
public void shouldMigratePlaintextHashes() {
    // given
    PlayerAuth auth1 = authWithNickAndHash("bobby", "test");
    PlayerAuth auth2 = authWithNickAndHash("user", "myPassword");
    PlayerAuth auth3 = authWithNickAndHash("Tester12", "$tester12_pw");
    given(dataSource.getAllAuths()).willReturn(Arrays.asList(auth1, auth2, auth3));
    setSha256MockToUppercase(sha256);
    given(settings.getProperty(SecuritySettings.PASSWORD_HASH)).willReturn(HashAlgorithm.PLAINTEXT);
    // when
    MigrationService.changePlainTextToSha256(settings, dataSource, sha256);
    // then
    verify(sha256, times(3)).computeHash(anyString(), anyString());
    // need to verify this because we use verifyNoMoreInteractions() after
    verify(dataSource).getAllAuths();
    verify(dataSource).updatePassword(auth1);
    assertThat(auth1.getPassword(), equalToHash("TEST"));
    verify(dataSource).updatePassword(auth2);
    assertThat(auth2.getPassword(), equalToHash("MYPASSWORD"));
    verify(dataSource).updatePassword(auth3);
    assertThat(auth3.getPassword(), equalToHash("$TESTER12_PW"));
    verifyNoMoreInteractions(dataSource);
    verify(settings).setProperty(SecuritySettings.PASSWORD_HASH, HashAlgorithm.SHA256);
}
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