Commit 3b64eed1 authored by Tomas Madeja's avatar Tomas Madeja
Browse files

test: incorrect password

parent a140136f
Loading
Loading
Loading
Loading
+17 −4
Original line number Original line Diff line number Diff line
@@ -48,15 +48,28 @@ class UserAuthServiceImplTest {


    @Test
    @Test
    public void authenticateCorrectPassword() {
    public void authenticateCorrectPassword() {
        buildMockDB();

        softly.assertThat(
                authService.authenticateUser(CORRECT_USERNAME, CORRECT_PASSWORD)
        ).isTrue();
    }

    @Test
    public void authenticateIncorrectPassword() {
        buildMockDB();

        softly.assertThat(
                authService.authenticateUser(CORRECT_USERNAME, INCORRECT_PASSWORD)
        ).isFalse();
    }

    private void buildMockDB() {
        String password = argonEncoder.encodePassword(CORRECT_PASSWORD);
        String password = argonEncoder.encodePassword(CORRECT_PASSWORD);
        var user = buildUser(1L, CORRECT_USERNAME, password);
        var user = buildUser(1L, CORRECT_USERNAME, password);


        when(userAuthDaoMock.findByUsername(CORRECT_USERNAME))
        when(userAuthDaoMock.findByUsername(CORRECT_USERNAME))
                .thenReturn(Optional.of(user));
                .thenReturn(Optional.of(user));

        softly.assertThat(
                authService.authenticateUser(CORRECT_USERNAME, CORRECT_PASSWORD)
        ).isTrue();
    }
    }


    private static User buildUser(Long id, String username, String passwordHash) {
    private static User buildUser(Long id, String username, String passwordHash) {