Skip to content

Commit cd34793

Browse files
author
Martin Vrachev
committed
Move nonunique sigs test to serialization tests
Move the duplicating signatures tests from test_metadata_base function in test_api.py into test_metadata_serialization.py. This is a more logical place to store this test case as test_metadata_base is actually focused on testing Metadata.signed.is_expired. That also is the reason why I renamed test_metadata_base to test_metadata_signed_is_expired. Signed-off-by: Martin Vrachev <mvrachev@vmware.com>
1 parent d2a840f commit cd34793

2 files changed

Lines changed: 7 additions & 10 deletions

File tree

tests/test_api.py

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ def test_verify_failures(self) -> None:
276276
timestamp_key.verify_signature(md_obj)
277277
sig.signature = correct_sig
278278

279-
def test_metadata_base(self) -> None:
279+
def test_metadata_signed_is_expired(self) -> None:
280280
# Use of Snapshot is arbitrary, we're just testing the base class
281281
# features with real data
282282
snapshot_path = os.path.join(self.repo_dir, "metadata", "snapshot.json")
@@ -303,14 +303,6 @@ def test_metadata_base(self) -> None:
303303
self.assertFalse(is_expired)
304304
md.signed.expires = expires
305305

306-
# Test deserializing metadata with non-unique signatures:
307-
data = md.to_dict()
308-
data["signatures"].append(
309-
{"keyid": data["signatures"][0]["keyid"], "sig": "foo"}
310-
)
311-
with self.assertRaises(ValueError):
312-
Metadata.from_dict(data)
313-
314306
def test_metadata_verify_delegate(self) -> None:
315307
root_path = os.path.join(self.repo_dir, "metadata", "root.json")
316308
root = Metadata[Root].from_file(root_path)

tests/test_metadata_serialization.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,16 @@ class TestSerialization(unittest.TestCase):
4242
{ "_type": "timestamp", "spec_version": "1.0.0", "version": 1, "expires": "2030-01-01T00:00:00Z", \
4343
"meta": {"snapshot.json": {"hashes": {"sha256" : "abc"}, "version": 1}}} \
4444
}',
45+
"non unique duplicating signatures": b'{"signed": \
46+
{ "_type": "timestamp", "spec_version": "1.0.0", "version": 1, "expires": "2030-01-01T00:00:00Z", \
47+
"meta": {"snapshot.json": {"hashes": {"sha256" : "abc"}, "version": 1}}}, \
48+
"signatures": [{"keyid": "id", "sig": "b"}, {"keyid": "id", "sig": "b"}] \
49+
}',
4550
}
4651

4752
@utils.run_sub_tests_with_dataset(invalid_metadata)
4853
def test_invalid_metadata_serialization(self, test_data: bytes) -> None:
49-
# We expect a DeserializationError reraised from KeyError.
54+
# We expect a DeserializationError reraised from ValueError or KeyError.
5055
with self.assertRaises(DeserializationError):
5156
Metadata.from_bytes(test_data)
5257

0 commit comments

Comments
 (0)