Skip to content

Commit

Permalink
Mock SSL credentials for MTLS test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
lidizheng committed Jun 10, 2020
1 parent 9bba848 commit 94c0a99
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions tests/system/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,22 @@ def identity():

@pytest.fixture
def async_identity():
transport = IdentityAsyncClient.get_transport_class('grpc_asyncio')(
channel=aio.insecure_channel('localhost:7469'),
)
return IdentityAsyncClient(transport=transport)
if use_mtls:
with mock.patch("grpc.ssl_channel_credentials", autospec=True) as mock_ssl_cred:
mock_ssl_cred.return_value = ssl_credentials
client = IdentityAsyncClient(
credentials=credentials.AnonymousCredentials(),
client_options=client_options,
)
mock_ssl_cred.assert_called_once_with(
certificate_chain=cert, private_key=key
)
return client
else:
transport = IdentityAsyncClient.get_transport_class('grpc_asyncio')(
channel=aio.insecure_channel('localhost:7469'),
)
return IdentityAsyncClient(transport=transport)


@pytest.fixture
Expand Down

0 comments on commit 94c0a99

Please sign in to comment.