forked from mtusi2026/mtusi2026lab5
Реализована лабораторная работа 5 на оценку 4
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
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")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user