1# Copyright 2019 The gRPC Authors. 2# 3# Licensed under the Apache License, Version 2.0 (the "License"); 4# you may not use this file except in compliance with the License. 5# You may obtain a copy of the License at 6# 7# http://www.apache.org/licenses/LICENSE-2.0 8# 9# Unless required by applicable law or agreed to in writing, software 10# distributed under the License is distributed on an "AS IS" BASIS, 11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12# See the License for the specific language governing permissions and 13# limitations under the License. 14import logging 15import unittest 16 17import grpc 18 19from grpc.experimental import aio 20from tests_aio.unit._test_server import start_test_server 21from tests_aio.unit._test_base import AioTestBase 22 23from tests.unit import resources 24 25_PRIVATE_KEY = resources.private_key() 26_CERTIFICATE_CHAIN = resources.certificate_chain() 27_TEST_ROOT_CERTIFICATES = resources.test_root_certificates() 28 29 30class TestChannel(AioTestBase): 31 32 async def test_insecure_channel(self): 33 server_target, _ = await start_test_server() # pylint: disable=unused-variable 34 35 channel = aio.insecure_channel(server_target) 36 self.assertIsInstance(channel, aio.Channel) 37 38 async def test_secure_channel(self): 39 server_target, _ = await start_test_server(secure=True) # pylint: disable=unused-variable 40 credentials = grpc.ssl_channel_credentials( 41 root_certificates=_TEST_ROOT_CERTIFICATES, 42 private_key=_PRIVATE_KEY, 43 certificate_chain=_CERTIFICATE_CHAIN, 44 ) 45 secure_channel = aio.secure_channel(server_target, credentials) 46 47 self.assertIsInstance(secure_channel, aio.Channel) 48 49 50if __name__ == '__main__': 51 logging.basicConfig(level=logging.DEBUG) 52 unittest.main(verbosity=2) 53