@@ -132,6 +132,57 @@ describe('AuthenticateHandler integration', function() {
132
132
} ) ;
133
133
} ) ;
134
134
135
+ it ( 'should set the `WWW-Authenticate` header if an InvalidRequestError is thrown' , function ( ) {
136
+ const model = {
137
+ getAccessToken : function ( ) {
138
+ throw new InvalidRequestError ( ) ;
139
+ }
140
+ } ;
141
+ const handler = new AuthenticateHandler ( { model : model } ) ;
142
+ const request = new Request ( { body : { } , headers : { 'Authorization' : 'Bearer foo' } , method : { } , query : { } } ) ;
143
+ const response = new Response ( { body : { } , headers : { } } ) ;
144
+
145
+ return handler . handle ( request , response )
146
+ . then ( should . fail )
147
+ . catch ( function ( ) {
148
+ response . get ( 'WWW-Authenticate' ) . should . equal ( 'Bearer realm="Service",error="invalid_request"' ) ;
149
+ } ) ;
150
+ } ) ;
151
+
152
+ it ( 'should set the `WWW-Authenticate` header if an InvalidTokenError is thrown' , function ( ) {
153
+ const model = {
154
+ getAccessToken : function ( ) {
155
+ throw new InvalidTokenError ( ) ;
156
+ }
157
+ } ;
158
+ const handler = new AuthenticateHandler ( { model : model } ) ;
159
+ const request = new Request ( { body : { } , headers : { 'Authorization' : 'Bearer foo' } , method : { } , query : { } } ) ;
160
+ const response = new Response ( { body : { } , headers : { } } ) ;
161
+
162
+ return handler . handle ( request , response )
163
+ . then ( should . fail )
164
+ . catch ( function ( ) {
165
+ response . get ( 'WWW-Authenticate' ) . should . equal ( 'Bearer realm="Service",error="invalid_token"' ) ;
166
+ } ) ;
167
+ } ) ;
168
+
169
+ it ( 'should set the `WWW-Authenticate` header if an InsufficientScopeError is thrown' , function ( ) {
170
+ const model = {
171
+ getAccessToken : function ( ) {
172
+ throw new InsufficientScopeError ( ) ;
173
+ }
174
+ } ;
175
+ const handler = new AuthenticateHandler ( { model : model } ) ;
176
+ const request = new Request ( { body : { } , headers : { 'Authorization' : 'Bearer foo' } , method : { } , query : { } } ) ;
177
+ const response = new Response ( { body : { } , headers : { } } ) ;
178
+
179
+ return handler . handle ( request , response )
180
+ . then ( should . fail )
181
+ . catch ( function ( ) {
182
+ response . get ( 'WWW-Authenticate' ) . should . equal ( 'Bearer realm="Service",error="insufficient_scope"' ) ;
183
+ } ) ;
184
+ } ) ;
185
+
135
186
it ( 'should throw the error if an oauth error is thrown' , function ( ) {
136
187
const model = {
137
188
getAccessToken : function ( ) {
0 commit comments