blob: 656cba8fec64c8f99cb0512f7f57fd3810195d37 [file] [log] [blame]
Jorge Canizalese8543b02015-08-01 17:37:40 -07001/*
2 *
Paul Querna40f11aa2016-03-03 23:09:06 -08003 * Copyright 2015-2016, Google Inc.
Jorge Canizalese8543b02015-08-01 17:37:40 -07004 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are
8 * met:
9 *
10 * * Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * * Redistributions in binary form must reproduce the above
13 * copyright notice, this list of conditions and the following disclaimer
14 * in the documentation and/or other materials provided with the
15 * distribution.
16 * * Neither the name of Google Inc. nor the names of its
17 * contributors may be used to endorse or promote products derived from
18 * this software without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 *
32 */
33
34#import "GRPCCall+Tests.h"
35
36#import "private/GRPCHost.h"
37
38@implementation GRPCCall (Tests)
Jorge Canizalesb2bd0672015-08-01 23:19:11 -070039
Jorge Canizalese8543b02015-08-01 17:37:40 -070040+ (void)useTestCertsPath:(NSString *)certsPath
41 testName:(NSString *)testName
42 forHost:(NSString *)host {
Jorge Canizales54fa62e2015-10-28 14:46:23 -070043 if (!host || !certsPath || !testName) {
44 [NSException raise:NSInvalidArgumentException format:@"host, path and name must be provided."];
45 }
Paul Querna40f11aa2016-03-03 23:09:06 -080046 NSError *error = nil;
47 NSString *certs = [NSString stringWithContentsOfFile:certsPath
48 encoding:NSUTF8StringEncoding
49 error:&error];
50 if (error != nil) {
51 [NSException raise:[error localizedDescription] format:@"failed to load certs"];
52 }
53
Jorge Canizalese8543b02015-08-01 17:37:40 -070054 GRPCHost *hostConfig = [GRPCHost hostWithAddress:host];
Paul Querna40f11aa2016-03-03 23:09:06 -080055 [hostConfig setTLSPEMRootCerts:certs withPrivateKey:nil withCertChain:nil error:nil];
Jorge Canizalese8543b02015-08-01 17:37:40 -070056 hostConfig.hostNameOverride = testName;
57}
Jorge Canizalesb2bd0672015-08-01 23:19:11 -070058
59+ (void)useInsecureConnectionsForHost:(NSString *)host {
60 GRPCHost *hostConfig = [GRPCHost hostWithAddress:host];
61 hostConfig.secure = NO;
62}
63
Jorge Canizales32fde7a2016-07-29 17:31:07 -070064+ (void)resetHostSettings {
65 [GRPCHost resetAllHostSettings];
Jorge Canizales6af4add2016-07-28 23:05:18 -070066}
Jorge Canizalese8543b02015-08-01 17:37:40 -070067@end