Search in sources :

Example 51 with HashedPassword

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);
}
Also used : PasswordEncryptionEvent(fr.xephi.authme.events.PasswordEncryptionEvent) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) HashedPassword(fr.xephi.authme.security.crypts.HashedPassword) Test(org.junit.Test)

Example 52 with HashedPassword

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);
}
Also used : PasswordEncryptionEvent(fr.xephi.authme.events.PasswordEncryptionEvent) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) HashedPassword(fr.xephi.authme.security.crypts.HashedPassword) Test(org.junit.Test)

Example 53 with HashedPassword

use of fr.xephi.authme.security.crypts.HashedPassword in project AuthMeReloaded by AuthMe.

the class NoOpExtensionTest method shouldNotHaveAnyInteractionsWithConnection.

@Test
public void shouldNotHaveAnyInteractionsWithConnection() throws SQLException {
    // given
    Connection connection = mock(Connection.class);
    PlayerAuth auth = mock(PlayerAuth.class);
    int id = 3;
    String name = "Bobby";
    HashedPassword password = new HashedPassword("test", "toast");
    // when
    extension.extendAuth(auth, id, connection);
    extension.changePassword(name, password, connection);
    extension.removeAuth(name, connection);
    extension.saveAuth(auth, connection);
    // then
    verifyNoInteractions(connection, auth);
}
Also used : Connection(java.sql.Connection) PlayerAuth(fr.xephi.authme.data.auth.PlayerAuth) HashedPassword(fr.xephi.authme.security.crypts.HashedPassword) Test(org.junit.Test)

Example 54 with HashedPassword

use of fr.xephi.authme.security.crypts.HashedPassword in project AuthMeReloaded by AuthMe.

the class AbstractDataSourceIntegrationTest method shouldReturnPassword.

@Test
public void shouldReturnPassword() {
    // given
    DataSource dataSource = getDataSource();
    // when
    HashedPassword bobbyPassword = dataSource.getPassword("bobby");
    HashedPassword invalidPassword = dataSource.getPassword("doesNotExist");
    HashedPassword userPassword = dataSource.getPassword("User");
    // then
    assertThat(bobbyPassword, equalToHash("$SHA$11aa0706173d7272$dbba966"));
    assertThat(invalidPassword, nullValue());
    assertThat(userPassword, equalToHash("b28c32f624a4eb161d6adc9acb5bfc5b", "f750ba32"));
}
Also used : HashedPassword(fr.xephi.authme.security.crypts.HashedPassword) Test(org.junit.Test)

Example 55 with HashedPassword

use of fr.xephi.authme.security.crypts.HashedPassword in project AuthMeReloaded by AuthMe.

the class AbstractDataSourceIntegrationTest method shouldUpdatePasswordWithPlayerAuth.

@Test
public void shouldUpdatePasswordWithPlayerAuth() {
    // given
    DataSource dataSource = getDataSource("salt");
    PlayerAuth bobbyAuth = PlayerAuth.builder().name("bobby").password(new HashedPassword("tt", "cc")).build();
    PlayerAuth invalidAuth = PlayerAuth.builder().name("invalid").password(new HashedPassword("tt", "cc")).build();
    // when
    boolean response1 = dataSource.updatePassword(bobbyAuth);
    boolean response2 = dataSource.updatePassword(invalidAuth);
    // then
    assertThat(response1, equalTo(true));
    // no record modified
    assertThat(response2, equalTo(false));
    assertThat(dataSource.getPassword("bobby"), equalToHash("tt", "cc"));
}
Also used : PlayerAuth(fr.xephi.authme.data.auth.PlayerAuth) HashedPassword(fr.xephi.authme.security.crypts.HashedPassword) Test(org.junit.Test)

Aggregations

HashedPassword (fr.xephi.authme.security.crypts.HashedPassword)55 Test (org.junit.Test)35 PlayerAuth (fr.xephi.authme.data.auth.PlayerAuth)22 Player (org.bukkit.entity.Player)14 ValidationResult (fr.xephi.authme.service.ValidationService.ValidationResult)9 CommandSender (org.bukkit.command.CommandSender)9 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)6 PasswordEncryptionEvent (fr.xephi.authme.events.PasswordEncryptionEvent)5 PreparedStatement (java.sql.PreparedStatement)4 ResultSet (java.sql.ResultSet)3 SQLException (java.sql.SQLException)3 ValidationService (fr.xephi.authme.service.ValidationService)2 Connection (java.sql.Connection)2 PotionEffect (org.bukkit.potion.PotionEffect)2 AuthMeMatchers.hasAuthLocation (fr.xephi.authme.AuthMeMatchers.hasAuthLocation)1 EncryptionMethod (fr.xephi.authme.security.crypts.EncryptionMethod)1 Joomla (fr.xephi.authme.security.crypts.Joomla)1 BufferedReader (java.io.BufferedReader)1 File (java.io.File)1 FileReader (java.io.FileReader)1