Skip to content

Commit

Permalink
Remove the need of accessing delegator for hash
Browse files Browse the repository at this point in the history
Signed-off-by: Martin Vrachev <mvrachev@vmware.com>
  • Loading branch information
MVrachev committed Aug 3, 2021
1 parent 2c9eee1 commit f65e196
Showing 1 changed file with 10 additions and 13 deletions.
23 changes: 10 additions & 13 deletions tests/test_updater_ng.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,22 +114,16 @@ def tearDown(self):
# Logs stdout and stderr from the sever subprocess.
self.server_process_handler.flush_log()

def _create_consistent_target(self, delegator_filename: str, targetname: str):
def _create_consistent_target(self, targetname: str, target_hash:str):
"""Create consistent targets copies of their non-consistent counterparts
inside the repository directory.
Args:
delegator_filename: Name of the delegator metadata file.
targetname: Name of the target file.
targetname: A string denoting the name of the target file.
target_hash: A string denoting the hash of the target.
"""
delegator_path = os.path.join(self.client_directory, delegator_filename)
with open(delegator_path, "rb") as f:
delegator_dict = json.loads(f.read())

target_info = delegator_dict["signed"]["targets"][targetname]
hashes = list(target_info["hashes"].values())
consistent_target_name = hashes[0] + "." + targetname
consistent_target_name = target_hash + "." + targetname
source_path = os.path.join(self.repository_directory, "targets", targetname)
destination_path = os.path.join(
self.repository_directory, "targets", consistent_target_name
Expand All @@ -154,9 +148,6 @@ def _root_make_consistent_snapshot_true(self) -> bytes:


def test_refresh_on_consistent_targets(self):
# Create consistent targets with file path HASH.FILENAME.EXT
self._create_consistent_target("targets.json", "file1.txt")
self._create_consistent_target("role1.json", "file3.txt")

# Make root consistent snapshot true.
root_modified_bytes = self._root_make_consistent_snapshot_true()
Expand All @@ -174,6 +165,12 @@ def test_refresh_on_consistent_targets(self):
# Get targetinfo for "file3.txt" listed in the delegated role1
targetinfo3 = self.repository_updater.get_one_valid_targetinfo("file3.txt")

# Create consistent targets with file path HASH.FILENAME.EXT
target1_hash = list(targetinfo1["fileinfo"].hashes.values())[0]
target3_hash =list(targetinfo3["fileinfo"].hashes.values())[0]
self._create_consistent_target("file1.txt", target1_hash)
self._create_consistent_target("file3.txt", target3_hash)

destination_directory = self.make_temp_directory()
updated_targets = self.repository_updater.updated_targets(
[targetinfo1, targetinfo3], destination_directory
Expand Down

0 comments on commit f65e196

Please sign in to comment.