diff options
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) + } + } +} |
