1
1
'use strict' ;
2
2
var test = require ( 'tape' ) ,
3
- pw = require ( '../credential.js' ) ;
3
+ credential = require ( '../credential.js' ) ;
4
4
5
5
test ( 'hash' , function ( t ) {
6
6
7
+ var pw = credential ( ) ;
8
+
7
9
pw . hash ( 'foo' , function ( err , hash ) {
8
10
9
11
t . equal ( typeof hash , 'string' ,
@@ -19,6 +21,8 @@ test('hash', function (t) {
19
21
20
22
test ( 'hash with different passwords' , function ( t ) {
21
23
24
+ var pw = credential ( ) ;
25
+
22
26
pw . hash ( 'foo' , function ( err , fooHash ) {
23
27
24
28
pw . hash ( 'bar' , function ( err , barHash ) {
@@ -33,6 +37,8 @@ test('hash with different passwords', function (t) {
33
37
34
38
test ( 'hash with same passwords' , function ( t ) {
35
39
40
+ var pw = credential ( ) ;
41
+
36
42
pw . hash ( 'foo' , function ( err , fooHash ) {
37
43
38
44
pw . hash ( 'foo' , function ( err , barHash ) {
@@ -47,6 +53,8 @@ test('hash with same passwords', function (t) {
47
53
48
54
test ( 'hash with undefined password' , function ( t ) {
49
55
56
+ var pw = credential ( ) ;
57
+
50
58
try {
51
59
pw . hash ( undefined , function ( err ) {
52
60
t . ok ( err ,
@@ -61,6 +69,8 @@ test('hash with undefined password', function (t) {
61
69
62
70
test ( 'hash with empty password' , function ( t ) {
63
71
72
+ var pw = credential ( ) ;
73
+
64
74
try {
65
75
pw . hash ( '' , function ( err ) {
66
76
t . ok ( err ,
@@ -75,7 +85,8 @@ test('hash with empty password', function (t) {
75
85
76
86
77
87
test ( 'verify with right pw' , function ( t ) {
78
- var pass = 'foo' ;
88
+ var pass = 'foo' ,
89
+ pw = credential ( ) ;
79
90
80
91
pw . hash ( pass , function ( err , storedHash ) {
81
92
pw . verify ( storedHash , pass , function ( err , isValid ) {
@@ -92,7 +103,8 @@ test('verify with right pw', function (t) {
92
103
93
104
test ( 'verify with broken stored hash' , function ( t ) {
94
105
var pass = 'foo' ,
95
- storedHash = 'aoeuntkh;kbanotehudil,.prcgidax$aoesnitd,riouxbx;qjkwmoeuicgr' ;
106
+ storedHash = 'aoeuntkh;kbanotehudil,.prcgidax$aoesnitd,riouxbx;qjkwmoeuicgr' ,
107
+ pw = credential ( ) ;
96
108
97
109
pw . verify ( storedHash , pass , function ( err ) {
98
110
@@ -106,7 +118,8 @@ test('verify with broken stored hash', function (t) {
106
118
107
119
108
120
test ( 'verify with wrong pw' , function ( t ) {
109
- var pass = 'foo' ;
121
+ var pass = 'foo' ,
122
+ pw = credential ( ) ;
110
123
111
124
pw . hash ( pass , function ( err , storedHash ) {
112
125
pw . verify ( storedHash , 'bar' , function ( err , isValid ) {
@@ -119,7 +132,8 @@ test('verify with wrong pw', function (t) {
119
132
} ) ;
120
133
121
134
test ( 'verify with undefined password' , function ( t ) {
122
- var pass = 'foo' ;
135
+ var pass = 'foo' ,
136
+ pw = credential ( ) ;
123
137
124
138
pw . hash ( pass , function ( err , storedHash ) {
125
139
try {
@@ -138,7 +152,8 @@ test('verify with undefined password', function (t) {
138
152
} ) ;
139
153
140
154
test ( 'verify with empty password' , function ( t ) {
141
- var pass = 'foo' ;
155
+ var pass = 'foo' ,
156
+ pw = credential ( ) ;
142
157
143
158
pw . hash ( pass , function ( err , storedHash ) {
144
159
try {
@@ -157,7 +172,8 @@ test('verify with empty password', function (t) {
157
172
} ) ;
158
173
159
174
test ( 'expired with valid hash and default expiry' , function ( t ) {
160
- var pass = 'foo' ;
175
+ var pass = 'foo' ,
176
+ pw = credential ( ) ;
161
177
162
178
pw . hash ( pass , function ( err , storedHash ) {
163
179
t . notOk ( pw . expired ( storedHash ) ,
@@ -168,7 +184,8 @@ test('expired with valid hash and default expiry', function (t) {
168
184
} ) ;
169
185
170
186
test ( 'expired with short expiry' , function ( t ) {
171
- var pass = 'foo' ;
187
+ var pass = 'foo' ,
188
+ pw = credential ( ) ;
172
189
173
190
pw . hash ( pass , function ( err , storedHash ) {
174
191
t . notOk ( pw . expired ( storedHash , 2 ) ,
@@ -179,7 +196,8 @@ test('expired with short expiry', function (t) {
179
196
} ) ;
180
197
181
198
test ( 'expired with expiry in the past' , function ( t ) {
182
- var pass = 'foo' ;
199
+ var pass = 'foo' ,
200
+ pw = credential ( ) ;
183
201
184
202
pw . hash ( pass , function ( err , storedHash ) {
185
203
t . ok ( pw . expired ( storedHash , - 2 ) ,
@@ -243,7 +261,8 @@ test('constantEquals exposes no timings', function (t) {
243
261
test ( 'overrides' , function ( t ) {
244
262
var work = 0.5 ;
245
263
var keyLength = 12 ;
246
- pw . configure ( {
264
+
265
+ var pw = credential ( {
247
266
work : work ,
248
267
keyLength : keyLength
249
268
} ) ;
0 commit comments