use of fr.xephi.authme.security.crypts.HashedPassword 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");
PasswordRegisterParams params = PasswordRegisterParams.of(player, "pass", "mail@example.org");
// when
PlayerAuth auth = executor.buildPlayerAuth(params);
// then
assertThat(auth, hasAuthBasicData("s1m0n", "S1m0N", "mail@example.org", null));
assertThat(auth.getRegistrationIp(), equalTo("123.45.67.89"));
assertIsCloseTo(auth.getRegistrationDate(), System.currentTimeMillis(), 500);
assertThat(auth.getPassword(), equalToHash("pass"));
}
use of fr.xephi.authme.security.crypts.HashedPassword 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);
given(service.getProperty(RegistrationSettings.APPLY_BLIND_EFFECT)).willReturn(true);
given(service.getProperty(RestrictionSettings.TIMEOUT)).willReturn(21);
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);
verify(teleportationService).teleportOnJoin(player);
verifyCalledUnregisterEventFor(player);
verify(commandManager).runCommandsOnUnregister(player);
verify(bungeeSender).sendAuthMeBungeecordMessage(MessageType.UNREGISTER, name);
verify(player).addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, 21 * 20, 2));
}
use of fr.xephi.authme.security.crypts.HashedPassword 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);
given(service.getProperty(RegistrationSettings.APPLY_BLIND_EFFECT)).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);
verify(teleportationService).teleportOnJoin(player);
verifyCalledUnregisterEventFor(player);
verify(commandManager).runCommandsOnUnregister(player);
verify(bungeeSender).sendAuthMeBungeecordMessage(MessageType.UNREGISTER, name);
verify(player, never()).addPotionEffect(any(PotionEffect.class));
}
use of fr.xephi.authme.security.crypts.HashedPassword 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);
verifyNoInteractions(dataSource, limboService, teleportationService, bukkitService, bungeeSender);
verify(player, only()).getName();
}
use of fr.xephi.authme.security.crypts.HashedPassword in project AuthMeReloaded by AuthMe.
the class AsyncChangePassword method changePasswordAsAdmin.
/**
* Change a user's password as an administrator, without asking for the previous one
*
* @param sender who is performing the operation, null if called by other plugins
* @param playerName the player name
* @param newPassword the new password chosen for the player
*/
public void changePasswordAsAdmin(CommandSender sender, final String playerName, String newPassword) {
final String lowerCaseName = playerName.toLowerCase();
if (!(playerCache.isAuthenticated(lowerCaseName) || dataSource.isAuthAvailable(lowerCaseName))) {
if (sender == null) {
logger.warning("Tried to change password for user " + lowerCaseName + " but it doesn't exist!");
} else {
commonService.send(sender, MessageKey.UNKNOWN_USER);
}
return;
}
HashedPassword hashedPassword = passwordSecurity.computeHash(newPassword, lowerCaseName);
if (dataSource.updatePassword(lowerCaseName, hashedPassword)) {
bungeeSender.sendAuthMeBungeecordMessage(MessageType.REFRESH_PASSWORD, lowerCaseName);
if (sender != null) {
commonService.send(sender, MessageKey.PASSWORD_CHANGED_SUCCESS);
logger.info(sender.getName() + " changed password of " + lowerCaseName);
} else {
logger.info("Changed password of " + lowerCaseName);
}
} else {
if (sender != null) {
commonService.send(sender, MessageKey.ERROR);
}
logger.warning("An error occurred while changing password for user " + lowerCaseName + "!");
}
}
Aggregations