IOS-1270 CRASHING TEST encrypt message with from == nil IOS-1270_CRASHING_TEST
authorDirk Zimmermann <dirk@pep-project.org>
Wed, 29 Aug 2018 12:23:10 +0200
branchIOS-1270_CRASHING_TEST
changeset 64485fe4a5107ad
parent 643 ea0df7273ea2
child 645 164c29ee1ae0
IOS-1270 CRASHING TEST encrypt message with from == nil
pEpObjCTests/PEPSessionTest.m
     1.1 --- a/pEpObjCTests/PEPSessionTest.m	Wed Aug 08 10:45:05 2018 +0200
     1.2 +++ b/pEpObjCTests/PEPSessionTest.m	Wed Aug 29 12:23:10 2018 +0200
     1.3 @@ -1101,6 +1101,62 @@
     1.4      XCTAssertNotNil(decMsg);
     1.5  }
     1.6  
     1.7 +- (void)testEncryptMessageWithoutFromWithoutKeys
     1.8 +{
     1.9 +    PEPSession *session = [PEPSession new];
    1.10 +
    1.11 +    PEPIdentity *identMe = [[PEPIdentity alloc]
    1.12 +                            initWithAddress:@"me-myself-and-i@pep-project.org"
    1.13 +                            userID:@"me-myself-and-i"
    1.14 +                            userName:@"pEp Me"
    1.15 +                            isOwn:YES];
    1.16 +    NSError *error = nil;
    1.17 +    XCTAssertTrue([session mySelf:identMe error:&error]);
    1.18 +    XCTAssertNil(error);
    1.19 +
    1.20 +    XCTAssertNotNil(identMe.fingerPrint);
    1.21 +
    1.22 +    PEPIdentity *identAlice = [[PEPIdentity alloc]
    1.23 +                               initWithAddress:@"alice@pep-project.org"
    1.24 +                               userID:@"alice"
    1.25 +                               userName:@"pEp Test Alice"
    1.26 +                               isOwn:NO];
    1.27 +
    1.28 +    PEPMessage *msg = [PEPMessage new];
    1.29 +    msg.from = nil;
    1.30 +    msg.to = @[identAlice];
    1.31 +    msg.shortMessage = @"Mail to Alice";
    1.32 +    msg.longMessage = @"Alice?";
    1.33 +    msg.direction = PEP_dir_outgoing;
    1.34 +
    1.35 +    NSNumber *numRating = [session outgoingRatingForMessage:msg error:&error];
    1.36 +    XCTAssertNotNil(numRating);
    1.37 +    XCTAssertNil(error);
    1.38 +    XCTAssertEqual(numRating.pEpRating, PEP_rating_unencrypted);
    1.39 +
    1.40 +    PEPMessage *encMsg = [session encryptMessage:msg extraKeys:nil status:nil error:&error];
    1.41 +    XCTAssertNotNil(encMsg);
    1.42 +    XCTAssertNil(error);
    1.43 +
    1.44 +    XCTAssertNotNil(encMsg);
    1.45 +
    1.46 +    PEPStringList *keys;
    1.47 +    PEP_rating pEpRating;
    1.48 +    error = nil;
    1.49 +    PEPMessage *decMsg = [session
    1.50 +                          decryptMessage:encMsg
    1.51 +                          flags:nil
    1.52 +                          rating:&pEpRating
    1.53 +                          extraKeys:&keys
    1.54 +                          status:nil
    1.55 +                          error:&error];
    1.56 +    XCTAssertNotNil(decMsg);
    1.57 +    XCTAssertNil(error);
    1.58 +
    1.59 +    XCTAssertEqual(pEpRating, PEP_rating_unencrypted);
    1.60 +    XCTAssertNotNil(decMsg);
    1.61 +}
    1.62 +
    1.63  /**
    1.64   ENGINE-364. Tries to invoke trustPersonalKey on an identity without key,
    1.65   giving it a fake fingerprint.