Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Root.add_key() argument's type #1386

Merged
merged 1 commit into from
May 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,6 @@
import_ed25519_privatekey_from_file
)

from securesystemslib.keys import (
format_keyval_to_metadata
)

from securesystemslib.signer import (
SSlibSigner
)
Expand Down Expand Up @@ -234,7 +230,7 @@ def test_metadata_base(self):
is_expired = md.signed.is_expired(md.signed.expires - timedelta(days=1))
self.assertFalse(is_expired)

# Test is_expired without reference_time,
# Test is_expired without reference_time,
# manipulating md.signed.expires
expires = md.signed.expires
md.signed.expires = datetime.utcnow()
Expand All @@ -244,7 +240,7 @@ def test_metadata_base(self):
is_expired = md.signed.is_expired()
self.assertFalse(is_expired)
md.signed.expires = expires

def test_metadata_snapshot(self):
snapshot_path = os.path.join(
self.repo_dir, 'metadata', 'snapshot.json')
Expand Down Expand Up @@ -394,9 +390,10 @@ def test_metadata_root(self):
root_key2 = import_ed25519_publickey_from_file(
os.path.join(self.keystore_dir, 'root_key2.pub'))


keyid = root_key2['keyid']
key_metadata = format_keyval_to_metadata(
root_key2['keytype'], root_key2['scheme'], root_key2['keyval'])
key_metadata = Key(root_key2['keytype'], root_key2['scheme'],
root_key2['keyval'])

# Assert that root does not contain the new key
self.assertNotIn(keyid, root.signed.roles['root'].keyids)
Expand All @@ -409,6 +406,10 @@ def test_metadata_root(self):
self.assertIn(keyid, root.signed.roles['root'].keyids)
self.assertIn(keyid, root.signed.keys)

# Confirm that the newly added key does not break
# the object serialization
root.to_dict()

# Try adding the same key again and assert its ignored.
pre_add_keyid = root.signed.roles['root'].keyids.copy()
root.signed.add_key('root', keyid, key_metadata)
Expand Down
4 changes: 1 addition & 3 deletions tuf/api/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -578,9 +578,7 @@ def to_dict(self) -> Dict[str, Any]:
return root_dict

# Update key for a role.
def add_key(
self, role: str, keyid: str, key_metadata: Dict[str, Any]
) -> None:
def add_key(self, role: str, keyid: str, key_metadata: Key) -> None:
"""Adds new key for 'role' and updates the key store."""
self.roles[role].keyids.add(keyid)
self.keys[keyid] = key_metadata
Expand Down