Merge pull request #826 from dod-ccpo/crl-silent-fail

Raise error if CRL download fails.
This commit is contained in:
dandds 2019-05-16 12:52:26 -04:00 committed by GitHub
commit 291cc6b3b3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 34 additions and 3 deletions

View File

@ -9,6 +9,10 @@ from libcloud.storage.providers import get_driver
from atst.domain.exceptions import UploadError
class CSPFileError(Exception):
pass
class FileProviderInterface:
_PERMITTED_MIMETYPES = ["application/pdf", "image/png"]
@ -99,14 +103,23 @@ class RackspaceCRLProvider(CRLProviderInterface):
)
self._crl_dir = app.config.get("CRL_STORAGE_CONTAINER")
self._object_name = app.config.get("STORAGE_CRL_ARCHIVE_NAME")
self._object = None
@property
def object(self):
if self._object is None:
self._object = self.container.get_object(object_name=self._object_name)
return self._object
def sync_crls(self):
if not os.path.exists(self._crl_dir):
os.mkdir(self._crl_dir)
obj = self.container.get_object(object_name=self._object_name)
with TemporaryDirectory() as tempdir:
dl_path = os.path.join(tempdir, self._object_name)
obj.download(dl_path, overwrite_existing=True)
success = self.object.download(dl_path, overwrite_existing=True)
if not success:
raise CSPFileError("The CRL package was not downloaded")
archive = tarfile.open(dl_path, "r:bz2")
archive.extractall(self._crl_dir)

View File

@ -1,8 +1,13 @@
import os
import pytest
from werkzeug.datastructures import FileStorage
from unittest.mock import Mock
from atst.domain.csp.files import RackspaceFileProvider
from atst.domain.csp.files import (
CSPFileError,
RackspaceFileProvider,
RackspaceCRLProvider,
)
from atst.domain.exceptions import UploadError
from tests.mocks import PDF_FILENAME
@ -55,3 +60,16 @@ def test_downloading_uploaded_object(uploader, pdf_upload):
pdf_content = pdf_upload.read()
assert stream_content == pdf_content
def test_crl_download_fails(app, monkeypatch):
mock_object = Mock()
mock_object.download.return_value = False
monkeypatch.setattr(
"atst.domain.csp.files.RackspaceCRLProvider.object", mock_object
)
rs_crl_provider = RackspaceCRLProvider(app)
with pytest.raises(CSPFileError):
rs_crl_provider.sync_crls()