Files
mtusi2026lab4/internal/password/password_test.go
T

24 lines
575 B
Go

package password
import "testing"
func TestArgon2idRoundTrip(t *testing.T) {
p := Params{Time: 1, Memory: 8, Threads: 1}
encoded, err := p.Hash("correct-horse-1")
if err != nil {
t.Fatal(err)
}
if encoded == "correct-horse-1" || len(encoded) < 20 {
t.Fatalf("hash is not a PHC string: %s", encoded)
}
if !Verify("correct-horse-1", encoded) {
t.Fatal("matching password rejected")
}
if Verify("other-password-1", encoded) {
t.Fatal("wrong password accepted")
}
if Verify("correct-horse-1", "sha256:deadbeef") {
t.Fatal("non-argon string accepted")
}
}