@@ -125,44 +125,33 @@ def test_set_auth_with_key_content(self, mock_load_private_key, mock_validate_co
125125 set_auth ()
126126
127127 @mock .patch ("oci.auth.signers.SecurityTokenSigner.__init__" )
128- @mock .patch ("oci.signer.load_private_key" )
129128 @mock .patch ("oci.signer.load_private_key_from_file" )
130129 @mock .patch ("ads.common.auth.SecurityToken._read_security_token_file" )
131- def test_security_token (
130+ def test_security_token_from_config (
132131 self ,
133132 mock_read_security_token_file ,
134133 mock_load_private_key_from_file ,
135- mock_load_private_key ,
136134 mock_security_token_signer
137135 ):
138136 config = {
139137 "fingerprint" : "test_fingerprint" ,
140138 "tenancy" : "test_tenancy" ,
141139 "region" : "us-ashburn-1" ,
140+ "key_file" : "test_key_file" ,
142141 "generic_headers" : [1 ,2 ,3 ],
143142 "body_headers" : [4 ,5 ,6 ]
144143 }
145144
146145 with pytest .raises (
147146 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."
149148 ):
150149 signer = security_token (
151150 oci_config = config ,
152151 client_kwargs = {"test_client_key" :"test_client_value" }
153152 )
154153
155154 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"
166155 mock_security_token_signer .return_value = None
167156 signer = security_token (
168157 oci_config = config ,
@@ -180,18 +169,51 @@ def test_security_token(
180169 assert signer ["config" ]["key_file" ] == "test_key_file"
181170 assert isinstance (signer ["signer" ], SecurityTokenSigner )
182171
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 = {
184188 "fingerprint" : "test_fingerprint" ,
185189 "tenancy" : "test_tenancy" ,
186190 "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 "
189193 }
194+ mock_isfile .return_value = True
195+ mock_security_token_signer .return_value = None
190196 signer = security_token (
191- oci_config = config ,
197+ oci_config = "test_config_location" ,
198+ profile = "test_key_profile" ,
192199 client_kwargs = {"test_client_key" :"test_client_value" }
193200 )
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 )
195217
196218
197219class TestOCIMixin (TestCase ):
0 commit comments