Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions FirebaseRemoteConfig/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Unreleased
- [changed] Throw exception if projectID is missing from FirebaseOptions. (#7725)

# v7.9.0
- [added] Enabled community supported watchOS build in Swift Package Manager. (#7696)
- [fixed] Don't generate missing Analytics warning on Catalyst. (#7693)
Expand Down
2 changes: 2 additions & 0 deletions FirebaseRemoteConfig/Sources/FIRRemoteConfigComponent.m
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ - (FIRRemoteConfig *)remoteConfigForNamespace:(NSString *)remoteConfigNamespace
errorPropertyName = @"googleAppID";
} else if (options.GCMSenderID.length == 0) {
errorPropertyName = @"GCMSenderID";
} else if (options.projectID.length == 0) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since projectID is static configuration, validating it during Component initialization is intuitive, so I think checking here is optimal, and the only change we need to make.

errorPropertyName = @"projectID";
}

if (errorPropertyName) {
Expand Down
12 changes: 2 additions & 10 deletions FirebaseRemoteConfig/Sources/RCNConfigFetch.m
Original file line number Diff line number Diff line change
Expand Up @@ -516,16 +516,8 @@ - (void)fetchWithUserProperties:(NSDictionary *)userProperties
- (NSString *)constructServerURL {
NSString *serverURLStr = [[NSString alloc] initWithString:kServerURLDomain];
serverURLStr = [serverURLStr stringByAppendingString:kServerURLVersion];

if (_options.projectID) {
serverURLStr = [serverURLStr stringByAppendingString:kServerURLProjects];
serverURLStr = [serverURLStr stringByAppendingString:_options.projectID];
} else {
FIRLogError(kFIRLoggerRemoteConfig, @"I-RCN000070",
@"Missing `projectID` from `FirebaseOptions`, please ensure the configured "
Copy link

@erikeldridge erikeldridge Mar 16, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've recommended just asserting project ID as a required input in FIRRemoteConfigComponent.m. Given that, and since project ID is the only thing we're checking here, simplifying this class by removing this logging makes sense.

@"`FirebaseApp` is configured with `FirebaseOptions` that contains a `projectID`.");
}

serverURLStr = [serverURLStr stringByAppendingString:kServerURLProjects];
serverURLStr = [serverURLStr stringByAppendingString:_options.projectID];
serverURLStr = [serverURLStr stringByAppendingString:kServerURLNamespaces];

// Get the namespace from the fully qualified namespace string of "namespace:FIRAppName".
Expand Down
29 changes: 29 additions & 0 deletions FirebaseRemoteConfig/Tests/Unit/FIRRemoteConfigComponentTest.m
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,35 @@ - (void)testThrowsWithNilGCMSenderID {
XCTAssertThrows([component remoteConfigForNamespace:@"some_namespace"]);
}

- (void)testThrowsWithEmptyProjectID {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fact we're only asserting FIRRemoteConfigComponentTest.m throws supports the idea that validating inputs there is sufficient.

FIROptions *options = [self fakeOptions];
options.projectID = @"";

// Create the provider to vend Remote Config instances.
NSString *appName = [self generatedTestAppName];
FIRApp *app = [[FIRApp alloc] initInstanceWithName:appName options:options];
FIRRemoteConfigComponent *component = [[FIRRemoteConfigComponent alloc] initWithApp:app];

// Creating a Remote Config instance should fail since the projectID is empty.
XCTAssertThrows([component remoteConfigForNamespace:@"some_namespace"]);
}

- (void)testThrowsWithNilProjectID {
FIROptions *options = [self fakeOptions];
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wnonnull"
options.projectID = nil;
#pragma clang diagnostic pop

// Create the provider to vend Remote Config instances.
NSString *appName = [self generatedTestAppName];
FIRApp *app = [[FIRApp alloc] initInstanceWithName:appName options:options];
FIRRemoteConfigComponent *component = [[FIRRemoteConfigComponent alloc] initWithApp:app];

// Creating a Remote Config instance should fail since the projectID is empty.
XCTAssertThrows([component remoteConfigForNamespace:@"some_namespace"]);
}

#pragma mark - Helpers

- (FIROptions *)fakeOptions {
Expand Down