IOSAD-94 test
authorDirk Zimmermann <dirk@pep-project.org>
Wed, 13 Jun 2018 11:30:24 +0200
changeset 628502f5b19c07f
parent 627 2f9d21f8b1a6
child 629 7e6343055e4d
IOSAD-94 test
pEpObjCTests/PEPSessionTest.m
     1.1 --- a/pEpObjCTests/PEPSessionTest.m	Wed Jun 13 11:19:35 2018 +0200
     1.2 +++ b/pEpObjCTests/PEPSessionTest.m	Wed Jun 13 11:30:24 2018 +0200
     1.3 @@ -1253,8 +1253,62 @@
     1.4      XCTAssertEqualObjects(encMessage.shortMessage, @"p≡p", @"Subject should be encrypted");
     1.5  }
     1.6  
     1.7 +#pragma mark - Passive mode
     1.8 +
     1.9 +- (void)testPassiveMode
    1.10 +{
    1.11 +    [self testPassiveModeEnabled:NO];
    1.12 +    [self testPassiveModeEnabled:YES];
    1.13 +}
    1.14 +
    1.15  #pragma mark - Helpers
    1.16  
    1.17 +- (void)testPassiveModeEnabled:(BOOL)passiveModeEnabled
    1.18 +{
    1.19 +    [PEPObjCAdapter setPassiveModeEnabled:passiveModeEnabled];
    1.20 +    PEPSession *session = [PEPSession new];
    1.21 +
    1.22 +    PEPIdentity *identMe = [[PEPIdentity alloc]
    1.23 +                            initWithAddress:@"me-myself-and-i@pep-project.org"
    1.24 +                            userID:@"me-myself-and-i"
    1.25 +                            userName:@"pEp Me"
    1.26 +                            isOwn:YES];
    1.27 +    NSError *error = nil;
    1.28 +    XCTAssertTrue([session mySelf:identMe error:&error]);
    1.29 +    XCTAssertNil(error);
    1.30 +
    1.31 +    XCTAssertNotNil(identMe.fingerPrint);
    1.32 +
    1.33 +    PEPIdentity *identAlice = [[PEPIdentity alloc]
    1.34 +                               initWithAddress:@"pep.test.alice@pep-project.org"
    1.35 +                               userID:@"alice_user_id"
    1.36 +                               userName:@"Alice"
    1.37 +                               isOwn:NO];
    1.38 +
    1.39 +    NSString *shortMessage = @"whatever it may be";
    1.40 +    NSString *longMessage = [NSString stringWithFormat:@"%@ %@", shortMessage, shortMessage];
    1.41 +    PEPMessage *message = [PEPMessage new];
    1.42 +    message.direction = PEP_dir_outgoing;
    1.43 +    message.from = identMe;
    1.44 +    message.to = @[identAlice];
    1.45 +    message.shortMessage = shortMessage;
    1.46 +    message.longMessage = longMessage;
    1.47 +
    1.48 +    PEP_STATUS status = PEP_KEY_NOT_FOUND;
    1.49 +    PEPMessage *encryptedMessage =  [session encryptMessage:message
    1.50 +                                                  extraKeys:@[]
    1.51 +                                                     status:&status
    1.52 +                                                      error:&error];
    1.53 +    XCTAssertNil(error);
    1.54 +    XCTAssertEqual(status, PEP_UNENCRYPTED);
    1.55 +
    1.56 +    if (passiveModeEnabled) {
    1.57 +        XCTAssertNil(encryptedMessage.attachments);
    1.58 +    } else {
    1.59 +        XCTAssertEqual(encryptedMessage.attachments.count, 1);
    1.60 +    }
    1.61 +}
    1.62 +
    1.63  /**
    1.64   Determines the rating for the given identity.
    1.65   @return PEP_rating_undefined on error