Skip to content

Commit

Permalink
Move tests to test_metadata_serialization
Browse files Browse the repository at this point in the history
Move the Delegation class serialization tests from "test_api.py"
to test_metadata_serialization.py module focused on serialization
testing.

Additionally, a test for empty keys and roles will be added in my
upcomming pr theupdateframework#1511.

Signed-off-by: Martin Vrachev <mvrachev@vmware.com>
  • Loading branch information
MVrachev committed Aug 25, 2021
1 parent 06579e4 commit 23af38a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 18 deletions.
17 changes: 0 additions & 17 deletions tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -510,23 +510,6 @@ def test_metadata_root(self):
root.signed.remove_key('root', 'nosuchkey')


def test_delegation_class(self):
# empty keys and roles
delegations_dict = {"keys":{}, "roles":[]}
delegations = Delegations.from_dict(delegations_dict.copy())
self.assertEqual(delegations_dict, delegations.to_dict())

# Test some basic missing or broken input
invalid_delegations_dicts = [
{},
{"keys":None, "roles":None},
{"keys":{"foo":0}, "roles":[]},
{"keys":{}, "roles":["foo"]},
]
for d in invalid_delegations_dicts:
with self.assertRaises((KeyError, AttributeError)):
Delegations.from_dict(d)

def test_metadata_targets(self):
targets_path = os.path.join(
self.repo_dir, 'metadata', 'targets.json')
Expand Down
7 changes: 6 additions & 1 deletion tests/test_metadata_serialization.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,11 @@ def test_invalid_delegated_role_serialization(self, test_case_data: str):


invalid_delegations: DataSet = {
"empty delegations": '{}',
"bad keys": '{"keys": "foo", \
"roles": [{"keyids": ["keyid"], "name": "a", "paths": ["fn1", "fn2"], "terminating": false, "threshold": 3}]}',
"bad roles": '{"keys": {"keyid" : {"keytype": "rsa", "scheme": "rsassa-pss-sha256", "keyval": {"public": "foo"}}}, \
"roles": ["foo"]}',
"duplicate role names": '{"keys": {"keyid" : {"keytype": "rsa", "scheme": "rsassa-pss-sha256", "keyval": {"public": "foo"}}}, \
"roles": [ \
{"keyids": ["keyid"], "name": "a", "paths": ["fn1", "fn2"], "terminating": false, "threshold": 3}, \
Expand All @@ -281,7 +286,7 @@ def test_invalid_delegated_role_serialization(self, test_case_data: str):
@run_sub_tests_with_dataset(invalid_delegations)
def test_invalid_delegation_serialization(self, test_case_data: str):
case_dict = json.loads(test_case_data)
with self.assertRaises(ValueError):
with self.assertRaises((ValueError, KeyError, AttributeError)):
Delegations.from_dict(copy.deepcopy(case_dict))


Expand Down

0 comments on commit 23af38a

Please sign in to comment.