diff --git a/FirebaseInstallations/Source/Library/FIRInstallationsItem.h b/FirebaseInstallations/Source/Library/FIRInstallationsItem.h index 316f73bf7ea..fa045da4c2a 100644 --- a/FirebaseInstallations/Source/Library/FIRInstallationsItem.h +++ b/FirebaseInstallations/Source/Library/FIRInstallationsItem.h @@ -20,8 +20,6 @@ @class FIRInstallationsStoredItem; @class FIRInstallationsStoredAuthToken; -@class FIRInstallationsStoredRegistrationError; -@class FIRInstallationsStoredRegistrationParameters; @class FIRInstallationsStoredIIDCheckin; NS_ASSUME_NONNULL_BEGIN @@ -46,8 +44,6 @@ NS_ASSUME_NONNULL_BEGIN @property(nonatomic, nullable) FIRInstallationsStoredAuthToken *authToken; @property(nonatomic, assign) FIRInstallationsStatus registrationStatus; -@property(nonatomic, nullable) FIRInstallationsStoredRegistrationError *registrationError; - /// Instance ID checkin data imported from IID checkin store as a part of IID migration. @property(nonatomic, nullable) FIRInstallationsStoredIIDCheckin *IIDCheckin; @@ -85,17 +81,6 @@ NS_ASSUME_NONNULL_BEGIN */ + (NSString *)generateFID; -/** - * Updates `registrationStatus` and `registrationError` accordingly. - * @param error The error for the Installation Registration API request. - * @param date The date when the error occurred. - * @param registrationParameters The parameters used for the Installation Registration API request. - */ -- (void)updateWithRegistrationError:(NSError *)error - date:(NSDate *)date - registrationParameters: - (FIRInstallationsStoredRegistrationParameters *)registrationParameters; - @end NS_ASSUME_NONNULL_END diff --git a/FirebaseInstallations/Source/Library/FIRInstallationsItem.m b/FirebaseInstallations/Source/Library/FIRInstallationsItem.m index 47449711a17..5d1a1850b20 100644 --- a/FirebaseInstallations/Source/Library/FIRInstallationsItem.m +++ b/FirebaseInstallations/Source/Library/FIRInstallationsItem.m @@ -18,7 +18,6 @@ #import "FIRInstallationsStoredAuthToken.h" #import "FIRInstallationsStoredItem.h" -#import "FIRInstallationsStoredRegistrationError.h" @implementation FIRInstallationsItem @@ -47,7 +46,6 @@ - (void)updateWithStoredItem:(FIRInstallationsStoredItem *)item { self.refreshToken = item.refreshToken; self.authToken = item.authToken; self.registrationStatus = item.registrationStatus; - self.registrationError = item.registrationError; self.IIDCheckin = item.IIDCheckin; } @@ -57,7 +55,6 @@ - (FIRInstallationsStoredItem *)storedItem { storedItem.refreshToken = self.refreshToken; storedItem.authToken = self.authToken; storedItem.registrationStatus = self.registrationStatus; - storedItem.registrationError = self.registrationError; storedItem.IIDCheckin = self.IIDCheckin; return storedItem; } @@ -104,17 +101,4 @@ + (NSString *)base64URLEncodedStringWithData:(NSData *)data { return string; } -- (void)updateWithRegistrationError:(NSError *)error - date:(NSDate *)date - registrationParameters: - (FIRInstallationsStoredRegistrationParameters *)registrationParameters { - self.registrationStatus = FIRInstallationStatusRegistrationFailed; - self.registrationError = [[FIRInstallationsStoredRegistrationError alloc] - initWithRegistrationParameters:registrationParameters - date:date - APIError:error]; - self.authToken = nil; - self.refreshToken = nil; -} - @end diff --git a/FirebaseInstallations/Source/Library/FIRInstallationsLogger.h b/FirebaseInstallations/Source/Library/FIRInstallationsLogger.h index 9c9e479f663..a8cf0138245 100644 --- a/FirebaseInstallations/Source/Library/FIRInstallationsLogger.h +++ b/FirebaseInstallations/Source/Library/FIRInstallationsLogger.h @@ -43,13 +43,6 @@ extern NSString *const kFIRInstallationsMessageCodeInstallationCoderVersionMisma // FIRInstallationsStoredAuthToken.m extern NSString *const kFIRInstallationsMessageCodeAuthTokenCoderVersionMismatch; -// FIRInstallationsStoredRegistrationError.m -extern NSString *const kFIRInstallationsMessageCodeRegistrationErrorCoderVersionMismatch; -extern NSString *const kFIRInstallationsMessageCodeRegistrationErrorFailedToDecode; - -// FIRInstallationsStoredRegistrationParameters.m -extern NSString *const kFIRInstallationsMessageCodeRegistrationParametersCoderVersionMismatch; - // FIRInstallationsStoredIIDCheckin.m extern NSString *const kFIRInstallationsMessageCodeIIDCheckinCoderVersionMismatch; extern NSString *const kFIRInstallationsMessageCodeIIDCheckinFailedToDecode; diff --git a/FirebaseInstallations/Source/Library/FIRInstallationsLogger.m b/FirebaseInstallations/Source/Library/FIRInstallationsLogger.m index 8c4f1ab92de..f193f9e0b86 100644 --- a/FirebaseInstallations/Source/Library/FIRInstallationsLogger.m +++ b/FirebaseInstallations/Source/Library/FIRInstallationsLogger.m @@ -41,14 +41,6 @@ // FIRInstallationsStoredAuthToken.m NSString *const kFIRInstallationsMessageCodeAuthTokenCoderVersionMismatch = @"I-FIS004000"; -// FIRInstallationsStoredRegistrationError.m -NSString *const kFIRInstallationsMessageCodeRegistrationErrorCoderVersionMismatch = @"I-FIS005000"; -NSString *const kFIRInstallationsMessageCodeRegistrationErrorFailedToDecode = @"I-FIS005001"; - -// FIRInstallationsStoredRegistrationParameters.m -NSString *const kFIRInstallationsMessageCodeRegistrationParametersCoderVersionMismatch = - @"I-FIS006000"; - // FIRInstallationsStoredIIDCheckin.m NSString *const kFIRInstallationsMessageCodeIIDCheckinCoderVersionMismatch = @"I-FIS007000"; NSString *const kFIRInstallationsMessageCodeIIDCheckinFailedToDecode = @"I-FIS007001"; diff --git a/FirebaseInstallations/Source/Library/InstallationsAPI/FIRInstallationsAPIService.h b/FirebaseInstallations/Source/Library/InstallationsAPI/FIRInstallationsAPIService.h index a510e2d9378..f0988634fa0 100644 --- a/FirebaseInstallations/Source/Library/InstallationsAPI/FIRInstallationsAPIService.h +++ b/FirebaseInstallations/Source/Library/InstallationsAPI/FIRInstallationsAPIService.h @@ -26,9 +26,6 @@ NS_ASSUME_NONNULL_BEGIN */ @interface FIRInstallationsAPIService : NSObject -@property(nonatomic, readonly) NSString *APIKey; -@property(nonatomic, readonly) NSString *projectID; - /** * The default initializer. * @param APIKey The Firebase project API key (see `FIROptions.APIKey`). diff --git a/FirebaseInstallations/Source/Library/InstallationsAPI/FIRInstallationsAPIService.m b/FirebaseInstallations/Source/Library/InstallationsAPI/FIRInstallationsAPIService.m index 09a49cf198b..49c128cd71b 100644 --- a/FirebaseInstallations/Source/Library/InstallationsAPI/FIRInstallationsAPIService.m +++ b/FirebaseInstallations/Source/Library/InstallationsAPI/FIRInstallationsAPIService.m @@ -57,6 +57,8 @@ - (instancetype)initWithResponse:(NSHTTPURLResponse *)response data:(nullable NS @interface FIRInstallationsAPIService () @property(nonatomic, readonly) NSURLSession *URLSession; +@property(nonatomic, readonly) NSString *APIKey; +@property(nonatomic, readonly) NSString *projectID; @end NS_ASSUME_NONNULL_END diff --git a/FirebaseInstallations/Source/Library/InstallationsIDController/FIRInstallationsIDController.m b/FirebaseInstallations/Source/Library/InstallationsIDController/FIRInstallationsIDController.m index 41b565ffdbf..81fa7ec5543 100644 --- a/FirebaseInstallations/Source/Library/InstallationsIDController/FIRInstallationsIDController.m +++ b/FirebaseInstallations/Source/Library/InstallationsIDController/FIRInstallationsIDController.m @@ -32,13 +32,11 @@ #import "FIRInstallationsLogger.h" #import "FIRInstallationsSingleOperationPromiseCache.h" #import "FIRInstallationsStore.h" -#import "FIRInstallationsStoredIIDCheckin.h" #import "FIRSecureStorage.h" #import "FIRInstallationsHTTPError.h" #import "FIRInstallationsStoredAuthToken.h" -#import "FIRInstallationsStoredRegistrationError.h" -#import "FIRInstallationsStoredRegistrationParameters.h" +#import "FIRInstallationsStoredIIDCheckin.h" const NSNotificationName FIRInstallationIDDidChangeNotification = @"FIRInstallationIDDidChangeNotification"; @@ -47,8 +45,6 @@ NSTimeInterval const kFIRInstallationsTokenExpirationThreshold = 60 * 60; // 1 hour. -NSTimeInterval const kFIRInstallationsRegistrationErrorTimeout = 24 * 60 * 60; // 1 day. - @interface FIRInstallationsIDController () @property(nonatomic, readonly) NSString *appID; @property(nonatomic, readonly) NSString *appName; @@ -149,22 +145,9 @@ - (instancetype)initWithGoogleAppID:(NSString *)appID __PRETTY_FUNCTION__, self.appName); FBLPromise *installationItemPromise = - [self getStoredInstallation] - .recover(^id(NSError *error) { - return [self createAndSaveFID]; - }) - .then(^id(FIRInstallationsItem *installation) { - // Validate if a previous registration attempt failed with an error requiring Firebase - // configuration changes. - if (installation.registrationStatus == FIRInstallationStatusRegistrationFailed && - [self isRegistrationErrorWithDateUpToDate:installation.registrationError.date] && - [self areInstallationRegistrationParametersEqualToCurrent: - installation.registrationError.registrationParameters]) { - return installation.registrationError.APIError; - } - - return installation; - }); + [self getStoredInstallation].recover(^id(NSError *error) { + return [self createAndSaveFID]; + }); // Initiate registration process on success if needed, but return the installation without waiting // for it. @@ -183,7 +166,6 @@ - (instancetype)initWithGoogleAppID:(NSString *)appID switch (installation.registrationStatus) { case FIRInstallationStatusUnregistered: case FIRInstallationStatusRegistered: - case FIRInstallationStatusRegistrationFailed: isValid = YES; break; @@ -249,19 +231,6 @@ - (FIRInstallationsItem *)createInstallationWithFID:(NSString *)FID return installation; } -- (BOOL)areInstallationRegistrationParametersEqualToCurrent: - (FIRInstallationsStoredRegistrationParameters *)parameters { - NSString *APIKey = self.APIService.APIKey; - NSString *projectID = self.APIService.projectID; - return (parameters.APIKey == APIKey || [parameters.APIKey isEqual:APIKey]) && - (parameters.projectID == projectID || [parameters.projectID isEqual:projectID]); -} - -- (BOOL)isRegistrationErrorWithDateUpToDate:(NSDate *)errorDate { - return errorDate != nil && - -[errorDate timeIntervalSinceNow] <= kFIRInstallationsRegistrationErrorTimeout; -} - #pragma mark - FID registration - (FBLPromise *)registerInstallationIfNeeded: @@ -273,14 +242,19 @@ - (BOOL)isRegistrationErrorWithDateUpToDate:(NSDate *)errorDate { case FIRInstallationStatusUnknown: case FIRInstallationStatusUnregistered: - case FIRInstallationStatusRegistrationFailed: // Registration required. Proceed. break; } return [self.APIService registerInstallation:installation] - .recover(^id(NSError *error) { - return [self handleRegistrationRequestError:error installation:installation]; + .catch(^(NSError *_Nonnull error) { + if ([self doesRegistrationErrorRequireConfigChange:error]) { + FIRLogError(kFIRLoggerInstallations, + kFIRInstallationsMessageCodeInvalidFirebaseConfiguration, + @"Firebase Installation registration failed for app with name: %@, error: " + @"%@\nPlease make sure you use valid GoogleService-Info.plist", + self.appName, error); + } }) .then(^id(FIRInstallationsItem *registeredInstallation) { // Expected successful result: @[FIRInstallationsItem *registeredInstallation, NSNull] @@ -299,32 +273,6 @@ - (BOOL)isRegistrationErrorWithDateUpToDate:(NSDate *)errorDate { }); } -- (FBLPromise *)handleRegistrationRequestError:(NSError *)error - installation: - (FIRInstallationsItem *)installation { - if ([self doesRegistrationErrorRequireConfigChange:error]) { - FIRLogError(kFIRLoggerInstallations, kFIRInstallationsMessageCodeInvalidFirebaseConfiguration, - @"Firebase Installation registration failed for app with name: %@, error: " - @"%@\nPlease make sure you use valid GoogleService-Info.plist", - self.appName, error); - - FIRInstallationsItem *failedInstallation = [installation copy]; - [failedInstallation updateWithRegistrationError:error - date:[NSDate date] - registrationParameters:[self currentRegistrationParameters]]; - - // Save the error and then fail with the API error. - return - [self.installationsStore saveInstallation:failedInstallation].then(^NSError *(id result) { - return error; - }); - } - - FBLPromise *errorPromise = [FBLPromise pendingPromise]; - [errorPromise reject:error]; - return errorPromise; -} - - (BOOL)doesRegistrationErrorRequireConfigChange:(NSError *)error { FIRInstallationsHTTPError *HTTPError = (FIRInstallationsHTTPError *)error; if (![HTTPError isKindOfClass:[FIRInstallationsHTTPError class]]) { @@ -344,12 +292,6 @@ - (BOOL)doesRegistrationErrorRequireConfigChange:(NSError *)error { } } -- (FIRInstallationsStoredRegistrationParameters *)currentRegistrationParameters { - return [[FIRInstallationsStoredRegistrationParameters alloc] - initWithAPIKey:self.APIService.APIKey - projectID:self.APIService.projectID]; -} - #pragma mark - Auth Token - (FBLPromise *)getAuthTokenForcingRefresh:(BOOL)forceRefresh { @@ -455,7 +397,6 @@ - (id)regenerateFIDOnRefreshTokenErrorIfNeeded:(NSError *)error { switch (installation.registrationStatus) { case FIRInstallationStatusUnknown: case FIRInstallationStatusUnregistered: - case FIRInstallationStatusRegistrationFailed: // The installation is not registered, so it is safe to be deleted as is, so return early. return [FBLPromise resolvedWith:installation]; break; diff --git a/FirebaseInstallations/Source/Library/InstallationsIDController/FIRInstallationsStatus.h b/FirebaseInstallations/Source/Library/InstallationsIDController/FIRInstallationsStatus.h index 4fc747de5ca..3edc6920114 100644 --- a/FirebaseInstallations/Source/Library/InstallationsIDController/FIRInstallationsStatus.h +++ b/FirebaseInstallations/Source/Library/InstallationsIDController/FIRInstallationsStatus.h @@ -32,7 +32,4 @@ typedef NS_ENUM(NSInteger, FIRInstallationsStatus) { FIRInstallationStatusUnregistered, /// The Firebase Installation has successfully been registered with FIS. FIRInstallationStatusRegistered, - /// The Firebase Installation registration with FIS failed. Firebase configuration changes are - /// required. - FIRInstallationStatusRegistrationFailed, }; diff --git a/FirebaseInstallations/Source/Library/InstallationsStore/FIRInstallationsStoredItem.h b/FirebaseInstallations/Source/Library/InstallationsStore/FIRInstallationsStoredItem.h index 9504f7a4402..365b8e0e16c 100644 --- a/FirebaseInstallations/Source/Library/InstallationsStore/FIRInstallationsStoredItem.h +++ b/FirebaseInstallations/Source/Library/InstallationsStore/FIRInstallationsStoredItem.h @@ -19,7 +19,6 @@ #import "FIRInstallationsStatus.h" @class FIRInstallationsStoredAuthToken; -@class FIRInstallationsStoredRegistrationError; @class FIRInstallationsStoredIIDCheckin; NS_ASSUME_NONNULL_BEGIN @@ -42,8 +41,6 @@ NS_ASSUME_NONNULL_BEGIN @property(nonatomic, nullable) FIRInstallationsStoredAuthToken *authToken; @property(nonatomic) FIRInstallationsStatus registrationStatus; -@property(nonatomic, nullable) FIRInstallationsStoredRegistrationError *registrationError; - /// Instance ID checkin data imported from IID checkin store as a part of IID migration. @property(nonatomic, nullable) FIRInstallationsStoredIIDCheckin *IIDCheckin; diff --git a/FirebaseInstallations/Source/Library/InstallationsStore/FIRInstallationsStoredItem.m b/FirebaseInstallations/Source/Library/InstallationsStore/FIRInstallationsStoredItem.m index b34cc3427ee..b7e842cf032 100644 --- a/FirebaseInstallations/Source/Library/InstallationsStore/FIRInstallationsStoredItem.m +++ b/FirebaseInstallations/Source/Library/InstallationsStore/FIRInstallationsStoredItem.m @@ -19,13 +19,11 @@ #import "FIRInstallationsLogger.h" #import "FIRInstallationsStoredAuthToken.h" #import "FIRInstallationsStoredIIDCheckin.h" -#import "FIRInstallationsStoredRegistrationError.h" NSString *const kFIRInstallationsStoredItemFirebaseInstallationIDKey = @"firebaseInstallationID"; NSString *const kFIRInstallationsStoredItemRefreshTokenKey = @"refreshToken"; NSString *const kFIRInstallationsStoredItemAuthTokenKey = @"authToken"; NSString *const kFIRInstallationsStoredItemRegistrationStatusKey = @"registrationStatus"; -NSString *const kFIRInstallationsStoredItemRegistrationErrorKey = @"registrationError"; NSString *const kFIRInstallationsStoredItemIIDCheckinKey = @"IIDCheckin"; NSString *const kFIRInstallationsStoredItemStorageVersionKey = @"storageVersion"; @@ -44,8 +42,6 @@ - (void)encodeWithCoder:(nonnull NSCoder *)aCoder { [aCoder encodeObject:self.authToken forKey:kFIRInstallationsStoredItemAuthTokenKey]; [aCoder encodeInteger:self.registrationStatus forKey:kFIRInstallationsStoredItemRegistrationStatusKey]; - [aCoder encodeObject:self.registrationError - forKey:kFIRInstallationsStoredItemRegistrationErrorKey]; [aCoder encodeObject:self.IIDCheckin forKey:kFIRInstallationsStoredItemIIDCheckinKey]; [aCoder encodeInteger:self.storageVersion forKey:kFIRInstallationsStoredItemStorageVersionKey]; } @@ -71,9 +67,6 @@ - (nullable instancetype)initWithCoder:(nonnull NSCoder *)aDecoder { forKey:kFIRInstallationsStoredItemAuthTokenKey]; item.registrationStatus = [aDecoder decodeIntegerForKey:kFIRInstallationsStoredItemRegistrationStatusKey]; - item.registrationError = - [aDecoder decodeObjectOfClass:[FIRInstallationsStoredRegistrationError class] - forKey:kFIRInstallationsStoredItemRegistrationErrorKey]; item.IIDCheckin = [aDecoder decodeObjectOfClass:[FIRInstallationsStoredIIDCheckin class] forKey:kFIRInstallationsStoredItemIIDCheckinKey]; diff --git a/FirebaseInstallations/Source/Library/InstallationsStore/FIRInstallationsStoredRegistrationError.h b/FirebaseInstallations/Source/Library/InstallationsStore/FIRInstallationsStoredRegistrationError.h deleted file mode 100644 index 9c923d851c1..00000000000 --- a/FirebaseInstallations/Source/Library/InstallationsStore/FIRInstallationsStoredRegistrationError.h +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright 2019 Google - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#import - -@class FIRInstallationsStoredRegistrationParameters; - -NS_ASSUME_NONNULL_BEGIN - -/** - * This class serializes and deserializes the installation data into/from `NSData` to be stored in - * Keychain. This class is primarily used by `FIRInstallationsStore`. It is also used on the logic - * level as a data object (see `FIRInstallationsItem.registrationError`). - * - * WARNING: Modification of the class properties can lead to incompatibility with the stored data - * encoded by the previous class versions. Any modification must be evaluated and, if it is really - * needed, the `storageVersion` must be bumped and proper migration code added. - */ - -@interface FIRInstallationsStoredRegistrationError : NSObject - -@property(nonatomic, readonly) FIRInstallationsStoredRegistrationParameters *registrationParameters; -@property(nonatomic, readonly) NSDate *date; -@property(nonatomic, readonly) NSError *APIError; - -/// The version of local storage. -@property(nonatomic, readonly) NSInteger storageVersion; - -- (instancetype)initWithRegistrationParameters: - (FIRInstallationsStoredRegistrationParameters *)registrationParameters - date:(NSDate *)date - APIError:(NSError *)error; - -@end - -NS_ASSUME_NONNULL_END diff --git a/FirebaseInstallations/Source/Library/InstallationsStore/FIRInstallationsStoredRegistrationError.m b/FirebaseInstallations/Source/Library/InstallationsStore/FIRInstallationsStoredRegistrationError.m deleted file mode 100644 index 5788a30f148..00000000000 --- a/FirebaseInstallations/Source/Library/InstallationsStore/FIRInstallationsStoredRegistrationError.m +++ /dev/null @@ -1,99 +0,0 @@ -/* - * Copyright 2019 Google - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#import "FIRInstallationsStoredRegistrationError.h" - -#import "FIRInstallationsHTTPError.h" -#import "FIRInstallationsStoredRegistrationParameters.h" - -#import "FIRInstallationsLogger.h" - -NSString *const kFIRInstallationsStoredRegistrationErrorRegistrationParametersKey = - @"registrationParameters"; -NSString *const kFIRInstallationsStoredRegistrationErrorAPIErrorKey = @"APIError"; -NSString *const kFIRInstallationsStoredRegistrationErrorStorageVersionKey = @"storageVersion"; -NSString *const kFIRInstallationsStoredRegistrationErrorDateKey = @"date"; - -NSInteger const kFIRInstallationsStoredRegistrationErrorStorageVersion = 1; - -@implementation FIRInstallationsStoredRegistrationError - -- (instancetype)initWithRegistrationParameters: - (FIRInstallationsStoredRegistrationParameters *)registrationParameters - date:(NSDate *)date - APIError:(NSError *)error { - self = [super init]; - if (self) { - _registrationParameters = registrationParameters; - _date = date; - _APIError = error; - } - return self; -} - -- (NSInteger)storageVersion { - return kFIRInstallationsStoredRegistrationErrorStorageVersion; -} - -#pragma mark - NSSecureCoding - -+ (BOOL)supportsSecureCoding { - return YES; -} - -- (void)encodeWithCoder:(nonnull NSCoder *)coder { - [coder encodeObject:self.registrationParameters - forKey:kFIRInstallationsStoredRegistrationErrorRegistrationParametersKey]; - [coder encodeObject:self.date forKey:kFIRInstallationsStoredRegistrationErrorDateKey]; - [coder encodeObject:self.APIError forKey:kFIRInstallationsStoredRegistrationErrorAPIErrorKey]; - [coder encodeInteger:kFIRInstallationsStoredRegistrationErrorStorageVersion - forKey:kFIRInstallationsStoredRegistrationErrorStorageVersionKey]; -} - -- (nullable instancetype)initWithCoder:(nonnull NSCoder *)coder { - NSInteger storageVersion = - [coder decodeIntegerForKey:kFIRInstallationsStoredRegistrationErrorStorageVersionKey]; - if (storageVersion > self.storageVersion) { - FIRLogWarning(kFIRLoggerInstallations, - kFIRInstallationsMessageCodeRegistrationErrorCoderVersionMismatch, - @"FIRInstallationsStoredRegistrationError was encoded by a newer coder version " - @"%ld. Current coder version is %ld. Some installation data may be lost.", - (long)storageVersion, (long)self.storageVersion); - } - - FIRInstallationsStoredRegistrationParameters *registrationParameters = - [coder decodeObjectOfClass:[FIRInstallationsStoredRegistrationParameters class] - forKey:kFIRInstallationsStoredRegistrationErrorRegistrationParametersKey]; - NSDate *date = [coder decodeObjectOfClass:[NSDate class] - forKey:kFIRInstallationsStoredRegistrationErrorDateKey]; - - NSSet *allowedErrorClasses = - [NSSet setWithArray:@ [[FIRInstallationsHTTPError class], [NSError class]]]; - NSError *APIError = - [coder decodeObjectOfClasses:allowedErrorClasses - forKey:kFIRInstallationsStoredRegistrationErrorAPIErrorKey]; - - if (registrationParameters == nil || APIError == nil) { - FIRLogWarning(kFIRLoggerInstallations, - kFIRInstallationsMessageCodeRegistrationErrorFailedToDecode, - @"Failed to decode FIRInstallationsStoredRegistrationError."); - return nil; - } - - return [self initWithRegistrationParameters:registrationParameters date:date APIError:APIError]; -} - -@end diff --git a/FirebaseInstallations/Source/Library/InstallationsStore/FIRInstallationsStoredRegistrationParameters.h b/FirebaseInstallations/Source/Library/InstallationsStore/FIRInstallationsStoredRegistrationParameters.h deleted file mode 100644 index 9b787d6d5c9..00000000000 --- a/FirebaseInstallations/Source/Library/InstallationsStore/FIRInstallationsStoredRegistrationParameters.h +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright 2019 Google - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#import - -NS_ASSUME_NONNULL_BEGIN - -/** - * This class serializes and deserializes the installation data into/from `NSData` to be stored in - * Keychain. This class is primarily used by `FIRInstallationsStore`. It is also used on the logic - * level as a data object (see `FIRInstallationsStoredRegistrationError`). - * - * WARNING: Modification of the class properties can lead to incompatibility with the stored data - * encoded by the previous class versions. Any modification must be evaluated and, if it is really - * needed, the `storageVersion` must be bumped and proper migration code added. - */ - -@interface FIRInstallationsStoredRegistrationParameters : NSObject - -@property(nonatomic, readonly, nullable) NSString *APIKey; -@property(nonatomic, readonly, nullable) NSString *projectID; - -/// The version of local storage. -@property(nonatomic, readonly) NSInteger storageVersion; - -- (instancetype)initWithAPIKey:(nullable NSString *)APIKey projectID:(nullable NSString *)projectID; - -@end - -NS_ASSUME_NONNULL_END diff --git a/FirebaseInstallations/Source/Library/InstallationsStore/FIRInstallationsStoredRegistrationParameters.m b/FirebaseInstallations/Source/Library/InstallationsStore/FIRInstallationsStoredRegistrationParameters.m deleted file mode 100644 index c091db0527c..00000000000 --- a/FirebaseInstallations/Source/Library/InstallationsStore/FIRInstallationsStoredRegistrationParameters.m +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Copyright 2019 Google - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#import "FIRInstallationsStoredRegistrationParameters.h" - -#import "FIRInstallationsLogger.h" - -NSString *const kFIRInstallationsStoredRegistrationParametersAPIKeyKey = @"APIKey"; -NSString *const kFIRInstallationsStoredRegistrationParametersProjectID = @"projectID"; -NSString *const FIRInstallationsStoredRegistrationParametersStorageVersionKey = @"storageVersion"; - -NSInteger const FIRInstallationsStoredRegistrationParametersStorageVersion = 1; - -@implementation FIRInstallationsStoredRegistrationParameters - -- (instancetype)initWithAPIKey:(NSString *)APIKey projectID:(NSString *)projectID { - self = [super init]; - if (self) { - _APIKey = APIKey; - _projectID = projectID; - } - return self; -} - -- (NSInteger)storageVersion { - return FIRInstallationsStoredRegistrationParametersStorageVersion; -} - -#pragma mark - NSSecureCoding - -+ (BOOL)supportsSecureCoding { - return YES; -} - -- (void)encodeWithCoder:(nonnull NSCoder *)coder { - [coder encodeObject:self.APIKey forKey:kFIRInstallationsStoredRegistrationParametersAPIKeyKey]; - [coder encodeObject:self.projectID forKey:kFIRInstallationsStoredRegistrationParametersProjectID]; - [coder encodeInteger:self.storageVersion - forKey:FIRInstallationsStoredRegistrationParametersStorageVersionKey]; -} - -- (nullable instancetype)initWithCoder:(nonnull NSCoder *)coder { - NSInteger storageVersion = - [coder decodeIntegerForKey:FIRInstallationsStoredRegistrationParametersStorageVersionKey]; - if (storageVersion > self.storageVersion) { - FIRLogWarning(kFIRLoggerInstallations, - kFIRInstallationsMessageCodeRegistrationParametersCoderVersionMismatch, - @"FIRInstallationsStoredRegistrationParameters was encoded by a newer coder " - @"version %ld. Current coder version is %ld. Some installation data may be lost.", - (long)storageVersion, (long)self.storageVersion); - } - - NSString *APIKey = - [coder decodeObjectForKey:kFIRInstallationsStoredRegistrationParametersAPIKeyKey]; - NSString *projectID = - [coder decodeObjectForKey:kFIRInstallationsStoredRegistrationParametersProjectID]; - - return [self initWithAPIKey:APIKey projectID:projectID]; -} - -@end diff --git a/FirebaseInstallations/Source/Tests/Integration/FIRInstallationsIntegrationTests.m b/FirebaseInstallations/Source/Tests/Integration/FIRInstallationsIntegrationTests.m index c3b10e8bc25..a8a221c8d60 100644 --- a/FirebaseInstallations/Source/Tests/Integration/FIRInstallationsIntegrationTests.m +++ b/FirebaseInstallations/Source/Tests/Integration/FIRInstallationsIntegrationTests.m @@ -188,34 +188,6 @@ - (FIRInstallationsAuthTokenResult *)getAuthToken { return retrievedTokenResult; } -- (void)testGetInstallationIDWithInvalidFirebaseApp { - NSString *appName = [[NSUUID UUID] UUIDString]; - FIRApp *app = [self createAndConfigureAppWithName:appName]; - - XCTestExpectation *getIDExpectation1 = [self expectationWithDescription:@"getIDExpectation1"]; - [[FIRInstallations installationsWithApp:app] - installationIDWithCompletion:^(NSString *_Nullable identifier, NSError *_Nullable error) { - XCTAssertNotNil(identifier); - XCTAssertNil(error); - [getIDExpectation1 fulfill]; - }]; - - [self waitForExpectations:@[ getIDExpectation1 ] timeout:5]; - - // Wait for the registration request to be sent. - FBLWaitForPromisesWithTimeout(10); - - XCTestExpectation *getIDExpectation2 = [self expectationWithDescription:@"getIDExpectation2"]; - [[FIRInstallations installationsWithApp:app] - installationIDWithCompletion:^(NSString *_Nullable identifier, NSError *_Nullable error) { - XCTAssertNil(identifier); - XCTAssertNotNil(error); - [getIDExpectation2 fulfill]; - }]; - - [self waitForExpectations:@[ getIDExpectation2 ] timeout:5]; -} - - (FIRInstallations *)assertInstallationsWithAppNamed:(NSString *)appName { FIRApp *app = [self createAndConfigureAppWithName:appName]; FIRInstallations *installations = [FIRInstallations installationsWithApp:app]; diff --git a/FirebaseInstallations/Source/Tests/Unit/FIRInstallationsAPIServiceTests.m b/FirebaseInstallations/Source/Tests/Unit/FIRInstallationsAPIServiceTests.m index 6d490a0fe64..3fba4976fe7 100644 --- a/FirebaseInstallations/Source/Tests/Unit/FIRInstallationsAPIServiceTests.m +++ b/FirebaseInstallations/Source/Tests/Unit/FIRInstallationsAPIServiceTests.m @@ -19,7 +19,6 @@ #import #import "FBLPromise+Testing.h" #import "FIRInstallationsItem+Tests.h" -#import "XCTestCase+DateAsserts.h" #import "FIRInstallationsAPIService.h" #import "FIRInstallationsErrorUtil.h" @@ -606,6 +605,16 @@ - (NSURLResponse *)responseWithStatusCode:(NSUInteger)statusCode { return response; } +- (void)assertDate:(NSDate *)date + isApproximatelyEqualCurrentPlusTimeInterval:(NSTimeInterval)timeInterval { + NSDate *expectedDate = [NSDate dateWithTimeIntervalSinceNow:timeInterval]; + + NSTimeInterval precision = 10; + XCTAssert(ABS([date timeIntervalSinceDate:expectedDate]) <= precision, + @"date: %@ is not equal to expected %@ with precision %f - %@", date, expectedDate, + precision, self.name); +} + - (id)refreshTokenRequestValidationArgWithInstallation:(FIRInstallationsItem *)installation { return [OCMArg checkWithBlock:^BOOL(NSURLRequest *request) { XCTAssertEqualObjects(request.HTTPMethod, @"POST"); diff --git a/FirebaseInstallations/Source/Tests/Unit/FIRInstallationsIDControllerTests.m b/FirebaseInstallations/Source/Tests/Unit/FIRInstallationsIDControllerTests.m index b05135e526c..d151191be09 100644 --- a/FirebaseInstallations/Source/Tests/Unit/FIRInstallationsIDControllerTests.m +++ b/FirebaseInstallations/Source/Tests/Unit/FIRInstallationsIDControllerTests.m @@ -23,7 +23,6 @@ #import "FBLPromise+Testing.h" #import "FIRInstallationsErrorUtil+Tests.h" #import "FIRInstallationsItem+Tests.h" -#import "XCTestCase+DateAsserts.h" #import "FIRInstallations.h" #import "FIRInstallationsAPIService.h" @@ -36,8 +35,6 @@ #import "FIRInstallationsStoredIIDCheckin.h" #import "FIRInstallationsStoredAuthToken.h" -#import "FIRInstallationsStoredRegistrationError.h" -#import "FIRInstallationsStoredRegistrationParameters.h" @interface FIRInstallationsIDController (Tests) - (instancetype)initWithGoogleAppID:(NSString *)appID @@ -56,9 +53,6 @@ @interface FIRInstallationsIDControllerTests : XCTestCase @property(nonatomic) id mockIIDCheckinStore; @property(nonatomic) NSString *appID; @property(nonatomic) NSString *appName; - -@property(nonatomic) NSString *APIKey; -@property(nonatomic) NSString *projectID; @end @implementation FIRInstallationsIDControllerTests @@ -70,16 +64,11 @@ - (void)setUp { - (void)setUpWithAppName:(NSString *)appName { self.appID = @"appID"; self.appName = appName; - self.APIKey = @"APIKey"; - self.projectID = @"projectID"; - self.mockInstallationsStore = OCMStrictClassMock([FIRInstallationsStore class]); self.mockAPIService = OCMStrictClassMock([FIRInstallationsAPIService class]); self.mockIIDStore = OCMStrictClassMock([FIRInstallationsIIDStore class]); self.mockIIDCheckinStore = OCMStrictClassMock([FIRInstallationsIIDCheckinStore class]); - [self stubAPIServiceParameters]; - self.controller = [[FIRInstallationsIDController alloc] initWithGoogleAppID:self.appID appName:self.appName @@ -98,11 +87,6 @@ - (void)tearDown { self.appName = nil; } -- (void)stubAPIServiceParameters { - OCMStub([self.mockAPIService APIKey]).andReturn(self.APIKey); - OCMStub([self.mockAPIService projectID]).andReturn(self.projectID); -} - #pragma mark - Get Installation - (void)testGetInstallationItem_WhenFIDExists_ThenItIsReturned { @@ -1004,190 +988,6 @@ - (void)testRegisterInstallation_WhenServerRespondsWithDifferentFID_ThenFIDDidCh OCMVerifyAll(self.mockAPIService); } -#pragma mark - Registration Failures - -- (void)testRegisterInstallation_WhenServerRespondsWith429_ThenErrorIsNotStoredAndReturned { - // 1.1. Expect installation to be requested from the store. - FIRInstallationsItem *storedInstallation = - [FIRInstallationsItem createUnregisteredInstallationItem]; - OCMExpect([self.mockInstallationsStore installationForAppID:self.appID appName:self.appName]) - .andReturn([FBLPromise resolvedWith:storedInstallation]); - - // 1.2. Receive HTTP 429. - NSError *APIError = [FIRInstallationsErrorUtil APIErrorWithHTTPCode:429]; - FBLPromise *rejectedAPIPromise = [FBLPromise pendingPromise]; - [rejectedAPIPromise reject:APIError]; - OCMExpect([self.mockAPIService registerInstallation:storedInstallation]) - .andReturn(rejectedAPIPromise); - - // 1.3. Don't expect the installation to be stored with the error. - OCMReject([self.mockInstallationsStore saveInstallation:[OCMArg any]]); - - // 2. Request Installation. - FBLPromise *promise = [self.controller getInstallationItem]; - XCTAssert(FBLWaitForPromisesWithTimeout(0.5)); - - // 4. Check. - XCTAssertNil(promise.error); - XCTAssertNotNil(promise.value); - - // The unregistered installation should be returned before the registration attempt. - XCTAssertEqual(promise.value.registrationStatus, FIRInstallationStatusUnregistered); - - OCMVerifyAll(self.mockInstallationsStore); - OCMVerifyAll(self.mockAPIService); -} - -- (void)testRegisterInstallation_WhenServerRespondsWith400_ThenErrorStoredAndReturned { - // 1.1. Expect installation to be requested from the store. - FIRInstallationsItem *storedInstallation = - [FIRInstallationsItem createUnregisteredInstallationItem]; - OCMExpect([self.mockInstallationsStore installationForAppID:self.appID appName:self.appName]) - .andReturn([FBLPromise resolvedWith:storedInstallation]); - - // 1.2. Receive HTTP 400. - NSError *APIError = [FIRInstallationsErrorUtil APIErrorWithHTTPCode:400]; - FBLPromise *rejectedAPIPromise = [FBLPromise pendingPromise]; - [rejectedAPIPromise reject:APIError]; - OCMExpect([self.mockAPIService registerInstallation:storedInstallation]) - .andReturn(rejectedAPIPromise); - - // 1.3. Expect the installation to be stored with the error. - OCMExpect([self.mockInstallationsStore - saveInstallation:[OCMArg checkWithBlock:^BOOL(FIRInstallationsItem *installation) { - XCTAssertEqual(installation.registrationStatus, - FIRInstallationStatusRegistrationFailed); - XCTAssertEqualObjects(installation.registrationError.APIError, APIError); - XCTAssertEqualObjects( - installation.registrationError.registrationParameters.APIKey, self.APIKey); - XCTAssertEqualObjects( - installation.registrationError.registrationParameters.projectID, - self.projectID); - XCTAssertNotNil(installation.registrationError.date); - [self assertDate:installation.registrationError.date - isApproximatelyEqualCurrentPlusTimeInterval:0]; - return YES; - }]]) - .andReturn([FBLPromise resolvedWith:[NSNull null]]); - - // 2. Request Installation. - FBLPromise *promise = [self.controller getInstallationItem]; - XCTAssert(FBLWaitForPromisesWithTimeout(0.5)); - - // 4. Check. - XCTAssertNil(promise.error); - XCTAssertNotNil(promise.value); - - // The unregistered installation should be returned before the registration attempt. - XCTAssertEqual(promise.value.registrationStatus, FIRInstallationStatusUnregistered); - - OCMVerifyAll(self.mockInstallationsStore); - OCMVerifyAll(self.mockAPIService); -} - -- (void)testGetInstallation_WhenRegistrationErrorStoredAndConfigurationIsTheSame_ThenFails { - // 1.1. Expect installation to be requested from the store. - FIRInstallationsItem *storedInstallation = - [self createFailedToRegisterInstallationWithParameters:[self currentRegistrationParameters]]; - OCMExpect([self.mockInstallationsStore installationForAppID:self.appID appName:self.appName]) - .andReturn([FBLPromise resolvedWith:storedInstallation]); - - // 1.2. Don't expect registration API request to be sent. - OCMReject([self.mockAPIService registerInstallation:[OCMArg any]]); - - // 2. Request Installation. - FBLPromise *promise = [self.controller getInstallationItem]; - XCTAssert(FBLWaitForPromisesWithTimeout(0.5)); - - // 3. Check. - XCTAssertFalse(promise.isFulfilled); - XCTAssertEqualObjects(promise.error, storedInstallation.registrationError.APIError); - - OCMVerifyAll(self.mockInstallationsStore); - OCMVerifyAll(self.mockAPIService); -} - -- (void) - testGetInstallation_WhenRegistrationErrorStoredAndConfigurationDifferent_ThenSendsAPIRequest { - __block FBLPromise *storedInstallationPromise; - OCMExpect([self.mockInstallationsStore installationForAppID:self.appID appName:self.appName]) - .andDo(^(NSInvocation *invocation) { - [invocation setReturnValue:&storedInstallationPromise]; - }); - - // 1.1. Expect installation to be requested from the store. - FIRInstallationsItem *storedInstallation = - [self createFailedToRegisterInstallationWithParameters:[self otherRegistrationParameters]]; - storedInstallationPromise = [FBLPromise resolvedWith:storedInstallation]; - - // 1.2. Expect registration API request to be sent. - FIRInstallationsItem *registeredInstallation = - [FIRInstallationsItem createRegisteredInstallationItem]; - OCMExpect([self.mockAPIService registerInstallation:storedInstallation]) - .andReturn([FBLPromise resolvedWith:registeredInstallation]); - - // 1.3. Expect registered Installation to be stored. - OCMExpect([self.mockInstallationsStore saveInstallation:[OCMArg checkWithBlock:^BOOL(id obj) { - XCTAssertEqualObjects(obj, registeredInstallation); - storedInstallationPromise = - [FBLPromise resolvedWith:obj]; - return YES; - }]]) - .andReturn([FBLPromise resolvedWith:[NSNull null]]); - - // 2. Request Installation. - FBLPromise *promise = [self.controller getInstallationItem]; - XCTAssert(FBLWaitForPromisesWithTimeout(0.5)); - - // 3. Check. - XCTAssertEqualObjects(promise.value.identifier, registeredInstallation.identifier); - XCTAssertNil(promise.error); - - OCMVerifyAll(self.mockInstallationsStore); - OCMVerifyAll(self.mockAPIService); -} - -- (void)testGetInstallation_WhenStoredRegistrationErrorIsOutdated_ThenSendsAPIRequest { - __block FBLPromise *storedInstallationPromise; - OCMExpect([self.mockInstallationsStore installationForAppID:self.appID appName:self.appName]) - .andDo(^(NSInvocation *invocation) { - [invocation setReturnValue:&storedInstallationPromise]; - }); - - // 1.1. Expect installation to be requested from the store. - NSDate *date25HoursAgo = [NSDate dateWithTimeIntervalSinceNow:-25 * 60 * 60]; - FIRInstallationsItem *storedInstallation = - [self createFailedToRegisterInstallationWithParameters:[self currentRegistrationParameters] - date:date25HoursAgo]; - storedInstallationPromise = [FBLPromise resolvedWith:storedInstallation]; - - // 1.2. Expect registration API request to be sent. - FIRInstallationsItem *registeredInstallation = - [FIRInstallationsItem createRegisteredInstallationItem]; - OCMExpect([self.mockAPIService registerInstallation:storedInstallation]) - .andReturn([FBLPromise resolvedWith:registeredInstallation]); - - // 1.3. Expect registered Installation to be stored. - OCMExpect([self.mockInstallationsStore saveInstallation:[OCMArg checkWithBlock:^BOOL(id obj) { - XCTAssertEqualObjects(obj, registeredInstallation); - storedInstallationPromise = - [FBLPromise resolvedWith:obj]; - return YES; - }]]) - .andReturn([FBLPromise resolvedWith:[NSNull null]]); - - // 2. Request Installation. - FBLPromise *promise = [self.controller getInstallationItem]; - XCTAssert(FBLWaitForPromisesWithTimeout(0.5)); - - // 3. Check. - XCTAssertEqualObjects(promise.value.identifier, registeredInstallation.identifier); - XCTAssertNil(promise.error); - - OCMVerifyAll(self.mockInstallationsStore); - OCMVerifyAll(self.mockAPIService); -} - #pragma mark - Helpers - (void)expectInstallationsStoreGetInstallationNotFound { @@ -1229,35 +1029,6 @@ - (XCTestExpectation *)installationIDDidChangeNotificationExpectation { return notificationExpectation; } -- (FIRInstallationsItem *)createFailedToRegisterInstallationWithParameters: - (FIRInstallationsStoredRegistrationParameters *)registrationParameters - date:(NSDate *)date { - FIRInstallationsStoredRegistrationError *error = [[FIRInstallationsStoredRegistrationError alloc] - initWithRegistrationParameters:registrationParameters - date:date - APIError:[FIRInstallationsErrorUtil APIErrorWithHTTPCode:400]]; - FIRInstallationsItem *installation = [FIRInstallationsItem createWithRegistrationFailure:error]; - return installation; -} - -- (FIRInstallationsItem *)createFailedToRegisterInstallationWithParameters: - (FIRInstallationsStoredRegistrationParameters *)registrationParameters { - return [self createFailedToRegisterInstallationWithParameters:registrationParameters - date:[NSDate date]]; -} - -- (FIRInstallationsStoredRegistrationParameters *)currentRegistrationParameters { - return [[FIRInstallationsStoredRegistrationParameters alloc] initWithAPIKey:self.APIKey - projectID:self.projectID]; -} - -- (FIRInstallationsStoredRegistrationParameters *)otherRegistrationParameters { - NSString *APIKey = [@"another" stringByAppendingString:self.APIKey]; - NSString *projectID = [@"another" stringByAppendingString:self.projectID]; - return [[FIRInstallationsStoredRegistrationParameters alloc] initWithAPIKey:APIKey - projectID:projectID]; -} - - (void)expectInstallationStoreToBeRequestedAndReturnInstallation: (FIRInstallationsItem *)storedInstallation { OCMExpect([self.mockInstallationsStore installationForAppID:self.appID appName:self.appName]) diff --git a/FirebaseInstallations/Source/Tests/Unit/FIRInstallationsStoredItemTests.m b/FirebaseInstallations/Source/Tests/Unit/FIRInstallationsStoredItemTests.m index 8f4820e83f4..9a04352b8c1 100644 --- a/FirebaseInstallations/Source/Tests/Unit/FIRInstallationsStoredItemTests.m +++ b/FirebaseInstallations/Source/Tests/Unit/FIRInstallationsStoredItemTests.m @@ -21,8 +21,6 @@ #import "FIRInstallationsStoredAuthToken.h" #import "FIRInstallationsStoredIIDCheckin.h" #import "FIRInstallationsStoredItem.h" -#import "FIRInstallationsStoredRegistrationError.h" -#import "FIRInstallationsStoredRegistrationParameters.h" @interface FIRInstallationsStoredItemTests : XCTestCase @@ -41,7 +39,6 @@ - (void)testItemArchivingUnarchiving { item.refreshToken = @"refresh-token"; item.authToken = authToken; item.registrationStatus = FIRInstallationStatusRegistered; - item.registrationError = [self createRegistrationError]; item.IIDCheckin = [self createIIDCheckin]; NSError *error; @@ -59,35 +56,10 @@ - (void)testItemArchivingUnarchiving { XCTAssertEqualObjects(unarchivedItem.authToken.token, item.authToken.token); XCTAssertEqualObjects(unarchivedItem.authToken.expirationDate, item.authToken.expirationDate); XCTAssertEqual(unarchivedItem.registrationStatus, item.registrationStatus); - - XCTAssertEqualObjects(unarchivedItem.registrationError.APIError, item.registrationError.APIError); - XCTAssertEqualObjects(unarchivedItem.registrationError.date, item.registrationError.date); - XCTAssertEqualObjects(unarchivedItem.registrationError.registrationParameters.APIKey, - item.registrationError.registrationParameters.APIKey); - XCTAssertEqualObjects(unarchivedItem.registrationError.registrationParameters.projectID, - item.registrationError.registrationParameters.projectID); XCTAssertEqualObjects(unarchivedItem.IIDCheckin.deviceID, item.IIDCheckin.deviceID); XCTAssertEqualObjects(unarchivedItem.IIDCheckin.secretToken, item.IIDCheckin.secretToken); } -- (FIRInstallationsStoredRegistrationError *)createRegistrationError { - FIRInstallationsStoredRegistrationParameters *params = - [[FIRInstallationsStoredRegistrationParameters alloc] initWithAPIKey:@"key" projectID:@"id"]; - XCTAssertEqualObjects(params.APIKey, @"key"); - XCTAssertEqualObjects(params.projectID, @"id"); - - NSError *error = [NSError errorWithDomain:@"FIRInstallationsStoredItemTests" - code:-1 - userInfo:@{NSLocalizedFailureReasonErrorKey : @"value"}]; - FIRInstallationsStoredRegistrationError *registrationError = - [[FIRInstallationsStoredRegistrationError alloc] initWithRegistrationParameters:params - date:[NSDate date] - APIError:error]; - XCTAssertEqualObjects(registrationError.APIError, error); - XCTAssertEqualObjects(registrationError.registrationParameters, params); - return registrationError; -} - - (FIRInstallationsStoredIIDCheckin *)createIIDCheckin { return [[FIRInstallationsStoredIIDCheckin alloc] initWithDeviceID:@"IIDDeviceID" secretToken:@"IIDSecretToken"]; diff --git a/FirebaseInstallations/Source/Tests/Utils/FIRInstallationsItem+Tests.h b/FirebaseInstallations/Source/Tests/Utils/FIRInstallationsItem+Tests.h index 2e7118027e5..83a6ee6a2cc 100644 --- a/FirebaseInstallations/Source/Tests/Utils/FIRInstallationsItem+Tests.h +++ b/FirebaseInstallations/Source/Tests/Utils/FIRInstallationsItem+Tests.h @@ -26,9 +26,6 @@ NS_ASSUME_NONNULL_BEGIN + (FIRInstallationsItem *)createRegisteredInstallationItemWithAppID:(NSString *)appID appName:(NSString *)appName; -+ (FIRInstallationsItem *)createWithRegistrationFailure: - (FIRInstallationsStoredRegistrationError *)error; - @end NS_ASSUME_NONNULL_END diff --git a/FirebaseInstallations/Source/Tests/Utils/FIRInstallationsItem+Tests.m b/FirebaseInstallations/Source/Tests/Utils/FIRInstallationsItem+Tests.m index 4127e18ecc1..10c3628ec82 100644 --- a/FirebaseInstallations/Source/Tests/Utils/FIRInstallationsItem+Tests.m +++ b/FirebaseInstallations/Source/Tests/Utils/FIRInstallationsItem+Tests.m @@ -56,15 +56,4 @@ + (FIRInstallationsItem *)createRegisteredInstallationItemWithAppID:(NSString *) return item; } -+ (FIRInstallationsItem *)createWithRegistrationFailure: - (FIRInstallationsStoredRegistrationError *)error { - FIRInstallationsItem *item = [[FIRInstallationsItem alloc] initWithAppID:@"appID" - firebaseAppName:kFIRDefaultAppName]; - item.firebaseInstallationID = @"firebaseInstallationID"; - item.registrationStatus = FIRInstallationStatusRegistrationFailed; - item.registrationError = error; - - return item; -} - @end diff --git a/FirebaseInstallations/Source/Tests/Utils/FIRTestKeychain.h b/FirebaseInstallations/Source/Tests/Utils/FIRTestKeychain.h index e0beca5bd58..78c1a7ab556 100644 --- a/FirebaseInstallations/Source/Tests/Utils/FIRTestKeychain.h +++ b/FirebaseInstallations/Source/Tests/Utils/FIRTestKeychain.h @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - #import #import diff --git a/FirebaseInstallations/Source/Tests/Utils/XCTestCase+DateAsserts.h b/FirebaseInstallations/Source/Tests/Utils/XCTestCase+DateAsserts.h deleted file mode 100644 index aad34ee0331..00000000000 --- a/FirebaseInstallations/Source/Tests/Utils/XCTestCase+DateAsserts.h +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright 2019 Google - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#import - -NS_ASSUME_NONNULL_BEGIN - -@interface XCTestCase (FIRTestsDateUtils) - -- (void)assertDate:(NSDate *)date - isApproximatelyEqualCurrentPlusTimeInterval:(NSTimeInterval)timeInterval; - -@end - -NS_ASSUME_NONNULL_END diff --git a/FirebaseInstallations/Source/Tests/Utils/XCTestCase+DateAsserts.m b/FirebaseInstallations/Source/Tests/Utils/XCTestCase+DateAsserts.m deleted file mode 100644 index 762d35a9a23..00000000000 --- a/FirebaseInstallations/Source/Tests/Utils/XCTestCase+DateAsserts.m +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright 2019 Google - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#import "XCTestCase+DateAsserts.h" - -@implementation XCTestCase (FIRTestsDateUtils) - -- (void)assertDate:(NSDate *)date - isApproximatelyEqualCurrentPlusTimeInterval:(NSTimeInterval)timeInterval { - NSDate *expectedDate = [NSDate dateWithTimeIntervalSinceNow:timeInterval]; - - NSTimeInterval precision = 10; - XCTAssert(ABS([date timeIntervalSinceDate:expectedDate]) <= precision, - @"date: %@ is not equal to expected %@ with precision %f - %@", date, expectedDate, - precision, self.name); -} - -@end