@@ -119,11 +119,14 @@ def test_schemas(self):
119119 'keyval' : {'public' : 'pubkey' ,
120120 'private' : 'privkey' }}),
121121
122- 'FILEINFO_SCHEMA ' : (tuf .formats .FILEINFO_SCHEMA ,
122+ 'TARGETS_FILEINFO_SCHEMA ' : (tuf .formats .TARGETS_FILEINFO_SCHEMA ,
123123 {'length' : 1024 ,
124124 'hashes' : {'sha256' : 'A4582BCF323BCEF' },
125125 'custom' : {'type' : 'paintjob' }}),
126126
127+ 'METADATA_FILEINFO_SCHEMA' : (tuf .formats .METADATA_FILEINFO_SCHEMA ,
128+ {'version' : 1 }),
129+
127130 'FILEDICT_SCHEMA' : (tuf .formats .FILEDICT_SCHEMA ,
128131 {'metadata/root.json' : {'length' : 1024 ,
129132 'hashes' : {'sha256' : 'ABCD123' },
@@ -241,7 +244,8 @@ def test_schemas(self):
241244 'version' : 8 ,
242245 'expires' : '1985-10-21T13:20:00Z' ,
243246 'meta' : {'metadattimestamp.json' : {'length' : 1024 ,
244- 'hashes' : {'sha256' : 'AB1245' }}}}),
247+ 'hashes' : {'sha256' : 'AB1245' },
248+ 'version' : 1 }}}),
245249
246250 'MIRROR_SCHEMA' : (tuf .formats .MIRROR_SCHEMA ,
247251 {'url_prefix' : 'http://localhost:8001' ,
@@ -394,7 +398,7 @@ def test_build_dict_conforming_to_schema(self):
394398 length = 88
395399 hashes = {'sha256' : '3c7fe3eeded4a34' }
396400 expires = '1985-10-21T13:20:00Z'
397- filedict = {'snapshot.json' : {'length' : length , 'hashes' : hashes }}
401+ filedict = {'snapshot.json' : {'length' : length , 'hashes' : hashes , 'version' : 1 }}
398402
399403
400404 # Try with and without _type and spec_version, both of which are
@@ -797,28 +801,60 @@ def test_make_signable(self):
797801
798802
799803
800- def test_make_fileinfo (self ):
804+ def test_make_targets_fileinfo (self ):
801805 # Test conditions for valid arguments.
802806 length = 1024
803807 hashes = {'sha256' : 'A4582BCF323BCEF' , 'sha512' : 'A4582BCF323BFEF' }
804- version = 8
805808 custom = {'type' : 'paintjob' }
806809
807- FILEINFO_SCHEMA = tuf .formats .FILEINFO_SCHEMA
808- make_fileinfo = tuf .formats .make_fileinfo
809- self .assertTrue (FILEINFO_SCHEMA .matches (make_fileinfo (length , hashes , version , custom )))
810- self .assertTrue (FILEINFO_SCHEMA .matches (make_fileinfo (length , hashes )))
810+ TARGETS_FILEINFO_SCHEMA = tuf .formats .TARGETS_FILEINFO_SCHEMA
811+ make_targets_fileinfo = tuf .formats .make_targets_fileinfo
812+ self .assertTrue (TARGETS_FILEINFO_SCHEMA .matches (make_targets_fileinfo (length , hashes , custom )))
813+ self .assertTrue (TARGETS_FILEINFO_SCHEMA .matches (make_targets_fileinfo (length , hashes )))
811814
812815 # Test conditions for invalid arguments.
813816 bad_length = 'bad'
814817 bad_hashes = 'bad'
815818 bad_custom = 'bad'
816819
817- self .assertRaises (securesystemslib .exceptions .FormatError , make_fileinfo , bad_length , hashes , custom )
818- self .assertRaises (securesystemslib .exceptions .FormatError , make_fileinfo , length , bad_hashes , custom )
819- self .assertRaises (securesystemslib .exceptions .FormatError , make_fileinfo , length , hashes , bad_custom )
820- self .assertRaises (securesystemslib .exceptions .FormatError , make_fileinfo , bad_length , hashes )
821- self .assertRaises (securesystemslib .exceptions .FormatError , make_fileinfo , length , bad_hashes )
820+ self .assertRaises (securesystemslib .exceptions .FormatError , make_targets_fileinfo ,
821+ bad_length , hashes , custom )
822+ self .assertRaises (securesystemslib .exceptions .FormatError , make_targets_fileinfo ,
823+ length , bad_hashes , custom )
824+ self .assertRaises (securesystemslib .exceptions .FormatError , make_targets_fileinfo ,
825+ length , hashes , bad_custom )
826+ self .assertRaises (securesystemslib .exceptions .FormatError , make_targets_fileinfo ,
827+ bad_length , hashes )
828+ self .assertRaises (securesystemslib .exceptions .FormatError , make_targets_fileinfo ,
829+ length , bad_hashes )
830+
831+
832+
833+ def test_make_metadata_fileinfo (self ):
834+ # Test conditions for valid arguments.
835+ length = 1024
836+ hashes = {'sha256' : 'A4582BCF323BCEF' , 'sha512' : 'A4582BCF323BFEF' }
837+ version = 8
838+
839+ METADATA_FILEINFO_SCHEMA = tuf .formats .METADATA_FILEINFO_SCHEMA
840+ make_metadata_fileinfo = tuf .formats .make_metadata_fileinfo
841+ self .assertTrue (METADATA_FILEINFO_SCHEMA .matches (make_metadata_fileinfo (
842+ version , length , hashes )))
843+ self .assertTrue (METADATA_FILEINFO_SCHEMA .matches (make_metadata_fileinfo (version )))
844+
845+ # Test conditions for invalid arguments.
846+ bad_version = 'bad'
847+ bad_length = 'bad'
848+ bad_hashes = 'bad'
849+
850+ self .assertRaises (securesystemslib .exceptions .FormatError , make_metadata_fileinfo ,
851+ bad_version , length , hashes )
852+ self .assertRaises (securesystemslib .exceptions .FormatError , make_metadata_fileinfo ,
853+ version , bad_length , hashes )
854+ self .assertRaises (securesystemslib .exceptions .FormatError , make_metadata_fileinfo ,
855+ version , length , bad_hashes )
856+ self .assertRaises (securesystemslib .exceptions .FormatError , make_metadata_fileinfo ,
857+ bad_version )
822858
823859
824860
0 commit comments