1
- # Copyright 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
- #
3
- # Licensed under the Apache License, Version 2.0 (the "License"). You
4
- # may not use this file except in compliance with the License. A copy of
5
- # the License is located at
6
- #
7
- # http://aws.amazon.com/apache2.0/
8
- #
9
- # or in the "license" file accompanying this file. This file is
10
- # distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
11
- # ANY KIND, either express or implied. See the License for the specific
12
- # language governing permissions and limitations under the License.
13
1
"""Unit test suite for ``aws_encryption_sdk.internal.crypto.authentication.Signer``."""
14
2
import pytest
15
- from mock import MagicMock , sentinel
3
+ from mock import MagicMock , sentinel , patch
16
4
from pytest_mock import mocker # noqa pylint: disable=unused-import
17
5
18
6
import aws_encryption_sdk .internal .crypto .authentication
@@ -30,6 +18,12 @@ def patch_default_backend(mocker):
30
18
yield aws_encryption_sdk .internal .crypto .authentication .default_backend
31
19
32
20
21
+ @pytest .fixture
22
+ def patch_ec (mocker ):
23
+ mocker .patch .object (aws_encryption_sdk .internal .crypto .authentication , "ec" )
24
+ yield aws_encryption_sdk .internal .crypto .authentication .ec
25
+
26
+
33
27
@pytest .fixture
34
28
def patch_serialization (mocker ):
35
29
mocker .patch .object (aws_encryption_sdk .internal .crypto .authentication , "serialization" )
@@ -71,8 +65,11 @@ def test_f_signer_key_bytes():
71
65
assert test .key_bytes () == VALUES ["ecc_private_key_prime_private_bytes" ]
72
66
73
67
74
- def test_signer_from_key_bytes (patch_default_backend , patch_serialization , patch_build_hasher ):
75
- _algorithm = MagicMock ()
68
+ def test_signer_from_key_bytes (patch_default_backend , patch_serialization , patch_build_hasher , patch_ec ):
69
+ patch_ec .EllipticCurve .__abstractmethods__ = set ()
70
+ mock_algorithm_info = MagicMock (return_value = sentinel .algorithm_info , spec = patch_ec .EllipticCurve )
71
+ _algorithm = MagicMock (signing_algorithm_info = mock_algorithm_info )
72
+
76
73
signer = Signer .from_key_bytes (algorithm = _algorithm , key_bytes = sentinel .key_bytes )
77
74
78
75
patch_serialization .load_der_private_key .assert_called_once_with (
@@ -83,9 +80,12 @@ def test_signer_from_key_bytes(patch_default_backend, patch_serialization, patch
83
80
assert signer .key is patch_serialization .load_der_private_key .return_value
84
81
85
82
86
- def test_signer_key_bytes (patch_default_backend , patch_serialization , patch_build_hasher ):
83
+ def test_signer_key_bytes (patch_default_backend , patch_serialization , patch_build_hasher , patch_ec ):
84
+ patch_ec .EllipticCurve .__abstractmethods__ = set ()
85
+ mock_algorithm_info = MagicMock (return_value = sentinel .algorithm_info , spec = patch_ec .EllipticCurve )
86
+ algorithm = MagicMock (signing_algorithm_info = mock_algorithm_info )
87
87
private_key = MagicMock ()
88
- signer = Signer (MagicMock () , key = private_key )
88
+ signer = Signer (algorithm , key = private_key )
89
89
90
90
test = signer .key_bytes ()
91
91
@@ -98,30 +98,45 @@ def test_signer_key_bytes(patch_default_backend, patch_serialization, patch_buil
98
98
99
99
100
100
def test_signer_encoded_public_key (
101
- patch_default_backend , patch_serialization , patch_build_hasher , patch_ecc_encode_compressed_point , patch_base64
101
+ patch_default_backend ,
102
+ patch_serialization ,
103
+ patch_build_hasher ,
104
+ patch_ecc_encode_compressed_point ,
105
+ patch_base64 ,
106
+ patch_ec
102
107
):
103
108
patch_ecc_encode_compressed_point .return_value = sentinel .compressed_point
104
109
patch_base64 .b64encode .return_value = sentinel .encoded_point
105
110
private_key = MagicMock ()
106
111
107
- signer = Signer (MagicMock (), key = private_key )
112
+ patch_ec .EllipticCurve .__abstractmethods__ = set ()
113
+
114
+ mock_algorithm_info = MagicMock (return_value = sentinel .algorithm_info , spec = patch_ec .EllipticCurve )
115
+ algorithm = MagicMock (signing_algorithm_info = mock_algorithm_info )
116
+
117
+ signer = Signer (algorithm , key = private_key )
108
118
test_key = signer .encoded_public_key ()
109
119
110
120
patch_ecc_encode_compressed_point .assert_called_once_with (private_key )
111
121
patch_base64 .b64encode .assert_called_once_with (sentinel .compressed_point )
112
122
assert test_key == sentinel .encoded_point
113
123
114
124
115
- def test_signer_update (patch_default_backend , patch_serialization , patch_build_hasher ):
116
- signer = Signer (MagicMock (), key = MagicMock ())
125
+ def test_signer_update (patch_default_backend , patch_serialization , patch_build_hasher , patch_ec ):
126
+ patch_ec .EllipticCurve .__abstractmethods__ = set ()
127
+ mock_algorithm_info = MagicMock (return_value = sentinel .algorithm_info , spec = patch_ec .EllipticCurve )
128
+ algorithm = MagicMock (signing_algorithm_info = mock_algorithm_info )
129
+ signer = Signer (algorithm , key = MagicMock ())
117
130
signer .update (sentinel .data )
118
131
patch_build_hasher .return_value .update .assert_called_once_with (sentinel .data )
119
132
120
133
121
134
def test_signer_finalize (
122
- patch_default_backend , patch_serialization , patch_build_hasher , patch_ecc_static_length_signature
135
+ patch_default_backend , patch_serialization , patch_build_hasher , patch_ecc_static_length_signature , patch_ec
123
136
):
124
- algorithm = MagicMock ()
137
+ patch_ec .EllipticCurve .__abstractmethods__ = set ()
138
+ mock_algorithm_info = MagicMock (return_value = sentinel .algorithm_info , spec = patch_ec .EllipticCurve )
139
+ algorithm = MagicMock (signing_algorithm_info = mock_algorithm_info )
125
140
private_key = MagicMock ()
126
141
127
142
signer = Signer (algorithm , key = private_key )
0 commit comments