diff --git a/tests/test_updater_ng.py b/tests/test_updater_ng.py index 3e62b6c831..69fbeef8cd 100644 --- a/tests/test_updater_ng.py +++ b/tests/test_updater_ng.py @@ -202,8 +202,8 @@ def consistent_snapshot_modifier(root): ) # Get targetinfos, assert cache does not contain the files - info1 = updater.get_one_valid_targetinfo("file1.txt") - info3 = updater.get_one_valid_targetinfo("file3.txt") + info1 = updater.get_targetinfo("file1.txt") + info3 = updater.get_targetinfo("file3.txt") self.assertIsNone(updater.find_cached_target(info1)) self.assertIsNone(updater.find_cached_target(info3)) @@ -238,11 +238,11 @@ def test_refresh_and_download(self): self._assert_files(["root", "snapshot", "targets", "timestamp"]) # Get targetinfos, assert that cache does not contain files - info1 = self.updater.get_one_valid_targetinfo("file1.txt") + info1 = self.updater.get_targetinfo("file1.txt") self._assert_files(["root", "snapshot", "targets", "timestamp"]) # Get targetinfo for 'file3.txt' listed in the delegated role1 - info3 = self.updater.get_one_valid_targetinfo("file3.txt") + info3 = self.updater.get_targetinfo("file3.txt") expected_files = ["role1", "root", "snapshot", "targets", "timestamp"] self._assert_files(expected_files) self.assertIsNone(self.updater.find_cached_target(info1)) @@ -275,7 +275,7 @@ def test_refresh_with_only_local_root(self): self._assert_files(["root", "snapshot", "targets", "timestamp"]) # Get targetinfo for 'file3.txt' listed in the delegated role1 - targetinfo3 = self.updater.get_one_valid_targetinfo("file3.txt") + targetinfo3 = self.updater.get_targetinfo("file3.txt") expected_files = ["role1", "root", "snapshot", "targets", "timestamp"] self._assert_files(expected_files) @@ -297,13 +297,13 @@ def test_no_target_dir_no_filepath(self): def test_external_targets_url(self): self.updater.refresh() - info = self.updater.get_one_valid_targetinfo("file1.txt") + info = self.updater.get_targetinfo("file1.txt") self.updater.download_target(info, target_base_url=self.targets_url) def test_length_hash_mismatch(self): self.updater.refresh() - targetinfo = self.updater.get_one_valid_targetinfo("file1.txt") + targetinfo = self.updater.get_targetinfo("file1.txt") length = targetinfo.length with self.assertRaises(exceptions.RepositoryError): @@ -325,7 +325,7 @@ def test_missing_targetinfo(self): self.updater.refresh() # Get targetinfo for non-existing file - self.assertIsNone(self.updater.get_one_valid_targetinfo("file33.txt")) + self.assertIsNone(self.updater.get_targetinfo("file33.txt")) if __name__ == "__main__": diff --git a/tests/test_updater_with_simulator.py b/tests/test_updater_with_simulator.py index e1f10ce67e..8cfb9de72a 100644 --- a/tests/test_updater_with_simulator.py +++ b/tests/test_updater_with_simulator.py @@ -95,7 +95,7 @@ def test_targets(self, test_case_data: Tuple[str, bytes, str]): updater = self._run_refresh() # target does not exist yet, configuration is what we expect - self.assertIsNone(updater.get_one_valid_targetinfo(targetpath)) + self.assertIsNone(updater.get_targetinfo(targetpath)) self.assertTrue(self.sim.root.consistent_snapshot) self.assertTrue(updater.config.prefix_targets_with_hash) @@ -106,7 +106,7 @@ def test_targets(self, test_case_data: Tuple[str, bytes, str]): updater = self._run_refresh() # target now exists, is not in cache yet - info = updater.get_one_valid_targetinfo(targetpath) + info = updater.get_targetinfo(targetpath) self.assertIsNotNone(info) # Test without and with explicit local filepath self.assertIsNone(updater.find_cached_target(info)) @@ -145,7 +145,7 @@ def test_fishy_rolenames(self): updater = self._run_refresh() # trigger updater to fetch the delegated metadata, check filenames - updater.get_one_valid_targetinfo("anything") + updater.get_targetinfo("anything") local_metadata = os.listdir(self.metadata_dir) for fname in roles_to_filenames.values(): self.assertTrue(fname in local_metadata) diff --git a/tuf/ngclient/updater.py b/tuf/ngclient/updater.py index fee09904e9..5094ae3620 100644 --- a/tuf/ngclient/updater.py +++ b/tuf/ngclient/updater.py @@ -21,7 +21,7 @@ snapshot is consistent so multiple targets can be downloaded without fear of repository content changing. For each target: - * :func:`~tuf.ngclient.updater.Updater.get_one_valid_targetinfo()` is + * :func:`~tuf.ngclient.updater.Updater.get_targetinfo()` is used to find information about a specific target. This will load new targets metadata as needed (from local cache or remote repository). * :func:`~tuf.ngclient.updater.Updater.find_cached_target()` can be used @@ -56,7 +56,7 @@ updater.refresh() # Update metadata, then download target if needed - info = updater.get_one_valid_targetinfo("file.txt") + info = updater.get_targetinfo("file.txt") path = updater.find_cached_target(info) if path is None: path = updater.download_target(info) @@ -131,7 +131,7 @@ def refresh(self) -> None: all the checks required in the TUF client workflow. The metadata for delegated roles are not refreshed by this method as - that happens on demand during get_one_valid_targetinfo(). + that happens on demand during get_targetinfo(). The refresh() method should be called by the client before any other method calls. @@ -147,19 +147,16 @@ def refresh(self) -> None: self._load_snapshot() self._load_targets("targets", "root") - def get_one_valid_targetinfo( - self, target_path: str - ) -> Optional[TargetFile]: + def get_targetinfo(self, target_path: str) -> Optional[TargetFile]: """Returns TargetFile instance with information for 'target_path'. The return value can be used as an argument to :func:`download_target()` and :func:`find_cached_target()`. - :func:`refresh()` must be called before calling - `get_one_valid_targetinfo()`. Subsequent calls to - `get_one_valid_targetinfo()` will use the same consistent repository + `get_targetinfo()`. Subsequent calls to + `get_targetinfo()` will use the same consistent repository state: Changes that happen in the repository between calling - :func:`refresh()` and `get_one_valid_targetinfo()` will not be + :func:`refresh()` and `get_targetinfo()` will not be seen by the updater. As a side-effect this method downloads all the additional (delegated @@ -193,7 +190,7 @@ def find_cached_target( generated based on the target path like in ``download_target()`` Args: - targetinfo: TargetFile from ``get_one_valid_targetinfo()``. + targetinfo: TargetFile from ``get_targetinfo()``. filepath: Local path to file. By default a filename is generated and file is looked for in ``target_dir`` (see note above). @@ -201,8 +198,8 @@ def find_cached_target( ValueError: Incorrect arguments Returns: - Local file path if the file is an up to date target file, or None - if file is not found or it is not up to date. + Local file path if the file is an up to date target file. + None if file is not found or it is not up to date. """ if filepath is not None: pass @@ -233,8 +230,7 @@ def download_target( generated based on the target path. Args: - targetinfo: TargetFile with target information from - get_one_valid_targetinfo(). + targetinfo: TargetFile from ``get_targetinfo()``. filepath: Local path to download into. By default the file is downloaded into ``target_dir`` (see note above) with a generated filename. If file already exists, it is overwritten. @@ -247,7 +243,7 @@ def download_target( TODO: file write errors Returns: - Path to downloaded file + Local path to downloaded file """ if filepath is not None: