1# Copyright 2015 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. 14"""Secure client-server interoperability as a unit test.""" 15 16import unittest 17 18import grpc 19from src.proto.grpc.testing import test_pb2_grpc 20 21from tests.interop import _intraop_test_case 22from tests.interop import service 23from tests.interop import resources 24from tests.unit import test_common 25 26_SERVER_HOST_OVERRIDE = 'foo.test.google.fr' 27 28 29class SecureIntraopTest(_intraop_test_case.IntraopTestCase, unittest.TestCase): 30 31 def setUp(self): 32 self.server = test_common.test_server() 33 test_pb2_grpc.add_TestServiceServicer_to_server(service.TestService(), 34 self.server) 35 port = self.server.add_secure_port( 36 '[::]:0', 37 grpc.ssl_server_credentials([(resources.private_key(), 38 resources.certificate_chain())])) 39 self.server.start() 40 self.stub = test_pb2_grpc.TestServiceStub( 41 grpc.secure_channel( 42 'localhost:{}'.format(port), 43 grpc.ssl_channel_credentials( 44 resources.test_root_certificates()), (( 45 'grpc.ssl_target_name_override', 46 _SERVER_HOST_OVERRIDE, 47 ),))) 48 49 def tearDown(self): 50 self.server.stop(None) 51 52 53if __name__ == '__main__': 54 unittest.main(verbosity=2) 55