From 384ae81b8acc53eafe758cf0eb88aeede00b41f8 Mon Sep 17 00:00:00 2001 From: Maximilian Georg Kurzawski <52952859+MKLepium@users.noreply.github.com> Date: Wed, 22 Nov 2023 00:47:16 +0100 Subject: [PATCH] added testcase for newline in api key (#185) Closes #184 --- 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..bec4ba729 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" + hopsworks.login(api_key_value=imaginaryApiKey) + except Exception as e: + self.assertNotIn(imaginaryApiKey.strip(), str(e))