@@ -53,6 +53,10 @@ class TestSerialization(unittest.TestCase):
5353 valid_keys : DataSet = {
5454 "all" : '{"keytype": "rsa", "scheme": "rsassa-pss-sha256", \
5555 "keyval": {"public": "foo"}}' ,
56+ "unrecognized field" : '{"keytype": "rsa", "scheme": "rsassa-pss-sha256", \
57+ "keyval": {"public": "foo"}, "foo": "bar"}' ,
58+ "unrecognized field in keyval" : '{"keytype": "rsa", "scheme": "rsassa-pss-sha256", \
59+ "keyval": {"public": "foo", "foo": "bar"}}' ,
5660 }
5761
5862 @run_sub_tests_with_dataset (valid_keys )
@@ -63,7 +67,8 @@ def test_key_serialization(self, test_case_data: str):
6367
6468
6569 valid_roles : DataSet = {
66- "all" : '{"keyids": ["keyid"], "threshold": 3}'
70+ "all" : '{"keyids": ["keyid"], "threshold": 3}' ,
71+ "unrecognized field" : '{"keyids": ["keyid"], "threshold": 3, "foo": "bar"}' ,
6772 }
6873
6974 @run_sub_tests_with_dataset (valid_roles )
@@ -84,6 +89,11 @@ def test_role_serialization(self, test_case_data: str):
8489 "keys": {"keyid" : {"keytype": "rsa", "scheme": "rsassa-pss-sha256", "keyval": {"public": "foo"} }}, \
8590 "roles": { "targets": {"keyids": ["keyid"], "threshold": 3} } \
8691 }' ,
92+ "unrecognized field" : '{"_type": "root", "spec_version": "1.0.0", "version": 1, \
93+ "expires": "2030-01-01T00:00:00Z", "consistent_snapshot": false, \
94+ "keys": {"keyid" : {"keytype": "rsa", "scheme": "rsassa-pss-sha256", "keyval": {"public": "foo"}}}, \
95+ "roles": { "targets": {"keyids": ["keyid"], "threshold": 3}}, \
96+ "foo": "bar"}' ,
8797 }
8898
8999 @run_sub_tests_with_dataset (valid_roots )
@@ -95,7 +105,9 @@ def test_root_serialization(self, test_case_data: str):
95105 valid_metafiles : DataSet = {
96106 "all" : '{"hashes": {"sha256" : "abc"}, "length": 12, "version": 1}' ,
97107 "no length" : '{"hashes": {"sha256" : "abc"}, "version": 1 }' ,
98- "no hashes" : '{"length": 12, "version": 1}'
108+ "no hashes" : '{"length": 12, "version": 1}' ,
109+ "unrecognized field" : '{"hashes": {"sha256" : "abc"}, "length": 12, "version": 1, \
110+ "foo": "bar"}' ,
99111 }
100112
101113 @run_sub_tests_with_dataset (valid_metafiles )
@@ -107,7 +119,9 @@ def test_metafile_serialization(self, test_case_data: str):
107119
108120 valid_timestamps : DataSet = {
109121 "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}}}'
122+ "meta": {"snapshot.json": {"hashes": {"sha256" : "abc"}, "version": 1}}}' ,
123+ "unrecognized field" : '{ "_type": "timestamp", "spec_version": "1.0.0", "version": 1, "expires": "2030-01-01T00:00:00Z", \
124+ "meta": {"snapshot.json": {"hashes": {"sha256" : "abc"}, "version": 1}}, "foo": "bar"}' ,
111125 }
112126
113127 @run_sub_tests_with_dataset (valid_timestamps )
@@ -119,7 +133,9 @@ def test_timestamp_serialization(self, test_case_data: str):
119133
120134 valid_snapshots : DataSet = {
121135 "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 }}}'
136+ "meta": { "file.txt": { "hashes": {"sha256" : "abc"}, "version": 1 }}}' ,
137+ "unrecognized field" : '{ "_type": "snapshot", "spec_version": "1.0.0", "version": 1, "expires": "2030-01-01T00:00:00Z", \
138+ "meta": { "file.txt": { "hashes": {"sha256" : "abc"}, "version": 1 }}, "foo": "bar"}' ,
123139 }
124140
125141 @run_sub_tests_with_dataset (valid_snapshots )
@@ -138,6 +154,8 @@ def test_snapshot_serialization(self, test_case_data: str):
138154 "path_hash_prefixes": ["h1", "h2"], "threshold": 99}' ,
139155 "no hash or path prefix" :
140156 '{"keyids": ["keyid"], "name": "a", "terminating": true, "threshold": 3}' ,
157+ "unrecognized field" :
158+ '{"keyids": ["keyid"], "name": "a", "terminating": true, "threshold": 3, "foo": "bar"}' ,
141159 }
142160
143161 @run_sub_tests_with_dataset (valid_delegated_roles )
@@ -149,7 +167,11 @@ def test_delegated_role_serialization(self, test_case_data: str):
149167
150168 valid_delegations : DataSet = {
151169 "all" : '{"keys": {"keyid" : {"keytype": "rsa", "scheme": "rsassa-pss-sha256", "keyval": {"public": "foo"}}}, \
152- "roles": [ {"keyids": ["keyid"], "name": "a", "terminating": true, "threshold": 3} ]}'
170+ "roles": [ {"keyids": ["keyid"], "name": "a", "terminating": true, "threshold": 3} ]}' ,
171+ "unrecognized field" :
172+ '{"keys": {"keyid" : {"keytype": "rsa", "scheme": "rsassa-pss-sha256", "keyval": {"public": "foo"}}}, \
173+ "roles": [ {"keyids": ["keyid"], "name": "a", "terminating": true, "threshold": 3} ], \
174+ "foo": "bar"}' ,
153175 }
154176
155177 @run_sub_tests_with_dataset (valid_delegations )
@@ -162,7 +184,9 @@ def test_delegation_serialization(self, test_case_data: str):
162184 valid_targetfiles : DataSet = {
163185 "all" : '{"length": 12, "hashes": {"sha256" : "abc"}, \
164186 "custom" : {"foo": "bar"} }' ,
165- "no custom" : '{"length": 12, "hashes": {"sha256" : "abc"}}'
187+ "no custom" : '{"length": 12, "hashes": {"sha256" : "abc"}}' ,
188+ "unrecognized field" : '{"length": 12, "hashes": {"sha256" : "abc"}, \
189+ "custom" : {"foo": "bar"}, "foo": "bar"}' ,
166190 }
167191
168192 @run_sub_tests_with_dataset (valid_targetfiles )
@@ -187,7 +211,9 @@ def test_targetfile_serialization(self, test_case_data: str):
187211 }' ,
188212 "no delegations" : '{"_type": "targets", "spec_version": "1.0.0", "version": 1, "expires": "2030-01-01T00:00:00Z", \
189213 "targets": { "file.txt": {"length": 12, "hashes": {"sha256" : "abc"} } } \
190- }'
214+ }' ,
215+ "unrecognized_field" : '{"_type": "targets", "spec_version": "1.0.0", "version": 1, "expires": "2030-01-01T00:00:00Z", \
216+ "targets": {}, "foo": "bar"}' ,
191217 }
192218
193219 @run_sub_tests_with_dataset (valid_targets )
0 commit comments