package auth import "testing" func TestPasswordHashRoundTrip(t *testing.T) { hash, err := HashPassword("correct horse battery staple") if err != nil { t.Fatal(err) } if !VerifyPassword(hash, "correct horse battery staple") { t.Fatal("valid password was rejected") } if VerifyPassword(hash, "wrong password") { t.Fatal("invalid password was accepted") } if VerifyPassword("not-a-hash", "anything") { t.Fatal("malformed hash was accepted") } } func TestPasswordPolicy(t *testing.T) { if err := ValidatePassword("short"); err == nil { t.Fatal("short password accepted") } if err := ValidatePassword("this password is long enough"); err != nil { t.Fatal(err) } if err := ValidatePassword(string(make([]byte, 257))); err == nil { t.Fatal("overlong password accepted") } }