| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- /*
- * Copyright 2019, gRPC Authors All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
- import Foundation
- import GRPC
- import NIO
- import NIOSSL
- /// Makes a server for gRPC interoperability testing.
- ///
- /// - Parameters:
- /// - host: The host to bind the server socket to, defaults to "localhost".
- /// - port: The port to bind the server socket to.
- /// - eventLoopGroup: Event loop group to run the server on.
- /// - serviceProviders: Service providers to handle requests with, defaults to provider for the
- /// "Test" service.
- /// - useTLS: Whether to use TLS or not. If `true` then the server will use the "server1"
- /// certificate and CA as set out in the interoperability test specification. The common name
- /// is "*.test.google.fr"; clients should set their hostname override accordingly.
- /// - Returns: A future `Server` configured to serve the test service.
- public func makeInteroperabilityTestServer(
- host: String = "localhost",
- port: Int,
- eventLoopGroup: EventLoopGroup,
- serviceProviders: [CallHandlerProvider] = [TestServiceProvider()],
- useTLS: Bool
- ) throws -> EventLoopFuture<Server> {
- let builder: Server.Builder
- if useTLS {
- print("Using the gRPC interop testing CA for TLS; clients should expect the host to be '*.test.google.fr'")
- let caCert = InteroperabilityTestCredentials.caCertificate
- let serverCert = InteroperabilityTestCredentials.server1Certificate
- let serverKey = InteroperabilityTestCredentials.server1Key
- builder = Server.secure(group: eventLoopGroup, certificateChain: [serverCert], privateKey: serverKey)
- .withTLS(trustRoots: .certificates([caCert]))
- } else {
- builder = Server.insecure(group: eventLoopGroup)
- }
- return builder
- .withMessageCompression(.enabled(.init(decompressionLimit: .absolute(1024 * 1024))))
- .withServiceProviders(serviceProviders)
- .bind(host: host, port: port)
- }
|