@@ -61,19 +61,20 @@ describe('ExpressOAuthServer', function() {
6161 oauth . server . authenticate . firstCall . args [ 1 ] . should . be . an . instanceOf ( Response ) ;
6262 oauth . server . authenticate . firstCall . args [ 2 ] . should . eql ( { options : true } ) ;
6363 oauth . server . authenticate . restore ( ) ;
64-
6564 done ( ) ;
6665 } ) ;
6766 } ) ;
6867 } ) ;
6968
7069 describe ( 'authorize()' , function ( ) {
71- it ( 'should call `authorize()`' , function ( done ) {
70+ it ( 'should call `authorize()` and end middleware execution' , function ( done ) {
71+ var nextMiddleware = sinon . spy ( )
7272 var oauth = new ExpressOAuthServer ( { model : { } } ) ;
7373
7474 sinon . stub ( oauth . server , 'authorize' ) . returns ( { } ) ;
7575
7676 app . use ( oauth . authorize ( ) ) ;
77+ app . use ( nextMiddleware ) ;
7778
7879 request ( app . listen ( ) )
7980 . get ( '/' )
@@ -84,7 +85,31 @@ describe('ExpressOAuthServer', function() {
8485 oauth . server . authorize . firstCall . args [ 1 ] . should . be . an . instanceOf ( Response ) ;
8586 should . not . exist ( oauth . server . authorize . firstCall . args [ 2 ] ) ;
8687 oauth . server . authorize . restore ( ) ;
88+ nextMiddleware . called . should . be . false ( ) ;
89+ done ( ) ;
90+ } ) ;
91+ } ) ;
92+
93+ it ( 'should call `authorize()` and continue middleware chain' , function ( done ) {
94+ var nextMiddleware = sinon . spy ( )
95+ var oauth = new ExpressOAuthServer ( { model : { } , continueMiddleware : true } ) ;
8796
97+ sinon . stub ( oauth . server , 'authorize' ) . returns ( { } ) ;
98+
99+ app . use ( oauth . authorize ( ) ) ;
100+ app . use ( nextMiddleware ) ;
101+
102+ request ( app . listen ( ) )
103+ . get ( '/' )
104+ . end ( function ( ) {
105+ oauth . server . authorize . callCount . should . equal ( 1 ) ;
106+ oauth . server . authorize . firstCall . args . should . have . length ( 3 ) ;
107+ oauth . server . authorize . firstCall . args [ 0 ] . should . be . an . instanceOf ( Request ) ;
108+ oauth . server . authorize . firstCall . args [ 1 ] . should . be . an . instanceOf ( Response ) ;
109+ should . not . exist ( oauth . server . authorize . firstCall . args [ 2 ] ) ;
110+ oauth . server . authorize . restore ( ) ;
111+ nextMiddleware . called . should . be . true ( ) ;
112+ nextMiddleware . args [ 0 ] . length . should . eql ( 3 ) ;
88113 done ( ) ;
89114 } ) ;
90115 } ) ;
@@ -105,19 +130,20 @@ describe('ExpressOAuthServer', function() {
105130 oauth . server . authorize . firstCall . args [ 1 ] . should . be . an . instanceOf ( Response ) ;
106131 oauth . server . authorize . firstCall . args [ 2 ] . should . eql ( { options : true } ) ;
107132 oauth . server . authorize . restore ( ) ;
108-
109133 done ( ) ;
110134 } ) ;
111135 } ) ;
112136 } ) ;
113137
114138 describe ( 'token()' , function ( ) {
115- it ( 'should call `token()`' , function ( done ) {
139+ it ( 'should call `token()` and end middleware chain' , function ( done ) {
140+ var nextMiddleware = sinon . spy ( )
116141 var oauth = new ExpressOAuthServer ( { model : { } } ) ;
117142
118143 sinon . stub ( oauth . server , 'token' ) . returns ( { } ) ;
119144
120145 app . use ( oauth . token ( ) ) ;
146+ app . use ( nextMiddleware ) ;
121147
122148 request ( app . listen ( ) )
123149 . get ( '/' )
@@ -128,7 +154,31 @@ describe('ExpressOAuthServer', function() {
128154 oauth . server . token . firstCall . args [ 1 ] . should . be . an . instanceOf ( Response ) ;
129155 should . not . exist ( oauth . server . token . firstCall . args [ 2 ] ) ;
130156 oauth . server . token . restore ( ) ;
157+ nextMiddleware . called . should . be . false ( ) ;
158+ done ( ) ;
159+ } ) ;
160+ } ) ;
131161
162+ it ( 'should call `token()` and continue middleware chain' , function ( done ) {
163+ var nextMiddleware = sinon . spy ( )
164+ var oauth = new ExpressOAuthServer ( { model : { } , continueMiddleware : true } ) ;
165+
166+ sinon . stub ( oauth . server , 'token' ) . returns ( { } ) ;
167+
168+ app . use ( oauth . token ( ) ) ;
169+ app . use ( nextMiddleware ) ;
170+
171+ request ( app . listen ( ) )
172+ . get ( '/' )
173+ . end ( function ( ) {
174+ oauth . server . token . callCount . should . equal ( 1 ) ;
175+ oauth . server . token . firstCall . args . should . have . length ( 3 ) ;
176+ oauth . server . token . firstCall . args [ 0 ] . should . be . an . instanceOf ( Request ) ;
177+ oauth . server . token . firstCall . args [ 1 ] . should . be . an . instanceOf ( Response ) ;
178+ should . not . exist ( oauth . server . token . firstCall . args [ 2 ] ) ;
179+ oauth . server . token . restore ( ) ;
180+ nextMiddleware . called . should . be . true ( ) ;
181+ nextMiddleware . args [ 0 ] . length . should . eql ( 3 ) ;
132182 done ( ) ;
133183 } ) ;
134184 } ) ;
@@ -149,7 +199,6 @@ describe('ExpressOAuthServer', function() {
149199 oauth . server . token . firstCall . args [ 1 ] . should . be . an . instanceOf ( Response ) ;
150200 oauth . server . token . firstCall . args [ 2 ] . should . eql ( { options : true } ) ;
151201 oauth . server . token . restore ( ) ;
152-
153202 done ( ) ;
154203 } ) ;
155204 } ) ;
0 commit comments