From 6057177204d71b244a0e878f248b186b7d459716 Mon Sep 17 00:00:00 2001 From: Muhammad Sufyan Date: Fri, 19 Apr 2024 13:16:55 +0500 Subject: [PATCH] fix(auth-utility): handle runtime exception in base64 encoding utility This commit handles the exception when the provided props are an array of None items because when any of the item is None the `delimiter.join` throws an exception because it expects the str instances. Closes #55 --- apimatic_core/utilities/auth_helper.py | 2 +- setup.py | 2 +- tests/apimatic_core/utility_tests/test_auth_helper.py | 9 +++++++++ 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/apimatic_core/utilities/auth_helper.py b/apimatic_core/utilities/auth_helper.py index 2ee0dec..5a167b4 100644 --- a/apimatic_core/utilities/auth_helper.py +++ b/apimatic_core/utilities/auth_helper.py @@ -7,7 +7,7 @@ class AuthHelper: @staticmethod def get_base64_encoded_value(*props, delimiter=':'): - if props: + if props.__len__() > 0 and not any(prop is None for prop in props): joined = delimiter.join(props) encoded = base64.b64encode(str.encode(joined)).decode('iso-8859-1') return encoded diff --git a/setup.py b/setup.py index b637602..b1239e8 100644 --- a/setup.py +++ b/setup.py @@ -12,7 +12,7 @@ setup( name='apimatic-core', - version='0.2.8', + version='0.2.9', description='A library that contains core logic and utilities for ' 'consuming REST APIs using Python SDKs generated by APIMatic.', long_description=long_description, diff --git a/tests/apimatic_core/utility_tests/test_auth_helper.py b/tests/apimatic_core/utility_tests/test_auth_helper.py index 2cf097b..7fea37c 100644 --- a/tests/apimatic_core/utility_tests/test_auth_helper.py +++ b/tests/apimatic_core/utility_tests/test_auth_helper.py @@ -8,6 +8,15 @@ def test_base64_encoded_none_value(self): expected_base64_encoded_value = None assert actual_base64_encoded_value == expected_base64_encoded_value + def test_base64_encoded_provided_none_values(self): + actual_base64_encoded_value = AuthHelper.get_base64_encoded_value(None, None) + expected_base64_encoded_value = None + assert actual_base64_encoded_value == expected_base64_encoded_value + + actual_base64_encoded_value = AuthHelper.get_base64_encoded_value('test_username', None) + expected_base64_encoded_value = None + assert actual_base64_encoded_value == expected_base64_encoded_value + def test_base64_encoded_value(self): actual_base64_encoded_value = AuthHelper.get_base64_encoded_value('test_username', 'test_password') expected_base64_encoded_value = 'dGVzdF91c2VybmFtZTp0ZXN0X3Bhc3N3b3Jk'