Skip to content
Snippets Groups Projects
Commit 6a9d6561 authored by Florian Spreckelsen's avatar Florian Spreckelsen
Browse files

Merge branch 'f-fix-login-failed-on-long-request' into 'dev'

Prevent auth_token from being overwritten with None

See merge request !162
parents 0e81a8e3 7796b956
Branches
Tags
2 merge requests!175BUG: Request responses without the "Set-Cookie" header no longer overwrite the...,!162Prevent auth_token from being overwritten with None
Pipeline #58256 passed
...@@ -19,6 +19,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ...@@ -19,6 +19,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* [#89](https://gitlab.com/linkahead/linkahead-pylib/-/issues/89) * [#89](https://gitlab.com/linkahead/linkahead-pylib/-/issues/89)
`to_xml` does not add `noscript` or `TransactionBenchmark` tags anymore `to_xml` does not add `noscript` or `TransactionBenchmark` tags anymore
* [#103](https://gitlab.com/linkahead/linkahead-pylib/-/issues/103)
`authentication/interface/on_response()` does not overwrite
`auth_token` if new value is `None`
### Security ### ### Security ###
...@@ -50,7 +53,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ...@@ -50,7 +53,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixed ### ### Fixed ###
* [gitlab.indiscale.com#200](https://gitlab.indiscale.com/caosdb/src/caosdb-pylib/-/merge_requests/153) * [gitlab.indiscale.com#200](https://gitlab.indiscale.com/caosdb/src/caosdb-pylib/-/issues/200)
``linkahead_admin.py`` prints reasonable error messages when users ``linkahead_admin.py`` prints reasonable error messages when users
or roles don't exist. or roles don't exist.
......
...@@ -125,8 +125,9 @@ class AbstractAuthenticator(ABC): ...@@ -125,8 +125,9 @@ class AbstractAuthenticator(ABC):
Returns Returns
------- -------
""" """
self.auth_token = parse_auth_token( new_token = parse_auth_token(response.getheader("Set-Cookie"))
response.getheader("Set-Cookie")) if new_token is not None:
self.auth_token = new_token
def on_request(self, method: str, path: str, headers: QueryDict, **kwargs): def on_request(self, method: str, path: str, headers: QueryDict, **kwargs):
# pylint: disable=unused-argument # pylint: disable=unused-argument
...@@ -190,7 +191,7 @@ class CredentialsAuthenticator(AbstractAuthenticator): ...@@ -190,7 +191,7 @@ class CredentialsAuthenticator(AbstractAuthenticator):
def _logout(self): def _logout(self):
self.logger.debug("[LOGOUT]") self.logger.debug("[LOGOUT]")
if self.auth_token is not None: if self.auth_token is not None:
self._connection.request(method="DELETE", path="logout") self._connection.request(method="GET", path="logout")
self.auth_token = None self.auth_token = None
def _login(self): def _login(self):
......
...@@ -75,7 +75,7 @@ class MockUpServerConnection(CaosDBServerConnection): ...@@ -75,7 +75,7 @@ class MockUpServerConnection(CaosDBServerConnection):
just returns predefined responses which mimic the LinkAhead server.""" just returns predefined responses which mimic the LinkAhead server."""
def __init__(self): def __init__(self):
self.resources = [self._login] self.resources = [self._login, self._logout]
def _login(self, method, path, headers, body): def _login(self, method, path, headers, body):
if method == "POST" and path == "login": if method == "POST" and path == "login":
...@@ -84,6 +84,12 @@ class MockUpServerConnection(CaosDBServerConnection): ...@@ -84,6 +84,12 @@ class MockUpServerConnection(CaosDBServerConnection):
"mockup-auth-token"}, "mockup-auth-token"},
body="") body="")
def _logout(self, method, path, headers, body):
if method in ["DELETE", "GET"] and path == "logout":
return MockUpResponse(200,
headers={},
body="")
def configure(self, **kwargs): def configure(self, **kwargs):
"""This configure method does nothing.""" """This configure method does nothing."""
......
...@@ -96,6 +96,6 @@ def test_logout_calls_delete(): ...@@ -96,6 +96,6 @@ def test_logout_calls_delete():
auth_token="[request token]", auth_token="[request token]",
implementation=MockUpServerConnection) implementation=MockUpServerConnection)
c._delegate_connection.resources.append(logout_resource) c._delegate_connection.resources.insert(1, logout_resource)
c._logout() c._logout()
mock.method.assert_called_once() mock.method.assert_called_once()
...@@ -220,9 +220,9 @@ def test_init_connection(): ...@@ -220,9 +220,9 @@ def test_init_connection():
def test_resources_list(): def test_resources_list():
connection = test_init_connection() connection = test_init_connection()
assert hasattr(connection, "resources") assert hasattr(connection, "resources")
assert len(connection.resources) == 1
connection.resources.append(lambda **kwargs: test_init_response())
assert len(connection.resources) == 2 assert len(connection.resources) == 2
connection.resources.append(lambda **kwargs: test_init_response())
assert len(connection.resources) == 3
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