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);
}
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);
}
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);
}
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);
}
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);
}
Aggregations