-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Throw exception when projectID is missing from FIROptions #7725
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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 " | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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". | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -167,6 +167,35 @@ - (void)testThrowsWithNilGCMSenderID { | |
| XCTAssertThrows([component remoteConfigForNamespace:@"some_namespace"]); | ||
| } | ||
|
|
||
| - (void)testThrowsWithEmptyProjectID { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 { | ||
|
|
||
There was a problem hiding this comment.
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.