package main import "testing" func TestArgonProfiles(t *testing.T) { for _, test := range []struct { name, hash string match, upgrade bool }{ {"current", hashPassword("test-password"), true, false}, {"legacy", makePasswordHash("test-password", argonLegacy, 19*1024, 2), true, true}, {"other password", hashPassword("other-password"), false, false}, {"unsupported parameters", "$argon2id$v=19$m=999999999,t=10,p=50$abcd$efgh", false, false}, } { t.Run(test.name, func(t *testing.T) { match, upgrade := verifyPassword(test.hash, "test-password") if match != test.match || upgrade != test.upgrade { t.Fatalf("verify = (%v, %v), want (%v, %v)", match, upgrade, test.match, test.upgrade) } }) } } func BenchmarkArgonVerification(b *testing.B) { for _, test := range []struct { name, params string memory, rounds uint32 }{ {"19MiB-2", argonLegacy, 19 * 1024, 2}, {"64MiB-3", argonCurrent, 64 * 1024, 3}, } { b.Run(test.name, func(b *testing.B) { hash := makePasswordHash("benchmark-password", test.params, test.memory, test.rounds) b.ReportAllocs() b.ResetTimer() for range b.N { if valid, _ := verifyPassword(hash, "benchmark-password"); !valid { b.Fatal("benchmark hash rejected") } } }) } }