Skip to content

Commit

Permalink
tests check for appropriate exceptions. updaterconfig class ignores t…
Browse files Browse the repository at this point in the history
…oo-many-instance-attributes

Signed-off-by: Emile Baez <ebaezmunne@gmail.com>
  • Loading branch information
emilejbm committed May 27, 2023
1 parent 323eadf commit 8cee811
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
13 changes: 9 additions & 4 deletions tests/test_updater_top_level_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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()
Expand All @@ -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)
)
Expand All @@ -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()
Expand Down
6 changes: 4 additions & 2 deletions tuf/ngclient/_internal/trusted_metadata_set.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions tuf/ngclient/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@


@dataclass
# pylint: disable=too-many-instance-attributes
class UpdaterConfig:
"""Used to store ``Updater`` configuration.
Expand Down

0 comments on commit 8cee811

Please sign in to comment.