Skip to content

Commit b7454ed

Browse files
committed
fix: Add sign all files test with V2 spec
1 parent c847f79 commit b7454ed

File tree

1 file changed

+68
-0
lines changed

1 file changed

+68
-0
lines changed

tests/test_unit_tests.py

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1745,6 +1745,74 @@ def test_sign_all_files(self):
17451745
except Exception as e:
17461746
self.fail(f"Failed to sign {filename}: {str(e)}")
17471747

1748+
def test_sign_all_files_V2(self):
1749+
"""Test signing all files in both fixtures directories"""
1750+
signing_dir = os.path.join(self.data_dir, "files-for-signing-tests")
1751+
reading_dir = os.path.join(self.data_dir, "files-for-reading-tests")
1752+
1753+
# Map of file extensions to MIME types
1754+
mime_types = {
1755+
'.jpg': 'image/jpeg',
1756+
'.jpeg': 'image/jpeg',
1757+
'.png': 'image/png',
1758+
'.gif': 'image/gif',
1759+
'.webp': 'image/webp',
1760+
'.heic': 'image/heic',
1761+
'.heif': 'image/heif',
1762+
'.avif': 'image/avif',
1763+
'.tif': 'image/tiff',
1764+
'.tiff': 'image/tiff',
1765+
'.mp4': 'video/mp4',
1766+
'.avi': 'video/x-msvideo',
1767+
'.mp3': 'audio/mpeg',
1768+
'.m4a': 'audio/mp4',
1769+
'.wav': 'audio/wav'
1770+
}
1771+
1772+
# Skip files that are known to be invalid or unsupported
1773+
skip_files = {
1774+
'sample3.invalid.wav', # Invalid file
1775+
}
1776+
1777+
# Process both directories
1778+
for directory in [signing_dir, reading_dir]:
1779+
for filename in os.listdir(directory):
1780+
if filename in skip_files:
1781+
continue
1782+
1783+
file_path = os.path.join(directory, filename)
1784+
if not os.path.isfile(file_path):
1785+
continue
1786+
1787+
# Get file extension and corresponding MIME type
1788+
_, ext = os.path.splitext(filename)
1789+
ext = ext.lower()
1790+
if ext not in mime_types:
1791+
continue
1792+
1793+
mime_type = mime_types[ext]
1794+
1795+
try:
1796+
with open(file_path, "rb") as file:
1797+
builder = Builder(self.manifestDefinitionV2)
1798+
output = io.BytesIO(bytearray())
1799+
builder.sign(self.signer, mime_type, file, output)
1800+
builder.close()
1801+
output.seek(0)
1802+
reader = Reader(mime_type, output)
1803+
json_data = reader.json()
1804+
self.assertIn("Python Test", json_data)
1805+
# Needs trust configuration to be set up to validate as Trusted,
1806+
# or validation_status on read reports `signing certificate untrusted`
1807+
# which makes the manifest validation_state become Invalid.
1808+
self.assertIn("Invalid", json_data)
1809+
reader.close()
1810+
output.close()
1811+
except Error.NotSupported:
1812+
continue
1813+
except Exception as e:
1814+
self.fail(f"Failed to sign {filename}: {str(e)}")
1815+
17481816
def test_builder_no_added_ingredient_on_closed_builder(self):
17491817
builder = Builder(self.manifestDefinition)
17501818

0 commit comments

Comments
 (0)