feat(auth): add argon2id passwords, replay-safe totp and redis rate limits
Refs #3 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017GpWAskjmYtZpuQ5JwYTX3
This commit is contained in:
1 parent
96c1555889
commit
caff396264
6 files changed
+243
-3
No files matched your search
@@ -0,0 +1,41 @@
|
||||
package auth
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestPasswordHash(t *testing.T) {
|
||||
h, err := HashPassword("correct horse battery")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if ok, rehash, err := VerifyPassword(h, "correct horse battery"); !ok || rehash || err != nil {
|
||||
t.Fatalf("ok=%v rehash=%v err=%v", ok, rehash, err)
|
||||
}
|
||||
if ok, _, _ := VerifyPassword(h, "correct horse batterz"); ok {
|
||||
t.Fatal("wrong password accepted")
|
||||
}
|
||||
if _, err := HashPassword("short"); err != ErrPasswordTooShort {
|
||||
t.Fatalf("got %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestPasswordRehashOnWeakerParams(t *testing.T) {
|
||||
saved := current
|
||||
current = argonParams{memory: 8 * 1024, time: 1, threads: 1, keyLen: 32}
|
||||
h, _ := HashPassword("correct horse battery")
|
||||
current = saved
|
||||
ok, rehash, err := VerifyPassword(h, "correct horse battery")
|
||||
if !ok || !rehash || err != nil {
|
||||
t.Fatalf("ok=%v rehash=%v err=%v", ok, rehash, err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestPasswordHashRejectsForeignFormats(t *testing.T) {
|
||||
for _, h := range []string{"", "$2a$10$abc", strings.Replace(dummyHash, "argon2id", "argon2i", 1)} {
|
||||
if _, _, err := VerifyPassword(h, "x"); err == nil {
|
||||
t.Errorf("accepted %q", h)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user