MCPcopy Create free account
hub / github.com/dwin/goSecretBoxPassword / TestHash

Function TestHash

password_test.go:51–95  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

49}
50
51func TestHash(t *testing.T) {
52
53 var total int
54 runs := 52
55 // Test expect success
56 for i := 2; i < runs; i++ {
57 // Generate Test Password
58 testUserPass := fake.Password(i*4, 1000, true, true, true)
59 testMasterPass := fake.Password(i*4, 1000, true, true, true)
60 // Hash Password
61 output, err := Hash(testUserPass, testMasterPass, 0, ScryptParams{N: 32768, R: 16, P: 1}, DefaultParams)
62 if err != nil {
63 t.Log(err)
64 t.FailNow()
65 }
66 t.Logf("Output: " + output)
67
68 // Check Output Length
69 lgth := len(output)
70 if lgth > 225 {
71 t.Logf("Output Length over 225 chars at %v for input userpass length %v", lgth, len(testUserPass))
72 }
73 total = total + lgth
74
75 // Verify Password
76 if err := Verify(testUserPass, testMasterPass, output); err != nil {
77 t.Log(err)
78 t.FailNow()
79 }
80 }
81 fmt.Printf("Average length of %v runs: %v\n", runs, total/runs)
82
83 // Test with Bad Params
84 _, err := Hash("password1234", "masterpassphrase", 0, ScryptParams{N: 2048, R: 16, P: 1}, DefaultParams)
85 if err != ErrScryptParamN {
86 t.Log("Expected Scrypt N failure for user params")
87 t.FailNow()
88 }
89 _, err = Hash("password1234", "masterpassphrase", 0, DefaultParams, ScryptParams{N: 2048, R: 16, P: 1})
90 if err != ErrScryptParamN {
91 t.Log("Expected Scrypt N failure for master params")
92 t.FailNow()
93 }
94
95}
96func TestGetHashVersion(t *testing.T) {
97 v, err := GetHashVersion("secBoxv1$0$tKTBCfdTcn5gA9xRR9yPNczryWV/f+7MVkdDgxFtuYuzvTcNGMNTHBE2pCoPjRjTDIN1449gwVHfrkzvkzWdwZBEUCVWVZFjlRTdu8kCD7uBDmfozwyX+U/T7k8cyfaHFgB8y8cPEvk=$Ek8NWSL34KE=$32768$16$1$16384$8$1")
98 if err != nil {

Callers

nothing calls this directly

Calls 2

HashFunction · 0.85
VerifyFunction · 0.85

Tested by

no test coverage detected