0

[iOS] Fix CPE multi_store_credential_store crash

The root cause was the |valueForKeyPath| expression. It was
distinctUnionOfObjects at first, which yielded an array of the
subarrays, instead distinctUnionOfArrays, which combines all the
subarrays into the top level array.

Bug: 1224977
Change-Id: I37d8c53b558927854f318abad29fc0e3dc1503d6
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3015501
Commit-Queue: Robbie Gibson <rkgibson@google.com>
Reviewed-by: Javier Flores <javierrobles@chromium.org>
Cr-Commit-Position: refs/heads/master@{#899779}
This commit is contained in:
Robbie Gibson
2021-07-09 00:22:36 +00:00
committed by Chromium LUCI CQ
parent 0188a4d64f
commit ed50f3d2da
2 changed files with 9 additions and 3 deletions

@ -14,13 +14,13 @@
@interface MultiStoreCredentialStore ()
@property(nonatomic, strong) NSArray<NSArray<id<CredentialStore>>*>* stores;
@property(nonatomic, strong) NSArray<id<CredentialStore>>* stores;
@end
@implementation MultiStoreCredentialStore
- (instancetype)initWithStores:(NSArray<NSArray<id<CredentialStore>>*>*)stores {
- (instancetype)initWithStores:(NSArray<id<CredentialStore>>*)stores {
DCHECK(stores);
self = [super init];
if (self) {
@ -33,7 +33,7 @@
- (NSArray<id<Credential>>*)credentials {
return
[self.stores valueForKeyPath:@"credentials.@distinctUnionOfObjects.self"];
[self.stores valueForKeyPath:@"credentials.@distinctUnionOfArrays.self"];
}
- (id<Credential>)credentialWithRecordIdentifier:(NSString*)recordIdentifier {

@ -54,6 +54,12 @@ TEST_F(MultiStoreCredentialStoreTest, CombineData) {
MultiStoreCredentialStore* credentialStore =
[[MultiStoreCredentialStore alloc] initWithStores:TestStoreArray()];
EXPECT_EQ(2u, credentialStore.credentials.count);
id<Credential> firstCredential =
TestStoreArray().firstObject.credentials.firstObject;
EXPECT_NSEQ(credentialStore.credentials[0], firstCredential);
EXPECT_NSEQ(credentialStore.credentials[0].user, @"store1user");
}
// Tests that MultiStoreCredentialStore don't duplicate data from stores.