Browse Source

IOSAD-180 testEnsurePassphrase

IOSAD-180
Dirk Zimmermann 2 years ago
parent
commit
430349bb45
3 changed files with 39 additions and 0 deletions
  1. +37
    -0
      pEpObjCTests/PEPSessionTest.m
  2. +1
    -0
      pEpObjCTests/TestUtils/PEPPassphraseProviderMock.h
  3. +1
    -0
      pEpObjCTests/TestUtils/PEPPassphraseProviderMock.m

+ 37
- 0
pEpObjCTests/PEPSessionTest.m View File

@ -1621,6 +1621,43 @@
XCTAssertNil(error);
}
/// @Note This test *assumes* that a key reset on an own key (with set passphrase)
/// will call ensure_passphrase if that passphrase has been "forgotten",
/// which in turn invokes the currently set passphrase provider.
/// That the passphrase provider was invoked
/// by ensure_passphrase (and not by the earlier passphrase handling in
/// `[PEPInternalSession keyResetAllOwnKeysError]` *cannot be easily proven*.
- (void)testEnsurePassphrase
{
NSString *passphrase = @"a";
NSError *error = nil;
PEPSession *session = [PEPSession new];
XCTAssertTrue([PEPObjCAdapter configurePassphraseForNewKeys:passphrase error:&error]);
XCTAssertNil(error);
PEPIdentity *identMe = [[PEPIdentity alloc]
initWithAddress:@"me-myself-and-i@pep-project.org"
userID:@"me-myself-and-i"
userName:@"pEp Me"
isOwn:YES];
error = nil;
XCTAssertTrue([session mySelf:identMe error:&error]);
XCTAssertNil(error);
[[PEPPassphraseCache passphraseCache] setStoredPassphrase:nil];
PEPPassphraseProviderMock *mock = [[PEPPassphraseProviderMock alloc] initWithPassphrases:@[]];
[PEPObjCAdapter setPassphraseProvider:mock];
error = nil;
XCTAssertFalse([session keyResetAllOwnKeysError:&error]);
XCTAssertNotNil(error);
XCTAssertTrue(mock.passphraseRequiredWasCalled);
}
#pragma mark - Helpers
- (void)setupEncryptWithImportedKeySession:(PEPSession **)session


+ 1
- 0
pEpObjCTests/TestUtils/PEPPassphraseProviderMock.h View File

@ -14,6 +14,7 @@ NS_ASSUME_NONNULL_BEGIN
@interface PEPPassphraseProviderMock : NSObject<PEPPassphraseProviderProtocol>
@property (nonatomic) BOOL passphraseRequiredWasCalled;
@property (nonatomic) BOOL passphraseTooLongWasCalled;
- (instancetype)initWithPassphrases:(NSArray<NSString *> *)passphrases;


+ 1
- 0
pEpObjCTests/TestUtils/PEPPassphraseProviderMock.m View File

@ -30,6 +30,7 @@
}
- (void)passphraseRequired:(nonnull PEPPassphraseProviderCallback)completion {
self.passphraseRequiredWasCalled = YES;
[self answerWithLatestPassphrase:completion];
}


Loading…
Cancel
Save