Browse Source

IOSAD-172 Passphrase cache itself doesn't deal with empty password

IOSAD-172
Dirk Zimmermann 2 years ago
parent
commit
aa30a71ea4
3 changed files with 19 additions and 18 deletions
  1. +5
    -1
      pEpObjCAdapter/PEPInternalSession+PassphraseCache.m
  2. +3
    -4
      pEpObjCAdapter/PEPPassphraseCache.m
  3. +11
    -13
      pEpObjCTests/PEPPassphraseCacheTest.m

+ 5
- 1
pEpObjCAdapter/PEPInternalSession+PassphraseCache.m View File

@ -18,7 +18,11 @@
{
PEP_STATUS lastStatus = PEP_UNKNOWN_ERROR;
NSArray *passphrases = [[PEPPassphraseCache sharedInstance] passphrases];
NSMutableArray *passphrases = [NSMutableArray
arrayWithArray:[[PEPPassphraseCache sharedInstance]
passphrases]];
[passphrases insertObject:@"" atIndex:0];
for (NSString *passphrase in passphrases) {
PEP_STATUS status = config_passphrase(self.session, [passphrase UTF8String]);


+ 3
- 4
pEpObjCAdapter/PEPPassphraseCache.m View File

@ -60,7 +60,7 @@ static NSTimeInterval s_defaultCheckExpiryInterval = 60;
- (NSArray<NSString *> *)passphrases
{
NSMutableArray *resultingPassphrases = [NSMutableArray
arrayWithCapacity:PEPPassphraseCacheMaxNumberOfPassphrases + 1];
arrayWithCapacity:PEPPassphraseCacheMaxNumberOfPassphrases];
dispatch_sync(self.queue, ^{
for (PEPPassphraseCacheEntry *entry in self.mutablePassphraseEntries) {
if (![self isExpiredPassphraseEntry:entry]) {
@ -68,15 +68,14 @@ static NSTimeInterval s_defaultCheckExpiryInterval = 60;
}
}
});
[resultingPassphrases insertObject:@"" atIndex:0];
return [NSArray arrayWithArray:resultingPassphrases];
}
- (void)resetTimeoutForPassphrase:(NSString *)passphrase
{
if ([passphrase isEqualToString:@""]) {
// Ignore the empty passphrase, it's always there from the client's view,
// but not contained in the internal model.
// Ignore the empty passphrase.
return;
}


+ 11
- 13
pEpObjCTests/PEPPassphraseCacheTest.m View File

@ -26,16 +26,16 @@
- (void)testContainsEmptyPassphrase
{
XCTAssertEqual(self.cache.passphrases.count, 1);
XCTAssertEqualObjects(self.cache.passphrases, @[@""]);
XCTAssertEqual(self.cache.passphrases.count, 0);
XCTAssertEqualObjects(self.cache.passphrases, @[]);
}
- (void)testContainsSetPassphrase
{
NSString *passphrase = @"somepass";
[self.cache addPassphrase:passphrase];
XCTAssertEqual(self.cache.passphrases.count, 2);
NSArray *expected = @[@"", passphrase];
XCTAssertEqual(self.cache.passphrases.count, 1);
NSArray *expected = @[passphrase];
XCTAssertEqualObjects(self.cache.passphrases, expected);
}
@ -47,8 +47,8 @@
[self.cache addPassphrase:passphrase1];
[self.cache addPassphrase:passphrase2];
XCTAssertEqual(self.cache.passphrases.count, 3);
NSArray *expected = @[@"", passphrase2, passphrase1];
XCTAssertEqual(self.cache.passphrases.count, 2);
NSArray *expected = @[passphrase2, passphrase1];
XCTAssertEqualObjects(self.cache.passphrases, expected);
}
@ -63,8 +63,7 @@
NSMutableArray *expected = [NSMutableArray arrayWithArray:[self reversedArray:passphrases]];
XCTAssertEqual(self.cache.passphrases.count, expected.count + 1);
[expected insertObject:@"" atIndex:0];
XCTAssertEqual(self.cache.passphrases.count, expected.count);
XCTAssertEqualObjects(self.cache.passphrases, expected);
}
@ -87,7 +86,6 @@
// There are 21 passphrases, so the oldest (last) is removed.
[expectedPassphrases removeLastObject];
[expectedPassphrases insertObject:@"" atIndex:0];
XCTAssertEqualObjects(self.cache.passphrases, expectedPassphrases);
}
@ -101,11 +99,11 @@
NSString *ownPassphrase = @"blah";
[ownCache addPassphrase:ownPassphrase];
NSArray *expectedBefore = @[@"", ownPassphrase];
NSArray *expectedBefore = @[ownPassphrase];
XCTAssertEqualObjects(ownCache.passphrases, expectedBefore);
[NSThread sleepForTimeInterval:2*timeout];
XCTAssertEqualObjects(ownCache.passphrases, @[@""]);
XCTAssertEqualObjects(ownCache.passphrases, @[]);
}
- (void)testResetTimeout
@ -120,11 +118,11 @@
[self.cache resetTimeoutForPassphrase:passphrase1];
NSArray *expected1 = @[@"", passphrase1, passphrase3, passphrase2];
NSArray *expected1 = @[passphrase1, passphrase3, passphrase2];
XCTAssertEqualObjects(self.cache.passphrases, expected1);
[self.cache resetTimeoutForPassphrase:passphrase3];
NSArray *expected2 = @[@"", passphrase3, passphrase1, passphrase2];
NSArray *expected2 = @[passphrase3, passphrase1, passphrase2];
XCTAssertEqualObjects(self.cache.passphrases, expected2);
}


Loading…
Cancel
Save