@@ -123,6 +123,7 @@ async def test_no_keys_to_decode_with(single_tenant_app, mock_openid_and_empty_k
123
123
'detail' : {'error' : 'invalid_token' , 'message' : 'Unable to verify token, no signing keys found' }
124
124
}
125
125
assert response .status_code == 401
126
+ assert response .headers ['www-authenticate' ] == 'Bearer'
126
127
127
128
128
129
@pytest .mark .anyio
@@ -159,6 +160,7 @@ async def test_invalid_token_claims(single_tenant_app, mock_openid_and_keys):
159
160
response = await ac .get ('api/v1/hello' )
160
161
assert response .json () == {'detail' : {'error' : 'invalid_token' , 'message' : 'Token contains invalid claims' }}
161
162
assert response .status_code == 401
163
+ assert response .headers ['www-authenticate' ] == 'Bearer'
162
164
163
165
164
166
@pytest .mark .anyio
@@ -173,6 +175,7 @@ async def test_no_valid_keys_for_token(single_tenant_app, mock_openid_and_no_val
173
175
'detail' : {'error' : 'invalid_token' , 'message' : 'Unable to verify token, no signing keys found' }
174
176
}
175
177
assert response .status_code == 401
178
+ assert response .headers ['www-authenticate' ] == 'Bearer'
176
179
177
180
178
181
@pytest .mark .anyio
@@ -211,6 +214,7 @@ async def test_no_valid_invalid_formatted_scope(single_tenant_app, mock_openid_a
211
214
'detail' : {'error' : 'insufficient_scope' , 'message' : 'Token contains invalid formatted scopes' }
212
215
}
213
216
assert response .status_code == 403
217
+ assert response .headers ['www-authenticate' ] == 'Bearer'
214
218
215
219
216
220
@pytest .mark .anyio
@@ -223,6 +227,7 @@ async def test_expired_token(single_tenant_app, mock_openid_and_keys):
223
227
response = await ac .get ('api/v1/hello' )
224
228
assert response .json () == {'detail' : {'error' : 'invalid_token' , 'message' : 'Token signature has expired' }}
225
229
assert response .status_code == 401
230
+ assert response .headers ['www-authenticate' ] == 'Bearer'
226
231
227
232
228
233
@pytest .mark .anyio
@@ -236,6 +241,7 @@ async def test_evil_token(single_tenant_app, mock_openid_and_keys):
236
241
response = await ac .get ('api/v1/hello' )
237
242
assert response .json () == {'detail' : {'error' : 'invalid_token' , 'message' : 'Unable to validate token' }}
238
243
assert response .status_code == 401
244
+ assert response .headers ['www-authenticate' ] == 'Bearer'
239
245
240
246
241
247
@pytest .mark .anyio
@@ -247,6 +253,10 @@ async def test_malformed_token(single_tenant_app, mock_openid_and_keys):
247
253
response = await ac .get ('api/v1/hello' )
248
254
assert response .json () == {'detail' : {'error' : 'invalid_token' , 'message' : 'Invalid token format' }}
249
255
assert response .status_code == 401
256
+ assert (
257
+ response .headers ['www-authenticate' ]
258
+ == 'Bearer, authorization_uri="https://login.microsoftonline.com/intility_tenant_id/oauth2/v2.0/authorize", client_id="oauth299-9999-9999-abcd-efghijkl1234567890"'
259
+ )
250
260
251
261
252
262
@pytest .mark .anyio
@@ -263,6 +273,10 @@ async def test_only_header(single_tenant_app, mock_openid_and_keys):
263
273
response = await ac .get ('api/v1/hello' )
264
274
assert response .json () == {'detail' : {'error' : 'invalid_token' , 'message' : 'Invalid token format' }}
265
275
assert response .status_code == 401
276
+ assert (
277
+ response .headers ['www-authenticate' ]
278
+ == 'Bearer, authorization_uri="https://login.microsoftonline.com/intility_tenant_id/oauth2/v2.0/authorize", client_id="oauth299-9999-9999-abcd-efghijkl1234567890"'
279
+ )
266
280
267
281
268
282
@pytest .mark .anyio
@@ -276,6 +290,10 @@ async def test_none_token(single_tenant_app, mock_openid_and_keys, mocker):
276
290
response = await ac .get ('api/v1/hello' )
277
291
assert response .json () == {'detail' : {'error' : 'invalid_token' , 'message' : 'Invalid token format' }}
278
292
assert response .status_code == 401
293
+ assert (
294
+ response .headers ['www-authenticate' ]
295
+ == 'Bearer, authorization_uri="https://login.microsoftonline.com/intility_tenant_id/oauth2/v2.0/authorize", client_id="oauth299-9999-9999-abcd-efghijkl1234567890"'
296
+ )
279
297
280
298
281
299
@pytest .mark .anyio
@@ -289,6 +307,8 @@ async def test_exception_raised(single_tenant_app, mock_openid_and_keys, mocker)
289
307
response = await ac .get ('api/v1/hello' )
290
308
assert response .json () == {'detail' : {'error' : 'invalid_token' , 'message' : 'Unable to process token' }}
291
309
assert response .status_code == 401
310
+ print (f"header: { response .headers .get ('www-authenticate' )} " )
311
+ assert response .headers ['www-authenticate' ] == 'Bearer'
292
312
293
313
294
314
@pytest .mark .anyio
@@ -316,6 +336,7 @@ async def test_change_of_keys_works(single_tenant_app, mock_openid_ok_then_empty
316
336
'detail' : {'error' : 'invalid_token' , 'message' : 'Unable to verify token, no signing keys found' }
317
337
}
318
338
assert second_resonse .status_code == 401
339
+ assert 'www-authenticate' not in response .headers
319
340
320
341
321
342
@pytest .mark .anyio
0 commit comments