diff --git a/tests/test_repository_lib.py b/tests/test_repository_lib.py index b4109683..e0f727d9 100755 --- a/tests/test_repository_lib.py +++ b/tests/test_repository_lib.py @@ -735,6 +735,21 @@ def test_write_metadata_file(self): self.assertRaises(tuf.FormatError, repo_lib.write_metadata_file, root_signable, output_filename, version_number, compression_algorithms, 3) + + + + def test__write_compressed_metadata(self): + # Test for invalid 'compressed_filename' argument and set + # 'write_new_metadata' to False. + file_object = tuf.util.TempFile() + non_existent_filename = \ + os.path.join(cls.temporary_directory, 'non-existent_compressed_filename') + write_new_metadata = False + repo_lib._write_compressed_metadata(file_object, + compressed_filename=non_existent_filename, + write_new_metadata=write_new_metadata, + consistent_snapshot=False, + version_number=8) diff --git a/tuf/repository_lib.py b/tuf/repository_lib.py index c0414793..cbacab7e 100755 --- a/tuf/repository_lib.py +++ b/tuf/repository_lib.py @@ -341,7 +341,6 @@ def _check_role_keys(rolename): """ Non-public function that verifies the public and signing keys of 'rolename'. If either contain an invalid threshold of keys, raise an exception. - 'rolename' is the full rolename (e.g., 'targets/unclaimed/django'). """ # Extract the total number of public and private keys of 'rolename' from its @@ -354,15 +353,13 @@ def _check_role_keys(rolename): # Raise an exception for an invalid threshold of public keys. if total_keyids < threshold: - message = repr(rolename) + ' role contains ' + \ - repr(total_keyids) + ' / ' + repr(threshold) + ' public keys.' - raise tuf.InsufficientKeysError(message) + raise tuf.InsufficientKeysError(repr(rolename) + ' role contains' + ' ' + repr(total_keyids) + ' / ' + repr(threshold) + ' public keys.') # Raise an exception for an invalid threshold of signing keys. if total_signatures == 0 and total_signing_keys < threshold: - message = repr(rolename) + ' role contains ' + \ - repr(total_signing_keys) + ' / ' + repr(threshold) + ' signing keys.' - raise tuf.InsufficientKeysError(message) + raise tuf.InsufficientKeysError(repr(rolename) + ' role contains' + ' ' + repr(total_signing_keys) + ' / ' + repr(threshold) + ' signing keys.') @@ -2059,7 +2056,10 @@ def _write_compressed_metadata(file_object, compressed_filename, if basename.endswith(compression_extension): basename = basename.split(compression_extension, 1)[0] version_and_filename = str(version_number) + '.' + basename + compression_extension - + + else: + logger.debug('Skipping unsupported compressed file: ' + repr(basename)) + consistent_filenames.append(os.path.join(dirname, version_and_filename)) # Move the 'tuf.util.TempFile' object to one of the filenames so that it is @@ -2070,12 +2070,20 @@ def _write_compressed_metadata(file_object, compressed_filename, logger.info('Saving ' + repr(compressed_filename)) file_object.move(compressed_filename) + else: + logger.debug('Skipping already written compressed file:' + ' ' + repr(compressed_filename)) + # Save any remaining compressed consistent snapshots. for consistent_filename in consistent_filenames: if not os.path.exists(consistent_filename): logger.info('Linking ' + repr(consistent_filename)) os.link(compressed_filename, consistent_filename) + else: + logger.debug('Skipping linking of already written compressed file: ' + ' ' + repr(consistent_filename)) +