Skip to content

Commit 458fe73

Browse files
author
Martin Vrachev
committed
new API: test containers for zero or more elements
Test metadata (de)serialization with input data containing containers with zero or more elements. Here is the status for the different use cases: Root keys: - many keys: added Root roles: - many roles: added Root role keyids: - many keids: already added in #1481 MetaFile hashes: - many hashes: already tested - zero hashes: added. Testing as invalid test case. Delegation keys: - many keys: added Delegation role keyids: - many keyids: added Delegation role paths: - many paths: already tested Delegation role path_hash_prefixes: - many path_hash_path_prefixes: already tested According to the spec having an empty container for any of these cases: - Root keys - Root roles - Root role keyids - Delegation keys - DelegationRole keyids - DelegationRole paths - DelegationRole path_hash_prefixes is not allowed, but for the purpose of interactive object construction we don't block those use-cases. We don't want to add tests, because we don't want to advertise this behavior. In the future, we are going to add validation that those cases don't occur which will be called when serializing the object back to bytes/dictionary/file. Signed-off-by: Martin Vrachev <mvrachev@vmware.com>
1 parent 8e9677d commit 458fe73

1 file changed

Lines changed: 28 additions & 0 deletions

File tree

tests/test_metadata_serialization.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,24 @@ def test_role_serialization(self, test_case_data: str):
168168
"keys": {"keyid" : {"keytype": "rsa", "scheme": "rsassa-pss-sha256", "keyval": {"public": "foo"}}}, \
169169
"roles": { "targets": {"keyids": ["keyid"], "threshold": 3}}, \
170170
"foo": "bar"}',
171+
"many keys": '{"_type": "root", "spec_version": "1.0.0", "version": 1, \
172+
"expires": "2030-01-01T00:00:00Z", "consistent_snapshot": false, \
173+
"keys": { \
174+
"keyid1" : {"keytype": "rsa", "scheme": "rsassa-pss-sha256", "keyval": {"public": "foo"}}, \
175+
"keyid2" : {"keytype": "ed25519", "scheme": "ed25519", "keyval": {"public": "bar"}}}, \
176+
"roles": { "targets": {"keyids": ["keyid"], "threshold": 3}}}',
177+
"many roles": '{"_type": "root", "spec_version": "1.0.0", "version": 1, \
178+
"expires": "2030-01-01T00:00:00Z", "consistent_snapshot": false, \
179+
"keys": {"keyid" : {"keytype": "rsa", "scheme": "rsassa-pss-sha256", "keyval": {"public": "foo"}}}, \
180+
"roles": { \
181+
"targets": {"keyids": ["keyid1"], "threshold": 1}, \
182+
"snapshot": {"keyids": ["keyid2"], "threshold": 1}} \
183+
}',
184+
"many role keyids": '{"_type": "root", "spec_version": "1.0.0", "version": 1, \
185+
"expires": "2030-01-01T00:00:00Z", "consistent_snapshot": false, \
186+
"keys": {"keyid" : {"keytype": "rsa", "scheme": "rsassa-pss-sha256", "keyval": {"public": "foo"}}}, \
187+
"roles": { "targets": {"keyids": ["keyid1", "keyid2"], "threshold": 3}} \
188+
}',
171189
}
172190

173191
@run_sub_tests_with_dataset(valid_roots)
@@ -184,6 +202,7 @@ def test_root_serialization(self, test_case_data: str):
184202
"empty hashes dict": '{"version": 1, "length": 1, "hashes": {}}',
185203
"hashes wrong type": '{"version": 1, "length": 1, "hashes": 1}',
186204
"hashes values wrong type": '{"version": 1, "length": 1, "hashes": {"sha256": 1}}',
205+
"zero hashes": '{"version": 1, "length": 1, "hashes": {}}',
187206
}
188207

189208
@run_sub_tests_with_dataset(invalid_metafiles)
@@ -198,6 +217,7 @@ def test_invalid_metafile_serialization(self, test_case_data: Dict[str, str]):
198217
"no length": '{"hashes": {"sha256" : "abc"}, "version": 1 }',
199218
"no hashes": '{"length": 12, "version": 1}',
200219
"unrecognized field": '{"hashes": {"sha256" : "abc"}, "length": 12, "version": 1, "foo": "bar"}',
220+
"many hashes": '{"hashes": {"sha256" : "abc", "sha512": "cde"}, "length": 12, "version": 1}',
201221
}
202222

203223
@run_sub_tests_with_dataset(valid_metafiles)
@@ -246,6 +266,9 @@ def test_snapshot_serialization(self, test_case_data: str):
246266
'{"keyids": ["keyid"], "name": "a", "terminating": true, "threshold": 3}',
247267
"unrecognized field":
248268
'{"keyids": ["keyid"], "name": "a", "terminating": true, "threshold": 3, "foo": "bar"}',
269+
"many keyids":
270+
'{"keyids": ["keyid1", "keyid2"], "name": "a", "paths": ["fn1", "fn2"], \
271+
"terminating": false, "threshold": 1}',
249272
}
250273

251274
@run_sub_tests_with_dataset(valid_delegated_roles)
@@ -262,6 +285,11 @@ def test_delegated_role_serialization(self, test_case_data: str):
262285
'{"keys": {"keyid" : {"keytype": "rsa", "scheme": "rsassa-pss-sha256", "keyval": {"public": "foo"}}}, \
263286
"roles": [ {"keyids": ["keyid"], "name": "a", "terminating": true, "threshold": 3} ], \
264287
"foo": "bar"}',
288+
"many keys":
289+
'{"keys": { \
290+
"keyid1" : {"keytype": "rsa", "scheme": "rsassa-pss-sha256", "keyval": {"public": "foo"}}, \
291+
"keyid2" : {"keytype": "ed25519", "scheme": "ed25519", "keyval": {"public": "bar"}}}, \
292+
"roles": [ {"keyids": ["keyid"], "name": "a", "terminating": true, "threshold": 3} ]}',
265293
}
266294

267295
@run_sub_tests_with_dataset(valid_delegations)

0 commit comments

Comments
 (0)