IOSAD-172 Test for own key with password IOSAD-172
authorDirk Zimmermann <dz@pep.security>
Mon, 29 Jun 2020 16:39:43 +0200
branchIOSAD-172
changeset 155011f5bc962f19
parent 1549 cf7b3b9c0e96
child 1551 2aba8a261e07
IOSAD-172 Test for own key with password
pEpObjCTests/PEPSessionTest.m
     1.1 --- a/pEpObjCTests/PEPSessionTest.m	Mon Jun 29 16:39:43 2020 +0200
     1.2 +++ b/pEpObjCTests/PEPSessionTest.m	Mon Jun 29 16:39:43 2020 +0200
     1.3 @@ -1497,6 +1497,52 @@
     1.4      }
     1.5  }
     1.6  
     1.7 +- (void)testOwnKeyWithPasswordAndEncryptToSelf
     1.8 +{
     1.9 +    NSString *passphrase = @"passphrase";
    1.10 +
    1.11 +    PEPSession *session = [PEPSession new];
    1.12 +
    1.13 +    NSError *error = nil;
    1.14 +
    1.15 +    XCTAssertTrue([session configurePassphraseForNewKeys:passphrase enable:YES error:&error]);
    1.16 +
    1.17 +    PEPIdentity *identMeWithPassphrase = [[PEPIdentity alloc]
    1.18 +                                          initWithAddress:@"me-myself-and-i@pep-project.org"
    1.19 +                                          userID:@"me-myself-and-i"
    1.20 +                                          userName:@"pEp Me"
    1.21 +                                          isOwn:YES];
    1.22 +
    1.23 +    XCTAssertTrue([session mySelf:identMeWithPassphrase error:&error]);
    1.24 +    XCTAssertNil(error);
    1.25 +
    1.26 +    PEPIdentity *receiver1 = [[PEPIdentity alloc]
    1.27 +                              initWithAddress:@"partner1@example.com"
    1.28 +                              userID:@"partner1"
    1.29 +                              userName:@"Partner 1"
    1.30 +                                          isOwn:NO];
    1.31 +
    1.32 +    PEPMessage *draftMail = [PEPTestUtils
    1.33 +                             mailFrom:identMeWithPassphrase
    1.34 +                             toIdent:receiver1
    1.35 +                             shortMessage:@"hey"
    1.36 +                             longMessage:@"hey hey"
    1.37 +                             outgoing:YES];
    1.38 +
    1.39 +    error = nil;
    1.40 +    PEPStatus status = PEPStatusOutOfMemory;
    1.41 +
    1.42 +    XCTAssertFalse([session
    1.43 +                    encryptMessage:draftMail
    1.44 +                    forSelf:identMeWithPassphrase
    1.45 +                    extraKeys:nil
    1.46 +                    status:&status
    1.47 +                    error:&error]);
    1.48 +    XCTAssertNotNil(error);
    1.49 +    XCTAssertEqualObjects(error.domain, PEPObjCAdapterEngineStatusErrorDomain);
    1.50 +    XCTAssertEqual(error.code, PEPStatusPassphraseRequired);
    1.51 +}
    1.52 +
    1.53  #pragma mark - Helpers
    1.54  
    1.55  - (void)testSendMessageOnSession:(PEPSession *)session