@@ -131,6 +131,13 @@ def test_update(self):
131
131
# the 4 top level metadata objects + 2 additional delegated targets
132
132
self .assertTrue (len (self .trusted_set ), 6 )
133
133
134
+ count = 0
135
+ for md in self .trusted_set :
136
+ self .assertIsInstance (md , Metadata )
137
+ count += 1
138
+
139
+ self .assertTrue (count , 6 )
140
+
134
141
def test_out_of_order_ops (self ):
135
142
# Update timestamp before root is finished
136
143
with self .assertRaises (RuntimeError ):
@@ -214,6 +221,13 @@ def test_update_with_invalid_json(self):
214
221
215
222
update_func (metadata )
216
223
224
+ def test_update_root_new_root (self ):
225
+ # test that root can be updated with a new valid version
226
+ def root_new_version_modifier (root : Root ) -> None :
227
+ root .version += 1
228
+
229
+ root = self .modify_metadata ("root" , root_new_version_modifier )
230
+ self .trusted_set .update_root (root )
217
231
218
232
def test_update_root_new_root_cannot_be_verified_with_threshold (self ):
219
233
# new_root data with threshold which cannot be verified.
@@ -227,7 +241,6 @@ def test_update_root_new_root_ver_same_as_trusted_root_ver(self):
227
241
with self .assertRaises (exceptions .ReplayedMetadataError ):
228
242
self .trusted_set .update_root (self .metadata ["root" ])
229
243
230
-
231
244
def test_root_update_finished_expired (self ):
232
245
def root_expired_modifier (root : Root ) -> None :
233
246
root .expires = datetime (1970 , 1 , 1 )
@@ -249,13 +262,15 @@ def version_modifier(timestamp: Timestamp) -> None:
249
262
with self .assertRaises (exceptions .ReplayedMetadataError ):
250
263
self .trusted_set .update_timestamp (self .metadata ["timestamp" ])
251
264
252
- def test_update_timestamp_snapshot_ver_below_trusted_snapshot_ver (self ):
253
- def version_modifier (timestamp : Timestamp ) -> None :
254
- timestamp .version = 3
265
+ def test_update_timestamp_snapshot_ver_below_current (self ):
266
+ def bump_snapshot_version (timestamp : Timestamp ) -> None :
267
+ timestamp .meta [ "snapshot.json" ]. version = 2
255
268
256
- modified_timestamp = self .modify_metadata ("timestamp" , version_modifier )
257
- self ._root_updated_and_update_timestamp (modified_timestamp )
258
- # new_timestamp.snapshot.version < trusted_timestamp.snapshot.version
269
+ # set current known snapshot.json version to 2
270
+ timestamp = self .modify_metadata ("timestamp" , bump_snapshot_version )
271
+ self ._root_updated_and_update_timestamp (timestamp )
272
+
273
+ # newtimestamp.meta["snapshot.json"].version < trusted_timestamp.meta["snapshot.json"].version
259
274
with self .assertRaises (exceptions .ReplayedMetadataError ):
260
275
self .trusted_set .update_timestamp (self .metadata ["timestamp" ])
261
276
@@ -269,6 +284,16 @@ def timestamp_expired_modifier(timestamp: Timestamp) -> None:
269
284
with self .assertRaises (exceptions .ExpiredMetadataError ):
270
285
self .trusted_set .update_timestamp (timestamp )
271
286
287
+ def test_update_snapshot_length_or_hash_mismatch (self ):
288
+ def modify_snapshot_length (timestamp : Timestamp ) -> None :
289
+ timestamp .meta ["snapshot.json" ].length = 1
290
+
291
+ # set known snapshot.json length to 1
292
+ timestamp = self .modify_metadata ("timestamp" , modify_snapshot_length )
293
+ self ._root_updated_and_update_timestamp (timestamp )
294
+
295
+ with self .assertRaises (exceptions .RepositoryError ):
296
+ self .trusted_set .update_snapshot (self .metadata ["snapshot" ])
272
297
273
298
def test_update_snapshot_cannot_verify_snapshot_with_threshold (self ):
274
299
self ._root_updated_and_update_timestamp (self .metadata ["timestamp" ])
@@ -323,7 +348,6 @@ def snapshot_expired_modifier(snapshot: Snapshot) -> None:
323
348
with self .assertRaises (exceptions .ExpiredMetadataError ):
324
349
self .trusted_set .update_snapshot (snapshot )
325
350
326
-
327
351
def test_update_targets_no_meta_in_snapshot (self ):
328
352
def no_meta_modifier (snapshot : Snapshot ) -> None :
329
353
snapshot .meta = {}
0 commit comments