summaryrefslogtreecommitdiff
path: root/internal/security/password_test.go
blob: 8c9b7741d3d8b44f40a6865268ce4f33970a3f67 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
package security

import "testing"

func TestPasswordHashRoundTrip(t *testing.T) {
	hash, salt, iterations, err := HashPassword("correct-horse-42")
	if err != nil {
		t.Fatal(err)
	}
	if !VerifyPassword("correct-horse-42", hash, salt, iterations) {
		t.Fatal("correct password was rejected")
	}
	if VerifyPassword("wrong-password-42", hash, salt, iterations) {
		t.Fatal("wrong password was accepted")
	}
}

func TestPasswordPolicy(t *testing.T) {
	for _, password := range []string{"short1", "onlyletterslong", "123456789012345"} {
		if err := ValidatePassword(password); err == nil {
			t.Fatalf("password %q unexpectedly passed policy", password)
		}
	}
}