-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpwCheck_test.go
42 lines (36 loc) · 1.09 KB
/
pwCheck_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package pwcheck
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestCheckForPwnage(t *testing.T) {
// Check Password "password" for pwnage, should return no error and pwned true
pass := "password"
pwd, err := CheckForPwnage(pass)
assert.Nil(t, err)
assert.True(t, pwd.Pwned)
assert.Equal(t, pass, pwd.Pass)
assert.NotZero(t, pwd.TimesPwned)
// Check Password "", should return Passphrase Empty error
pwd2, err := CheckForPwnage("")
assert.Error(t, err, ErrPassphraseEmpty.Error())
assert.EqualValues(t, false, pwd2.Pwned)
assert.EqualValues(t, 0, pwd2.TimesPwned)
}
func TestIsPwned(t *testing.T) {
// Test is pwned with known bad password
err := IsPwned("password")
assert.EqualError(t, err, "Password is pwned")
// Test is pwned with good password
err = IsPwned("90-hasnlkkjklafo;da-hasnfolkkjklafdsj90;dafdsj")
assert.NoError(t, err)
}
func TestCheckPass(t *testing.T) {
pass := "password"
res, err := CheckPass(pass)
assert.NoError(t, err)
assert.NotEmpty(t, res)
assert.Equal(t, pass, res.Pass)
assert.Zero(t, res.Score)
assert.Zero(t, res.CrackTimeSeconds)
}