From 86b1f42e3c5601ff10621a9779cf0076590797a1 Mon Sep 17 00:00:00 2001 From: Chia Date: Wed, 5 Aug 2026 09:26:05 +1200 Subject: add sth. --- internal/security/password_test.go | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 internal/security/password_test.go (limited to 'internal/security/password_test.go') diff --git a/internal/security/password_test.go b/internal/security/password_test.go new file mode 100644 index 0000000..8c9b774 --- /dev/null +++ b/internal/security/password_test.go @@ -0,0 +1,24 @@ +package security + +import "testing" + +func TestPasswordHashRoundTrip(t *testing.T) { + hash, salt, iterations, err := HashPassword("correct-horse-42") + if err != nil { + t.Fatal(err) + } + if !VerifyPassword("correct-horse-42", hash, salt, iterations) { + t.Fatal("correct password was rejected") + } + if VerifyPassword("wrong-password-42", hash, salt, iterations) { + t.Fatal("wrong password was accepted") + } +} + +func TestPasswordPolicy(t *testing.T) { + for _, password := range []string{"short1", "onlyletterslong", "123456789012345"} { + if err := ValidatePassword(password); err == nil { + t.Fatalf("password %q unexpectedly passed policy", password) + } + } +} -- cgit v1.2.3