@@ -801,6 +801,59 @@ describe('session()', function(){
801801 } )
802802 } )
803803 } )
804+
805+ describe ( 'when "cookie" is a function' , function ( ) {
806+ it ( 'should call custom function and apply cookie options' , function ( done ) {
807+ var cookieCallbackCalled = false ;
808+ var cookieCallback = function ( ) {
809+ cookieCallbackCalled = true ;
810+ return { path : '/test' , httpOnly : true , secure : false } ;
811+ } ;
812+ var server = createServer ( { cookie : cookieCallback } ) ;
813+ request ( server )
814+ . get ( '/test' )
815+ . expect (
816+ shouldSetCookieWithAttributeAndValue ( 'connect.sid' , 'Path' , '/test' )
817+ )
818+ . expect ( shouldSetCookieWithAttribute ( 'connect.sid' , 'HttpOnly' ) )
819+ . expect ( shouldSetCookieWithoutAttribute ( 'connect.sid' , 'Secure' ) )
820+ . expect ( 200 , function ( err ) {
821+ if ( err ) return done ( err ) ;
822+ assert . strictEqual (
823+ cookieCallbackCalled ,
824+ true ,
825+ 'should have called cookie callback'
826+ ) ;
827+ done ( ) ;
828+ } ) ;
829+ } ) ;
830+
831+ it ( 'should provide req argument' , function ( done ) {
832+ var _path = '/test' ;
833+ var cookieCallbackCalled = false ;
834+ var cookieCallback = function ( req ) {
835+ cookieCallbackCalled = true ;
836+ return { path : req . url , httpOnly : true , secure : false } ;
837+ } ;
838+ var server = createServer ( { cookie : cookieCallback } ) ;
839+ request ( server )
840+ . get ( _path )
841+ . expect (
842+ shouldSetCookieWithAttributeAndValue ( 'connect.sid' , 'Path' , _path )
843+ )
844+ . expect ( shouldSetCookieWithAttribute ( 'connect.sid' , 'HttpOnly' ) )
845+ . expect ( shouldSetCookieWithoutAttribute ( 'connect.sid' , 'Secure' ) )
846+ . expect ( 200 , function ( err ) {
847+ if ( err ) return done ( err ) ;
848+ assert . strictEqual (
849+ cookieCallbackCalled ,
850+ true ,
851+ 'should have called cookie callback'
852+ ) ;
853+ done ( ) ;
854+ } ) ;
855+ } ) ;
856+ } ) ;
804857 } )
805858
806859 describe ( 'genid option' , function ( ) {
0 commit comments