Skip to content

Commit cc5e9d5

Browse files
authored
Merge pull request #247 from MerginMaps/allow-mc-without-auth
allow client creation without authorization
2 parents e876fd1 + 82eb39d commit cc5e9d5

File tree

2 files changed

+22
-12
lines changed

2 files changed

+22
-12
lines changed

mergin/client.py

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -146,20 +146,15 @@ def __init__(
146146
self.opener = urllib.request.build_opener(*handlers, https_handler)
147147
urllib.request.install_opener(self.opener)
148148

149-
if login or password:
150-
if login and not password:
151-
raise ClientError("Unable to log in: no password provided for '{}'".format(login))
152-
if password and not login:
153-
raise ClientError("Unable to log in: password provided but no username/email")
149+
if login and not password:
150+
raise ClientError("Unable to log in: no password provided for '{}'".format(login))
151+
if password and not login:
152+
raise ClientError("Unable to log in: password provided but no username/email")
154153

155-
if login and password:
156-
self._auth_params = {"login": login, "password": password}
157-
if not self._auth_session:
158-
self.login(login, password)
159-
160-
else:
154+
if login and password:
155+
self._auth_params = {"login": login, "password": password}
161156
if not self._auth_session:
162-
raise ClientError("Unable to log in: no auth token provided for login")
157+
self.login(login, password)
163158

164159
def setup_logging(self):
165160
"""Setup Mergin Maps client logging."""

mergin/test/test_client.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2871,3 +2871,18 @@ def server_config(self):
28712871

28722872
with pytest.raises(ClientError, match="The requested URL was not found on the server"):
28732873
mc.send_logs(logs_path)
2874+
2875+
2876+
def test_mc_without_login():
2877+
2878+
# client without login should be able to access server config
2879+
mc = MerginClient(SERVER_URL)
2880+
config = mc.server_config()
2881+
assert config
2882+
assert isinstance(config, dict)
2883+
assert "server_configured" in config
2884+
assert config["server_configured"]
2885+
2886+
# without login should not be able to access workspaces
2887+
with pytest.raises(ClientError, match="Authentication information is missing or invalid."):
2888+
mc.workspaces_list()

0 commit comments

Comments
 (0)