Add test for gzip compression in share mode

This commit is contained in:
Miguel Jacq 2023-05-30 16:23:31 +10:00
parent e434c0463c
commit 32bb224d20
No known key found for this signature in database
GPG Key ID: 59B3F0C24135C6A9
2 changed files with 34 additions and 0 deletions

View File

@ -58,6 +58,13 @@ class GuiBaseTest(unittest.TestCase):
"<html><body><p>This is a test website hosted by OnionShare</p></body></html>" "<html><body><p>This is a test website hosted by OnionShare</p></body></html>"
) )
# A file called "test.html"
cls.tmpfile_test_html = os.path.join(cls.tmpdir.name, "test.html")
with open(cls.tmpfile_test_html, "w") as file:
file.write(
"<html><body><p>Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem. Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur? Quis autem vel eum iure reprehenderit qui in ea voluptate velit esse quam nihil molestiae consequatur, vel illum qui dolorem eum fugiat quo voluptas nulla pariatur?</p></body></html>"
)
# A large file # A large file
size = 1024 * 1024 * 155 size = 1024 * 1024 * 155
cls.tmpfile_large = os.path.join(cls.tmpdir.name, "large_file") cls.tmpfile_large = os.path.join(cls.tmpdir.name, "large_file")

View File

@ -541,3 +541,30 @@ class TestShare(GuiBaseTest):
self.hit_405(url, expected_resp="OnionShare: 405 Method Not Allowed", data = {'foo':'bar'}, methods = ["put", "post", "delete", "options"]) self.hit_405(url, expected_resp="OnionShare: 405 Method Not Allowed", data = {'foo':'bar'}, methods = ["put", "post", "delete", "options"])
self.history_widgets_present(tab) self.history_widgets_present(tab)
self.close_all_tabs() self.close_all_tabs()
def test_1_compression(self):
"""
A file with a compressable mimetype should return a Content-Encoding header
with gzip compression enabled.
"""
tab = self.new_share_tab()
tab.get_mode().autostop_sharing_checkbox.click()
self.run_all_common_setup_tests()
self.run_all_share_mode_setup_tests(tab)
tab.get_mode().mode_settings_widget.public_checkbox.click()
tab.get_mode().remove_all_button.click()
tab.get_mode().server_status.file_selection.file_list.add_file(
self.tmpfile_test_html
)
self.run_all_share_mode_started_tests(tab)
url = f"http://127.0.0.1:{tab.app.port}/test.html"
r = requests.get(url)
self.assertTrue("Content-Encoding" in r.headers)
self.assertEqual("gzip", r.headers["Content-Encoding"])
self.server_is_stopped(tab)
self.web_server_is_stopped(tab)
self.server_status_indicator_says_closed(tab)
self.close_all_tabs()