add tests for PasswordEncryptionService

This commit is contained in:
Athou
2023-12-18 16:06:54 +01:00
parent 6c3895e60a
commit 241c465eba

View File

@@ -0,0 +1,23 @@
package com.commafeed.backend.service;
import java.util.HexFormat;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
class PasswordEncryptionServiceTest {
@Test
void authenticate() {
String password = "password";
byte[] salt = "abcdefgh".getBytes();
PasswordEncryptionService passwordEncryptionService = new PasswordEncryptionService();
byte[] encryptedPassword = passwordEncryptionService.getEncryptedPassword(password, salt);
// make sure the encrypted password is always the same for a fixed salt
Assertions.assertEquals("8b4660158141d9f4f7865718b9a2b940a3e3cea9", HexFormat.of().formatHex(encryptedPassword));
Assertions.assertTrue(passwordEncryptionService.authenticate(password, encryptedPassword, salt));
}
}