From e4e52d635b253ad544c530e6a589ededc5519ca2 Mon Sep 17 00:00:00 2001 From: Jan Caha Date: Wed, 25 Jun 2025 13:54:24 +0200 Subject: [PATCH 1/5] allow client creation without authorization --- mergin/client.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/mergin/client.py b/mergin/client.py index 10089345..f2bf2245 100644 --- a/mergin/client.py +++ b/mergin/client.py @@ -157,10 +157,6 @@ def __init__( if not self._auth_session: self.login(login, password) - else: - if not self._auth_session: - raise ClientError("Unable to log in: no auth token provided for login") - def setup_logging(self): """Setup Mergin Maps client logging.""" client_log_file = os.environ.get("MERGIN_CLIENT_LOG", None) From 84ca9178ede91b6a1f01c72f10ab487ffd889d75 Mon Sep 17 00:00:00 2001 From: Jan Caha Date: Wed, 25 Jun 2025 14:02:13 +0200 Subject: [PATCH 2/5] add test --- mergin/test/test_client.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/mergin/test/test_client.py b/mergin/test/test_client.py index 31de795f..6a751074 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="The requested URL was not found on the server"): + mc.workspaces_list() From 51586109f5500a524c2c92c2f028fa620939d780 Mon Sep 17 00:00:00 2001 From: Jan Caha Date: Wed, 25 Jun 2025 14:34:47 +0200 Subject: [PATCH 3/5] simplify --- mergin/client.py | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/mergin/client.py b/mergin/client.py index f2bf2245..9e70a93c 100644 --- a/mergin/client.py +++ b/mergin/client.py @@ -146,16 +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 password: - self._auth_params = {"login": login, "password": password} - if not self._auth_session: - self.login(login, 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 password: + self._auth_params = {"login": login, "password": password} + if not self._auth_session: + self.login(login, password) def setup_logging(self): """Setup Mergin Maps client logging.""" From d7961a2c126fa6c9e219a628cfb739bba28e0203 Mon Sep 17 00:00:00 2001 From: Jan Caha Date: Wed, 25 Jun 2025 18:23:33 +0200 Subject: [PATCH 4/5] change error --- mergin/test/test_client.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/mergin/test/test_client.py b/mergin/test/test_client.py index 6a751074..14d6a594 100644 --- a/mergin/test/test_client.py +++ b/mergin/test/test_client.py @@ -10,6 +10,7 @@ import pytz import sqlite3 import glob +from urllib.error import HTTPError from .. import InvalidProject from ..client import ( @@ -2884,5 +2885,5 @@ def test_mc_without_login(): assert config["server_configured"] # without login should not be able to access workspaces - with pytest.raises(ClientError, match="The requested URL was not found on the server"): + with pytest.raises(HTTPError): mc.workspaces_list() From 82eb39ddd1925abcb2012a93ca1e1315f0bed836 Mon Sep 17 00:00:00 2001 From: Jan Caha Date: Wed, 25 Jun 2025 20:20:31 +0200 Subject: [PATCH 5/5] fix catch error --- mergin/test/test_client.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/mergin/test/test_client.py b/mergin/test/test_client.py index 14d6a594..f3d4c4b1 100644 --- a/mergin/test/test_client.py +++ b/mergin/test/test_client.py @@ -10,7 +10,6 @@ import pytz import sqlite3 import glob -from urllib.error import HTTPError from .. import InvalidProject from ..client import ( @@ -2885,5 +2884,5 @@ def test_mc_without_login(): assert config["server_configured"] # without login should not be able to access workspaces - with pytest.raises(HTTPError): + with pytest.raises(ClientError, match="Authentication information is missing or invalid."): mc.workspaces_list()