use of fr.xephi.authme.security.crypts.HashedPassword in project AuthMeReloaded by AuthMe.
the class PasswordSecurityTest method shouldReturnPasswordMatch.
@Test
public void shouldReturnPasswordMatch() {
// given
HashedPassword password = new HashedPassword("$TEST$10$SOME_HASH", null);
String playerName = "Tester";
// Calls to EncryptionMethod are always with the lower-case version of the name
String playerLowerCase = playerName.toLowerCase();
String clearTextPass = "myPassTest";
given(dataSource.getPassword(playerName)).willReturn(password);
given(method.comparePassword(clearTextPass, password, playerLowerCase)).willReturn(true);
// when
boolean result = passwordSecurity.comparePassword(clearTextPass, playerName);
// then
assertThat(result, equalTo(true));
verify(dataSource).getPassword(playerName);
verify(pluginManager).callEvent(any(PasswordEncryptionEvent.class));
verify(method).comparePassword(clearTextPass, password, playerLowerCase);
}
use of fr.xephi.authme.security.crypts.HashedPassword in project AuthMeReloaded by AuthMe.
the class PasswordSecurityTest method shouldReturnPasswordMismatch.
@Test
public void shouldReturnPasswordMismatch() {
// given
HashedPassword password = new HashedPassword("$TEST$10$SOME_HASH", null);
String playerName = "My_PLayer";
String playerLowerCase = playerName.toLowerCase();
String clearTextPass = "passw0Rd1";
given(dataSource.getPassword(playerName)).willReturn(password);
given(method.comparePassword(clearTextPass, password, playerLowerCase)).willReturn(false);
// when
boolean result = passwordSecurity.comparePassword(clearTextPass, playerName);
// then
assertThat(result, equalTo(false));
verify(dataSource).getPassword(playerName);
verify(pluginManager).callEvent(any(PasswordEncryptionEvent.class));
verify(method).comparePassword(clearTextPass, password, playerLowerCase);
}
use of fr.xephi.authme.security.crypts.HashedPassword 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);
setBukkitServiceToScheduleSyncTaskFromOptionallyAsyncTask(bukkitService);
// 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);
verifyNoInteractions(teleportationService, limboService);
verifyCalledUnregisterEventFor(player);
verify(bungeeSender).sendAuthMeBungeecordMessage(MessageType.UNREGISTER, name);
verify(commandManager).runCommandsOnUnregister(player);
}
use of fr.xephi.authme.security.crypts.HashedPassword 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);
verifyNoInteractions(teleportationService);
verifyCalledUnregisterEventFor(player);
verify(bungeeSender).sendAuthMeBungeecordMessage(MessageType.UNREGISTER, name);
}
use of fr.xephi.authme.security.crypts.HashedPassword in project AuthMeReloaded by AuthMe.
the class AsynchronousUnregisterTest method shouldHandleDatabaseError.
@Test
public void shouldHandleDatabaseError() {
// given
Player player = mock(Player.class);
String name = "Frank21";
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(true);
given(dataSource.removeAuth(name)).willReturn(false);
// when
asynchronousUnregister.unregister(player, userPassword);
// then
verify(passwordSecurity).comparePassword(userPassword, password, name);
verify(dataSource).removeAuth(name);
verify(service).send(player, MessageKey.ERROR);
verifyNoInteractions(teleportationService, bukkitService, bungeeSender);
}
Aggregations