|
|
@@ -191,62 +191,6 @@ static int64_t const kLastCheckinTimestamp = 123456;
|
|
|
[self waitForExpectationsWithTimeout:kExpectationTimeout handler:nil];
|
|
|
}
|
|
|
|
|
|
-// Write fake checkin data to legacy location, then test if migration worked.
|
|
|
-- (void)testCheckinMigrationMovesToNewLocationInKeychain {
|
|
|
- XCTestExpectation *checkinMigrationExpectation =
|
|
|
- [self expectationWithDescription:@"checkin migration should move to the new location"];
|
|
|
- // Create checkin store class.
|
|
|
- FIRInstanceIDBackupExcludedPlist *checkinPlist =
|
|
|
- [[FIRInstanceIDBackupExcludedPlist alloc] initWithFileName:kFakeCheckinPlistName
|
|
|
- subDirectory:kSubDirectoryName];
|
|
|
-
|
|
|
- FIRInstanceIDFakeKeychain *fakeKeychain = [[FIRInstanceIDFakeKeychain alloc] init];
|
|
|
- FIRInstanceIDFakeKeychain *weakKeychain = fakeKeychain;
|
|
|
-
|
|
|
- // Create fake checkin preferences object.
|
|
|
- FIRInstanceIDCheckinPreferences *preferences =
|
|
|
- [[FIRInstanceIDCheckinPreferences alloc] initWithDeviceID:kAuthID secretToken:kSecret];
|
|
|
- [preferences updateWithCheckinPlistContents:[[self class] newCheckinPlistPreferences]];
|
|
|
-
|
|
|
- // Write checkin into legacy location in Fake keychain.
|
|
|
- NSString *checkinKeychainContent = [preferences checkinKeychainContent];
|
|
|
- NSData *data = [checkinKeychainContent dataUsingEncoding:NSUTF8StringEncoding];
|
|
|
- [fakeKeychain setData:data
|
|
|
- forService:kFIRInstanceIDLegacyCheckinKeychainService
|
|
|
- account:kFIRInstanceIDLegacyCheckinKeychainAccount
|
|
|
- handler:^(NSError *error) {
|
|
|
- XCTAssertNil(error);
|
|
|
- // Check that we saved it correctly to the legacy location.
|
|
|
- NSData *dataInLegacyLocation =
|
|
|
- [weakKeychain dataForService:kFIRInstanceIDLegacyCheckinKeychainService
|
|
|
- account:kFIRInstanceIDLegacyCheckinKeychainAccount];
|
|
|
- XCTAssertNotNil(dataInLegacyLocation);
|
|
|
-
|
|
|
- FIRInstanceIDCheckinStore *checkinStore =
|
|
|
- [[FIRInstanceIDCheckinStore alloc] initWithCheckinPlist:checkinPlist
|
|
|
- keychain:weakKeychain];
|
|
|
- // Perform migration.
|
|
|
- [checkinStore migrateCheckinItemIfNeeded];
|
|
|
-
|
|
|
- // Ensure the item is no longer in the old location.
|
|
|
- dataInLegacyLocation =
|
|
|
- [weakKeychain dataForService:kFIRInstanceIDLegacyCheckinKeychainService
|
|
|
- account:kFIRInstanceIDLegacyCheckinKeychainAccount];
|
|
|
- XCTAssertNil(dataInLegacyLocation);
|
|
|
- // Check that it exists in the new location.
|
|
|
- NSData *dataInMigratedLocation =
|
|
|
- [weakKeychain dataForService:kFIRInstanceIDCheckinKeychainService
|
|
|
- account:checkinStore.bundleIdentifierForKeychainAccount];
|
|
|
- XCTAssertNotNil(dataInMigratedLocation);
|
|
|
- // Ensure that the data is the same as what we originally saved.
|
|
|
- XCTAssertEqualObjects(dataInMigratedLocation, data);
|
|
|
-
|
|
|
- [checkinMigrationExpectation fulfill];
|
|
|
- }];
|
|
|
-
|
|
|
- [self waitForExpectationsWithTimeout:kExpectationTimeout handler:nil];
|
|
|
-}
|
|
|
-
|
|
|
#pragma mark - Private Helpers
|
|
|
|
|
|
- (BOOL)savePreferencesToPlist:(NSDictionary *)preferences {
|