IOSAD-177 Split into several test methods IOSAD-177
authorDirk Zimmermann <dz@pep.security>
Thu, 09 Jul 2020 16:10:13 +0200
branchIOSAD-177
changeset 167595924f231e49
parent 1674 340b400e98cc
child 1676 209254da4dd8
IOSAD-177 Split into several test methods
pEpObjCTests/PEPSessionTest.m
     1.1 --- a/pEpObjCTests/PEPSessionTest.m	Thu Jul 09 16:10:13 2020 +0200
     1.2 +++ b/pEpObjCTests/PEPSessionTest.m	Thu Jul 09 16:10:13 2020 +0200
     1.3 @@ -1592,8 +1592,8 @@
     1.4  
     1.5  #pragma mark - Passphrase Cache
     1.6  
     1.7 -/// Tests encryption with an imported key (with passphrase set)
     1.8 -- (void)testEnrcyptWithImportedKeyWithPassphraseUsingPassphraseProvider
     1.9 +/// Use case: No passphrase provider
    1.10 +- (void)testEnrcyptWithImportedKeyWithPassphraseWithoutPassphraseProvider
    1.11  {
    1.12      // Variables set by set up method
    1.13  
    1.14 @@ -1607,8 +1607,6 @@
    1.15                                   ownIdentity:&identMe
    1.16                              messageToEncrypt:&draftMail];
    1.17  
    1.18 -    // Use case: No passphrase provider
    1.19 -
    1.20      NSError *error = nil;
    1.21      PEPStatus status = PEPStatusOutOfMemory;
    1.22  
    1.23 @@ -1622,10 +1620,25 @@
    1.24  
    1.25      XCTAssertEqualObjects(error.domain, PEPObjCAdapterEngineStatusErrorDomain);
    1.26      XCTAssertEqual(error.code, PEPStatusPassphraseRequired);
    1.27 +}
    1.28  
    1.29 -    // Use case: Passphrase provider set, but never delivers passphrases
    1.30 +/// Use case: Passphrase provider set, but never delivers passphrases
    1.31 +- (void)testEnrcyptWithImportedKeyWithPassphraseUsingEmptyPassphraseProvider
    1.32 +{
    1.33 +    // Variables set by set up method
    1.34  
    1.35 -    error = nil;
    1.36 +    PEPMessage *draftMail = nil;
    1.37 +    PEPSession *session = nil;
    1.38 +    PEPIdentity *identMe = nil;
    1.39 +
    1.40 +    // Set up
    1.41 +
    1.42 +    [self setupEncryptWithImportedKeySession:&session
    1.43 +                                 ownIdentity:&identMe
    1.44 +                            messageToEncrypt:&draftMail];
    1.45 +
    1.46 +    NSError *error = nil;
    1.47 +    PEPStatus status = PEPStatusOutOfMemory;
    1.48  
    1.49      [PEPObjCAdapter setPassphraseProvider:[[PEPPassphraseProviderMock alloc]
    1.50                                             initWithPassphrases:@[]]];
    1.51 @@ -1640,10 +1653,25 @@
    1.52  
    1.53      XCTAssertEqualObjects(error.domain, PEPObjCAdapterEngineStatusErrorDomain);
    1.54      XCTAssertEqual(error.code, PEPStatusPassphraseRequired);
    1.55 +}
    1.56  
    1.57 -    // Use case: Passphrase provider set, only delivers incorrect passphrases
    1.58 +/// Use case: Passphrase provider set, only delivers incorrect passphrases
    1.59 +- (void)testEnrcyptWithImportedKeyWithPassphrasePassphraseProviderWrongPassphrases
    1.60 +{
    1.61 +    // Variables set by set up method
    1.62  
    1.63 -    error = nil;
    1.64 +    PEPMessage *draftMail = nil;
    1.65 +    PEPSession *session = nil;
    1.66 +    PEPIdentity *identMe = nil;
    1.67 +
    1.68 +    // Set up
    1.69 +
    1.70 +    [self setupEncryptWithImportedKeySession:&session
    1.71 +                                 ownIdentity:&identMe
    1.72 +                            messageToEncrypt:&draftMail];
    1.73 +
    1.74 +    NSError *error = nil;
    1.75 +    PEPStatus status = PEPStatusOutOfMemory;
    1.76  
    1.77      NSArray *nonsensePassphrases = @[@"blah1", @"blah2", @"blah3"];
    1.78      [PEPObjCAdapter setPassphraseProvider:[[PEPPassphraseProviderMock alloc]
    1.79 @@ -1659,10 +1687,25 @@
    1.80  
    1.81      XCTAssertEqualObjects(error.domain, PEPObjCAdapterEngineStatusErrorDomain);
    1.82      XCTAssertEqual(error.code, PEPStatusWrongPassphrase);
    1.83 +}
    1.84  
    1.85 -    // Use case: 1 Passphrase, but too long
    1.86 +/// Use case: 1 Passphrase, but too long
    1.87 +- (void)testEnrcyptWithImportedKeyWithPassphraseWithPassphraseProviderPassphraseTooLong
    1.88 +{
    1.89 +    // Variables set by set up method
    1.90  
    1.91 -    error = nil;
    1.92 +    PEPMessage *draftMail = nil;
    1.93 +    PEPSession *session = nil;
    1.94 +    PEPIdentity *identMe = nil;
    1.95 +
    1.96 +    // Set up
    1.97 +
    1.98 +    [self setupEncryptWithImportedKeySession:&session
    1.99 +                                 ownIdentity:&identMe
   1.100 +                            messageToEncrypt:&draftMail];
   1.101 +
   1.102 +    NSError *error = nil;
   1.103 +    PEPStatus status = PEPStatusOutOfMemory;
   1.104  
   1.105      NSString *passphraseBase = @"base";
   1.106      NSString *passphraseTooLong = passphraseBase;
   1.107 @@ -1687,10 +1730,25 @@
   1.108      XCTAssertEqualObjects(error.domain, PEPObjCAdapterEngineStatusErrorDomain);
   1.109      XCTAssertEqual(error.code, PEPStatusWrongPassphrase);
   1.110      XCTAssertTrue(passphraseProviderMock1.passphraseTooLongWasCalled);
   1.111 +}
   1.112  
   1.113 -    // Use case: Passphrase provider set, has correct passphrase after 2 unsuccessful attempts
   1.114 +/// Use case: Passphrase provider set, has correct passphrase after 2 unsuccessful attempts
   1.115 +- (void)testEnrcyptWithImportedKeyWithPassphraseWithPassphraseProviderCorrectPassphrase
   1.116 +{
   1.117 +    // Variables set by set up method
   1.118  
   1.119 -    error = nil;
   1.120 +    PEPMessage *draftMail = nil;
   1.121 +    PEPSession *session = nil;
   1.122 +    PEPIdentity *identMe = nil;
   1.123 +
   1.124 +    // Set up
   1.125 +
   1.126 +    [self setupEncryptWithImportedKeySession:&session
   1.127 +                                 ownIdentity:&identMe
   1.128 +                            messageToEncrypt:&draftMail];
   1.129 +
   1.130 +    NSError *error = nil;
   1.131 +    PEPStatus status = PEPStatusOutOfMemory;
   1.132  
   1.133      NSString *correctPassphrase = @"uiae";
   1.134      NSArray *passphrases = @[@"blah1", @"blah2", correctPassphrase];