diff --git a/onionshare/web.py b/onionshare/web.py index 8d80810b..006150e9 100644 --- a/onionshare/web.py +++ b/onionshare/web.py @@ -246,9 +246,13 @@ class Web(object): # Close the server, if necessary if not self.stay_open and not canceled: print(strings._("closing_automatically")) - if shutdown_func is None: - raise RuntimeError('Not running with the Werkzeug Server') - shutdown_func() + self.running = False + try: + if shutdown_func is None: + raise RuntimeError('Not running with the Werkzeug Server') + shutdown_func() + except: + pass r = Response(generate()) r.headers.set('Content-Length', self.zip_filesize) diff --git a/test/test_onionshare_web.py b/test/test_onionshare_web.py index cfcf8719..f96b0c60 100644 --- a/test/test_onionshare_web.py +++ b/test/test_onionshare_web.py @@ -42,6 +42,8 @@ def web_obj(common_obj, recieve_mode, num_files=0): web = Web(common_obj, False, recieve_mode) web.generate_slug() web.stay_open = True + web.running = True + web.app.testing = True # Share mode @@ -67,22 +69,38 @@ class TestWeb: with web.app.test_client() as c: # Load 404 pages res = c.get('/') + res.get_data() assert res.status_code == 404 res = c.get('/invalidslug'.format(web.slug)) + res.get_data() assert res.status_code == 404 # Load download page res = c.get('/{}'.format(web.slug)) + res.get_data() assert res.status_code == 200 # Download res = c.get('/{}/download'.format(web.slug)) + res.get_data() assert res.status_code == 200 assert res.mimetype == 'application/zip' def test_share_mode_close_after_first_download(self, common_obj, temp_file_1024): - pass + web = web_obj(common_obj, False, 3) + web.stay_open = False + + assert web.running == True + + with web.app.test_client() as c: + # Download the first time + res = c.get('/{}/download'.format(web.slug)) + res.get_data() + assert res.status_code == 200 + assert res.mimetype == 'application/zip' + + assert web.running == False class TestZipWriterDefault: