1/*
2 *
3 * Copyright 2015 gRPC authors.
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 *     http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 *
17 */
18
19#import <GRPCClient/GRPCCall+Tests.h>
20#import <GRPCClient/GRPCTransport.h>
21#import <GRPCClient/internal_testing/GRPCCall+InternalTests.h>
22
23#import "InteropTests.h"
24// The server address is derived from preprocessor macro, which is
25// in turn derived from environment variable of the same name.
26#define NSStringize_helper(x) #x
27#define NSStringize(x) @NSStringize_helper(x)
28static NSString *const kLocalSSLHost = NSStringize(HOST_PORT_LOCALSSL);
29
30// The Protocol Buffers encoding overhead of local interop server. Acquired
31// by experiment. Adjust this when server's proto file changes.
32static int32_t kLocalInteropServerOverhead = 10;
33
34/** Tests in InteropTests.m, sending the RPCs to a local SSL server. */
35@interface InteropTestsLocalSSL : InteropTests
36@end
37
38@implementation InteropTestsLocalSSL
39
40+ (NSString *)host {
41  return kLocalSSLHost;
42}
43
44+ (NSString *)PEMRootCertificates {
45  NSBundle *bundle = [NSBundle bundleForClass:[self class]];
46  NSString *certsPath = [bundle pathForResource:@"TestCertificates.bundle/test-certificates"
47                                         ofType:@"pem"];
48  NSError *error;
49  return [NSString stringWithContentsOfFile:certsPath encoding:NSUTF8StringEncoding error:&error];
50}
51
52+ (NSString *)hostNameOverride {
53  return @"foo.test.google.fr";
54}
55
56- (int32_t)encodingOverhead {
57  return kLocalInteropServerOverhead;  // bytes
58}
59
60+ (GRPCTransportID)transport {
61  return GRPCDefaultTransportImplList.core_secure;
62}
63
64- (void)setUp {
65  [super setUp];
66
67  // Register test server certificates and name.
68  NSBundle *bundle = [NSBundle bundleForClass:[self class]];
69  NSString *certsPath = [bundle pathForResource:@"TestCertificates.bundle/test-certificates"
70                                         ofType:@"pem"];
71  [GRPCCall useTestCertsPath:certsPath testName:@"foo.test.google.fr" forHost:kLocalSSLHost];
72}
73
74- (void)testExceptions {
75  // Try to set userAgentPrefix for host that is nil. This should cause
76  // an exception.
77  @try {
78    [GRPCCall useTestCertsPath:nil testName:nil forHost:nil];
79    XCTFail(@"Did not receive an exception when parameters are nil");
80  } @catch (NSException *theException) {
81    NSLog(@"Received exception as expected: %@", theException.name);
82  }
83}
84
85@end
86