Skip to content

Commit

Permalink
Remove the "SIGNED_COMMON" constant and f-strings
Browse files Browse the repository at this point in the history
Signed-off-by: Martin Vrachev <mvrachev@vmware.com>
  • Loading branch information
MVrachev committed Jun 16, 2021
1 parent a774091 commit dfc5104
Showing 1 changed file with 29 additions and 32 deletions.
61 changes: 29 additions & 32 deletions tests/test_metadata_serialization.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,6 @@ def wrapper(test_cls: "TestSerialization"):

class TestSerialization(unittest.TestCase):

SIGNED_COMMON = '"spec_version": "1.0.0", "version": 1, \
"expires": "2030-01-01T00:00:00Z"'

valid_keys: DataSet = {
"all": '{"keytype": "rsa", "scheme": "rsassa-pss-sha256", \
"keyval": {"public": "foo"}}',
Expand All @@ -77,14 +74,16 @@ def test_role_serialization(self, test_case_data: str):


valid_roots: DataSet = {
"all": f'{{ "_type": "root", {SIGNED_COMMON}, "consistent_snapshot": false, \
"keys": {{"keyid" : {{"keytype": "rsa", "scheme": "rsassa-pss-sha256", "keyval": {{"public": "foo"}} }} }}, \
"roles": {{ "targets": {{"keyids": ["keyid"], "threshold": 3}} }} \
}}',
"no consistent_snapshot": f'{{ "_type": "root", {SIGNED_COMMON}, \
"keys": {{"keyid" : {{"keytype": "rsa", "scheme": "rsassa-pss-sha256", "keyval": {{"public": "foo"}} }}}}, \
"roles": {{ "targets": {{"keyids": ["keyid"], "threshold": 3}} }} \
}}',
"all": '{"_type": "root", "spec_version": "1.0.0", "version": 1, \
"expires": "2030-01-01T00:00:00Z", "consistent_snapshot": false, \
"keys": {"keyid" : {"keytype": "rsa", "scheme": "rsassa-pss-sha256", "keyval": {"public": "foo"}}}, \
"roles": { "targets": {"keyids": ["keyid"], "threshold": 3}} \
}',
"no consistent_snapshot": '{ "_type": "root", "spec_version": "1.0.0", "version": 1, \
"expires": "2030-01-01T00:00:00Z", \
"keys": {"keyid" : {"keytype": "rsa", "scheme": "rsassa-pss-sha256", "keyval": {"public": "foo"} }}, \
"roles": { "targets": {"keyids": ["keyid"], "threshold": 3} } \
}',
}

@run_sub_tests_with_dataset(valid_roots)
Expand All @@ -107,9 +106,8 @@ def test_metafile_serialization(self, test_case_data: str):


valid_timestamps: DataSet = {
"all": f'{{ "_type": "timestamp", {SIGNED_COMMON}, \
"meta": {{ "snapshot.json": {{ "hashes": {{"sha256" : "abc"}}, "version": 1 }} }} \
}}'
"all": '{ "_type": "timestamp", "spec_version": "1.0.0", "version": 1, "expires": "2030-01-01T00:00:00Z", \
"meta": {"snapshot.json": {"hashes": {"sha256" : "abc"}, "version": 1}}}'
}

@run_sub_tests_with_dataset(valid_timestamps)
Expand All @@ -120,9 +118,8 @@ def test_timestamp_serialization(self, test_case_data: str):


valid_snapshots: DataSet = {
"all": f'{{ "_type": "snapshot", {SIGNED_COMMON}, \
"meta": {{ "file.txt": \
{{ "hashes": {{"sha256" : "abc"}}, "version": 1 }} }} }}'
"all": '{ "_type": "snapshot", "spec_version": "1.0.0", "version": 1, "expires": "2030-01-01T00:00:00Z", \
"meta": { "file.txt": { "hashes": {"sha256" : "abc"}, "version": 1 }}}'
}

@run_sub_tests_with_dataset(valid_snapshots)
Expand Down Expand Up @@ -176,21 +173,21 @@ def test_targetfile_serialization(self, test_case_data: str):


valid_targets: DataSet = {
"all attributes": f'{{"_type": "targets", {SIGNED_COMMON}, \
"targets": {{ "file.txt": {{"length": 12, "hashes": {{"sha256" : "abc"}} }} }}, \
"delegations": {{"keys": {{"keyid" : {{"keytype": "rsa", \
"scheme": "rsassa-pss-sha256", "keyval": {{"public": "foo"}} }}}}, \
"roles": [ {{"keyids": ["keyid"], "name": "a", "terminating": true, "threshold": 3}} ]}} \
}}',
"empty targets": f'{{"_type": "targets", {SIGNED_COMMON}, \
"targets": {{}}, \
"delegations": {{"keys": {{"keyid" : {{"keytype": "rsa", \
"scheme": "rsassa-pss-sha256", "keyval": {{"public": "foo"}} }}}}, \
"roles": [ {{"keyids": ["keyid"], "name": "a", "terminating": true, "threshold": 3}} ]}} \
}}',
"no delegations": f'{{"_type": "targets", {SIGNED_COMMON}, \
"targets": {{ "file.txt": {{"length": 12, "hashes": {{"sha256" : "abc"}} }} }} \
}}'
"all attributes": '{"_type": "targets", "spec_version": "1.0.0", "version": 1, "expires": "2030-01-01T00:00:00Z", \
"targets": { "file.txt": {"length": 12, "hashes": {"sha256" : "abc"} } }, \
"delegations": {"keys": {"keyid" : {"keytype": "rsa", \
"scheme": "rsassa-pss-sha256", "keyval": {"public": "foo"} }}, \
"roles": [ {"keyids": ["keyid"], "name": "a", "terminating": true, "threshold": 3} ]} \
}',
"empty targets": '{"_type": "targets", "spec_version": "1.0.0", "version": 1, "expires": "2030-01-01T00:00:00Z", \
"targets": {}, \
"delegations": {"keys": {"keyid" : {"keytype": "rsa", \
"scheme": "rsassa-pss-sha256", "keyval": {"public": "foo"} }}, \
"roles": [ {"keyids": ["keyid"], "name": "a", "terminating": true, "threshold": 3} ]} \
}',
"no delegations": '{"_type": "targets", "spec_version": "1.0.0", "version": 1, "expires": "2030-01-01T00:00:00Z", \
"targets": { "file.txt": {"length": 12, "hashes": {"sha256" : "abc"} } } \
}'
}

@run_sub_tests_with_dataset(valid_targets)
Expand Down

0 comments on commit dfc5104

Please sign in to comment.