Skip to content

Commit

Permalink
Add test for delegations update
Browse files Browse the repository at this point in the history
Add a new test case in test_generate_targets_metadata
to check if targets metadata is up-to-date with its delegated
roles.

Signed-off-by: Teodora Sechkova <[email protected]>
  • Loading branch information
sechkova committed Aug 11, 2020
1 parent f1a0fb1 commit e7fecb8
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions tests/test_repository_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import sys
import unittest
import platform
import copy

import tuf
import tuf.formats
Expand Down Expand Up @@ -368,6 +369,34 @@ def test_generate_targets_metadata(self):
False)
self.assertTrue(tuf.formats.TARGETS_SCHEMA.matches(targets_metadata))

# Test update in targets' delegations
keystore_path = os.path.join('repository_data', 'keystore')
targets_public_keypath = os.path.join(keystore_path, 'targets_key.pub')
targets_public_key = securesystemslib.interface.\
import_ed25519_publickey_from_file(targets_public_keypath)

# Add new key and threshold to delegated role
repository.targets('role1').add_verification_key(targets_public_key)
repository.targets('role1').threshold = 2
role1_keyids = tuf.roledb.get_role_keyids('role1')
role1_threshold = tuf.roledb.get_role_threshold('role1')
roleinfo = tuf.roledb.get_roleinfo('targets')
delegations = roleinfo['delegations']
old_delegations = copy.deepcopy(delegations)

targets_metadata = \
repo_lib.generate_targets_metadata(targets_directory, target_files,
version, expiration_date, delegations,
False)
self.assertNotEqual(old_delegations, delegations)
self.assertEqual(role1_keyids,
targets_metadata['delegations']['roles'][0]['keyids'])
self.assertEqual(role1_threshold,
targets_metadata['delegations']['roles'][0]['threshold'])
for keyid in role1_keyids:
self.assertIn(keyid, targets_metadata['delegations']['keys'])


# Verify that 'digest.filename' file is saved to 'targets_directory' if
# the 'write_consistent_targets' argument is True.
list_targets_directory = os.listdir(targets_directory)
Expand Down

0 comments on commit e7fecb8

Please sign in to comment.