|
17 | 17 | #import "Firestore/Example/Tests/Util/FSTIntegrationTestCase.h"
|
18 | 18 |
|
19 | 19 | #import <FirebaseCore/FIRLogger.h>
|
| 20 | +#import <FirebaseCore/FIROptions.h> |
20 | 21 | #import <FirebaseFirestore/FIRCollectionReference.h>
|
21 | 22 | #import <FirebaseFirestore/FIRDocumentChange.h>
|
22 | 23 | #import <FirebaseFirestore/FIRDocumentReference.h>
|
@@ -64,6 +65,9 @@ @interface FIRFirestore (Testing)
|
64 | 65 | @property(nonatomic, strong) FSTDispatchQueue *workerDispatchQueue;
|
65 | 66 | @end
|
66 | 67 |
|
| 68 | +static NSString *defaultProjectId; |
| 69 | +static FIRFirestoreSettings *defaultSettings; |
| 70 | + |
67 | 71 | @implementation FSTIntegrationTestCase {
|
68 | 72 | NSMutableArray<FIRFirestore *> *_firestores;
|
69 | 73 | }
|
@@ -103,46 +107,70 @@ - (FIRFirestore *)firestore {
|
103 | 107 | return [self firestoreWithProjectID:[FSTIntegrationTestCase projectID]];
|
104 | 108 | }
|
105 | 109 |
|
106 |
| -+ (NSString *)projectID { |
| 110 | ++ (void)setUpDefaults { |
| 111 | + defaultSettings = [[FIRFirestoreSettings alloc] init]; |
| 112 | + defaultSettings.persistenceEnabled = YES; |
| 113 | + defaultSettings.timestampsInSnapshotsEnabled = YES; |
| 114 | + |
| 115 | + // Check for a MobileHarness configuration, running against nightly or prod, which have live |
| 116 | + // SSL certs. |
107 | 117 | NSString *project = [[NSProcessInfo processInfo] environment][@"PROJECT_ID"];
|
108 |
| - if (!project) { |
109 |
| - project = @"test-db"; |
| 118 | + NSString *host = [[NSProcessInfo processInfo] environment][@"DATASTORE_HOST"]; |
| 119 | + if (project && host) { |
| 120 | + defaultProjectId = project; |
| 121 | + defaultSettings.host = host; |
| 122 | + return; |
110 | 123 | }
|
111 |
| - return project; |
112 |
| -} |
113 | 124 |
|
114 |
| -+ (FIRFirestoreSettings *)settings { |
115 |
| - FIRFirestoreSettings *settings = [[FIRFirestoreSettings alloc] init]; |
116 |
| - NSString *host = [[NSProcessInfo processInfo] environment][@"DATASTORE_HOST"]; |
117 |
| - settings.sslEnabled = YES; |
118 |
| - if (!host) { |
119 |
| - // If host is nil, there is no GoogleService-Info.plist. Check if a hexa integration test |
120 |
| - // configuration is configured. The first bundle location is used by bazel builds. The |
121 |
| - // second is used for github clones. |
122 |
| - host = @"localhost:8081"; |
123 |
| - settings.sslEnabled = YES; |
124 |
| - NSString *certsPath = |
125 |
| - [[NSBundle mainBundle] pathForResource:@"PlugIns/IntegrationTests.xctest/CAcert" |
126 |
| - ofType:@"pem"]; |
127 |
| - if (certsPath == nil) { |
128 |
| - certsPath = [[NSBundle bundleForClass:[self class]] pathForResource:@"CAcert" ofType:@"pem"]; |
| 125 | + // Check for configuration of a prod project via GoogleServices-Info.plist. |
| 126 | + FIROptions *options = [FIROptions defaultOptions]; |
| 127 | + if (options && ![options.projectID isEqualToString:@"abc-xyz-123"]) { |
| 128 | + defaultProjectId = options.projectID; |
| 129 | + if (host) { |
| 130 | + // Allow access to nightly or other hosts via this mechanism too. |
| 131 | + defaultSettings.host = host; |
129 | 132 | }
|
130 |
| - unsigned long long fileSize = |
131 |
| - [[[NSFileManager defaultManager] attributesOfItemAtPath:certsPath error:nil] fileSize]; |
| 133 | + return; |
| 134 | + } |
132 | 135 |
|
133 |
| - if (fileSize == 0) { |
134 |
| - NSLog( |
135 |
| - @"The cert is not properly configured. Make sure setup_integration_tests.py " |
136 |
| - "has been run."); |
137 |
| - } |
138 |
| - [GRPCCall useTestCertsPath:certsPath testName:@"test_cert_2" forHost:host]; |
| 136 | + // Otherwise fall back on assuming Hexa on localhost. |
| 137 | + defaultProjectId = @"test-db"; |
| 138 | + defaultSettings.host = @"localhost:8081"; |
| 139 | + |
| 140 | + // Hexa uses a self-signed cert: the first bundle location is used by bazel builds. The second is |
| 141 | + // used for github clones. |
| 142 | + NSString *certsPath = |
| 143 | + [[NSBundle mainBundle] pathForResource:@"PlugIns/IntegrationTests.xctest/CAcert" |
| 144 | + ofType:@"pem"]; |
| 145 | + if (certsPath == nil) { |
| 146 | + certsPath = [[NSBundle bundleForClass:[self class]] pathForResource:@"CAcert" ofType:@"pem"]; |
| 147 | + } |
| 148 | + unsigned long long fileSize = |
| 149 | + [[[NSFileManager defaultManager] attributesOfItemAtPath:certsPath error:nil] fileSize]; |
| 150 | + |
| 151 | + if (fileSize == 0) { |
| 152 | + NSLog( |
| 153 | + @"Please set up a GoogleServices-Info.plist for Firestore in Firestore/Example/App using " |
| 154 | + "instructions at <https://github.com/firebase/firebase-ios-sdk#running-sample-apps>. " |
| 155 | + "Alternatively, if you're a Googler with a Hexa preproduction environment, run " |
| 156 | + "setup_integration_tests.py to properly configure testing SSL certificates."); |
139 | 157 | }
|
140 |
| - settings.host = host; |
141 |
| - settings.persistenceEnabled = YES; |
142 |
| - settings.timestampsInSnapshotsEnabled = YES; |
143 |
| - NSLog(@"Configured integration test for %@ with SSL: %@", settings.host, |
144 |
| - settings.sslEnabled ? @"YES" : @"NO"); |
145 |
| - return settings; |
| 158 | + [GRPCCall useTestCertsPath:certsPath testName:@"test_cert_2" forHost:defaultSettings.host]; |
| 159 | +} |
| 160 | + |
| 161 | ++ (NSString *)projectID { |
| 162 | + if (!defaultProjectId) { |
| 163 | + [self setUpDefaults]; |
| 164 | + } |
| 165 | + return defaultProjectId; |
| 166 | +} |
| 167 | + |
| 168 | ++ (FIRFirestoreSettings *)settings { |
| 169 | + if (!defaultSettings) { |
| 170 | + [self setUpDefaults]; |
| 171 | + } |
| 172 | + |
| 173 | + return defaultSettings; |
146 | 174 | }
|
147 | 175 |
|
148 | 176 | - (FIRFirestore *)firestoreWithProjectID:(NSString *)projectID {
|
|
0 commit comments