diff --git a/mergin/client.py b/mergin/client.py index 10089345..9e70a93c 100644 --- a/mergin/client.py +++ b/mergin/client.py @@ -146,20 +146,15 @@ def __init__( self.opener = urllib.request.build_opener(*handlers, https_handler) urllib.request.install_opener(self.opener) - if login or password: - if login and not password: - raise ClientError("Unable to log in: no password provided for '{}'".format(login)) - if password and not login: - raise ClientError("Unable to log in: password provided but no username/email") + if login and not password: + raise ClientError("Unable to log in: no password provided for '{}'".format(login)) + if password and not login: + raise ClientError("Unable to log in: password provided but no username/email") - if login and password: - self._auth_params = {"login": login, "password": password} - if not self._auth_session: - self.login(login, password) - - else: + if login and password: + self._auth_params = {"login": login, "password": password} if not self._auth_session: - raise ClientError("Unable to log in: no auth token provided for login") + self.login(login, password) def setup_logging(self): """Setup Mergin Maps client logging.""" diff --git a/mergin/test/test_client.py b/mergin/test/test_client.py index 31de795f..f3d4c4b1 100644 --- a/mergin/test/test_client.py +++ b/mergin/test/test_client.py @@ -2871,3 +2871,18 @@ def server_config(self): with pytest.raises(ClientError, match="The requested URL was not found on the server"): mc.send_logs(logs_path) + + +def test_mc_without_login(): + + # client without login should be able to access server config + mc = MerginClient(SERVER_URL) + config = mc.server_config() + assert config + assert isinstance(config, dict) + assert "server_configured" in config + assert config["server_configured"] + + # without login should not be able to access workspaces + with pytest.raises(ClientError, match="Authentication information is missing or invalid."): + mc.workspaces_list()