1313# limitations under the License.
1414
1515import json
16+ import os
1617import ssl
1718from unittest import mock
1819
3233
3334
3435class TestSessionsMtls :
36+ @mock .patch .dict (os .environ , {"GOOGLE_API_USE_CLIENT_CERTIFICATE" : "true" })
3537 @mock .patch ("os.path.exists" )
3638 @mock .patch (
3739 "builtins.open" ,
3840 new_callable = mock .mock_open ,
3941 read_data = json .dumps (VALID_WORKLOAD_CONFIG ),
4042 )
41- @mock .patch ("google.auth.transport._mtls_helper._get_workload_cert_and_key " )
43+ @mock .patch ("google.auth.aio. transport.mtls.get_client_cert_and_key " )
4244 @mock .patch ("ssl.create_default_context" )
4345 @pytest .mark .asyncio
4446 async def test_configure_mtls_channel (
@@ -49,7 +51,7 @@ async def test_configure_mtls_channel(
4951 valid workload config is mocked.
5052 """
5153 mock_exists .return_value = True
52- mock_helper .return_value = (b"fake_cert_data" , b"fake_key_data" )
54+ mock_helper .return_value = (True , b"fake_cert_data" , b"fake_key_data" )
5355
5456 mock_context = mock .Mock (spec = ssl .SSLContext )
5557 mock_ssl .return_value = mock_context
@@ -61,6 +63,7 @@ async def test_configure_mtls_channel(
6163 assert session ._is_mtls is True
6264 assert mock_context .load_cert_chain .called
6365
66+ @mock .patch .dict (os .environ , {"GOOGLE_API_USE_CLIENT_CERTIFICATE" : "true" })
6467 @mock .patch ("os.path.exists" )
6568 @pytest .mark .asyncio
6669 async def test_configure_mtls_channel_disabled (self , mock_exists ):
@@ -89,10 +92,10 @@ async def test_configure_mtls_channel_invalid_format(self, mock_file, mock_exist
8992 mock_creds = mock .Mock (spec = credentials .Credentials )
9093
9194 session = sessions .AsyncAuthorizedSession (mock_creds )
92- with pytest .raises (
93- exceptions .MutualTLSChannelError ):
95+ with pytest .raises (exceptions .MutualTLSChannelError ):
9496 await session .configure_mtls_channel ()
9597
98+ @mock .patch .dict (os .environ , {"GOOGLE_API_USE_CLIENT_CERTIFICATE" : "true" })
9699 @pytest .mark .asyncio
97100 @mock .patch (
98101 "google.auth.aio.transport.mtls.has_default_client_cert_source" ,
0 commit comments