Merge pull request #540 from dod-ccpo/crl-fix
catch additional CRL download exception
This commit is contained in:
commit
b8c36f371f
@ -72,7 +72,8 @@ def write_crl(out_dir, target_dir, crl_location):
|
|||||||
|
|
||||||
def remove_bad_crl(out_dir, crl_location):
|
def remove_bad_crl(out_dir, crl_location):
|
||||||
crl = crl_local_path(out_dir, crl_location)
|
crl = crl_local_path(out_dir, crl_location)
|
||||||
os.remove(crl)
|
if os.path.isfile(crl):
|
||||||
|
os.remove(crl)
|
||||||
|
|
||||||
|
|
||||||
def refresh_crls(out_dir, target_dir, logger):
|
def refresh_crls(out_dir, target_dir, logger):
|
||||||
@ -85,7 +86,7 @@ def refresh_crls(out_dir, target_dir, logger):
|
|||||||
logger.info("successfully synced CRL from {}".format(crl_location))
|
logger.info("successfully synced CRL from {}".format(crl_location))
|
||||||
else:
|
else:
|
||||||
logger.info("no updates for CRL from {}".format(crl_location))
|
logger.info("no updates for CRL from {}".format(crl_location))
|
||||||
except requests.exceptions.ChunkedEncodingError:
|
except requests.exceptions.RequestException:
|
||||||
if logger:
|
if logger:
|
||||||
logger.error(
|
logger.error(
|
||||||
"Error downloading {}, removing file and continuing anyway".format(
|
"Error downloading {}, removing file and continuing anyway".format(
|
||||||
|
@ -127,3 +127,37 @@ def test_skips_crl_if_it_has_not_been_modified(tmpdir, monkeypatch):
|
|||||||
"requests.get", lambda u, **kwargs: MockStreamingResponse([b"it worked"], 304)
|
"requests.get", lambda u, **kwargs: MockStreamingResponse([b"it worked"], 304)
|
||||||
)
|
)
|
||||||
assert not util.write_crl(tmpdir, "random_target_dir", "crl_file_name")
|
assert not util.write_crl(tmpdir, "random_target_dir", "crl_file_name")
|
||||||
|
|
||||||
|
|
||||||
|
class FakeLogger:
|
||||||
|
def __init__(self):
|
||||||
|
self.messages = []
|
||||||
|
|
||||||
|
def info(self, msg):
|
||||||
|
self.messages.append(msg)
|
||||||
|
|
||||||
|
def warning(self, msg):
|
||||||
|
self.messages.append(msg)
|
||||||
|
|
||||||
|
def error(self, msg):
|
||||||
|
self.messages.append(msg)
|
||||||
|
|
||||||
|
|
||||||
|
def test_refresh_crls_with_error(tmpdir, monkeypatch):
|
||||||
|
def _mock_create_connection(*args, **kwargs):
|
||||||
|
raise TimeoutError
|
||||||
|
|
||||||
|
fake_crl = "https://fakecrl.com/fake.crl"
|
||||||
|
|
||||||
|
monkeypatch.setattr(
|
||||||
|
"urllib3.util.connection.create_connection", _mock_create_connection
|
||||||
|
)
|
||||||
|
monkeypatch.setattr("atst.domain.authnid.crl.util.fetch_disa", lambda *args: None)
|
||||||
|
monkeypatch.setattr(
|
||||||
|
"atst.domain.authnid.crl.util.crl_list_from_disa_html", lambda *args: [fake_crl]
|
||||||
|
)
|
||||||
|
|
||||||
|
logger = FakeLogger()
|
||||||
|
util.refresh_crls(tmpdir, tmpdir, logger)
|
||||||
|
|
||||||
|
assert "Error downloading {}".format(fake_crl) in logger.messages[-1]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user