|
84 | 84 | return [NSError errorWithDomain:@"ERROR" code:-1 userInfo:nil];
|
85 | 85 | }
|
86 | 86 |
|
| 87 | +@interface FIRAuthKeychainServices () |
| 88 | + |
| 89 | +// Exposed for testing. |
| 90 | +- (nullable NSData *)itemWithQuery:(NSDictionary *)query error:(NSError **_Nullable)error; |
| 91 | + |
| 92 | +@end |
| 93 | + |
87 | 94 | /** @class FIRAuthKeychainTests
|
88 | 95 | @brief Tests for @c FIRAuthKeychainTests .
|
89 | 96 | */
|
@@ -116,6 +123,30 @@ - (void)testReadExisting {
|
116 | 123 | [self deletePasswordWithAccount:accountFromKey(kKey) service:kService];
|
117 | 124 | }
|
118 | 125 |
|
| 126 | +/** @fn testReadMultiple |
| 127 | + @brief Tests reading multiple items from keychain returns only the first item. |
| 128 | + */ |
| 129 | +- (void)testReadMultiple { |
| 130 | + [self addPassword:kData account:accountFromKey(kKey) service:kService]; |
| 131 | + [self addPassword:kOtherData account:accountFromKey(kKey) service:kOtherService]; |
| 132 | + FIRAuthKeychainServices *keychain = [[FIRAuthKeychainServices alloc] initWithService:kService]; |
| 133 | + NSString *queriedAccount = accountFromKey(kKey); |
| 134 | + NSDictionary *query = @{ |
| 135 | + (__bridge id)kSecClass : (__bridge id)kSecClassGenericPassword, |
| 136 | + (__bridge id)kSecAttrAccount : queriedAccount, |
| 137 | + }; |
| 138 | + NSError *error = fakeError(); |
| 139 | + // Keychain on macOS returns items in a different order than keychain on iOS, |
| 140 | + // so test that the returned object is one of any of the added objects. |
| 141 | + NSData *queriedData = [keychain itemWithQuery:query error:&error]; |
| 142 | + BOOL isValidKeychainItem = |
| 143 | + [@[ dataFromString(kData), dataFromString(kOtherData) ] containsObject:queriedData]; |
| 144 | + XCTAssertTrue(isValidKeychainItem); |
| 145 | + XCTAssertNil(error); |
| 146 | + [self deletePasswordWithAccount:accountFromKey(kKey) service:kService]; |
| 147 | + [self deletePasswordWithAccount:accountFromKey(kKey) service:kOtherService]; |
| 148 | +} |
| 149 | + |
119 | 150 | /** @fn testNotReadOtherService
|
120 | 151 | @brief Tests not reading keychain item belonging to other service.
|
121 | 152 | */
|
|
0 commit comments