forked from mtusi2026/mtusi2026lab3
chore: import lab2 baseline
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
package password
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestHasher(t *testing.T) {
|
||||
hasher, err := New(testConfig())
|
||||
if err != nil {
|
||||
t.Fatalf("New() error = %v", err)
|
||||
}
|
||||
hash, err := hasher.Hash("T3st-password-123")
|
||||
if err != nil {
|
||||
t.Fatalf("Hash() error = %v", err)
|
||||
}
|
||||
|
||||
verified, err := hasher.Verify("T3st-password-123", hash)
|
||||
if err != nil {
|
||||
t.Fatalf("Verify() error = %v", err)
|
||||
}
|
||||
if !verified {
|
||||
t.Fatal("Verify() = false for the original password")
|
||||
}
|
||||
|
||||
verified, err = hasher.Verify("wrong-password", hash)
|
||||
if err != nil {
|
||||
t.Fatalf("Verify() error = %v", err)
|
||||
}
|
||||
if verified {
|
||||
t.Fatal("Verify() = true for a different password")
|
||||
}
|
||||
}
|
||||
|
||||
func TestVerifyRejectsMalformedHash(t *testing.T) {
|
||||
hasher, err := New(testConfig())
|
||||
if err != nil {
|
||||
t.Fatalf("New() error = %v", err)
|
||||
}
|
||||
if _, err := hasher.Verify("password", "invalid"); err == nil {
|
||||
t.Fatal("Verify() error = nil for malformed hash")
|
||||
}
|
||||
}
|
||||
|
||||
func testConfig() Config {
|
||||
return Config{MemoryKiB: 8 * 1024, Iterations: 1, Parallelism: 1, SaltLength: 16, KeyLength: 32}
|
||||
}
|
||||
Reference in New Issue
Block a user