Jorge Canizales | e8543b0 | 2015-08-01 17:37:40 -0700 | [diff] [blame] | 1 | /* |
| 2 | * |
Paul Querna | 40f11aa | 2016-03-03 23:09:06 -0800 | [diff] [blame] | 3 | * Copyright 2015-2016, Google Inc. |
Jorge Canizales | e8543b0 | 2015-08-01 17:37:40 -0700 | [diff] [blame] | 4 | * 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 Canizales | b2bd067 | 2015-08-01 23:19:11 -0700 | [diff] [blame] | 39 | |
Jorge Canizales | e8543b0 | 2015-08-01 17:37:40 -0700 | [diff] [blame] | 40 | + (void)useTestCertsPath:(NSString *)certsPath |
| 41 | testName:(NSString *)testName |
| 42 | forHost:(NSString *)host { |
Jorge Canizales | 54fa62e | 2015-10-28 14:46:23 -0700 | [diff] [blame] | 43 | if (!host || !certsPath || !testName) { |
| 44 | [NSException raise:NSInvalidArgumentException format:@"host, path and name must be provided."]; |
| 45 | } |
Paul Querna | 40f11aa | 2016-03-03 23:09:06 -0800 | [diff] [blame] | 46 | 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 Canizales | e8543b0 | 2015-08-01 17:37:40 -0700 | [diff] [blame] | 54 | GRPCHost *hostConfig = [GRPCHost hostWithAddress:host]; |
Paul Querna | 40f11aa | 2016-03-03 23:09:06 -0800 | [diff] [blame] | 55 | [hostConfig setTLSPEMRootCerts:certs withPrivateKey:nil withCertChain:nil error:nil]; |
Jorge Canizales | e8543b0 | 2015-08-01 17:37:40 -0700 | [diff] [blame] | 56 | hostConfig.hostNameOverride = testName; |
| 57 | } |
Jorge Canizales | b2bd067 | 2015-08-01 23:19:11 -0700 | [diff] [blame] | 58 | |
| 59 | + (void)useInsecureConnectionsForHost:(NSString *)host { |
| 60 | GRPCHost *hostConfig = [GRPCHost hostWithAddress:host]; |
| 61 | hostConfig.secure = NO; |
| 62 | } |
| 63 | |
Jorge Canizales | 32fde7a | 2016-07-29 17:31:07 -0700 | [diff] [blame] | 64 | + (void)resetHostSettings { |
| 65 | [GRPCHost resetAllHostSettings]; |
Jorge Canizales | 6af4add | 2016-07-28 23:05:18 -0700 | [diff] [blame] | 66 | } |
Jorge Canizales | e8543b0 | 2015-08-01 17:37:40 -0700 | [diff] [blame] | 67 | @end |