Skip to content

Commit 7a1d088

Browse files
committed
Sem-Ver: bugfix When a connection error is encountered while attempting to fetch public keys in HTTPSMultiRepositoryPublicKeyRetriever continue to attempt key retrieval using other retrievers.
Signed-off-by: David Black <[email protected]>
1 parent 5e004c3 commit 7a1d088

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

atlassian_jwt_auth/key.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import jwt
1111
import requests
1212
from cryptography.hazmat.primitives import serialization
13-
from requests.exceptions import RequestException
13+
from requests.exceptions import RequestException, ConnectionError
1414

1515
from atlassian_jwt_auth.exceptions import (KeyIdentifierException,
1616
PublicKeyRetrieverException,
@@ -141,6 +141,10 @@ def handle_retrieval_exception(self, retriever, exception):
141141
retrieval.
142142
"""
143143
if isinstance(exception, PublicKeyRetrieverException):
144+
original_exception = getattr(
145+
exception, 'original_exception', None)
146+
if isinstance(original_exception, ConnectionError):
147+
return
144148
if exception.status_code is None or exception.status_code < 500:
145149
raise
146150

atlassian_jwt_auth/tests/test_public_key_provider.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,23 @@ def test_retrieve_with_500_error(self, mock_get_method):
190190
retriever.retrieve('example/eg'),
191191
self._public_key_pem)
192192

193+
@mock.patch.object(requests.Session, 'get')
194+
def test_retrieve_with_connection_error(self, mock_get_method):
195+
""" tests that the retrieve method works as expected
196+
when the first key repository encounters a connection error.
197+
"""
198+
retriever = HTTPSMultiRepositoryPublicKeyRetriever(self.keystore_urls)
199+
_setup_mock_response_for_retriever(
200+
mock_get_method, self._public_key_pem)
201+
valid_response = mock_get_method.return_value
202+
del mock_get_method.return_value
203+
connection_exception = requests.exceptions.ConnectionError(
204+
response=mock.Mock(status_code=None))
205+
mock_get_method.side_effect = [connection_exception, valid_response]
206+
self.assertEqual(
207+
retriever.retrieve('example/eg'),
208+
self._public_key_pem)
209+
193210

194211
def _setup_mock_response_for_retriever(
195212
mock_method, public_key_pem, headers=None):

0 commit comments

Comments
 (0)