25 lines
687 B
Go
25 lines
687 B
Go
package password
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func TestVersionedPasswordEncoding(t *testing.T) {
|
|
encoded, err := Encode("correct-horse-battery-staple")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if !strings.HasPrefix(encoded, "bcrypt:v1:$2") || !Verify(encoded, "correct-horse-battery-staple") || Verify(encoded, "wrong-password") || Verify(strings.TrimPrefix(encoded, "bcrypt:v1:"), "correct-horse-battery-staple") {
|
|
t.Fatalf("versioned password verification failed")
|
|
}
|
|
}
|
|
func TestPasswordLength(t *testing.T) {
|
|
if _, err := Encode("short"); err == nil {
|
|
t.Fatal("short password accepted")
|
|
}
|
|
if Verify("bcrypt:v2:anything", "value") {
|
|
t.Fatal("unknown version accepted")
|
|
}
|
|
}
|