Skip to content

Commit

Permalink
Test delegation tree with succinct_roles
Browse files Browse the repository at this point in the history
Test traversing the delegation tree when there is a Targets using a
delegation with succinct roles.

Signed-off-by: Martin Vrachev <mvrachev@vmware.com>
  • Loading branch information
MVrachev committed May 20, 2022
1 parent 2f9a59a commit 417d0ef
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 1 deletion.
2 changes: 1 addition & 1 deletion tests/repository_simulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ def add_succinct_roles_to_delegations(
# Create delegation
if delegator.delegations is None:
delegator.delegations = Delegations(
{}, roles=None, succinct_roles=succinct_roles
keys={}, roles=None, succint_roles=succinct_roles
)
else:
delegator.delegations.succinct_roles = succinct_roles
Expand Down
84 changes: 84 additions & 0 deletions tests/test_updater_delegation_graphs.py
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,90 @@ def test_hash_bins_graph_traversal(
finally:
self.teardown_subtest()

@dataclass
class SuccinctRolesTestCase:
bit_length: int
target_path: str
expected_visited_bin: str

succinct_bins_graph: utils.DataSet = {
"case 1": SuccinctRolesTestCase(
bit_length=1,
target_path="othermissingpath",
expected_visited_bin="delegated-0",
),
"case 2": SuccinctRolesTestCase(
bit_length=1,
target_path="missingpath",
expected_visited_bin="delegated-1",
),
"case 3": SuccinctRolesTestCase(
bit_length=2,
target_path="foo",
expected_visited_bin="delegated-0",
),
"case 4": SuccinctRolesTestCase(
bit_length=2,
target_path="doo",
expected_visited_bin="delegated-1",
),
"case 5": SuccinctRolesTestCase(
bit_length=2,
target_path="missingpath",
expected_visited_bin="delegated-2",
),
"case 6": SuccinctRolesTestCase(
bit_length=2,
target_path="bar",
expected_visited_bin="delegated-3",
),
"many bins case": SuccinctRolesTestCase(
bit_length=8,
target_path="bar",
expected_visited_bin="delegated-fc",
),
}

@utils.run_sub_tests_with_dataset(succinct_bins_graph)
def test_succinct_roles_graph_traversal(
self, test_data: SuccinctRolesTestCase
) -> None:
# Test traversing the delegation tree when succinct roles is used. For a
# successful traversal all top level metadata files plus the expected
# bin should exist locally and only one bin must be downloaded.

try:
exp_files = [*TOP_LEVEL_ROLE_NAMES, test_data.expected_visited_bin]
exp_calls = [(test_data.expected_visited_bin, 1)]

self.sim = RepositorySimulator()
self.sim.add_succinct_roles_to_delegations(
"targets", test_data.bit_length, "delegated"
)
self.sim.update_snapshot()

self.setup_subtest()

updater = self._init_updater()
# Call explicitly refresh to simplify the expected_calls list
updater.refresh()
self.sim.fetch_tracker.metadata.clear()
# Check that metadata dir contains only top-level roles
self._assert_files_exist(TOP_LEVEL_ROLE_NAMES)

# Looking for a non-existing targetpath forces updater
# to visit a correspondning delegated role
targetfile = updater.get_targetinfo(test_data.target_path)
self.assertIsNone(targetfile)

# Check that the delegated roles were visited in the expected
# order and the corresponding metadata files were persisted
self.assertListEqual(self.sim.fetch_tracker.metadata, exp_calls)
self._assert_files_exist(exp_files)

finally:
self.teardown_subtest()


class TestTargetFileSearch(TestDelegations):
r"""
Expand Down

0 comments on commit 417d0ef

Please sign in to comment.