@@ -296,5 +296,50 @@ describe('authorization', function() {
296296 } ) ;
297297 } ) ;
298298 } ) ;
299-
299+
300+ describe ( 'immediate callback with scope and req' , function ( ) {
301+ function immediate ( req , client , user , scope , done ) {
302+ expect ( req . query . immediate ) . to . be . true ;
303+ if ( client . id == '1234' && user . id == 'u123' && scope == 'profile' ) {
304+ return done ( null , true , { scope : 'read' } ) ;
305+ }
306+ return done ( new Error ( 'something went wrong while checking immediate status' ) ) ;
307+ }
308+
309+ describe ( 'handling a request that is immediately authorized' , function ( ) {
310+ var request , response , err ;
311+
312+ before ( function ( done ) {
313+ chai . connect . use ( 'express' , authorization ( server , validate , immediate ) )
314+ . req ( function ( req ) {
315+ request = req ;
316+ req . query = { response_type : 'code' , client_id : '1234' , redirect_uri : 'http://example.com/auth/callback' , scope : 'profile' , immediate : true } ;
317+ req . session = { } ;
318+ req . user = { id : 'u123' } ;
319+ } )
320+ . end ( function ( res ) {
321+ response = res ;
322+ done ( ) ;
323+ } )
324+ . dispatch ( ) ;
325+ } ) ;
326+
327+ it ( 'should not error' , function ( ) {
328+ expect ( err ) . to . be . undefined ;
329+ } ) ;
330+
331+ it ( 'should respond' , function ( ) {
332+ expect ( response . getHeader ( 'Location' ) ) . to . equal ( 'http://example.com/auth/callback' ) ;
333+ } ) ;
334+
335+ it ( 'should add transaction' , function ( ) {
336+ expect ( request . oauth2 ) . to . be . an ( 'object' ) ;
337+ } ) ;
338+
339+ it ( 'should not store transaction in session' , function ( ) {
340+ expect ( request . session [ 'authorize' ] ) . to . be . undefined ;
341+ } ) ;
342+ } ) ;
343+ } ) ;
344+
300345} ) ;
0 commit comments