Skip to content
Merged
14 changes: 13 additions & 1 deletion hyperwallet/tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,9 @@ def test_receive_valid_json_error_response(self, session_mock):
data = {
"errors": [{
"message": "Houston, we have a problem",
"code": "FORBIDDEN"
"code": "FORBIDDEN",
"relatedResources": ["trm-f3d38df1-adb7-4127-9858-e72ebe682a79",
"trm-601b1401-4464-4f3f-97b3-09079ee7723b"]
}]
}

Expand All @@ -79,6 +81,16 @@ def test_receive_valid_json_error_response(self, session_mock):
'FORBIDDEN'
)

self.assertEqual(
exc.exception.message.get('errors')[0].get('relatedResources')[0],
'trm-f3d38df1-adb7-4127-9858-e72ebe682a79'
)

self.assertEqual(
exc.exception.message.get('errors')[0].get('relatedResources')[1],
'trm-601b1401-4464-4f3f-97b3-09079ee7723b'
)

@mock.patch('requests.Session.request')
def test_receive_valid_json_response(self, session_mock):

Expand Down
31 changes: 24 additions & 7 deletions hyperwallet/tests/test_encryption.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@
from jwcrypto.common import json_encode
from hyperwallet.exceptions import HyperwalletException
from hyperwallet.utils.encryption import Encryption
from django.core.validators import URLValidator
from django.core.exceptions import ValidationError
from six.moves.urllib.parse import urlparse


class EncryptionTest(unittest.TestCase):
Expand Down Expand Up @@ -158,19 +157,37 @@ def test_should_throw_exception_when_jws_signature_has_expired(self):
self.assertEqual(exc.exception.message, 'JWS signature has expired, checked by [exp] JWS header')

def __getJwkKeySet(self, location):

'''
Retrieves JWK key data from given location.

:param location:
Location(can be a URL or path to file) of JWK key data. **REQUIRED**
:returns:
JWK key set found at given location.
'''
try:
URLValidator()(location)
except ValidationError:
url = urlparse(location)
if url.scheme and url.netloc and url.path:
return requests.get(location).text
raise HyperwalletException('Failed to parse url from string = ' + location)
except Exception as e:
if os.path.isfile(location):
with open(location) as f:
return f.read()
else:
raise HyperwalletException('Wrong JWK key set location path = ' + location)

return requests.get(location).text

def __findJwkKeyByAlgorithm(self, jwkKeySet, algorithm):
'''
Finds JWK key by given algorithm.

:param jwkKeySet:
JSON representation of JWK key set. **REQUIRED**
:param algorithm:
Algorithm of the JWK key to be found in key set. **REQUIRED**
:returns:
JWK key with given algorithm.
'''

try:
keySet = json.loads(jwkKeySet)
Expand Down