1
- const test = require ( 'ava' )
2
1
const boom = require ( 'boom' )
2
+ const test = require ( 'ava' )
3
3
const helpers = require ( './_helpers' )
4
+ const fixtures = require ( './fixtures' )
4
5
const utils = require ( '../src/utils' )
5
6
6
7
test ( 'get boom error with default message' , ( t ) => {
@@ -113,12 +114,81 @@ test('throw error if options are invalid – secret', (t) => {
113
114
} )
114
115
} )
115
116
117
+ test ( 'throw error if options are invalid – publicKey' , ( t ) => {
118
+ const invalids = [
119
+ null ,
120
+ NaN ,
121
+ '' ,
122
+ 'foobar' ,
123
+ fixtures . common . baseUrl ,
124
+ 42 ,
125
+ true ,
126
+ false ,
127
+ [ ] ,
128
+ new RegExp ( ) ,
129
+ { }
130
+ ]
131
+
132
+ t . plan ( invalids . length )
133
+
134
+ invalids . forEach ( ( invalid ) => {
135
+ t . throws ( ( ) => utils . verify ( helpers . getOptions ( {
136
+ secret : undefined ,
137
+ publicKey : invalid
138
+ } ) ) , Error , helpers . log ( 'publicKey' , invalid ) )
139
+ } )
140
+ } )
141
+
142
+ test ( 'throw error if options are invalid – verifyOpts' , ( t ) => {
143
+ const invalids = [
144
+ null ,
145
+ NaN ,
146
+ '' ,
147
+ 'foobar' ,
148
+ fixtures . common . baseUrl ,
149
+ 42 ,
150
+ true ,
151
+ false ,
152
+ [ ] ,
153
+ { ignoreExpiration : true } ,
154
+ { ignoreNotBefore : true }
155
+ ]
156
+
157
+ t . plan ( invalids . length )
158
+
159
+ invalids . forEach ( ( invalid ) => {
160
+ t . throws ( ( ) => utils . verify ( helpers . getOptions ( {
161
+ secret : undefined ,
162
+ publicKey : fixtures . common . publicKey ,
163
+ verifyOpts : invalid
164
+ } ) ) , Error , helpers . log ( 'publicKey' , invalid ) )
165
+ } )
166
+ } )
167
+
168
+ test ( 'throw error if options are invalid – publicKey/secret conflict' , ( t ) => {
169
+ t . throws ( ( ) => utils . verify ( helpers . getOptions ( {
170
+ secret : undefined ,
171
+ publicKey : undefined
172
+ } ) ) , Error , 'publicKey/secret: both undefined' )
173
+
174
+ t . throws ( ( ) => utils . verify ( helpers . getOptions ( {
175
+ publicKey : fixtures . common . publicKey
176
+ } ) ) , Error , 'publicKey/secret: both defined' )
177
+ } )
178
+
179
+ test ( 'throw error if options are invalid – verifyOpts/secret conflict' , ( t ) => {
180
+ t . throws ( ( ) => utils . verify ( helpers . getOptions ( {
181
+ verifyOpts : { }
182
+ } ) ) , Error , 'verifyOpts/secret: both defined' )
183
+ } )
184
+
116
185
test ( 'throw error if options are invalid – cache' , ( t ) => {
117
186
const invalids = [
118
187
null ,
119
188
NaN ,
120
189
'' ,
121
190
'foobar' ,
191
+ fixtures . common . baseUrl ,
122
192
42 ,
123
193
[ ]
124
194
]
@@ -138,6 +208,7 @@ test('throw error if options are invalid – userInfo', (t) => {
138
208
NaN ,
139
209
'' ,
140
210
'foobar' ,
211
+ fixtures . common . baseUrl ,
141
212
42 ,
142
213
true ,
143
214
false ,
@@ -183,3 +254,29 @@ test('throw no error if options are valid', (t) => {
183
254
Error , helpers . log ( 'valid' , valid ) )
184
255
} )
185
256
} )
257
+
258
+ test ( 'throw no error if options are valid' , ( t ) => {
259
+ const valids = [
260
+ { } ,
261
+ { verifyOpts : undefined } ,
262
+ { verifyOpts : { } } ,
263
+ { verifyOpts : { audience : 'foobar' } } ,
264
+ { cache : { } } ,
265
+ { cache : { segment : 'foobar' } } ,
266
+ { cache : true } ,
267
+ { cache : false } ,
268
+ { userInfo : [ ] } ,
269
+ { userInfo : [ 'string' ] }
270
+ ]
271
+
272
+ t . plan ( valids . length )
273
+
274
+ valids . forEach ( ( valid ) => {
275
+ t . notThrows (
276
+ ( ) => utils . verify ( helpers . getOptions ( Object . assign ( {
277
+ secret : undefined ,
278
+ publicKey : fixtures . common . publicKey
279
+ } , valid ) ) ) ,
280
+ Error , helpers . log ( 'valid with publicKey' , valid ) )
281
+ } )
282
+ } )
0 commit comments