From 9c0282139a0969c8a9e4b4dfb43ceffe60ab0aea Mon Sep 17 00:00:00 2001 From: Steve Howell Date: Fri, 16 Sep 2016 08:32:55 -0700 Subject: [PATCH] tests: Add test_serve_s3_error_handling(). --- zerver/tests/test_upload.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/zerver/tests/test_upload.py b/zerver/tests/test_upload.py index 38e0d31d7e..7b1c51fe20 100644 --- a/zerver/tests/test_upload.py +++ b/zerver/tests/test_upload.py @@ -118,6 +118,30 @@ class FileUploadTest(ZulipTestCase): self.assertEquals(response.status_code, 404) self.assertIn('File not found', str(response.content)) + def test_serve_s3_error_handling(self): + # type: () -> None + self.login("hamlet@zulip.com") + use_s3 = lambda: self.settings(LOCAL_UPLOADS_DIR=None) + getting_realm_id = lambda realm_id: mock.patch( + 'zerver.views.upload.get_realm_for_filename', + return_value=realm_id + ) + + # nonexistent_file + with use_s3(), getting_realm_id(None): + response = self.client_get('/user_uploads/unk/nonexistent_file') + self.assertEquals(response.status_code, 404) + self.assertIn('File not found', str(response.content)) + + # invalid realm of 999999 (for non-zulip.com) + user = get_user_profile_by_email('hamlet@zulip.com') + user.realm.domain = 'example.com' + user.realm.save() + + with use_s3(), getting_realm_id(999999): + response = self.client_get('/user_uploads/unk/whatever') + self.assertEquals(response.status_code, 403) + # This test will go through the code path for uploading files onto LOCAL storage # when zulip is in DEVELOPMENT mode. def test_file_upload_authed(self):