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:
Sebastian UnterschützandClaude Opus 5.5 committed 2026-11-21 23:55:23 +01:00
1 parent 96c1555889
commit caff396264
6 files changed
+243 -3

No files matched your search

+43
View File
@@ -0,0 +1,43 @@
package auth
import (
"context"
"os"
"testing"
"time"
"github.com/google/uuid"
"github.com/pquerna/otp/totp"
"github.com/redis/go-redis/v9"
)
func TestTOTPRejectsReplay(t *testing.T) {
url := os.Getenv("UPTIME_TEST_REDIS_URL")
if url == "" {
t.Skip("UPTIME_TEST_REDIS_URL not set")
}
opts, _ := redis.ParseURL(url)
rdb := redis.NewClient(opts)
defer rdb.Close()
key, err := NewTOTPKey("a@example.test")
if err != nil {
t.Fatal(err)
}
now := time.Now()
code, _ := totp.GenerateCode(key.Secret(), now)
v := NewTOTPVerifier(rdb)
v.now = func() time.Time { return now }
user := uuid.New()
ctx := context.Background()
if ok, err := v.Verify(ctx, user, key.Secret(), code); !ok || err != nil {
t.Fatalf("first use rejected: %v", err)
}
if ok, _ := v.Verify(ctx, user, key.Secret(), code); ok {
t.Fatal("replayed code accepted")
}
if ok, _ := v.Verify(ctx, user, key.Secret(), "000000"); ok {
t.Fatal("wrong code accepted")
}
}