@@ -51,8 +51,13 @@ def wrapper(test_cls: "TestSerialization"):
5151class TestSerialization (unittest .TestCase ):
5252
5353 valid_keys : DataSet = {
54+ # Do we want to add unrecognized fields in the Key class?
5455 "all" : '{"keytype": "rsa", "scheme": "rsassa-pss-sha256", \
5556 "keyval": {"public": "foo"}}' ,
57+ "unrecognized field" : '{"keytype": "rsa", "scheme": "rsassa-pss-sha256", \
58+ "keyval": {"public": "foo"}, "foo": "bar"}' ,
59+ "unrecognized field in keyval" : '{"keytype": "rsa", "scheme": "rsassa-pss-sha256", \
60+ "keyval": {"public": "foo", "foo": "bar"}}' ,
5661 }
5762
5863 @run_sub_tests_with_dataset (valid_keys )
@@ -63,7 +68,8 @@ def test_key_serialization(self, test_case_data: str):
6368
6469
6570 valid_roles : DataSet = {
66- "all" : '{"keyids": ["keyid"], "threshold": 3}'
71+ "all" : '{"keyids": ["keyid"], "threshold": 3}' ,
72+ "unrecognized field" : '{"keyids": ["keyid"], "threshold": 3, "foo": "bar"}' ,
6773 }
6874
6975 @run_sub_tests_with_dataset (valid_roles )
@@ -84,6 +90,11 @@ def test_role_serialization(self, test_case_data: str):
8490 "keys": {"keyid" : {"keytype": "rsa", "scheme": "rsassa-pss-sha256", "keyval": {"public": "foo"} }}, \
8591 "roles": { "targets": {"keyids": ["keyid"], "threshold": 3} } \
8692 }' ,
93+ "unrecognized field" : '{"_type": "root", "spec_version": "1.0.0", "version": 1, \
94+ "expires": "2030-01-01T00:00:00Z", "consistent_snapshot": false, \
95+ "keys": {"keyid" : {"keytype": "rsa", "scheme": "rsassa-pss-sha256", "keyval": {"public": "foo"}}}, \
96+ "roles": { "targets": {"keyids": ["keyid"], "threshold": 3}}, \
97+ "foo": "bar"}' ,
8798 }
8899
89100 @run_sub_tests_with_dataset (valid_roots )
@@ -95,7 +106,9 @@ def test_root_serialization(self, test_case_data: str):
95106 valid_metafiles : DataSet = {
96107 "all" : '{"hashes": {"sha256" : "abc"}, "length": 12, "version": 1}' ,
97108 "no length" : '{"hashes": {"sha256" : "abc"}, "version": 1 }' ,
98- "no hashes" : '{"length": 12, "version": 1}'
109+ "no hashes" : '{"length": 12, "version": 1}' ,
110+ "unrecognized field" : '{"hashes": {"sha256" : "abc"}, "length": 12, "version": 1, \
111+ "foo": "bar"}' ,
99112 }
100113
101114 @run_sub_tests_with_dataset (valid_metafiles )
@@ -107,7 +120,9 @@ def test_metafile_serialization(self, test_case_data: str):
107120
108121 valid_timestamps : DataSet = {
109122 "all" : '{ "_type": "timestamp", "spec_version": "1.0.0", "version": 1, "expires": "2030-01-01T00:00:00Z", \
110- "meta": {"snapshot.json": {"hashes": {"sha256" : "abc"}, "version": 1}}}'
123+ "meta": {"snapshot.json": {"hashes": {"sha256" : "abc"}, "version": 1}}}' ,
124+ "unrecognized field" : '{ "_type": "timestamp", "spec_version": "1.0.0", "version": 1, "expires": "2030-01-01T00:00:00Z", \
125+ "meta": {"snapshot.json": {"hashes": {"sha256" : "abc"}, "version": 1}}, "foo": "bar"}' ,
111126 }
112127
113128 @run_sub_tests_with_dataset (valid_timestamps )
@@ -119,7 +134,9 @@ def test_timestamp_serialization(self, test_case_data: str):
119134
120135 valid_snapshots : DataSet = {
121136 "all" : '{ "_type": "snapshot", "spec_version": "1.0.0", "version": 1, "expires": "2030-01-01T00:00:00Z", \
122- "meta": { "file.txt": { "hashes": {"sha256" : "abc"}, "version": 1 }}}'
137+ "meta": { "file.txt": { "hashes": {"sha256" : "abc"}, "version": 1 }}}' ,
138+ "unrecognized field" : '{ "_type": "snapshot", "spec_version": "1.0.0", "version": 1, "expires": "2030-01-01T00:00:00Z", \
139+ "meta": { "file.txt": { "hashes": {"sha256" : "abc"}, "version": 1 }}, "foo": "bar"}' ,
123140 }
124141
125142 @run_sub_tests_with_dataset (valid_snapshots )
@@ -138,6 +155,8 @@ def test_snapshot_serialization(self, test_case_data: str):
138155 "path_hash_prefixes": ["h1", "h2"], "threshold": 99}' ,
139156 "no hash or path prefix" :
140157 '{"keyids": ["keyid"], "name": "a", "terminating": true, "threshold": 3}' ,
158+ "unrecognized field" :
159+ '{"keyids": ["keyid"], "name": "a", "terminating": true, "threshold": 3, "foo": "bar"}' ,
141160 }
142161
143162 @run_sub_tests_with_dataset (valid_delegated_roles )
@@ -149,7 +168,11 @@ def test_delegated_role_serialization(self, test_case_data: str):
149168
150169 valid_delegations : DataSet = {
151170 "all" : '{"keys": {"keyid" : {"keytype": "rsa", "scheme": "rsassa-pss-sha256", "keyval": {"public": "foo"}}}, \
152- "roles": [ {"keyids": ["keyid"], "name": "a", "terminating": true, "threshold": 3} ]}'
171+ "roles": [ {"keyids": ["keyid"], "name": "a", "terminating": true, "threshold": 3} ]}' ,
172+ "unrecognized field" :
173+ '{"keys": {"keyid" : {"keytype": "rsa", "scheme": "rsassa-pss-sha256", "keyval": {"public": "foo"}}}, \
174+ "roles": [ {"keyids": ["keyid"], "name": "a", "terminating": true, "threshold": 3} ], \
175+ "foo": "bar"}' ,
153176 }
154177
155178 @run_sub_tests_with_dataset (valid_delegations )
@@ -162,7 +185,9 @@ def test_delegation_serialization(self, test_case_data: str):
162185 valid_targetfiles : DataSet = {
163186 "all" : '{"length": 12, "hashes": {"sha256" : "abc"}, \
164187 "custom" : {"foo": "bar"} }' ,
165- "no custom" : '{"length": 12, "hashes": {"sha256" : "abc"}}'
188+ "no custom" : '{"length": 12, "hashes": {"sha256" : "abc"}}' ,
189+ "unrecognized field" : '{"length": 12, "hashes": {"sha256" : "abc"}, \
190+ "custom" : {"foo": "bar"}, "foo": "bar"}' ,
166191 }
167192
168193 @run_sub_tests_with_dataset (valid_targetfiles )
@@ -187,7 +212,9 @@ def test_targetfile_serialization(self, test_case_data: str):
187212 }' ,
188213 "no delegations" : '{"_type": "targets", "spec_version": "1.0.0", "version": 1, "expires": "2030-01-01T00:00:00Z", \
189214 "targets": { "file.txt": {"length": 12, "hashes": {"sha256" : "abc"} } } \
190- }'
215+ }' ,
216+ "unrecognized_field" : '{"_type": "targets", "spec_version": "1.0.0", "version": 1, "expires": "2030-01-01T00:00:00Z", \
217+ "targets": {}, "foo": "bar"}' ,
191218 }
192219
193220 @run_sub_tests_with_dataset (valid_targets )
0 commit comments