@@ -242,10 +242,9 @@ def test_snapshot_serialization(self, test_case_data: str):
242
242
"no path attribute" :
243
243
'{"keyids": ["keyid"], "name": "a", "terminating": false, \
244
244
"path_hash_prefixes": ["h1", "h2"], "threshold": 99}' ,
245
- "no hash or path prefix" :
246
- '{"keyids": ["keyid"], "name": "a", "terminating": true, "threshold": 3}' ,
247
245
"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"}' ,
249
248
}
250
249
251
250
@run_sub_tests_with_dataset (valid_delegated_roles )
@@ -255,12 +254,27 @@ def test_delegated_role_serialization(self, test_case_data: str):
255
254
self .assertDictEqual (case_dict , deserialized_role .to_dict ())
256
255
257
256
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
+
258
272
valid_delegations : DataSet = {
259
273
"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} ]}' ,
261
275
"unrecognized field" :
262
276
'{"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} ], \
264
278
"foo": "bar"}' ,
265
279
}
266
280
@@ -305,13 +319,13 @@ def test_targetfile_serialization(self, test_case_data: str):
305
319
"targets": { "file.txt": {"length": 12, "hashes": {"sha256" : "abc"} } }, \
306
320
"delegations": {"keys": {"keyid" : {"keytype": "rsa", \
307
321
"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} ]} \
309
323
}' ,
310
324
"empty targets" : '{"_type": "targets", "spec_version": "1.0.0", "version": 1, "expires": "2030-01-01T00:00:00Z", \
311
325
"targets": {}, \
312
326
"delegations": {"keys": {"keyid" : {"keytype": "rsa", \
313
327
"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} ]} \
315
329
}' ,
316
330
"no delegations" : '{"_type": "targets", "spec_version": "1.0.0", "version": 1, "expires": "2030-01-01T00:00:00Z", \
317
331
"targets": { "file.txt": {"length": 12, "hashes": {"sha256" : "abc"} } } \
0 commit comments