Skip to content

Commit

Permalink
Add test coverage for delegated hash bins target download
Browse files Browse the repository at this point in the history
This change adds tests coverage for `path_hash_prefixes` and
verifies that role names matching specific prefixed successfully
find and download the corresponding metadata files and do not
succeed to find existing, but non-matching files

Signed-off-by: Ivana Atanasova <[email protected]>
  • Loading branch information
ivanayov committed Mar 23, 2022
1 parent ff770ea commit b32d345
Showing 1 changed file with 77 additions and 1 deletion.
78 changes: 77 additions & 1 deletion tests/test_updater_delegation_graphs.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class TestDelegation:
keyids: List[str] = field(default_factory=list)
threshold: int = 1
terminating: bool = False
paths: List[str] = field(default_factory=lambda: ["*"])
paths: Optional[List[str]] = field(default_factory=lambda: ["*"])
path_hash_prefixes: Optional[List[str]] = None


Expand Down Expand Up @@ -438,6 +438,82 @@ def test_targetfile_search(self, test_data: TargetTestCase) -> None:
finally:
self.teardown_subtest()

hash_bins_metadata: utils.DataSet = {
"delegated hash bins": DelegationsTestCase(
delegations=[
TestDelegation(
"targets",
"f8-ff",
paths=None,
path_hash_prefixes=[
"f8",
"f9",
"fa",
"fb",
"fc",
"fd",
"fe",
"ff",
],
),
TestDelegation(
"targets",
"20-27",
paths=None,
path_hash_prefixes=[
"20",
"21",
"22",
"23",
"24",
"25",
"26",
"27",
],
),
],
target_files=[
TestTarget(
"f8-ff",
b"fff0838676c1dacb8827b02511e89f85b43814a74dd2c3ffb31d952a1db94311",
"non_matching_path_to_prefix.ext",
),
TestTarget(
"20-27",
b"22992ae806e6d652835f3c84e169f05127da69e599f902e4dbdc6ff27ce46d01",
"delegate_1.ext",
),
],
visited_order=["f8-ff", "20-27"],
),
}

@utils.run_sub_tests_with_dataset(hash_bins_metadata)
def test_delegated_hash_bins(self, test_data: DelegationsTestCase) -> None:
try:
self._init_repo(test_data)
self.setup_subtest()
updater = self._init_updater()
# Call explicitly refresh to simplify the expected_calls list
updater.refresh()
self.sim.fetch_tracker.metadata.clear()

# verify that no metadata file was downloaded for existing
# path that doesn't match correct prefix
target_info = updater.get_targetinfo(
"non_matching_path_to_prefix.ext"
)
self.assertIsNone(target_info)
# verify that the target info was successfully found
# and the correct delegated metadata file was downloaded
target_info = updater.get_targetinfo("delegate_1.ext")
assert target_info is not None
self.assertEqual(target_info.path, "delegate_1.ext")
target_file = updater.download_target(target_info)
self.assertEqual(target_file, os.path.join(self.targets_dir,"delegate_1.ext"))
finally:
self.teardown_subtest()


if __name__ == "__main__":
if "--dump" in sys.argv:
Expand Down

0 comments on commit b32d345

Please sign in to comment.