Skip to content

Commit

Permalink
Correct exception in from_dict
Browse files Browse the repository at this point in the history
Signed-off-by: Pradyumna Krishna <[email protected]>
  • Loading branch information
PradyumnaKrishna authored and lukpueh committed Jul 8, 2022
1 parent 6b9f839 commit 145ddf0
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
8 changes: 3 additions & 5 deletions securesystemslib/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

from typing import Any, List

from securesystemslib import formats
from securesystemslib import exceptions, formats
from securesystemslib.signer import Signature
from securesystemslib.util import b64dec, b64enc

Expand Down Expand Up @@ -56,7 +56,7 @@ def from_dict(cls, data: dict) -> "Envelope":
KeyError: If any of the "payload", "payloadType" and "signatures"
fields are missing from the "data".
TypeError: If type of any signature in "signatures" is incorrect.
FormatError: If signature in "signatures" is incorrect.
Returns:
A "Envelope" instance.
Expand All @@ -74,9 +74,7 @@ def from_dict(cls, data: dict) -> "Envelope":
signatures.append(Signature.from_dict(signature))

else:
raise TypeError(
f"expected type 'Signature', got {type(signature).__name__}"
)
raise exceptions.FormatError("Wanted a 'Signature'.")

return cls(payload, payload_type, signatures)

Expand Down
4 changes: 2 additions & 2 deletions tests/test_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
"""Test cases for "metadata.py". """

import copy
from typing import Type
import unittest

from securesystemslib import exceptions
from securesystemslib.metadata import Envelope
from securesystemslib.signer import Signature

Expand Down Expand Up @@ -39,7 +39,7 @@ def test_envelope_from_to_dict(self):

# Assert TypeError on invalid signature
envelope_dict["signatures"] = [""]
self.assertRaises(TypeError, Envelope.from_dict, envelope_dict)
self.assertRaises(exceptions.FormatError, Envelope.from_dict, envelope_dict)

def test_envelope_eq_(self):
"""Test envelope equality"""
Expand Down

0 comments on commit 145ddf0

Please sign in to comment.