diff --git a/securedrop_client/app.py b/securedrop_client/app.py index ea9c7c820..85cf1db6c 100644 --- a/securedrop_client/app.py +++ b/securedrop_client/app.py @@ -105,6 +105,9 @@ def arg_parser() -> ArgumentParser: type=expand_to_absolute, help=('SecureDrop Client home directory for storing files and state. ' '(Default {})'.format(DEFAULT_SDC_HOME))) + parser.add_argument( + '--proxy', action='store_true', + help='Use proxy AppVM name to connect to server.') return parser @@ -139,7 +142,8 @@ def start_app(args, qt_args) -> None: Session = sessionmaker(bind=engine) session = Session() - client = Client("http://localhost:8081/", gui, session, args.sdc_home) + client = Client("http://localhost:8081/", gui, session, + args.sdc_home, args.proxy) client.setup() configure_signal_handlers(app) @@ -151,13 +155,14 @@ def start_app(args, qt_args) -> None: def run() -> None: - config_file = "/etc/securdrop-client/client.ini" + config_file = "/etc/securedrop-client/client.ini" args, qt_args = arg_parser().parse_known_args() - if args.sdc_home == DEFAULT_SDC_HOME and \ + if args.sdc_home == expand_to_absolute(DEFAULT_SDC_HOME) and \ os.path.exists(config_file): # pragma: no cover config = configparser.ConfigParser() config.read(config_file) args.sdc_home = config["client"]["homedir"] + args.proxy = config["client"]["use_securedrop_proxy"] # reinsert the program's name qt_args.insert(0, 'securedrop-client') start_app(args, qt_args) diff --git a/securedrop_client/logic.py b/securedrop_client/logic.py index cd7277aee..4d1fe9f87 100644 --- a/securedrop_client/logic.py +++ b/securedrop_client/logic.py @@ -85,7 +85,8 @@ class Client(QObject): finish_api_call = pyqtSignal() # Acknowledges reciept of an API call. - def __init__(self, hostname, gui, session, home: str) -> None: + def __init__(self, hostname, gui, session, + home: str, proxy: bool = False) -> None: """ The hostname, gui and session objects are used to coordinate with the various other layers of the application: the location of the SecureDrop @@ -103,6 +104,7 @@ def __init__(self, hostname, gui, session, home: str) -> None: self.sync_flag = os.path.join(home, 'sync_flag') self.home = home # The "home" directory for client files. self.data_dir = os.path.join(self.home, 'data') # File data. + self.proxy = proxy def setup(self): """ @@ -159,7 +161,8 @@ def login(self, username, password, totp): Given a username, password and time based one-time-passcode (TOTP), create a new instance representing the SecureDrop api and authenticate. """ - self.api = sdclientapi.API(self.hostname, username, password, totp) + self.api = sdclientapi.API(self.hostname, username, + password, totp, self.proxy) self.call_api(self.api.authenticate, self.on_authenticate, self.on_login_timeout) diff --git a/tests/test_app.py b/tests/test_app.py index 01381a2ae..ccb5e3c44 100644 --- a/tests/test_app.py +++ b/tests/test_app.py @@ -55,6 +55,7 @@ def test_start_app(safe_tmpdir): mock_qt_args = mock.MagicMock() sdc_home = str(safe_tmpdir) mock_args.sdc_home = sdc_home + mock_args.proxy = False with mock.patch('securedrop_client.app.configure_logging') as conf_log, \ mock.patch('securedrop_client.app.QApplication') as mock_app, \ @@ -68,7 +69,7 @@ def test_start_app(safe_tmpdir): mock_win.assert_called_once_with() mock_client.assert_called_once_with('http://localhost:8081/', mock_win(), mock_session_class(), - sdc_home) + sdc_home, False) PERMISSIONS_CASES = [