diff --git a/blobxfer/models/metadata.py b/blobxfer/models/metadata.py index f47098c..ea8bb15 100644 --- a/blobxfer/models/metadata.py +++ b/blobxfer/models/metadata.py @@ -99,8 +99,12 @@ def get_md5_from_metadata(ase): # md5 in blobxfer extensions md5 = None if ase.is_encrypted: - md5 = ase.encryption_metadata.blobxfer_extensions.\ - pre_encrypted_content_md5 + try: + md5 = ase.encryption_metadata.blobxfer_extensions.\ + pre_encrypted_content_md5 + except AttributeError: + # this can happen if partial metadata is present + md5 = None if blobxfer.util.is_none_or_empty(md5): md5 = ase.md5 return md5 diff --git a/tests/test_blobxfer_models_metadata.py b/tests/test_blobxfer_models_metadata.py index 64b8cfe..a64d033 100644 --- a/tests/test_blobxfer_models_metadata.py +++ b/tests/test_blobxfer_models_metadata.py @@ -13,6 +13,12 @@ import pytest import blobxfer.models.metadata as md +class AseAE(object): + def __init__(self): + self.is_encrypted = True + self.md5 = 'aseae' + + def test_get_md5_from_metadata(): ase = mock.MagicMock() ase.is_encrypted = True @@ -24,6 +30,10 @@ def test_get_md5_from_metadata(): ase.md5 = 'md5' assert md.get_md5_from_metadata(ase) == 'md5' + ase = AseAE() + asemd5 = md.get_md5_from_metadata(ase) + assert asemd5 == 'aseae' + def test_generate_fileattr_metadata(): with mock.patch('blobxfer.util.on_windows', return_value=True):