Skip to content
Snippets Groups Projects
Commit 5236bca3 authored by Timm Fitschen's avatar Timm Fitschen Committed by Henrik tom Wörden
Browse files

BUG: anonymous user in python requires prior login

parent 5e6a6c72
Branches
Tags
No related merge requests found
...@@ -25,6 +25,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ...@@ -25,6 +25,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixed ### Fixed
- #1 - Problems with pass as a credentials provider - #1 - Problems with pass as a credentials provider
- #3 - Python client does login before the first request to circumvent problems
with anonymous role.
......
...@@ -148,6 +148,8 @@ class AbstractAuthenticator(ABC): ...@@ -148,6 +148,8 @@ class AbstractAuthenticator(ABC):
Returns Returns
------- -------
""" """
if self.auth_token is None:
self.login()
if self.auth_token is not None: if self.auth_token is not None:
headers['Cookie'] = auth_token_to_cookie(self.auth_token) headers['Cookie'] = auth_token_to_cookie(self.auth_token)
......
...@@ -75,7 +75,14 @@ class MockUpServerConnection(CaosDBServerConnection): ...@@ -75,7 +75,14 @@ class MockUpServerConnection(CaosDBServerConnection):
just returns predefined responses which mimic the caosdb server.""" just returns predefined responses which mimic the caosdb server."""
def __init__(self): def __init__(self):
self.resources = [] self.resources = [self._login]
def _login(self, method, path, headers, body):
if method == "POST" and path == "login":
return MockUpResponse(200,
headers={"AuthToken":
"mockup-auth-token"},
body="")
def configure(self, **kwargs): def configure(self, **kwargs):
"""This configure method does nothing.""" """This configure method does nothing."""
......
[tox] [tox]
envlist= py27, py34, py35, py36, py37 envlist=py34, py35, py36, py37
skip_missing_interpreters = true skip_missing_interpreters = true
[testenv] [testenv]
deps=nose deps=nose
......
...@@ -29,8 +29,9 @@ from caosdb import administration, configure_connection, get_connection ...@@ -29,8 +29,9 @@ from caosdb import administration, configure_connection, get_connection
from caosdb.connection.mockup import MockUpServerConnection, MockUpResponse from caosdb.connection.mockup import MockUpServerConnection, MockUpResponse
def setup(): def setup_module():
configure_connection(url="unittests", username="testuser", configure_connection(url="unittests", username="testuser",
password_method="plain",
password="testpassword", timeout=200, password="testpassword", timeout=200,
implementation=MockUpServerConnection) implementation=MockUpServerConnection)
......
...@@ -125,9 +125,9 @@ def test_connection_interface(): ...@@ -125,9 +125,9 @@ def test_connection_interface():
def test_use_mockup_implementation(): def test_use_mockup_implementation():
configure_connection(implementation=MockUpServerConnection)
with raiz(RuntimeError) as rerr: with raiz(RuntimeError) as rerr:
execute_query("FIND Something") execute_query("FIND Something")
print(rerr.exception.args[0])
eq(rerr.exception.args[0], eq(rerr.exception.args[0],
"No response for this request - GET: Entity?query=FIND%20Something") "No response for this request - GET: Entity?query=FIND%20Something")
...@@ -180,10 +180,10 @@ def test_init_connection(): ...@@ -180,10 +180,10 @@ def test_init_connection():
def test_resources_list(): def test_resources_list():
connection = test_init_connection() connection = test_init_connection()
tru(hasattr(connection, "resources")) assert hasattr(connection, "resources")
falz(connection.resources) assert len(connection.resources) == 1
connection.resources.append(lambda **kwargs: test_init_response()) connection.resources.append(lambda **kwargs: test_init_response())
tru(connection.resources) assert len(connection.resources) == 2
return connection return connection
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment