diff --git a/CHANGELOG.md b/CHANGELOG.md index 63a3df1a4256423aeda7a349f7d06d09dd480e84..05d780ffed1496663c08fcbe69b4ba892fdc074c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) `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 ### @@ -50,7 +53,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### 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 or roles don't exist. diff --git a/src/linkahead/connection/authentication/interface.py b/src/linkahead/connection/authentication/interface.py index b48e27c08312bf1358d32a9a1203627a9d0007c2..8288880583dc58fc82ab03d371861f067406b3d3 100644 --- a/src/linkahead/connection/authentication/interface.py +++ b/src/linkahead/connection/authentication/interface.py @@ -125,8 +125,9 @@ class AbstractAuthenticator(ABC): Returns ------- """ - self.auth_token = parse_auth_token( - response.getheader("Set-Cookie")) + new_token = parse_auth_token(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): # pylint: disable=unused-argument @@ -190,7 +191,7 @@ class CredentialsAuthenticator(AbstractAuthenticator): def _logout(self): self.logger.debug("[LOGOUT]") 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 def _login(self): diff --git a/src/linkahead/connection/mockup.py b/src/linkahead/connection/mockup.py index 9b69971c0409708f221c402f540fac85ff9c527e..d3bc13bb474a70d48446e8532607c3e11931ff05 100644 --- a/src/linkahead/connection/mockup.py +++ b/src/linkahead/connection/mockup.py @@ -75,7 +75,7 @@ class MockUpServerConnection(CaosDBServerConnection): just returns predefined responses which mimic the LinkAhead server.""" def __init__(self): - self.resources = [self._login] + self.resources = [self._login, self._logout] def _login(self, method, path, headers, body): if method == "POST" and path == "login": @@ -84,6 +84,12 @@ class MockUpServerConnection(CaosDBServerConnection): "mockup-auth-token"}, 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): """This configure method does nothing.""" diff --git a/unittests/test_authentication_auth_token.py b/unittests/test_authentication_auth_token.py index 3142f1f9f54230cb19666eeb8ff5809a906f9d49..4eb17bcc3892a0d0cad0f2c86289c2e8c625d426 100644 --- a/unittests/test_authentication_auth_token.py +++ b/unittests/test_authentication_auth_token.py @@ -96,6 +96,6 @@ def test_logout_calls_delete(): auth_token="[request token]", implementation=MockUpServerConnection) - c._delegate_connection.resources.append(logout_resource) + c._delegate_connection.resources.insert(1, logout_resource) c._logout() mock.method.assert_called_once() diff --git a/unittests/test_connection.py b/unittests/test_connection.py index a0d280c2cd40a77c3f1eb1ef1930373eb6e388ec..5d22efa46e3a6c10452085d735d1bd6f056a81fc 100644 --- a/unittests/test_connection.py +++ b/unittests/test_connection.py @@ -220,9 +220,9 @@ def test_init_connection(): def test_resources_list(): connection = test_init_connection() assert hasattr(connection, "resources") - assert len(connection.resources) == 1 - connection.resources.append(lambda **kwargs: test_init_response()) assert len(connection.resources) == 2 + connection.resources.append(lambda **kwargs: test_init_response()) + assert len(connection.resources) == 3 return connection