diff --git a/tests/test_updater_top_level_update.py b/tests/test_updater_top_level_update.py index 6d1655d1e8..b5d12fef25 100644 --- a/tests/test_updater_top_level_update.py +++ b/tests/test_updater_top_level_update.py @@ -18,9 +18,11 @@ from tests.repository_simulator import RepositorySimulator from tuf.api.exceptions import ( BadVersionNumberError, + DownloadError, DownloadLengthMismatchError, ExpiredMetadataError, LengthOrHashMismatchError, + RepositoryError, UnsignedMetadataError, ) from tuf.api.metadata import ( @@ -755,8 +757,11 @@ def test_refresh_with_offline(self, mock_time: Mock) -> None: updater.config.offline = False try: updater.refresh() - except ExpiredMetadataError: - self.assertTrue(True) + except Exception as e: + self.assertRaises( + (OSError, RepositoryError, DownloadError), + f"unexpected error raised {e}", + ) # Make sure local metadata is available updater = self._init_updater() @@ -782,7 +787,7 @@ def test_refresh_with_offline(self, mock_time: Mock) -> None: self.sim.update_snapshot() # Offline flag is set and local metadata is expired. New timestamp - # is available but should raise MetaDataError. + # is available but should raise ExpiredMetaDataError. mock_time.utcnow.return_value = ( self.sim.safe_expiry - datetime.timedelta(days=6) ) @@ -793,7 +798,7 @@ def test_refresh_with_offline(self, mock_time: Mock) -> None: try: updater.refresh() except ExpiredMetadataError: - self.assertFalse(False) + self.assertTrue(True) # Clean up fetch tracker data self.sim.fetch_tracker.metadata.clear() diff --git a/tuf/ngclient/_internal/trusted_metadata_set.py b/tuf/ngclient/_internal/trusted_metadata_set.py index 1825e33a01..235a3be8c6 100644 --- a/tuf/ngclient/_internal/trusted_metadata_set.py +++ b/tuf/ngclient/_internal/trusted_metadata_set.py @@ -251,7 +251,8 @@ def update_timestamp(self, data: bytes) -> Metadata[Timestamp]: logger.debug("Updated timestamp v%d", new_timestamp.signed.version) # timestamp is loaded: raise if it is not valid _final_ timestamp - self._check_final_timestamp() if not self.offline else None + if not self.offline: + self._check_final_timestamp() return new_timestamp @@ -301,7 +302,8 @@ def update_snapshot( logger.debug("Updating snapshot") # Snapshot cannot be loaded if final timestamp is expired - self._check_final_timestamp() if not self.offline else None + if not self.offline: + self._check_final_timestamp() snapshot_meta = self.timestamp.signed.snapshot_meta diff --git a/tuf/ngclient/config.py b/tuf/ngclient/config.py index 11a8fd3c09..98c574df8d 100644 --- a/tuf/ngclient/config.py +++ b/tuf/ngclient/config.py @@ -8,6 +8,7 @@ @dataclass +# pylint: disable=too-many-instance-attributes class UpdaterConfig: """Used to store ``Updater`` configuration. diff --git a/tuf/ngclient/updater.py b/tuf/ngclient/updater.py index 7c9b1af051..e24d6ed0c0 100644 --- a/tuf/ngclient/updater.py +++ b/tuf/ngclient/updater.py @@ -405,7 +405,7 @@ def _load_targets(self, role: str, parent_role: str) -> Metadata[Targets]: except (OSError, exceptions.RepositoryError) as e: # fails if local data is unavalible and in offline mode if self.config.offline: - raise exception.DownloadError("Local metadata is missing; cannot download new metadata in offline mode") + raise exceptions.DownloadError("Local metadata is missing; cannot download new metadata in offline mode") # Local 'role' does not exist or is invalid: update from remote logger.debug("Failed to load local %s: %s", role, e)