@@ -131,6 +131,13 @@ def test_update(self):
131131 # the 4 top level metadata objects + 2 additional delegated targets
132132 self .assertTrue (len (self .trusted_set ), 6 )
133133
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+
134141 def test_out_of_order_ops (self ):
135142 # Update timestamp before root is finished
136143 with self .assertRaises (RuntimeError ):
@@ -214,6 +221,13 @@ def test_update_with_invalid_json(self):
214221
215222 update_func (metadata )
216223
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 )
217231
218232 def test_update_root_new_root_cannot_be_verified_with_threshold (self ):
219233 # 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):
227241 with self .assertRaises (exceptions .ReplayedMetadataError ):
228242 self .trusted_set .update_root (self .metadata ["root" ])
229243
230-
231244 def test_root_update_finished_expired (self ):
232245 def root_expired_modifier (root : Root ) -> None :
233246 root .expires = datetime (1970 , 1 , 1 )
@@ -249,13 +262,15 @@ def version_modifier(timestamp: Timestamp) -> None:
249262 with self .assertRaises (exceptions .ReplayedMetadataError ):
250263 self .trusted_set .update_timestamp (self .metadata ["timestamp" ])
251264
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
255268
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
259274 with self .assertRaises (exceptions .ReplayedMetadataError ):
260275 self .trusted_set .update_timestamp (self .metadata ["timestamp" ])
261276
@@ -269,6 +284,16 @@ def timestamp_expired_modifier(timestamp: Timestamp) -> None:
269284 with self .assertRaises (exceptions .ExpiredMetadataError ):
270285 self .trusted_set .update_timestamp (timestamp )
271286
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" ])
272297
273298 def test_update_snapshot_cannot_verify_snapshot_with_threshold (self ):
274299 self ._root_updated_and_update_timestamp (self .metadata ["timestamp" ])
@@ -323,7 +348,6 @@ def snapshot_expired_modifier(snapshot: Snapshot) -> None:
323348 with self .assertRaises (exceptions .ExpiredMetadataError ):
324349 self .trusted_set .update_snapshot (snapshot )
325350
326-
327351 def test_update_targets_no_meta_in_snapshot (self ):
328352 def no_meta_modifier (snapshot : Snapshot ) -> None :
329353 snapshot .meta = {}
0 commit comments