-
Notifications
You must be signed in to change notification settings - Fork 3
/
password_test.go
96 lines (81 loc) · 2.81 KB
/
password_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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
package jess
import "testing"
func init() {
SetPasswordCallbacks(
func(signet *Signet, minSecurityLevel int) error {
return getTestPassword(signet)
},
getTestPassword,
)
}
func getTestPassword(signet *Signet) error {
pwSignet, err := testTrustStore.GetSignet(signet.ID, false)
if err != nil {
return err
}
signet.Key = pwSignet.Key
return nil
}
func TestCalculatePasswordSecurityLevel(t *testing.T) {
t.Parallel()
// basic weak
testPWSL(t, "asdf", -1)
testPWSL(t, "asdfasdf", -1)
testPWSL(t, "asdfasdxxxx", -1)
testPWSL(t, "asdfasdfasdf", -1)
testPWSL(t, "asdfasdfasdf", -1)
testPWSL(t, "WgEKCp8c8{bPrG{Zo(Ms97pxaaaaaaaa", -1)
testPWSL(t, "aaaaaaaaAAAAAAAA00000000********", -1)
// chars only
testPWSL(t, "AVWHBwmF", 64)
testPWSL(t, "AVWHBwmFGt", 76)
testPWSL(t, "AVWHBwmFGtLM", 87)
testPWSL(t, "AVWHBwmFGtLMGh", 98)
testPWSL(t, "AVWHBwmFGtLMGhYf", 110)
testPWSL(t, "AVWHBwmFGtLMGhYfPkcyawfmZXRTQdxs", 201)
// with number
testPWSL(t, "AVWHBwm1", 66)
testPWSL(t, "AVWHBwmFG1", 78)
testPWSL(t, "AVWHBwmFGtL1", 90)
testPWSL(t, "AVWHBwmFGtLMG1", 102)
testPWSL(t, "AVWHBwmFGtLMGhY1", 114)
testPWSL(t, "AVWHBwmFGtLMGhYfPkcyawfmZXRTQdx1", 209)
// with number and special
testPWSL(t, "AVWHBw1_", 67)
testPWSL(t, "AVWHBwmF1_", 79)
testPWSL(t, "AVWHBwmFGt1_", 91)
testPWSL(t, "AVWHBwmFGtLM1_", 103)
testPWSL(t, "AVWHBwmFGtLMGh1_", 116)
testPWSL(t, "AVWHBwmFGtLMGhYfPkcyawfmZXRTQd1_", 213)
// with number and more special
testPWSL(t, "AVWHBw1*", 70)
testPWSL(t, "AVWHBwmF1*", 83)
testPWSL(t, "AVWHBwmFGt1*", 96)
testPWSL(t, "AVWHBwmFGtLM1*", 109)
testPWSL(t, "AVWHBwmFGtLMGh1*", 122)
testPWSL(t, "AVWHBwmFGtLMGhYfPkcyawfmZXRTQd1*", 226)
// created, strong
// "Schneier scheme"
// source: https://www.schneier.com/blog/archives/2014/03/choosing_secure_1.html
testPWSL(t, "WIw7,mstmsritt...", 122)
testPWSL(t, "Wow...doestcst", 100)
testPWSL(t, "Ltime@go-inag~faaa!", 140)
testPWSL(t, "uTVM,TPw55:utvm,tpwstillsecure", 216)
// generated, strong
testPWSL(t, "YebGPQuuoxQwyeJMvEWACTLexUUxVBFdHYqqUybBUNfBttCvWQxDdDCdYfgMPCQp", 383)
testPWSL(t, "dpPyXmXpbECn6LWuQDJaitTTJguGfRTqNUxWfoHnBKDHvRhjR2WiQ7iDcuRJNnEd", 400)
testPWSL(t, "WgEKCp8c8{bPrG{Zo(Ms97pKt3EsR9ycz4R=kMjPp^Uafqxsd2ZTFtkfvnoueKJz", 434)
testPWSL(t, "galena-fighter-festival", 132)
testPWSL(t, "impotent-drug-dropout-damage", 157)
testPWSL(t, "artless-newswire-rill-belgium-marplot", 202)
testPWSL(t, "forbade-momenta-spook-sure-devilish-wobbly", 227)
}
func testPWSL(t *testing.T, password string, expectedSecurityLevel int) {
t.Helper()
securityLevel := CalculatePasswordSecurityLevel(password, 1<<20)
if securityLevel < expectedSecurityLevel {
t.Errorf("password %s (%di): %d - expected at least %d", password, 1<<20, securityLevel, expectedSecurityLevel)
} else {
t.Logf("password %s (%di): %d", password, 1<<20, securityLevel)
}
}