@@ -242,10 +242,9 @@ def test_snapshot_serialization(self, test_case_data: str):
242242 "no path attribute" :
243243 '{"keyids": ["keyid"], "name": "a", "terminating": false, \
244244 "path_hash_prefixes": ["h1", "h2"], "threshold": 99}' ,
245- "no hash or path prefix" :
246- '{"keyids": ["keyid"], "name": "a", "terminating": true, "threshold": 3}' ,
247245 "unrecognized field" :
248- '{"keyids": ["keyid"], "name": "a", "terminating": true, "threshold": 3, "foo": "bar"}' ,
246+ '{"keyids": ["keyid"], "name": "a", "paths": ["fn1", "fn2"], \
247+ "terminating": true, "threshold": 3, "foo": "bar"}' ,
249248 }
250249
251250 @run_sub_tests_with_dataset (valid_delegated_roles )
@@ -255,12 +254,27 @@ def test_delegated_role_serialization(self, test_case_data: str):
255254 self .assertDictEqual (case_dict , deserialized_role .to_dict ())
256255
257256
257+ invalid_delegated_roles : DataSet = {
258+ "missing hash prefixes and paths" :
259+ '{"name": "a", "keyids": ["keyid"], "threshold": 1, "terminating": false}' ,
260+ "both hash prefixes and paths" :
261+ '{"name": "a", "keyids": ["keyid"], "threshold": 1, "terminating": false, \
262+ "paths": ["fn1", "fn2"], "path_hash_prefixes": ["h1", "h2"]}' ,
263+ }
264+
265+ @run_sub_tests_with_dataset (invalid_delegated_roles )
266+ def test_invalid_delegated_role_serialization (self , test_case_data : str ):
267+ case_dict = json .loads (test_case_data )
268+ with self .assertRaises (ValueError ):
269+ DelegatedRole .from_dict (copy .copy (case_dict ))
270+
271+
258272 valid_delegations : DataSet = {
259273 "all" : '{"keys": {"keyid" : {"keytype": "rsa", "scheme": "rsassa-pss-sha256", "keyval": {"public": "foo"}}}, \
260- "roles": [ {"keyids": ["keyid"], "name": "a", "terminating": true, "threshold": 3} ]}' ,
274+ "roles": [ {"keyids": ["keyid"], "name": "a", "paths": ["fn1", "fn2"], " terminating": true, "threshold": 3} ]}' ,
261275 "unrecognized field" :
262276 '{"keys": {"keyid" : {"keytype": "rsa", "scheme": "rsassa-pss-sha256", "keyval": {"public": "foo"}}}, \
263- "roles": [ {"keyids": ["keyid"], "name": "a", "terminating": true, "threshold": 3} ], \
277+ "roles": [ {"keyids": ["keyid"], "name": "a", "paths": ["fn1", "fn2"], " terminating": true, "threshold": 3} ], \
264278 "foo": "bar"}' ,
265279 }
266280
@@ -305,13 +319,13 @@ def test_targetfile_serialization(self, test_case_data: str):
305319 "targets": { "file.txt": {"length": 12, "hashes": {"sha256" : "abc"} } }, \
306320 "delegations": {"keys": {"keyid" : {"keytype": "rsa", \
307321 "scheme": "rsassa-pss-sha256", "keyval": {"public": "foo"} }}, \
308- "roles": [ {"keyids": ["keyid"], "name": "a", "terminating": true, "threshold": 3} ]} \
322+ "roles": [ {"keyids": ["keyid"], "name": "a", "paths": ["fn1", "fn2"], " terminating": true, "threshold": 3} ]} \
309323 }' ,
310324 "empty targets" : '{"_type": "targets", "spec_version": "1.0.0", "version": 1, "expires": "2030-01-01T00:00:00Z", \
311325 "targets": {}, \
312326 "delegations": {"keys": {"keyid" : {"keytype": "rsa", \
313327 "scheme": "rsassa-pss-sha256", "keyval": {"public": "foo"} }}, \
314- "roles": [ {"keyids": ["keyid"], "name": "a", "terminating": true, "threshold": 3} ]} \
328+ "roles": [ {"keyids": ["keyid"], "name": "a", "paths": ["fn1", "fn2"], " terminating": true, "threshold": 3} ]} \
315329 }' ,
316330 "no delegations" : '{"_type": "targets", "spec_version": "1.0.0", "version": 1, "expires": "2030-01-01T00:00:00Z", \
317331 "targets": { "file.txt": {"length": 12, "hashes": {"sha256" : "abc"} } } \
0 commit comments