IOSAD-147 Test. IOSAD-147
authorDirk Zimmermann <dz@pep.security>
Sat, 28 Sep 2019 13:34:03 +0200
branchIOSAD-147
changeset 1282fa7a11ffe1aa
parent 1281 30f0601b438e
child 1283 c26debaf1c63
IOSAD-147 Test.
pEpObjCTests/PEPSessionTest.m
     1.1 --- a/pEpObjCTests/PEPSessionTest.m	Sat Sep 28 13:18:26 2019 +0200
     1.2 +++ b/pEpObjCTests/PEPSessionTest.m	Sat Sep 28 13:34:03 2019 +0200
     1.3 @@ -1426,6 +1426,62 @@
     1.4      }
     1.5  }
     1.6  
     1.7 +/**
     1.8 + Tests feeding an old beacon message to the engine, which can occur due to key reset.
     1.9 +
    1.10 + Tests the following:
    1.11 + * Do a mySelf.
    1.12 + * Catch the sent out beacon message.
    1.13 + * Do a key reset on the own identity.
    1.14 + * Decrypt the beacon message.
    1.15 + */
    1.16 +- (void)testDecryptOldBeaconAfterKeyReset
    1.17 +{
    1.18 +    PEPSession *session = [PEPSession new];
    1.19 +
    1.20 +    XCTAssertEqual(self.sendMessageDelegate.messages.count, 0);
    1.21 +    XCTAssertNil(self.sendMessageDelegate.lastMessage);
    1.22 +
    1.23 +    PEPIdentity *identMe = [[PEPIdentity alloc]
    1.24 +                            initWithAddress:@"me-myself-and-i@pep-project.org"
    1.25 +                            userID:@"me-myself-and-i"
    1.26 +                            userName:@"pEp Me"
    1.27 +                            isOwn:YES];
    1.28 +    NSError *error = nil;
    1.29 +    XCTAssertTrue([session mySelf:identMe error:&error]);
    1.30 +    XCTAssertNil(error);
    1.31 +    XCTAssertNotNil(identMe.fingerPrint);
    1.32 +
    1.33 +    [self startSync];
    1.34 +
    1.35 +    XCTKVOExpectation *expHaveMessage = [[XCTKVOExpectation alloc]
    1.36 +                                         initWithKeyPath:@"lastMessage"
    1.37 +                                         object:self.sendMessageDelegate];
    1.38 +
    1.39 +    [self waitForExpectations:@[expHaveMessage] timeout:PEPTestInternalSyncTimeout];
    1.40 +    XCTAssertNotNil(self.sendMessageDelegate.lastMessage);
    1.41 +    XCTAssertEqual(self.sendMessageDelegate.messages.count, 1);
    1.42 +
    1.43 +    PEPMessage *oldBeacon = self.sendMessageDelegate.lastMessage;
    1.44 +
    1.45 +    XCTAssertTrue([session keyReset:identMe fingerprint:identMe.fingerPrint error:&error]);
    1.46 +    XCTAssertNil(error);
    1.47 +
    1.48 +    PEPRating rating;
    1.49 +    PEPStringList *extraKeys;
    1.50 +    PEPStatus status;
    1.51 +    PEPMessage *decryptedOldBeacon = [session decryptMessage:oldBeacon
    1.52 +                                                       flags:nil
    1.53 +                                                      rating:&rating
    1.54 +                                                   extraKeys:&extraKeys
    1.55 +                                                      status:&status
    1.56 +                                                       error:&error];
    1.57 +    XCTAssertNotNil(decryptedOldBeacon);
    1.58 +    XCTAssertNil(error);
    1.59 +
    1.60 +    [self shutdownSync];
    1.61 +}
    1.62 +
    1.63  #pragma mark - Helpers
    1.64  
    1.65  - (void)testSendMessageOnSession:(PEPSession *)session