Skip to content

[DNM] Investigate macOS keychain issue #74

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

Closed
wants to merge 4 commits into from

Conversation

ncooke3
Copy link
Member

@ncooke3 ncooke3 commented Aug 14, 2022

#no-changelog

@ncooke3
Copy link
Member Author

ncooke3 commented Aug 14, 2022

The google-utilities / pod-lib-lint (macos) job is expected to fail because the GHA runner will time out due to the keychain access pop-up.

Comment on lines +178 to +274
#pragma mark - Version Compatibility

- (void)FAILS_testVersionCompatibility_GetObject {
// Given
// - Object is set with old implementation.
id oldMockCache = OCMPartialMock([[NSCache alloc] init]);
GULKeychainStorageV7_7_0 *oldKeychainStorage =
[[GULKeychainStorageV7_7_0 alloc] initWithService:kKeychainServiceName cache:oldMockCache];

[self assertSuccessWriteObject:@100
forKey:@"test-key1"
toStorage:(GULKeychainStorage *)oldKeychainStorage
withMockCache:oldMockCache];

// When
// - App is updated to include a Google Utilities version greater than 7.7.0.

// Then
// - Object is retrieved with new implementation.
[self.mockCache removeAllObjects];
[self assertSuccessReadObject:@100
forKey:@"test-key1"
class:[NSNumber class]
existsInCache:YES
fromStorage:self.storage
withMockCache:self.mockCache];
}

- (void)testVersionCompatibility_SetObject {
// Given
// - Object is set with old implementation.
id oldMockCache = OCMPartialMock([[NSCache alloc] init]);
GULKeychainStorageV7_7_0 *oldKeychainStorage =
[[GULKeychainStorageV7_7_0 alloc] initWithService:kKeychainServiceName cache:oldMockCache];

[self assertSuccessWriteObject:@100
forKey:@"test-key1"
toStorage:(GULKeychainStorage *)oldKeychainStorage
withMockCache:oldMockCache];

// When
// - App is updated to include a Google Utilities version greater than 7.7.0.

// Then
// - The same object is updated with new implementation.
[self assertSuccessWriteObject:@200
forKey:@"test-key1"
toStorage:self.storage
withMockCache:self.mockCache];

[self assertSuccessReadObject:@200
forKey:@"test-key1"
class:[NSNumber class]
existsInCache:YES
fromStorage:self.storage
withMockCache:self.mockCache];

[oldMockCache removeAllObjects];
[self assertSuccessReadObject:@200
forKey:@"test-key1"
class:[NSNumber class]
existsInCache:NO
fromStorage:(GULKeychainStorage *)oldKeychainStorage
withMockCache:oldMockCache];
}

- (void)FAILS_testVersionCompatibility_RemoveObject {
// Given
// - Object is set with old implementation.
[self assertNonExistingObjectForKey:@"test-key1" class:[NSNumber class]];

id oldMockCache = OCMPartialMock([[NSCache alloc] init]);
GULKeychainStorageV7_7_0 *oldKeychainStorage =
[[GULKeychainStorageV7_7_0 alloc] initWithService:kKeychainServiceName cache:oldMockCache];

[self assertSuccessWriteObject:@100
forKey:@"test-key1"
toStorage:(GULKeychainStorage *)oldKeychainStorage
withMockCache:oldMockCache];

// When
// - App is updated to include a Google Utilities version greater than 7.7.0.

// Then
// - The same object is removed with new implementation.
[self assertRemoveObjectForKey:@"test-key1"];

// The below assertion should not pass but does.
[oldMockCache removeAllObjects];
[self assertSuccessReadObject:@100
forKey:@"test-key1"
class:[NSNumber class]
existsInCache:NO
fromStorage:(GULKeychainStorage *)oldKeychainStorage
withMockCache:oldMockCache];
}

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are three cases to check for version compatibility. The first and third tests are prefixed with FAILS_ as they fail locally. The other case passes.

The failures indicate two things:

  • that when apps upgrade to the new implementation, they will not be able to receive any data that was stored with the previous implementation.
  • that when apps upgrade to the new implementation, they will not be able to remove any data that was stored with the previous implementation.

Comment on lines +182 to +184
if (@available(iOS 13.0, macOS 10.15, macCatalyst 13.0, tvOS 13.0, watchOS 6.0, *)) {
query[(__bridge id)kSecUseDataProtectionKeychain] = (__bridge id)kCFBooleanTrue;
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the necessary code to resolve the issue.

@ncooke3
Copy link
Member Author

ncooke3 commented Aug 25, 2022

Actual fix is in #75

@ncooke3 ncooke3 closed this Aug 25, 2022
@ncooke3 ncooke3 deleted the nc/keychain-investigation branch December 18, 2023 17:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant