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 sys 17import unittest 18 19import grpc 20 21from src.proto.grpc.testing import test_pb2_grpc 22from tests.interop import _intraop_test_case 23from tests.interop import resources 24from tests.interop import service 25from tests.unit import test_common 26 27_SERVER_HOST_OVERRIDE = "foo.test.google.fr" 28 29 30@unittest.skipIf( 31 sys.version_info[0] < 3, "ProtoBuf descriptor has moved on from Python2" 32) 33class SecureIntraopTest(_intraop_test_case.IntraopTestCase, unittest.TestCase): 34 def setUp(self): 35 self.server = test_common.test_server() 36 test_pb2_grpc.add_TestServiceServicer_to_server( 37 service.TestService(), self.server 38 ) 39 port = self.server.add_secure_port( 40 "[::]:0", 41 grpc.ssl_server_credentials( 42 [(resources.private_key(), resources.certificate_chain())] 43 ), 44 ) 45 self.server.start() 46 self.stub = test_pb2_grpc.TestServiceStub( 47 grpc.secure_channel( 48 "localhost:{}".format(port), 49 grpc.ssl_channel_credentials( 50 resources.test_root_certificates() 51 ), 52 ( 53 ( 54 "grpc.ssl_target_name_override", 55 _SERVER_HOST_OVERRIDE, 56 ), 57 ), 58 ) 59 ) 60 61 def tearDown(self): 62 self.server.stop(None) 63 64 65if __name__ == "__main__": 66 unittest.main(verbosity=2) 67