diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 911e0af5..1b5b969e 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -34,6 +34,7 @@ jobs: poetry run onionshare-cli --local-only --receive --auto-stop-timer 2 --qr --verbose poetry run onionshare-cli --local-only --website ../docs --auto-stop-timer 2 --qr --verbose poetry run onionshare-cli --local-only --chat --auto-stop-timer 5 --qr --verbose + touch /tmp/foo{1,2} && poetry run onionshare-cli --local-only --persistent tests/persistent.json --auto-stop-timer 5 --verbose test-desktop: runs-on: ubuntu-latest diff --git a/cli/onionshare_cli/__init__.py b/cli/onionshare_cli/__init__.py index 3ea0d76d..e15ecda1 100644 --- a/cli/onionshare_cli/__init__.py +++ b/cli/onionshare_cli/__init__.py @@ -33,6 +33,7 @@ from .onionshare import OnionShare from .mode_settings import ModeSettings from qrcode import QRCode + def main(cwd=None): """ The main() function implements all of the logic that the command-line version of @@ -124,7 +125,7 @@ def main(cwd=None): action="store_true", dest="log_filenames", default=False, - help="Log file download activity to stdout" + help="Log file download activity to stdout", ) parser.add_argument( "--qr", @@ -260,7 +261,9 @@ def main(cwd=None): mode_settings.set("receive", "disable_files", disable_files) if mode == "website": if disable_csp and custom_csp: - print("You cannot disable the CSP and set a custom one. Either set --disable-csp or --custom-csp but not both.") + print( + "You cannot disable the CSP and set a custom one. Either set --disable-csp or --custom-csp but not both." + ) sys.exit() if disable_csp: mode_settings.set("website", "disable_csp", True) @@ -277,19 +280,18 @@ def main(cwd=None): if mode == "share" or mode == "website": # Unless you passed in a persistent filename, in which case get the filenames from # the mode settings - if ( - persistent_filename - and not mode_settings.just_created - and len(filenames) != 0 - ): + if persistent_filename and not mode_settings.just_created: + # The assumption is that if we didn't just create the mode settings, + # this persistent json file already has validated the filenames + # defined therein. filenames = mode_settings.get(mode, "filenames") - else: - # Make sure filenames given if not using receiver mode + # Make sure filenames given. If it is somehow empty yet we had a persistent + # json file, something has gone wrong with that file, just remove it. if len(filenames) == 0: if persistent_filename: mode_settings.delete() - + print("No file(s) were provided") parser.print_help() sys.exit() @@ -515,7 +517,11 @@ def main(cwd=None): if not app.autostop_timer_thread.is_alive(): if mode == "share": # If there were no attempts to download the share, or all downloads are done, we can stop - if not web.share_mode.download_in_progress or web.share_mode.cur_history_id == 0 or web.done: + if ( + not web.share_mode.download_in_progress + or web.share_mode.cur_history_id == 0 + or web.done + ): print("Stopped because auto-stop timer ran out") web.stop(app.port) break diff --git a/cli/onionshare_cli/mode_settings.py b/cli/onionshare_cli/mode_settings.py index cfd9971c..a534a181 100644 --- a/cli/onionshare_cli/mode_settings.py +++ b/cli/onionshare_cli/mode_settings.py @@ -51,6 +51,7 @@ class ModeSettings: "autostart_timer": False, "autostop_timer": False, "service_id": None, + "qr": False }, "share": { "autostop_sharing": True, diff --git a/cli/tests/persistent.json b/cli/tests/persistent.json new file mode 100644 index 00000000..ab2f31d2 --- /dev/null +++ b/cli/tests/persistent.json @@ -0,0 +1,41 @@ +{ + "onion": { + "private_key": "cDGn/lagkwEa62rj+SxSXqFjfSG08fVLVDyZ8HgOS32J9JorEPPWVjDF3GRFolqDTNeUpqNDy39j0E86tqbJag==", + "client_auth_priv_key": "TYIU3TRRXWCQBSJYYRKOTR35M32YWNKQ3VBDGFDR74ASOW243OTA", + "client_auth_pub_key": "62VXAPXH5HTODLCGL7CNZHA3Q3OKJEPVLV2UGUKQUCZ5GW3YTAAQ" + }, + "persistent": { + "mode": "share", + "enabled": true, + "autostart_on_launch": false + }, + "general": { + "title": null, + "public": false, + "autostart_timer": false, + "autostop_timer": true, + "service_id": "frlqrdrt4arsgnp4xenzoug5osmfqaqdbniuf4ziejoiwnhju3jlazid", + "qr": false + }, + "share": { + "autostop_sharing": false, + "filenames": [ + "/tmp/foo1", + "/tmp/foo2" + ], + "log_filenames": false + }, + "receive": { + "data_dir": "/tmp", + "webhook_url": null, + "disable_text": false, + "disable_files": false + }, + "website": { + "disable_csp": false, + "custom_csp": null, + "log_filenames": false, + "filenames": [] + }, + "chat": {} +} \ No newline at end of file