@@ -125,44 +125,33 @@ def test_set_auth_with_key_content(self, mock_load_private_key, mock_validate_co
125
125
set_auth ()
126
126
127
127
@mock .patch ("oci.auth.signers.SecurityTokenSigner.__init__" )
128
- @mock .patch ("oci.signer.load_private_key" )
129
128
@mock .patch ("oci.signer.load_private_key_from_file" )
130
129
@mock .patch ("ads.common.auth.SecurityToken._read_security_token_file" )
131
- def test_security_token (
130
+ def test_security_token_from_config (
132
131
self ,
133
132
mock_read_security_token_file ,
134
133
mock_load_private_key_from_file ,
135
- mock_load_private_key ,
136
134
mock_security_token_signer
137
135
):
138
136
config = {
139
137
"fingerprint" : "test_fingerprint" ,
140
138
"tenancy" : "test_tenancy" ,
141
139
"region" : "us-ashburn-1" ,
140
+ "key_file" : "test_key_file" ,
142
141
"generic_headers" : [1 ,2 ,3 ],
143
142
"body_headers" : [4 ,5 ,6 ]
144
143
}
145
144
146
145
with pytest .raises (
147
146
ValueError ,
148
- match = "Parameter `security_token_file` or `security_token_content` must be provided for using `security_token` authentication."
147
+ match = "Parameter `security_token_file` must be provided for using `security_token` authentication."
149
148
):
150
149
signer = security_token (
151
150
oci_config = config ,
152
151
client_kwargs = {"test_client_key" :"test_client_value" }
153
152
)
154
153
155
154
config ["security_token_file" ] = "test_security_token"
156
- with pytest .raises (
157
- ValueError ,
158
- match = "Parameter `key_file` or `key_content` must be provided for using `security_token` authentication."
159
- ):
160
- signer = security_token (
161
- oci_config = config ,
162
- client_kwargs = {"test_client_key" :"test_client_value" }
163
- )
164
-
165
- config ["key_file" ] = "test_key_file"
166
155
mock_security_token_signer .return_value = None
167
156
signer = security_token (
168
157
oci_config = config ,
@@ -180,18 +169,51 @@ def test_security_token(
180
169
assert signer ["config" ]["key_file" ] == "test_key_file"
181
170
assert isinstance (signer ["signer" ], SecurityTokenSigner )
182
171
183
- config = {
172
+ @mock .patch ("oci.auth.signers.SecurityTokenSigner.__init__" )
173
+ @mock .patch ("oci.signer.load_private_key_from_file" )
174
+ @mock .patch ("builtins.open" )
175
+ @mock .patch ("os.path.isfile" )
176
+ @mock .patch ("os.system" )
177
+ @mock .patch ("oci.config.from_file" )
178
+ def test_security_token_from_file (
179
+ self ,
180
+ mock_from_file ,
181
+ mock_system ,
182
+ mock_isfile ,
183
+ mock_open ,
184
+ mock_load_private_key_from_file ,
185
+ mock_security_token_signer
186
+ ):
187
+ mock_from_file .return_value = {
184
188
"fingerprint" : "test_fingerprint" ,
185
189
"tenancy" : "test_tenancy" ,
186
190
"region" : "us-ashburn-1" ,
187
- "security_token_content " : "test_security_token_content " ,
188
- "key_content " : "test_key_content "
191
+ "key_file " : "test_key_file " ,
192
+ "security_token_file " : "test_security_token "
189
193
}
194
+ mock_isfile .return_value = True
195
+ mock_security_token_signer .return_value = None
190
196
signer = security_token (
191
- oci_config = config ,
197
+ oci_config = "test_config_location" ,
198
+ profile = "test_key_profile" ,
192
199
client_kwargs = {"test_client_key" :"test_client_value" }
193
200
)
194
- mock_load_private_key .assert_called_with ("test_key_content" )
201
+
202
+ mock_from_file .assert_called_with ("test_config_location" , "test_key_profile" )
203
+ mock_system .assert_called_with ("oci session refresh --profile test_key_profile" )
204
+ mock_isfile .assert_called_with ("test_security_token" )
205
+ mock_open .assert_called ()
206
+ mock_load_private_key_from_file .assert_called_with ("test_key_file" )
207
+ mock_security_token_signer .assert_called ()
208
+
209
+ assert signer ["client_kwargs" ] == {"test_client_key" : "test_client_value" }
210
+ assert "additional_user_agent" in signer ["config" ]
211
+ assert signer ["config" ]["fingerprint" ] == "test_fingerprint"
212
+ assert signer ["config" ]["tenancy" ] == "test_tenancy"
213
+ assert signer ["config" ]["region" ] == "us-ashburn-1"
214
+ assert signer ["config" ]["security_token_file" ] == "test_security_token"
215
+ assert signer ["config" ]["key_file" ] == "test_key_file"
216
+ assert isinstance (signer ["signer" ], SecurityTokenSigner )
195
217
196
218
197
219
class TestOCIMixin (TestCase ):
0 commit comments