@@ -59,7 +59,10 @@ describe('ExpressOAuthServer', function() {
5959 } ) ;
6060
6161 it ( 'should authenticate the request' , function ( done ) {
62- var token = { user : { } } ;
62+ var tokenExpires = new Date ( ) ;
63+ tokenExpires . setDate ( tokenExpires . getDate ( ) + 1 ) ;
64+
65+ var token = { user : { } , accessTokenExpiresAt : tokenExpires } ;
6366 var model = {
6467 getAccessToken : function ( ) {
6568 return token ;
@@ -83,7 +86,9 @@ describe('ExpressOAuthServer', function() {
8386 } ) ;
8487
8588 it ( 'should cache the authorization token' , function ( done ) {
86- var token = { user : { } } ;
89+ var tokenExpires = new Date ( ) ;
90+ tokenExpires . setDate ( tokenExpires . getDate ( ) + 1 ) ;
91+ var token = { user : { } , accessTokenExpiresAt : tokenExpires } ;
8792 var model = {
8893 getAccessToken : function ( ) {
8994 return token ;
@@ -95,27 +100,30 @@ describe('ExpressOAuthServer', function() {
95100
96101 var spy = sinon . spy ( function ( req , res , next ) {
97102 res . locals . oauth . token . should . equal ( token ) ;
98-
103+ res . send ( token ) ;
99104 next ( ) ;
100105 } ) ;
101106 app . use ( spy ) ;
102107
103108 request ( app . listen ( ) )
104109 . get ( '/' )
105110 . set ( 'Authorization' , 'Bearer foobar' )
106- . expect ( 200 , function ( ) {
107- spy . called . should . be . true ;
108- done ( ) ;
111+ . expect ( 200 , function ( err , res ) {
112+ spy . called . should . be . True ( ) ;
113+ done ( err ) ;
109114 } ) ;
110115 } ) ;
111116 } ) ;
112117
113118 describe ( 'authorize()' , function ( ) {
114119 it ( 'should cache the authorization code' , function ( done ) {
120+ var tokenExpires = new Date ( ) ;
121+ tokenExpires . setDate ( tokenExpires . getDate ( ) + 1 ) ;
122+
115123 var code = { authorizationCode : 123 } ;
116124 var model = {
117125 getAccessToken : function ( ) {
118- return { user : { } } ;
126+ return { user : { } , accessTokenExpiresAt : tokenExpires } ;
119127 } ,
120128 getClient : function ( ) {
121129 return { grants : [ 'authorization_code' ] , redirectUris : [ 'http://example.com' ] } ;
@@ -138,16 +146,16 @@ describe('ExpressOAuthServer', function() {
138146 . post ( '/?state=foobiz' )
139147 . set ( 'Authorization' , 'Bearer foobar' )
140148 . send ( { client_id : 12345 , response_type : 'code' } )
141- . expect ( 200 , function ( ) {
142- spy . called . should . be . true ;
143- done ( ) ;
149+ . expect ( 302 , function ( err , res ) {
150+ spy . called . should . be . True ( ) ;
151+ done ( err ) ;
144152 } ) ;
145153 } ) ;
146154
147- it ( 'should return a `location` header with the error' , function ( done ) {
155+ it ( 'should return an error' , function ( done ) {
148156 var model = {
149157 getAccessToken : function ( ) {
150- return { user : { } } ;
158+ return { user : { } , accessTokenExpiresAt : new Date ( ) } ;
151159 } ,
152160 getClient : function ( ) {
153161 return { grants : [ 'authorization_code' ] , redirectUris : [ 'http://example.com' ] } ;
@@ -164,14 +172,17 @@ describe('ExpressOAuthServer', function() {
164172 . post ( '/?state=foobiz' )
165173 . set ( 'Authorization' , 'Bearer foobar' )
166174 . send ( { client_id : 12345 } )
167- . expect ( 'Location' , 'http://example.com/?error=invalid_request&error_description=Missing%20parameter%3A%20%60response_type%60&state=foobiz' )
168- . end ( done ) ;
175+ . expect ( 400 , function ( err , res ) {
176+ res . body . error . should . eql ( 'invalid_request' ) ;
177+ res . body . error_description . should . eql ( 'Missing parameter: `response_type`' ) ;
178+ done ( err ) ;
179+ } ) ;
169180 } ) ;
170181
171182 it ( 'should return a `location` header with the code' , function ( done ) {
172183 var model = {
173184 getAccessToken : function ( ) {
174- return { user : { } } ;
185+ return { user : { } , accessTokenExpiresAt : new Date ( ) } ;
175186 } ,
176187 getClient : function ( ) {
177188 return { grants : [ 'authorization_code' ] , redirectUris : [ 'http://example.com' ] } ;
@@ -232,9 +243,9 @@ describe('ExpressOAuthServer', function() {
232243 . post ( '/' )
233244 . send ( 'client_id=foo&client_secret=bar&grant_type=password&username=qux&password=biz' )
234245 . expect ( { access_token : 'foobar' , token_type : 'Bearer' } )
235- . expect ( 200 , function ( ) {
236- spy . called . should . be . true ;
237- done ( ) ;
246+ . expect ( 200 , function ( err , res ) {
247+ spy . called . should . be . True ( ) ;
248+ done ( err ) ;
238249 } ) ;
239250 } ) ;
240251
0 commit comments