Skip to content

Commit 6e11684

Browse files
authored
Throw exception when projectID is missing from FIROptions (#7725)
1 parent 3c60d81 commit 6e11684

File tree

4 files changed

+36
-10
lines changed

4 files changed

+36
-10
lines changed

FirebaseRemoteConfig/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# Unreleased
2+
- [changed] Throw exception if projectID is missing from FirebaseOptions. (#7725)
3+
14
# v7.9.0
25
- [added] Enabled community supported watchOS build in Swift Package Manager. (#7696)
36
- [fixed] Don't generate missing Analytics warning on Catalyst. (#7693)

FirebaseRemoteConfig/Sources/FIRRemoteConfigComponent.m

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ - (FIRRemoteConfig *)remoteConfigForNamespace:(NSString *)remoteConfigNamespace
3838
errorPropertyName = @"googleAppID";
3939
} else if (options.GCMSenderID.length == 0) {
4040
errorPropertyName = @"GCMSenderID";
41+
} else if (options.projectID.length == 0) {
42+
errorPropertyName = @"projectID";
4143
}
4244

4345
if (errorPropertyName) {

FirebaseRemoteConfig/Sources/RCNConfigFetch.m

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -516,16 +516,8 @@ - (void)fetchWithUserProperties:(NSDictionary *)userProperties
516516
- (NSString *)constructServerURL {
517517
NSString *serverURLStr = [[NSString alloc] initWithString:kServerURLDomain];
518518
serverURLStr = [serverURLStr stringByAppendingString:kServerURLVersion];
519-
520-
if (_options.projectID) {
521-
serverURLStr = [serverURLStr stringByAppendingString:kServerURLProjects];
522-
serverURLStr = [serverURLStr stringByAppendingString:_options.projectID];
523-
} else {
524-
FIRLogError(kFIRLoggerRemoteConfig, @"I-RCN000070",
525-
@"Missing `projectID` from `FirebaseOptions`, please ensure the configured "
526-
@"`FirebaseApp` is configured with `FirebaseOptions` that contains a `projectID`.");
527-
}
528-
519+
serverURLStr = [serverURLStr stringByAppendingString:kServerURLProjects];
520+
serverURLStr = [serverURLStr stringByAppendingString:_options.projectID];
529521
serverURLStr = [serverURLStr stringByAppendingString:kServerURLNamespaces];
530522

531523
// Get the namespace from the fully qualified namespace string of "namespace:FIRAppName".

FirebaseRemoteConfig/Tests/Unit/FIRRemoteConfigComponentTest.m

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,35 @@ - (void)testThrowsWithNilGCMSenderID {
167167
XCTAssertThrows([component remoteConfigForNamespace:@"some_namespace"]);
168168
}
169169

170+
- (void)testThrowsWithEmptyProjectID {
171+
FIROptions *options = [self fakeOptions];
172+
options.projectID = @"";
173+
174+
// Create the provider to vend Remote Config instances.
175+
NSString *appName = [self generatedTestAppName];
176+
FIRApp *app = [[FIRApp alloc] initInstanceWithName:appName options:options];
177+
FIRRemoteConfigComponent *component = [[FIRRemoteConfigComponent alloc] initWithApp:app];
178+
179+
// Creating a Remote Config instance should fail since the projectID is empty.
180+
XCTAssertThrows([component remoteConfigForNamespace:@"some_namespace"]);
181+
}
182+
183+
- (void)testThrowsWithNilProjectID {
184+
FIROptions *options = [self fakeOptions];
185+
#pragma clang diagnostic push
186+
#pragma clang diagnostic ignored "-Wnonnull"
187+
options.projectID = nil;
188+
#pragma clang diagnostic pop
189+
190+
// Create the provider to vend Remote Config instances.
191+
NSString *appName = [self generatedTestAppName];
192+
FIRApp *app = [[FIRApp alloc] initInstanceWithName:appName options:options];
193+
FIRRemoteConfigComponent *component = [[FIRRemoteConfigComponent alloc] initWithApp:app];
194+
195+
// Creating a Remote Config instance should fail since the projectID is empty.
196+
XCTAssertThrows([component remoteConfigForNamespace:@"some_namespace"]);
197+
}
198+
170199
#pragma mark - Helpers
171200

172201
- (FIROptions *)fakeOptions {

0 commit comments

Comments
 (0)