forked from mtusi2026/mtusi2026lab3
34 lines
745 B
Go
34 lines
745 B
Go
package messenger
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func TestPasswordHash(t *testing.T) {
|
|
const password = "long-test-password"
|
|
first, err := hashPassword(password)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
second, err := hashPassword(password)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if first == password || strings.Contains(first, password) {
|
|
t.Fatal("hash contains the original password")
|
|
}
|
|
if first == second {
|
|
t.Fatal("independent hashes must use different salts")
|
|
}
|
|
if !verifyPassword(first, password) {
|
|
t.Fatal("correct password was rejected")
|
|
}
|
|
if verifyPassword(first, "wrong-test-password") {
|
|
t.Fatal("wrong password was accepted")
|
|
}
|
|
if verifyPassword("damaged-hash", password) {
|
|
t.Fatal("malformed hash was accepted")
|
|
}
|
|
}
|