Skip to content

Commit

Permalink
fix(auth-utility): handle runtime exception in base64 encoding utility (
Browse files Browse the repository at this point in the history
#56)

This commit handles the exception when the provided props are an array of None items. When any item is None, the `delimiter.join` throws an exception because it expects the str instances.
  • Loading branch information
sufyankhanrao authored Apr 19, 2024
1 parent 1a1cc33 commit 45ce9e1
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
2 changes: 1 addition & 1 deletion apimatic_core/utilities/auth_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
9 changes: 9 additions & 0 deletions tests/apimatic_core/utility_tests/test_auth_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down

0 comments on commit 45ce9e1

Please sign in to comment.