-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Firebase Installations: validation of FIROptions parameters #4683
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 12 commits
d2ea3bc
2f6898b
501af60
381f9a9
1254d1a
45208a6
060740c
832adfa
dac08c6
9af869a
83afada
5a74f2e
724ce8f
bff6efd
45d1a6a
43934b5
3f58525
6fbb14d
1761ed6
22c527d
0fd43bf
e1d0cf2
87922d5
d7ef952
c68b86c
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 |
---|---|---|
|
@@ -34,6 +34,7 @@ | |
#import "FIRInstallationsErrorUtil.h" | ||
#import "FIRInstallationsIDController.h" | ||
#import "FIRInstallationsItem.h" | ||
#import "FIRInstallationsLogger.h" | ||
#import "FIRInstallationsStoredAuthToken.h" | ||
#import "FIRInstallationsVersion.h" | ||
|
||
|
@@ -101,6 +102,7 @@ - (instancetype)initWithAppOptions:(FIROptions *)appOptions | |
prefetchAuthToken:(BOOL)prefetchAuthToken { | ||
self = [super init]; | ||
if (self) { | ||
[[self class] validateAppOptions:appOptions appName:appName]; | ||
maksymmalyhin marked this conversation as resolved.
Show resolved
Hide resolved
|
||
[[self class] assertCompatibleIIDVersion]; | ||
|
||
_appOptions = [appOptions copy]; | ||
|
@@ -117,12 +119,40 @@ - (instancetype)initWithAppOptions:(FIROptions *)appOptions | |
return self; | ||
} | ||
|
||
+ (void)validateAppOptions:(FIROptions *)appOptions appName:(NSString *)appName { | ||
NSMutableArray *missingFields = [NSMutableArray array]; | ||
if (appName.length < 1) { | ||
[missingFields addObject:@"`FirebaseApp.name`"]; | ||
} | ||
if (appOptions.APIKey.length < 1) { | ||
[missingFields addObject:@"`FirebaseOptions.APIKey`"]; | ||
} | ||
if (appOptions.googleAppID.length < 1) { | ||
[missingFields addObject:@"`FirebaseOptions.googleAppID`"]; | ||
} | ||
if (appOptions.GCMSenderID.length < 1) { | ||
[missingFields addObject:@"`FirebaseOptions.GCMSenderID`"]; | ||
maksymmalyhin marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
if (missingFields.count > 0) { | ||
[NSException | ||
raise:kFirebaseInstallationsErrorDomain | ||
format:@"%@[%@] Could not configure Firebase Installations due to invalid FirebaseApp " | ||
@"options. The following parameters are nil or empty: %@. If you use " | ||
@"GoogleServices-Info.plist please download the most recent version from Firebase " | ||
maksymmalyhin marked this conversation as resolved.
Show resolved
Hide resolved
|
||
@"Console. If you configure Firebase in code, please make sure you specify all " | ||
@"required parameters.", | ||
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 recommend that we list the required parameters: 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 list of the missing parameters will be added instead of |
||
kFIRLoggerInstallations, kFIRInstallationsMessageCodeInvalidFirebaseAppOptions, | ||
[missingFields componentsJoinedByString:@", "]]; | ||
} | ||
} | ||
|
||
#pragma mark - Public | ||
|
||
+ (FIRInstallations *)installations { | ||
FIRApp *defaultApp = [FIRApp defaultApp]; | ||
if (!defaultApp) { | ||
[NSException raise:NSInternalInconsistencyException | ||
[NSException raise:kFirebaseInstallationsErrorDomain | ||
format:@"The default FirebaseApp instance must be configured before the default" | ||
@"FirebaseApp instance can be initialized. One way to ensure that is to " | ||
@"call `[FIRApp configure];` (`FirebaseApp.configure()` in Swift) in the App" | ||
|
@@ -191,7 +221,7 @@ + (void)assertCompatibleIIDVersion { | |
return; | ||
#else | ||
if (![self isIIDVersionCompatible]) { | ||
[NSException raise:NSInternalInconsistencyException | ||
[NSException raise:kFirebaseInstallationsErrorDomain | ||
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 am kind of lost with this message and I have no idea what to do here. I have downloaded the info.plist again, I have checked your other PR, I have checked the release notes, I have also look into the code and still no idea, so this is kind of my last resort 😅. 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. @tiagoalmeida sounds like you are having issue with the Firebase update. I am sorry to hear if it is so. Would you like to create a ticket with a description of your issue so we can track all related details there and potentially help other people having similar problems? |
||
format:@"FirebaseInstallations will not work correctly with current version of " | ||
@"Firebase Instance ID. Please update your Firebase Instance ID version."]; | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -75,8 +75,12 @@ - (instancetype)initWithGoogleAppID:(NSString *)appID | |
FIRSecureStorage *secureStorage = [[FIRSecureStorage alloc] init]; | ||
FIRInstallationsStore *installationsStore = | ||
[[FIRInstallationsStore alloc] initWithSecureStorage:secureStorage accessGroup:accessGroup]; | ||
|
||
// Use `GCMSenderID` as `projectID` is not available. | ||
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. Please change to: 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. Good catch! |
||
NSString *APIServiceProjectID = (projectID.length > 0) ? projectID : GCMSenderID; | ||
FIRInstallationsAPIService *apiService = | ||
[[FIRInstallationsAPIService alloc] initWithAPIKey:APIKey projectID:projectID]; | ||
[[FIRInstallationsAPIService alloc] initWithAPIKey:APIKey projectID:APIServiceProjectID]; | ||
|
||
FIRInstallationsIIDStore *IIDStore = [[FIRInstallationsIIDStore alloc] init]; | ||
FIRInstallationsIIDTokenStore *IIDCheckingStore = | ||
[[FIRInstallationsIIDTokenStore alloc] initWithGCMSenderID:GCMSenderID]; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -59,15 +59,17 @@ NS_SWIFT_NAME(Installations) | |
|
||
/** | ||
* Returns a default instance of `Installations`. | ||
* @return Returns an instance of `Installations` for `FirebaseApp.defaultApp(). Throws an exception | ||
* if the default app is not configured yet. | ||
* @return Returns an instance of `Installations` for `FirebaseApp.defaultApp(). | ||
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 recommend removing the word "Returns" 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. Usage of cc @ryanwilson |
||
* @throw Throws an exception if the default app is not configured yet or required `FirebaseApp` | ||
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 recommend removing the word "Throws". 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. Good recommendation, but I'll probably keep it as is to be consistent with the rest of the AppleDocs in the repo. Objective C exceptions are not handled usually, so the exception type is not so important and is mostly informative for a crash report reader. Because of that we use just an SDK domain for most of exceptions. @ryanwilson do you have an opinion on it? 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. Keeping it like this is fine I think - when rendered it's just a text field so having it start with "Throws" is fine. 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. 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. |
||
* options are missing. | ||
*/ | ||
+ (FIRInstallations *)installations NS_SWIFT_NAME(installations()); | ||
|
||
/** | ||
* Returns an instance of `Installations` for an application. | ||
* @param application A configured `FirebaseApp` instance. | ||
* @return Returns an instance of `Installations` corresponding to the passed application. | ||
* @throw Throws an exception if required `FirebaseApp` options are missing. | ||
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. as above |
||
*/ | ||
+ (FIRInstallations *)installationsWithApp:(FIRApp *)application NS_SWIFT_NAME(installations(app:)); | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -87,6 +87,46 @@ - (void)tearDown { | |
self.appName = nil; | ||
} | ||
|
||
#pragma mark - Initialization | ||
|
||
- (void)testInitWhenProjectIDSetThenItIsPassedToAPIService { | ||
NSString *APIKey = @"api-key"; | ||
NSString *projectID = @"project-id"; | ||
OCMExpect([self.mockAPIService alloc]).andReturn(self.mockAPIService); | ||
OCMExpect([self.mockAPIService initWithAPIKey:APIKey projectID:projectID]) | ||
.andReturn(self.mockAPIService); | ||
|
||
FIRInstallationsIDController *controller = | ||
[[FIRInstallationsIDController alloc] initWithGoogleAppID:@"app-id" | ||
appName:@"app-name" | ||
APIKey:APIKey | ||
projectID:projectID | ||
GCMSenderID:@"sender-id" | ||
accessGroup:nil]; | ||
XCTAssertNotNil(controller); | ||
|
||
OCMVerifyAll(self.mockAPIService); | ||
} | ||
|
||
- (void)testInitWhenProjectIDIsNilThenGCMSenderIDIsPassedToAPIServiceAsProjectID { | ||
NSString *APIKey = @"api-key"; | ||
NSString *GCMSenderID = @"sender-id"; | ||
OCMExpect([self.mockAPIService alloc]).andReturn(self.mockAPIService); | ||
OCMExpect([self.mockAPIService initWithAPIKey:APIKey projectID:GCMSenderID]) | ||
.andReturn(self.mockAPIService); | ||
|
||
FIRInstallationsIDController *controller = | ||
[[FIRInstallationsIDController alloc] initWithGoogleAppID:@"app-id" | ||
appName:@"app-name" | ||
APIKey:APIKey | ||
projectID:@"" | ||
GCMSenderID:GCMSenderID | ||
accessGroup:nil]; | ||
XCTAssertNotNil(controller); | ||
|
||
OCMVerifyAll(self.mockAPIService); | ||
} | ||
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 didn't find a test that fails when no GCMSenderID and no projectID are set... 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. They are here |
||
|
||
#pragma mark - Get Installation | ||
|
||
- (void)testGetInstallationItem_WhenFIDExists_ThenItIsReturned { | ||
|
@@ -1134,4 +1174,8 @@ - (FIRInstallationsItem *)expectAuthTokenRefreshForInstallation: | |
return responseInstallation; | ||
} | ||
|
||
- (void)expectAPIServiceInitWithAPIKey:(NSString *)APIKey projectID:(NSString *)projectID { | ||
OCMExpect([self.mockAPIService initWithAPIKey:APIKey projectID:projectID]); | ||
} | ||
|
||
@end |
Uh oh!
There was an error while loading. Please reload this page.