diff options
| author | Chia <Chia@93.nz> | 2026-08-05 09:26:05 +1200 |
|---|---|---|
| committer | Chia <Chia@93.nz> | 2026-08-05 09:26:05 +1200 |
| commit | 86b1f42e3c5601ff10621a9779cf0076590797a1 (patch) | |
| tree | ccf584f0404dece2e4dae2eee847b665f57c0737 /internal/security/password_test.go | |
| parent | 1a3d7f9a8a181df48f0e911cbe17a3fad3ab9ac9 (diff) | |
add sth.
Diffstat (limited to 'internal/security/password_test.go')
| -rw-r--r-- | internal/security/password_test.go | 24 |
1 files changed, 24 insertions, 0 deletions
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) + } + } +} |
