From 06fb27ec08dbed72bb2caf2751febb7272d8649f Mon Sep 17 00:00:00 2001 From: MKLepium Date: Wed, 22 Nov 2023 00:02:38 +0100 Subject: [PATCH 1/2] added testcase for newline in api key --- python/hopsworks/client/auth.py | 4 ++-- python/tests/hopsworks/test_login.py | 7 +++++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/python/hopsworks/client/auth.py b/python/hopsworks/client/auth.py index d30c085cd..8bbd4ae53 100644 --- a/python/hopsworks/client/auth.py +++ b/python/hopsworks/client/auth.py @@ -24,7 +24,7 @@ def __init__(self, token): self._token = token def __call__(self, r): - r.headers["Authorization"] = "Bearer " + self._token + r.headers["Authorization"] = "Bearer " + self._token.strip() return r @@ -35,5 +35,5 @@ def __init__(self, token): self._token = token def __call__(self, r): - r.headers["Authorization"] = "ApiKey " + self._token + r.headers["Authorization"] = "ApiKey " + self._token.strip() return r diff --git a/python/tests/hopsworks/test_login.py b/python/tests/hopsworks/test_login.py index 363164c11..55f822937 100644 --- a/python/tests/hopsworks/test_login.py +++ b/python/tests/hopsworks/test_login.py @@ -225,3 +225,10 @@ def test_login_api_key_as_environ(self): raise e finally: del os.environ["HOPSWORKS_API_KEY"] + + def test_login_newline_in_api_key(self): + try: + imaginaryApiKey = "ImaginaryApiKey\n" + project = hopsworks.login(api_key_value=imaginaryApiKey) + except Exception as e: + self.assertNotIn(imaginaryApiKey.strip(), str(e)) From cd58aff46efe4ef9c2796ac490e56381d81ab998 Mon Sep 17 00:00:00 2001 From: MKLepium Date: Wed, 22 Nov 2023 00:35:20 +0100 Subject: [PATCH 2/2] removed assignment to unused variable --- python/tests/hopsworks/test_login.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/tests/hopsworks/test_login.py b/python/tests/hopsworks/test_login.py index 55f822937..bec4ba729 100644 --- a/python/tests/hopsworks/test_login.py +++ b/python/tests/hopsworks/test_login.py @@ -229,6 +229,6 @@ def test_login_api_key_as_environ(self): def test_login_newline_in_api_key(self): try: imaginaryApiKey = "ImaginaryApiKey\n" - project = hopsworks.login(api_key_value=imaginaryApiKey) + hopsworks.login(api_key_value=imaginaryApiKey) except Exception as e: self.assertNotIn(imaginaryApiKey.strip(), str(e))