mirror of https://github.com/gophish/gophish
42 lines
1.1 KiB
Go
42 lines
1.1 KiB
Go
|
package auth
|
||
|
|
||
|
import (
|
||
|
"testing"
|
||
|
)
|
||
|
|
||
|
func TestPasswordPolicy(t *testing.T) {
|
||
|
candidate := "short"
|
||
|
got := CheckPasswordPolicy(candidate)
|
||
|
if got != ErrPasswordTooShort {
|
||
|
t.Fatalf("unexpected error received. expected %v got %v", ErrPasswordTooShort, got)
|
||
|
}
|
||
|
|
||
|
candidate = "valid password"
|
||
|
got = CheckPasswordPolicy(candidate)
|
||
|
if got != nil {
|
||
|
t.Fatalf("unexpected error received. expected %v got %v", nil, got)
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func TestValidatePasswordChange(t *testing.T) {
|
||
|
newPassword := "valid password"
|
||
|
confirmPassword := "invalid"
|
||
|
currentPassword := "current password"
|
||
|
currentHash, err := GeneratePasswordHash(currentPassword)
|
||
|
if err != nil {
|
||
|
t.Fatalf("unexpected error generating password hash: %v", err)
|
||
|
}
|
||
|
|
||
|
_, got := ValidatePasswordChange(currentHash, newPassword, confirmPassword)
|
||
|
if got != ErrPasswordMismatch {
|
||
|
t.Fatalf("unexpected error received. expected %v got %v", ErrPasswordMismatch, got)
|
||
|
}
|
||
|
|
||
|
newPassword = currentPassword
|
||
|
confirmPassword = newPassword
|
||
|
_, got = ValidatePasswordChange(currentHash, newPassword, confirmPassword)
|
||
|
if got != ErrReusedPassword {
|
||
|
t.Fatalf("unexpected error received. expected %v got %v", ErrReusedPassword, got)
|
||
|
}
|
||
|
}
|