@@ -30,6 +30,12 @@ def patch_default_backend(mocker):
30
30
yield aws_encryption_sdk .internal .crypto .authentication .default_backend
31
31
32
32
33
+ @pytest .fixture
34
+ def patch_ec (mocker ):
35
+ mocker .patch .object (aws_encryption_sdk .internal .crypto .authentication , "ec" )
36
+ yield aws_encryption_sdk .internal .crypto .authentication .ec
37
+
38
+
33
39
@pytest .fixture
34
40
def patch_serialization (mocker ):
35
41
mocker .patch .object (aws_encryption_sdk .internal .crypto .authentication , "serialization" )
@@ -71,8 +77,13 @@ def test_f_signer_key_bytes():
71
77
assert test .key_bytes () == VALUES ["ecc_private_key_prime_private_bytes" ]
72
78
73
79
74
- def test_signer_from_key_bytes (patch_default_backend , patch_serialization , patch_build_hasher ):
75
- _algorithm = MagicMock ()
80
+ def test_signer_from_key_bytes (patch_default_backend , patch_serialization , patch_build_hasher , patch_ec ):
81
+ patch_ec .EllipticCurve .__abstractmethods__ = set ()
82
+ mock_algorithm_info = MagicMock (return_value = sentinel .algorithm_info , spec = patch_ec .EllipticCurve )
83
+ mock_algorithm_info .return_value .name = True
84
+ mock_algorithm_info .return_value .key_size = True
85
+ _algorithm = MagicMock (signing_algorithm_info = mock_algorithm_info )
86
+
76
87
signer = Signer .from_key_bytes (algorithm = _algorithm , key_bytes = sentinel .key_bytes )
77
88
78
89
patch_serialization .load_der_private_key .assert_called_once_with (
@@ -83,9 +94,12 @@ def test_signer_from_key_bytes(patch_default_backend, patch_serialization, patch
83
94
assert signer .key is patch_serialization .load_der_private_key .return_value
84
95
85
96
86
- def test_signer_key_bytes (patch_default_backend , patch_serialization , patch_build_hasher ):
97
+ def test_signer_key_bytes (patch_default_backend , patch_serialization , patch_build_hasher , patch_ec ):
98
+ patch_ec .EllipticCurve .__abstractmethods__ = set ()
99
+ mock_algorithm_info = MagicMock (return_value = sentinel .algorithm_info , spec = patch_ec .EllipticCurve )
100
+ algorithm = MagicMock (signing_algorithm_info = mock_algorithm_info )
87
101
private_key = MagicMock ()
88
- signer = Signer (MagicMock () , key = private_key )
102
+ signer = Signer (algorithm , key = private_key )
89
103
90
104
test = signer .key_bytes ()
91
105
@@ -98,30 +112,45 @@ def test_signer_key_bytes(patch_default_backend, patch_serialization, patch_buil
98
112
99
113
100
114
def test_signer_encoded_public_key (
101
- patch_default_backend , patch_serialization , patch_build_hasher , patch_ecc_encode_compressed_point , patch_base64
115
+ patch_default_backend ,
116
+ patch_serialization ,
117
+ patch_build_hasher ,
118
+ patch_ecc_encode_compressed_point ,
119
+ patch_base64 ,
120
+ patch_ec
102
121
):
103
122
patch_ecc_encode_compressed_point .return_value = sentinel .compressed_point
104
123
patch_base64 .b64encode .return_value = sentinel .encoded_point
105
124
private_key = MagicMock ()
106
125
107
- signer = Signer (MagicMock (), key = private_key )
126
+ patch_ec .EllipticCurve .__abstractmethods__ = set ()
127
+
128
+ mock_algorithm_info = MagicMock (return_value = sentinel .algorithm_info , spec = patch_ec .EllipticCurve )
129
+ algorithm = MagicMock (signing_algorithm_info = mock_algorithm_info )
130
+
131
+ signer = Signer (algorithm , key = private_key )
108
132
test_key = signer .encoded_public_key ()
109
133
110
134
patch_ecc_encode_compressed_point .assert_called_once_with (private_key )
111
135
patch_base64 .b64encode .assert_called_once_with (sentinel .compressed_point )
112
136
assert test_key == sentinel .encoded_point
113
137
114
138
115
- def test_signer_update (patch_default_backend , patch_serialization , patch_build_hasher ):
116
- signer = Signer (MagicMock (), key = MagicMock ())
139
+ def test_signer_update (patch_default_backend , patch_serialization , patch_build_hasher , patch_ec ):
140
+ patch_ec .EllipticCurve .__abstractmethods__ = set ()
141
+ mock_algorithm_info = MagicMock (return_value = sentinel .algorithm_info , spec = patch_ec .EllipticCurve )
142
+ algorithm = MagicMock (signing_algorithm_info = mock_algorithm_info )
143
+ signer = Signer (algorithm , key = MagicMock ())
117
144
signer .update (sentinel .data )
118
145
patch_build_hasher .return_value .update .assert_called_once_with (sentinel .data )
119
146
120
147
121
148
def test_signer_finalize (
122
- patch_default_backend , patch_serialization , patch_build_hasher , patch_ecc_static_length_signature
149
+ patch_default_backend , patch_serialization , patch_build_hasher , patch_ecc_static_length_signature , patch_ec
123
150
):
124
- algorithm = MagicMock ()
151
+ patch_ec .EllipticCurve .__abstractmethods__ = set ()
152
+ mock_algorithm_info = MagicMock (return_value = sentinel .algorithm_info , spec = patch_ec .EllipticCurve )
153
+ algorithm = MagicMock (signing_algorithm_info = mock_algorithm_info )
125
154
private_key = MagicMock ()
126
155
127
156
signer = Signer (algorithm , key = private_key )
0 commit comments