Skip to content

Commit 76ba6e9

Browse files
authored
Allow GoogleServices-Info.plist to configure Firestore integration tests (#1822)
* Add an empty GoogleService-Info.plist to the Firestore project * Add machinery to be able to use GoogleServices-Info.plist in integration tests. * Refer to instructions if neither a plist nor testing cert is set up
1 parent c7e9b2d commit 76ba6e9

File tree

5 files changed

+110
-46
lines changed

5 files changed

+110
-46
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>API_KEY</key>
6+
<string>correct_api_key</string>
7+
<key>TRACKING_ID</key>
8+
<string>correct_tracking_id</string>
9+
<key>CLIENT_ID</key>
10+
<string>correct_client_id</string>
11+
<key>REVERSED_CLIENT_ID</key>
12+
<string>correct_reversed_client_id</string>
13+
<key>GOOGLE_APP_ID</key>
14+
<string>1:123:ios:123abc</string>
15+
<key>GCM_SENDER_ID</key>
16+
<string>correct_gcm_sender_id</string>
17+
<key>PLIST_VERSION</key>
18+
<string>1</string>
19+
<key>BUNDLE_ID</key>
20+
<string>com.google.FirebaseSDKTests</string>
21+
<key>PROJECT_ID</key>
22+
<string>abc-xyz-123</string>
23+
<key>DATABASE_URL</key>
24+
<string>https://abc-xyz-123.firebaseio.com</string>
25+
<key>STORAGE_BUCKET</key>
26+
<string>project-id-123.storage.firebase.com</string>
27+
</dict>
28+
</plist>

Firestore/Example/Firestore.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@
123123
54A0353020A3B3D8003E0143 /* statusor_test.cc in Sources */ = {isa = PBXBuildFile; fileRef = 54A0352D20A3B3D7003E0143 /* statusor_test.cc */; };
124124
54A0353520A3D8CB003E0143 /* iterator_adaptors_test.cc in Sources */ = {isa = PBXBuildFile; fileRef = 54A0353420A3D8CB003E0143 /* iterator_adaptors_test.cc */; };
125125
54C2294F1FECABAE007D065B /* log_test.cc in Sources */ = {isa = PBXBuildFile; fileRef = 54C2294E1FECABAE007D065B /* log_test.cc */; };
126+
54D400D42148BACE001D2BCC /* GoogleService-Info.plist in Resources */ = {isa = PBXBuildFile; fileRef = 54D400D32148BACE001D2BCC /* GoogleService-Info.plist */; };
126127
54DA12A61F315EE100DD57A1 /* collection_spec_test.json in Resources */ = {isa = PBXBuildFile; fileRef = 54DA129C1F315EE100DD57A1 /* collection_spec_test.json */; };
127128
54DA12A71F315EE100DD57A1 /* existence_filter_spec_test.json in Resources */ = {isa = PBXBuildFile; fileRef = 54DA129D1F315EE100DD57A1 /* existence_filter_spec_test.json */; };
128129
54DA12A81F315EE100DD57A1 /* limbo_spec_test.json in Resources */ = {isa = PBXBuildFile; fileRef = 54DA129E1F315EE100DD57A1 /* limbo_spec_test.json */; };
@@ -407,6 +408,7 @@
407408
54C2294E1FECABAE007D065B /* log_test.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = log_test.cc; sourceTree = "<group>"; };
408409
54C9EDF12040E16300A969CD /* Firestore_SwiftTests_iOS.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = Firestore_SwiftTests_iOS.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
409410
54C9EDF52040E16300A969CD /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
411+
54D400D32148BACE001D2BCC /* GoogleService-Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = "GoogleService-Info.plist"; path = "App/GoogleService-Info.plist"; sourceTree = SOURCE_ROOT; };
410412
54DA129C1F315EE100DD57A1 /* collection_spec_test.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = collection_spec_test.json; sourceTree = "<group>"; };
411413
54DA129D1F315EE100DD57A1 /* existence_filter_spec_test.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = existence_filter_spec_test.json; sourceTree = "<group>"; };
412414
54DA129E1F315EE100DD57A1 /* limbo_spec_test.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = limbo_spec_test.json; sourceTree = "<group>"; };
@@ -623,6 +625,7 @@
623625
isa = PBXGroup;
624626
children = (
625627
6003F593195388D20070C39A /* iOS */,
628+
54D400D32148BACE001D2BCC /* GoogleService-Info.plist */,
626629
);
627630
path = App;
628631
sourceTree = "<group>";
@@ -1445,6 +1448,7 @@
14451448
isa = PBXResourcesBuildPhase;
14461449
buildActionMask = 2147483647;
14471450
files = (
1451+
54D400D42148BACE001D2BCC /* GoogleService-Info.plist in Resources */,
14481452
6003F5A9195388D20070C39A /* Images.xcassets in Resources */,
14491453
873B8AEB1B1F5CCA007FD442 /* Main.storyboard in Resources */,
14501454
71719F9F1E33DC2100824A3D /* LaunchScreen.storyboard in Resources */,

Firestore/Example/Tests/Integration/FSTDatastoreTests.mm

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -159,11 +159,7 @@ @implementation FSTDatastoreTests {
159159
- (void)setUp {
160160
[super setUp];
161161

162-
NSString *projectID = [[NSProcessInfo processInfo] environment][@"PROJECT_ID"];
163-
if (!projectID) {
164-
projectID = @"test-db";
165-
}
166-
162+
NSString *projectID = [FSTIntegrationTestCase projectID];
167163
FIRFirestoreSettings *settings = [FSTIntegrationTestCase settings];
168164
if (!settings.sslEnabled) {
169165
[GRPCCall useInsecureConnectionsForHost:settings.host];

Firestore/Example/Tests/Util/FSTIntegrationTestCase.mm

Lines changed: 62 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#import "Firestore/Example/Tests/Util/FSTIntegrationTestCase.h"
1818

1919
#import <FirebaseCore/FIRLogger.h>
20+
#import <FirebaseCore/FIROptions.h>
2021
#import <FirebaseFirestore/FIRCollectionReference.h>
2122
#import <FirebaseFirestore/FIRDocumentChange.h>
2223
#import <FirebaseFirestore/FIRDocumentReference.h>
@@ -64,6 +65,9 @@ @interface FIRFirestore (Testing)
6465
@property(nonatomic, strong) FSTDispatchQueue *workerDispatchQueue;
6566
@end
6667

68+
static NSString *defaultProjectId;
69+
static FIRFirestoreSettings *defaultSettings;
70+
6771
@implementation FSTIntegrationTestCase {
6872
NSMutableArray<FIRFirestore *> *_firestores;
6973
}
@@ -103,46 +107,70 @@ - (FIRFirestore *)firestore {
103107
return [self firestoreWithProjectID:[FSTIntegrationTestCase projectID]];
104108
}
105109

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.
107117
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;
110123
}
111-
return project;
112-
}
113124

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;
129132
}
130-
unsigned long long fileSize =
131-
[[[NSFileManager defaultManager] attributesOfItemAtPath:certsPath error:nil] fileSize];
133+
return;
134+
}
132135

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.");
139157
}
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;
146174
}
147175

148176
- (FIRFirestore *)firestoreWithProjectID:(NSString *)projectID {

Firestore/README.md

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,20 @@
11
## Usage
22

3-
```
4-
$ cd Firestore/Example
5-
$ pod update
6-
$ open Firestore.xcworkspace
7-
Select the FirestoreTests scheme
8-
⌘-u to build and run the unit tests
9-
```
3+
* Set up a workspace via CocoaPods
4+
```
5+
$ cd Firestore/Example
6+
$ pod update
7+
$ open Firestore.xcworkspace
8+
```
9+
* Select the Firestore_Tests_iOS scheme
10+
* ⌘-u to build and run the unit tests
11+
12+
### Running Integration Tests
13+
14+
* [Set up a `GoogleServices-Info.plist`](//github.com/firebase/firebase-ios-sdk#running-sample-apps)
15+
file in `Firestore/Example/App`.
16+
* In Xcode select the Firestore_IntegrationTests_iOS scheme
17+
* ⌘-u to build and run the integration tests
1018
1119
### Building Protos
1220

0 commit comments

Comments
 (0)