@@ -213,68 +213,111 @@ module.exports = function() {
213213
214214 describe ( 'security' , function ( ) {
215215
216- it ( 'should deny when missing handler' , function ( done ) {
217- request ( this . app )
218- . get ( '/hello_secured' )
219- . set ( 'Accept' , 'application/json' )
220- . expect ( 403 )
221- . expect ( 'Content-Type' , / j s o n / )
222- . end ( function ( err , res ) {
223- should . not . exist ( err ) ;
216+ describe ( 'loaded from path' , function ( ) {
224217
225- res . body . should . have . properties ( {
226- code : 'server_error' ,
227- message : 'Unknown security handler: api_key'
218+ it ( 'should deny when swagger-tools handler denies' , function ( done ) {
219+
220+ request ( this . app )
221+ . get ( '/hello_secured' )
222+ . set ( 'Accept' , 'application/json' )
223+ . expect ( 403 )
224+ . expect ( 'Content-Type' , / j s o n / )
225+ . end ( function ( err , res ) {
226+ should . not . exist ( err ) ;
227+
228+ res . body . should . have . properties ( {
229+ code : 'server_error' ,
230+ message : 'no way!'
231+ } ) ;
232+
233+ done ( ) ;
228234 } ) ;
235+ } ) ;
229236
230- done ( ) ;
231- } ) ;
237+ it ( 'should allow when swagger-tools handler accepts' , function ( done ) {
238+
239+ request ( this . app )
240+ . get ( '/hello_secured?name=Scott' )
241+ . set ( 'Accept' , 'application/json' )
242+ . expect ( 200 )
243+ . expect ( 'Content-Type' , / j s o n / )
244+ . end ( function ( err , res ) {
245+ should . not . exist ( err ) ;
246+ res . body . should . eql ( 'Hello, Scott!' ) ;
247+
248+ done ( ) ;
249+ } ) ;
250+ } ) ;
232251 } ) ;
233252
234- it ( 'should deny when swagger-tools handler denies ', function ( done ) {
253+ describe ( 'explicit in config ', function ( ) {
235254
236- this . runner . securityHandlers = {
237- api_key : function ( req , secDef , key , cb ) {
238- cb ( new Error ( 'no way!' ) ) ;
239- }
240- } ;
255+ it ( 'should deny when missing handler' , function ( done ) {
241256
242- request ( this . app )
243- . get ( '/hello_secured' )
244- . set ( 'Accept' , 'application/json' )
245- . expect ( 403 )
246- . expect ( 'Content-Type' , / j s o n / )
247- . end ( function ( err , res ) {
248- should . not . exist ( err ) ;
257+ this . runner . securityHandlers = { } ;
249258
250- res . body . should . have . properties ( {
251- code : 'server_error' ,
252- message : 'no way!'
259+ request ( this . app )
260+ . get ( '/hello_secured' )
261+ . set ( 'Accept' , 'application/json' )
262+ . expect ( 403 )
263+ . expect ( 'Content-Type' , / j s o n / )
264+ . end ( function ( err , res ) {
265+ should . not . exist ( err ) ;
266+
267+ res . body . should . have . properties ( {
268+ code : 'server_error' ,
269+ message : 'Unknown security handler: api_key'
270+ } ) ;
271+
272+ done ( ) ;
253273 } ) ;
274+ } ) ;
254275
255- done ( ) ;
256- } ) ;
257- } ) ;
276+ it ( 'should deny when swagger-tools handler denies' , function ( done ) {
258277
259- it ( 'should allow when swagger-tools handler accepts' , function ( done ) {
278+ this . runner . securityHandlers = {
279+ api_key : function ( req , secDef , key , cb ) {
280+ cb ( new Error ( 'no way!' ) ) ;
281+ }
282+ } ;
260283
261- this . runner . securityHandlers = {
262- api_key : function ( req , secDef , key , cb ) {
263- cb ( ) ;
264- }
265- } ;
284+ request ( this . app )
285+ . get ( '/hello_secured' )
286+ . set ( 'Accept' , 'application/json' )
287+ . expect ( 403 )
288+ . expect ( 'Content-Type' , / j s o n / )
289+ . end ( function ( err , res ) {
290+ should . not . exist ( err ) ;
266291
267- request ( this . app )
268- . get ( '/hello_secured' )
269- . set ( 'Accept' , 'application/json' )
270- . expect ( 200 )
271- . expect ( 'Content-Type' , / j s o n / )
272- . end ( function ( err , res ) {
273- should . not . exist ( err ) ;
274- res . body . should . eql ( 'Hello, stranger!' ) ;
292+ res . body . should . have . properties ( {
293+ code : 'server_error' ,
294+ message : 'no way!'
295+ } ) ;
275296
276- done ( ) ;
277- } ) ;
297+ done ( ) ;
298+ } ) ;
299+ } ) ;
300+
301+ it ( 'should allow when swagger-tools handler accepts' , function ( done ) {
302+
303+ this . runner . securityHandlers = {
304+ api_key : function ( req , secDef , key , cb ) {
305+ cb ( ) ;
306+ }
307+ } ;
308+
309+ request ( this . app )
310+ . get ( '/hello_secured' )
311+ . set ( 'Accept' , 'application/json' )
312+ . expect ( 200 )
313+ . expect ( 'Content-Type' , / j s o n / )
314+ . end ( function ( err , res ) {
315+ should . not . exist ( err ) ;
316+ res . body . should . eql ( 'Hello, stranger!' ) ;
317+
318+ done ( ) ;
319+ } ) ;
320+ } ) ;
278321 } ) ;
279322 } ) ;
280323
0 commit comments