Skip to content

Commit 7843a32

Browse files
M62 patch release: cherry pick Firebase Installations changes (#4683) (#4693)
* Firebase Installations: validation of FIROptions parameters (#4683) * FIS: Throw exception on incomplete Firebase config. * API docs updated. * FirebaseInstallations bump minor version: 1.1.0 * Fix tests * Text fixed * Make exception message more informative * Fix Remote Config tests. * Tests updated to use GCMSenderID if projectID is not available. * Use `GCMSenderID` when `projectID` is not available. * ./scripts/style.sh * Comments * GCMSenderID and projectID validation updated. * Comment * FirebaseInstallations: version bump to 1.0.1. * FIS changelog * FirebaseInstallations: version bump to 1.1.0 * FIS and Core changelogs. * Changelogs remove GCMSenderID * Typo * Typo * fix link * Revert Core changelog * FIS changelog fix. * Travis: Run tests on release-6.15.0-patch * FCM: fix distant future date in the tests. (#4667)
1 parent 51dc1ac commit 7843a32

16 files changed

+185
-12
lines changed

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -708,3 +708,4 @@ jobs:
708708
branches:
709709
only:
710710
- master
711+
- release-6.15.0-patch

Example/InstanceID/Tests/FIRInstanceIDTest.m

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,8 @@ - (void)testSharedInstance {
156156
// The shared instance relies on the default app being configured. Configure it.
157157
FIROptions *options = [[FIROptions alloc] initWithGoogleAppID:kGoogleAppID
158158
GCMSenderID:kGCMSenderID];
159+
options.APIKey = @"api-key";
160+
options.projectID = @"project-id";
159161
[FIRApp configureWithName:kFIRDefaultAppName options:options];
160162
FIRInstanceID *instanceID = [FIRInstanceID instanceID];
161163
XCTAssertNotNil(instanceID);

Example/Messaging/Tests/FIRMessagingContextManagerServiceTest.m

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,8 @@ - (void)testValidContextManagerMessage {
7272
- (void)testMessageWithFutureStartTime {
7373
#if TARGET_OS_IOS
7474
NSString *messageIdentifier = @"fcm-cm-test1";
75-
NSString *startTimeString = @"2020-01-12 12:00:00"; // way into the future
75+
// way into the future
76+
NSString *startTimeString = [self.dateFormatter stringFromDate:[NSDate distantFuture]];
7677
NSDictionary *message = @{
7778
kFIRMessagingContextManagerLocalTimeStart: startTimeString,
7879
kFIRMessagingContextManagerBodyKey : @"Hello world!",
@@ -154,7 +155,8 @@ - (void)testTimedNotificationsUserInfo {
154155
#if TARGET_OS_IOS
155156
NSString *messageIdentifierKey = @"message.id";
156157
NSString *messageIdentifier = @"fcm-cm-test1";
157-
NSString *startTimeString = @"2020-01-12 12:00:00"; // way into the future
158+
// way into the future
159+
NSString *startTimeString = [self.dateFormatter stringFromDate:[NSDate distantFuture]];
158160

159161
NSString *customDataKey = @"hello";
160162
NSString *customData = @"world";

Example/Messaging/Tests/FIRMessagingInstanceTest.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ class FIRMessagingInstanceTest: XCTestCase {
2424
// This is an example of a functional test case.
2525
// Use XCTAssert and related functions to verify your tests produce the correct results.
2626
let options = FirebaseOptions(googleAppID: "1:123:ios:123abc", gcmSenderID: "valid-sender-id")
27+
options.apiKey = "api-key"
28+
options.projectID = "project-id"
2729
FirebaseApp.configure(options: options)
2830
let original = Messaging.messaging()
2931

FirebaseInstallations.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Pod::Spec.new do |s|
22
s.name = 'FirebaseInstallations'
3-
s.version = '1.0.0'
3+
s.version = '1.1.0'
44
s.summary = 'Firebase Installations for iOS'
55

66
s.description = <<-DESC

FirebaseInstallations/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# v1.1.0 -- M62.1
2+
3+
- [changed] Throw an exception when there are missing required `FirebaseOptions` parameters (`APIKey`, `googleAppID`, and `projectID`). Please make sure your `GoogleServices-Info.plist` (or `FirebaseOptions` if you configure Firebase in code) is up to date. The file and settings can be downloaded from the [Firebase Console](https://console.firebase.google.com/). (#4683)
4+
15
# v1.0.0 -- M62
26

37
- [added] The Firebase Installations Service is an infrastructure service for Firebase services that creates unique identifiers and authentication tokens for Firebase clients (called "Firebase Installations") enabling Firebase Targeting, i.e. interoperation between Firebase services.

FirebaseInstallations/Source/Library/FIRInstallations.m

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
#import "FIRInstallationsErrorUtil.h"
3535
#import "FIRInstallationsIDController.h"
3636
#import "FIRInstallationsItem.h"
37+
#import "FIRInstallationsLogger.h"
3738
#import "FIRInstallationsStoredAuthToken.h"
3839
#import "FIRInstallationsVersion.h"
3940

@@ -101,6 +102,7 @@ - (instancetype)initWithAppOptions:(FIROptions *)appOptions
101102
prefetchAuthToken:(BOOL)prefetchAuthToken {
102103
self = [super init];
103104
if (self) {
105+
[[self class] validateAppOptions:appOptions appName:appName];
104106
[[self class] assertCompatibleIIDVersion];
105107

106108
_appOptions = [appOptions copy];
@@ -117,12 +119,44 @@ - (instancetype)initWithAppOptions:(FIROptions *)appOptions
117119
return self;
118120
}
119121

122+
+ (void)validateAppOptions:(FIROptions *)appOptions appName:(NSString *)appName {
123+
NSMutableArray *missingFields = [NSMutableArray array];
124+
if (appName.length < 1) {
125+
[missingFields addObject:@"`FirebaseApp.name`"];
126+
}
127+
if (appOptions.APIKey.length < 1) {
128+
[missingFields addObject:@"`FirebaseOptions.APIKey`"];
129+
}
130+
if (appOptions.googleAppID.length < 1) {
131+
[missingFields addObject:@"`FirebaseOptions.googleAppID`"];
132+
}
133+
134+
// TODO(#4692): Check for `appOptions.projectID.length < 1` only.
135+
// We can use `GCMSenderID` instead of `projectID` temporary.
136+
if (appOptions.projectID.length < 1 && appOptions.GCMSenderID.length < 1) {
137+
[missingFields addObject:@"`FirebaseOptions.projectID`"];
138+
}
139+
140+
if (missingFields.count > 0) {
141+
[NSException
142+
raise:kFirebaseInstallationsErrorDomain
143+
format:
144+
@"%@[%@] Could not configure Firebase Installations due to invalid FirebaseApp "
145+
@"options. The following parameters are nil or empty: %@. If you use "
146+
@"GoogleServices-Info.plist please download the most recent version from the Firebase "
147+
@"Console. If you configure Firebase in code, please make sure you specify all "
148+
@"required parameters.",
149+
kFIRLoggerInstallations, kFIRInstallationsMessageCodeInvalidFirebaseAppOptions,
150+
[missingFields componentsJoinedByString:@", "]];
151+
}
152+
}
153+
120154
#pragma mark - Public
121155

122156
+ (FIRInstallations *)installations {
123157
FIRApp *defaultApp = [FIRApp defaultApp];
124158
if (!defaultApp) {
125-
[NSException raise:NSInternalInconsistencyException
159+
[NSException raise:kFirebaseInstallationsErrorDomain
126160
format:@"The default FirebaseApp instance must be configured before the default"
127161
@"FirebaseApp instance can be initialized. One way to ensure that is to "
128162
@"call `[FIRApp configure];` (`FirebaseApp.configure()` in Swift) in the App"
@@ -191,7 +225,7 @@ + (void)assertCompatibleIIDVersion {
191225
return;
192226
#else
193227
if (![self isIIDVersionCompatible]) {
194-
[NSException raise:NSInternalInconsistencyException
228+
[NSException raise:kFirebaseInstallationsErrorDomain
195229
format:@"FirebaseInstallations will not work correctly with current version of "
196230
@"Firebase Instance ID. Please update your Firebase Instance ID version."];
197231
}

FirebaseInstallations/Source/Library/FIRInstallationsLogger.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,6 @@ extern NSString *const kFIRInstallationsMessageCodeAuthTokenCoderVersionMismatch
4646
// FIRInstallationsStoredIIDCheckin.m
4747
extern NSString *const kFIRInstallationsMessageCodeIIDCheckinCoderVersionMismatch;
4848
extern NSString *const kFIRInstallationsMessageCodeIIDCheckinFailedToDecode;
49+
50+
// FIRInstallations.m
51+
extern NSString *const kFIRInstallationsMessageCodeInvalidFirebaseAppOptions;

FirebaseInstallations/Source/Library/FIRInstallationsLogger.m

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,6 @@
4444
// FIRInstallationsStoredIIDCheckin.m
4545
NSString *const kFIRInstallationsMessageCodeIIDCheckinCoderVersionMismatch = @"I-FIS007000";
4646
NSString *const kFIRInstallationsMessageCodeIIDCheckinFailedToDecode = @"I-FIS007001";
47+
48+
// FIRInstallations.m
49+
NSString *const kFIRInstallationsMessageCodeInvalidFirebaseAppOptions = @"I-FIS008000";

FirebaseInstallations/Source/Library/InstallationsIDController/FIRInstallationsIDController.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ NS_ASSUME_NONNULL_BEGIN
3131
APIKey:(NSString *)APIKey
3232
projectID:(NSString *)projectID
3333
GCMSenderID:(NSString *)GCMSenderID
34-
accessGroup:(NSString *)accessGroup;
34+
accessGroup:(nullable NSString *)accessGroup;
3535

3636
- (FBLPromise<FIRInstallationsItem *> *)getInstallationItem;
3737

0 commit comments

Comments
 (0)