mirror of
https://github.com/zulip/zulip.git
synced 2025-11-04 14:03:30 +00:00
coverage: Add test for REST requests to /json API unauthed.
This commit is contained in:
@@ -104,6 +104,7 @@ def rest_dispatch(request, **kwargs):
|
||||
# If this looks like a request from a top-level page in a
|
||||
# browser, send the user to the login page
|
||||
if 'text/html' in request.META.get('HTTP_ACCEPT', ''):
|
||||
# TODO: It seems like the `?next=` part is unlikely to be helpful
|
||||
return HttpResponseRedirect('%s/?next=%s' % (settings.HOME_NOT_LOGGED_IN, request.path))
|
||||
# Ask for basic auth (email:apiKey)
|
||||
elif request.path.startswith("/api"):
|
||||
|
||||
@@ -1023,3 +1023,10 @@ class RestAPITest(ZulipTestCase):
|
||||
result = self.client_options('/json/streams/15')
|
||||
self.assertEqual(result.status_code, 204)
|
||||
self.assertEqual(str(result['Allow']), 'DELETE, PATCH')
|
||||
|
||||
def test_http_accept_redirect(self):
|
||||
# type: () -> None
|
||||
result = self.client_get('/json/users',
|
||||
HTTP_ACCEPT='text/html')
|
||||
self.assertEqual(result.status_code, 302)
|
||||
self.assertTrue(result["Location"].endswith("/login/?next=/json/users"))
|
||||
|
||||
Reference in New Issue
Block a user