@@ -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,10 @@ 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
+ mock_algorithm_info = MagicMock (return_value = sentinel .algorithm_info , spec = patch_ec .EllipticCurve )
82
+ _algorithm = MagicMock (signing_algorithm_info = mock_algorithm_info )
83
+
76
84
signer = Signer .from_key_bytes (algorithm = _algorithm , key_bytes = sentinel .key_bytes )
77
85
78
86
patch_serialization .load_der_private_key .assert_called_once_with (
@@ -83,9 +91,11 @@ def test_signer_from_key_bytes(patch_default_backend, patch_serialization, patch
83
91
assert signer .key is patch_serialization .load_der_private_key .return_value
84
92
85
93
86
- def test_signer_key_bytes (patch_default_backend , patch_serialization , patch_build_hasher ):
94
+ def test_signer_key_bytes (patch_default_backend , patch_serialization , patch_build_hasher , patch_ec ):
95
+ mock_algorithm_info = MagicMock (return_value = sentinel .algorithm_info , spec = patch_ec .EllipticCurve )
96
+ algorithm = MagicMock (signing_algorithm_info = mock_algorithm_info )
87
97
private_key = MagicMock ()
88
- signer = Signer (MagicMock () , key = private_key )
98
+ signer = Signer (algorithm , key = private_key )
89
99
90
100
test = signer .key_bytes ()
91
101
@@ -98,30 +108,41 @@ def test_signer_key_bytes(patch_default_backend, patch_serialization, patch_buil
98
108
99
109
100
110
def test_signer_encoded_public_key (
101
- patch_default_backend , patch_serialization , patch_build_hasher , patch_ecc_encode_compressed_point , patch_base64
111
+ patch_default_backend ,
112
+ patch_serialization ,
113
+ patch_build_hasher ,
114
+ patch_ecc_encode_compressed_point ,
115
+ patch_base64 ,
116
+ patch_ec
102
117
):
103
118
patch_ecc_encode_compressed_point .return_value = sentinel .compressed_point
104
119
patch_base64 .b64encode .return_value = sentinel .encoded_point
105
120
private_key = MagicMock ()
106
121
107
- signer = Signer (MagicMock (), key = private_key )
122
+ mock_algorithm_info = MagicMock (return_value = sentinel .algorithm_info , spec = patch_ec .EllipticCurve )
123
+ algorithm = MagicMock (signing_algorithm_info = mock_algorithm_info )
124
+
125
+ signer = Signer (algorithm , key = private_key )
108
126
test_key = signer .encoded_public_key ()
109
127
110
128
patch_ecc_encode_compressed_point .assert_called_once_with (private_key )
111
129
patch_base64 .b64encode .assert_called_once_with (sentinel .compressed_point )
112
130
assert test_key == sentinel .encoded_point
113
131
114
132
115
- def test_signer_update (patch_default_backend , patch_serialization , patch_build_hasher ):
116
- signer = Signer (MagicMock (), key = MagicMock ())
133
+ def test_signer_update (patch_default_backend , patch_serialization , patch_build_hasher , patch_ec ):
134
+ mock_algorithm_info = MagicMock (return_value = sentinel .algorithm_info , spec = patch_ec .EllipticCurve )
135
+ algorithm = MagicMock (signing_algorithm_info = mock_algorithm_info )
136
+ signer = Signer (algorithm , key = MagicMock ())
117
137
signer .update (sentinel .data )
118
138
patch_build_hasher .return_value .update .assert_called_once_with (sentinel .data )
119
139
120
140
121
141
def test_signer_finalize (
122
- patch_default_backend , patch_serialization , patch_build_hasher , patch_ecc_static_length_signature
142
+ patch_default_backend , patch_serialization , patch_build_hasher , patch_ecc_static_length_signature , patch_ec
123
143
):
124
- algorithm = MagicMock ()
144
+ mock_algorithm_info = MagicMock (return_value = sentinel .algorithm_info , spec = patch_ec .EllipticCurve )
145
+ algorithm = MagicMock (signing_algorithm_info = mock_algorithm_info )
125
146
private_key = MagicMock ()
126
147
127
148
signer = Signer (algorithm , key = private_key )
0 commit comments