Coverage for tests/admin/test_certificate_v2_element.py: 100%
32 statements
« prev ^ index » next coverage.py v7.5.3, created at 2025-07-10 13:43 +0000
« prev ^ index » next coverage.py v7.5.3, created at 2025-07-10 13:43 +0000
1# The MIT License (MIT)
2#
3# Copyright (c) 2021 RSK Labs Ltd
4#
5# Permission is hereby granted, free of charge, to any person obtaining a copy of
6# this software and associated documentation files (the "Software"), to deal in
7# the Software without restriction, including without limitation the rights to
8# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
9# of the Software, and to permit persons to whom the Software is furnished to do
10# so, subject to the following conditions:
11#
12# The above copyright notice and this permission notice shall be included in all
13# copies or substantial portions of the Software.
14#
15# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21# SOFTWARE.
23from unittest import TestCase
24from admin.certificate_v2 import HSMCertificateV2Element
27class TestHSMCertificateV2Element(TestCase):
28 def setUp(self):
29 class TestElement(HSMCertificateV2Element):
30 def __init__(self):
31 pass
33 self.instance = TestElement()
35 def test_from_dict_unknown_type(self):
36 with self.assertRaises(ValueError) as e:
37 HSMCertificateV2Element.from_dict({
38 "name": "a-strange-name",
39 "type": "an-unknown-type",
40 "some": "other",
41 "random": "attributes",
42 })
43 self.assertIn("a-strange-name", str(e.exception))
45 def test_from_dict_no_name(self):
46 with self.assertRaises(ValueError) as e:
47 HSMCertificateV2Element.from_dict({
48 "type": "sgx_quote",
49 "signed_by": "a-signer",
50 "some": "other",
51 "random": "attributes",
52 })
53 self.assertIn("Missing name", str(e.exception))
55 def test_from_dict_no_signed_by(self):
56 with self.assertRaises(ValueError) as e:
57 HSMCertificateV2Element.from_dict({
58 "name": "a name",
59 "type": "sgx_quote",
60 "some": "other",
61 "random": "attributes",
62 })
63 self.assertIn("Missing certifier", str(e.exception))
65 def test_cant_instantiate(self):
66 with self.assertRaises(NotImplementedError):
67 HSMCertificateV2Element()
69 def test_get_pubkey_notimplemented(self):
70 with self.assertRaises(NotImplementedError):
71 self.instance.get_pubkey()
73 def test_get_value_notimplemented(self):
74 with self.assertRaises(NotImplementedError):
75 self.instance.get_value()
77 def test_is_valid_notimplemented(self):
78 with self.assertRaises(NotImplementedError):
79 self.instance.is_valid("a-certifier")