andreas@392: // andreas@392: // PEPSessionTest.m andreas@392: // pEpObjCAdapterTests andreas@392: // andreas@392: // Created by Andreas Buff on 18.01.18. andreas@392: // Copyright © 2018 p≡p. All rights reserved. andreas@392: // andreas@392: andreas@392: #import andreas@392: andreas@392: #import "PEPObjCAdapter.h" andreas@392: #import "NSDictionary+Extension.h" andreas@392: #import "PEPIdentity.h" andreas@392: #import "PEPMessage.h" andreas@392: andreas@392: #import "PEPTestUtils.h" andreas@392: #import "PEPTestSyncDelegate.h" andreas@392: andreas@392: @interface PEPSessionTest : XCTestCase andreas@392: @end andreas@392: andreas@392: @implementation PEPSessionTest andreas@392: andreas@392: - (void)setUp andreas@392: { andreas@392: [super setUp]; andreas@416: [PEPObjCAdapter setUnecryptedSubjectEnabled:NO]; andreas@416: andreas@392: [self pEpCleanUp]; andreas@392: } andreas@392: andreas@392: - (void)tearDown { andreas@392: [self pEpCleanUp]; andreas@392: [super tearDown]; andreas@392: } andreas@392: andreas@392: - (void)testSyncSession andreas@392: { andreas@392: PEPSession *session = [PEPSession new]; andreas@392: PEPTestSyncDelegate *syncDelegate = [[PEPTestSyncDelegate alloc] init]; andreas@392: andreas@392: // This should attach session just created andreas@392: [PEPObjCAdapter startSync:syncDelegate]; andreas@392: andreas@392: PEPIdentity *identMe = [[PEPIdentity alloc] andreas@392: initWithAddress:@"pep.test.iosgenkey@pep-project.org" andreas@392: userID:@"Me" andreas@392: userName:@"pEp Test iOS GenKey" andreas@392: isOwn:YES]; andreas@392: andreas@392: [session mySelf:identMe]; andreas@392: andreas@392: bool res = [syncDelegate waitUntilSent:1]; andreas@392: andreas@392: // Can't currently work, engine doesn't contain sync. andreas@392: XCTAssertFalse(res); andreas@392: andreas@392: // This should detach session just created andreas@392: [PEPObjCAdapter stopSync]; andreas@392: } andreas@392: andreas@392: - (void)testTrustWords andreas@392: { andreas@392: PEPSession *session = [PEPSession new]; andreas@392: andreas@392: NSArray *trustwords = [session trustwords:@"DB47DB47DB47DB47DB47DB47DB47DB47DB47DB47" andreas@392: forLanguage:@"en" shortened:false]; andreas@392: XCTAssertEqual([trustwords count], 10); andreas@392: andreas@392: for(id word in trustwords) andreas@392: XCTAssertEqualObjects(word, @"BAPTISMAL"); andreas@392: } andreas@392: andreas@392: - (void)testGenKey andreas@392: { andreas@392: PEPSession *session = [PEPSession new]; andreas@392: andreas@392: PEPIdentity *identMe = [[PEPIdentity alloc] andreas@392: initWithAddress:@"pep.test.iosgenkey@pep-project.org" andreas@392: userID:@"Me" andreas@392: userName:@"pEp Test iOS GenKey" andreas@392: isOwn:YES]; andreas@392: andreas@392: [session mySelf:identMe]; andreas@392: andreas@392: XCTAssertNotNil(identMe.fingerPrint); andreas@392: XCTAssertNotEqual(identMe.commType, PEP_ct_unknown); andreas@392: andreas@392: // check that the comm type is not a PGP one andreas@392: XCTAssertFalse([identMe containsPGPCommType]); andreas@392: } andreas@392: andreas@392: - (void)testMySelfCommType andreas@392: { andreas@392: PEPSession *session = [PEPSession new]; andreas@392: andreas@392: PEPIdentity *identMe = [[PEPIdentity alloc] andreas@392: initWithAddress:@"pep.test.iosgenkey@pep-project.org" andreas@392: userID:@"Me" andreas@392: userName:@"pEp Test iOS GenKey" andreas@392: isOwn:YES]; andreas@392: andreas@392: [session mySelf:identMe]; andreas@392: andreas@392: XCTAssertNotNil(identMe.fingerPrint); andreas@392: XCTAssertNotEqual(identMe.commType, PEP_ct_unknown); andreas@392: andreas@392: // check that the comm type is not a PGP one andreas@392: XCTAssertFalse([identMe containsPGPCommType]); andreas@392: andreas@392: dispatch_queue_t queue = dispatch_get_global_queue(QOS_CLASS_USER_INITIATED, 0); andreas@392: dispatch_sync(queue, ^{ andreas@392: PEPSession *session2 = [PEPSession new]; andreas@392: andreas@392: // Now simulate an update from the app, which usually only caches andreas@392: // kPepUsername, kPepAddress and optionally kPepUserID. andreas@392: PEPIdentity *identMe2 = [[PEPIdentity alloc] andreas@392: initWithAddress:identMe.address andreas@392: userID:identMe.userID andreas@392: userName:identMe.userName andreas@392: isOwn:NO]; andreas@392: [session2 mySelf:identMe2]; andreas@392: XCTAssertNotNil(identMe2.fingerPrint); andreas@392: XCTAssertFalse([identMe2 containsPGPCommType]); andreas@392: XCTAssertEqualObjects(identMe2.fingerPrint, identMe.fingerPrint); andreas@392: andreas@392: // Now pretend the app only knows kPepUsername and kPepAddress andreas@411: PEPIdentity *identMe3 = [PEPTestUtils foreignPepIdentityWithAddress:identMe.address andreas@411: userName:identMe.userName]; andreas@392: [session2 mySelf:identMe3]; andreas@392: XCTAssertNotNil(identMe3.fingerPrint); andreas@392: XCTAssertFalse([identMe3 containsPGPCommType]); andreas@392: XCTAssertEqualObjects(identMe3.fingerPrint, identMe.fingerPrint); andreas@392: andreas@392: XCTAssertEqualObjects(identMe.address, identMe2.address); andreas@392: XCTAssertEqualObjects(identMe.address, identMe3.address); andreas@392: XCTAssertEqual(identMe.commType, identMe2.commType); andreas@392: XCTAssertEqual(identMe.commType, identMe3.commType); andreas@392: }); andreas@392: } andreas@392: dirk@435: - (void)testPartnerWithoutFingerPrint dirk@435: { dirk@435: PEPSession *session = [PEPSession new]; dirk@435: dirk@435: PEPIdentity *identRandom = [[PEPIdentity alloc] dirk@435: initWithAddress:@"does_not_exist@example.com" dirk@435: userID:@"got_out" dirk@435: userName:@"No Way Not Even Alice" dirk@435: isOwn:NO]; dirk@435: dirk@435: [session updateIdentity:identRandom]; dirk@435: XCTAssertNil(identRandom.fingerPrint); dirk@435: } dirk@435: dirk@437: - (void)testImportPartnerKeys dirk@436: { dirk@437: [self checkImportingKeyFilePath:@"6FF00E97_sec.asc" address:@"pep.test.alice@pep-project.org" dirk@437: userID:@"This Is Alice" dirk@437: fingerPrint:@"4ABE3AAF59AC32CFE4F86500A9411D176FF00E97"]; dirk@436: dirk@437: [self checkImportingKeyFilePath:@"0xC9C2EE39.asc" address:@"pep.test.bob@pep-project.org" dirk@437: userID:@"This Is Bob" dirk@437: fingerPrint:@"BFCDB7F301DEEEBBF947F29659BFF488C9C2EE39"]; dirk@436: } dirk@436: dirk@439: - (void)testIdentityRating dirk@439: { dirk@439: PEPSession *session = [PEPSession new]; dirk@439: dirk@439: PEPIdentity *me = [self dirk@439: checkMySelfImportingKeyFilePath:@"6FF00E97_sec.asc" dirk@439: address:@"pep.test.alice@pep-project.org" dirk@439: userID:@"Alice_User_ID" dirk@439: fingerPrint:@"4ABE3AAF59AC32CFE4F86500A9411D176FF00E97"]; dirk@439: XCTAssertEqual([session identityRating:me], PEP_rating_trusted_and_anonymized); dirk@439: dirk@439: PEPIdentity *alice = [self dirk@439: checkImportingKeyFilePath:@"6FF00E97_sec.asc" dirk@439: address:@"pep.test.alice@pep-project.org" dirk@439: userID:@"This Is Alice" dirk@439: fingerPrint:@"4ABE3AAF59AC32CFE4F86500A9411D176FF00E97"]; dirk@439: XCTAssertEqual([session identityRating:alice], PEP_rating_reliable); dirk@439: } dirk@439: dirk@445: - (void)testIdentityRatingMistrustUndo dirk@445: { dirk@445: PEPSession *session = [PEPSession new]; dirk@445: dirk@445: PEPIdentity *me = [self dirk@445: checkMySelfImportingKeyFilePath:@"6FF00E97_sec.asc" dirk@445: address:@"pep.test.alice@pep-project.org" dirk@445: userID:@"Alice_User_ID" dirk@445: fingerPrint:@"4ABE3AAF59AC32CFE4F86500A9411D176FF00E97"]; dirk@445: XCTAssertEqual([session identityRating:me], PEP_rating_trusted_and_anonymized); dirk@445: dirk@445: PEPIdentity *alice = [self dirk@445: checkImportingKeyFilePath:@"6FF00E97_sec.asc" dirk@445: address:@"pep.test.alice@pep-project.org" dirk@445: userID:@"This Is Alice" dirk@445: fingerPrint:@"4ABE3AAF59AC32CFE4F86500A9411D176FF00E97"]; dirk@445: XCTAssertEqual([session identityRating:alice], PEP_rating_reliable); dirk@445: dirk@445: [session keyMistrusted:alice]; dirk@445: XCTAssertEqual([session identityRating:alice], PEP_rating_have_no_key); dirk@445: dirk@445: [session undoLastMistrust]; dirk@445: XCTAssertEqual([session identityRating:alice], PEP_rating_reliable); dirk@445: } dirk@445: andreas@392: - (void)testOutgoingColors andreas@392: { andreas@392: PEPSession *session = [PEPSession new]; andreas@392: andreas@392: // Our test user : andreas@392: // pEp Test Alice (test key don't use) andreas@392: // 4ABE3AAF59AC32CFE4F86500A9411D176FF00E97 andreas@392: [PEPTestUtils importBundledKey:@"6FF00E97_sec.asc"]; andreas@392: andreas@392: // Our test user : dirk@440: PEPIdentity *identAlice = [self dirk@440: checkMySelfImportingKeyFilePath:@"6FF00E97_sec.asc" dirk@440: address:@"pep.test.alice@pep-project.org" dirk@440: userID:@"Alice_User_ID" andreas@392: fingerPrint:@"4ABE3AAF59AC32CFE4F86500A9411D176FF00E97"]; andreas@392: andreas@392: //Message andreas@392: dirk@441: { dirk@441: PEPIdentity *identUnknownBob = [[PEPIdentity alloc] dirk@441: initWithAddress:@"pep.test.unknown.bob@pep-project.org" dirk@441: userID:@"4242" userName:@"pEp Test Bob Unknown" dirk@441: isOwn:NO]; dirk@441: dirk@441: PEPMessage *msgGray = [PEPMessage new]; dirk@441: msgGray.from = identAlice; dirk@441: msgGray.to = @[identUnknownBob]; dirk@441: msgGray.shortMessage = @"All Gray Test"; dirk@441: msgGray.longMessage = @"This is a text content"; dirk@441: msgGray.direction = PEP_dir_outgoing; dirk@441: dirk@441: // Test with unknown Bob dirk@441: PEP_rating clr = [session outgoingColorForMessage:msgGray]; dirk@441: XCTAssertEqual(clr, PEP_rating_unencrypted); dirk@441: } dirk@441: dirk@441: PEPIdentity *identBob = [self dirk@441: checkImportingKeyFilePath:@"0xC9C2EE39.asc" dirk@441: address:@"pep.test.bob@pep-project.org" dirk@441: userID:@"42" dirk@441: fingerPrint:@"BFCDB7F301DEEEBBF947F29659BFF488C9C2EE39"]; dirk@438: andreas@392: PEPMessage *msg = [PEPMessage new]; andreas@392: msg.from = identAlice; dirk@438: msg.to = @[identBob]; dirk@441: msg.shortMessage = @"All Gray Test"; andreas@392: msg.longMessage = @"This is a text content"; andreas@392: msg.direction = PEP_dir_outgoing; andreas@392: dirk@441: // Should be yellow, since no handshake happened. andreas@392: PEP_rating clr = [session outgoingColorForMessage:msg]; dirk@420: XCTAssertEqual(clr, PEP_rating_reliable); andreas@392: andreas@392: clr = [session identityRating:identBob]; dirk@420: XCTAssertEqual(clr, PEP_rating_reliable); andreas@392: andreas@392: // Let' say we got that handshake, set PEP_ct_confirmed in Bob's identity andreas@392: [session trustPersonalKey:identBob]; andreas@392: andreas@392: // This time it should be green andreas@392: clr = [session outgoingColorForMessage:msg]; dirk@420: XCTAssertEqual(clr, PEP_rating_trusted); andreas@392: andreas@392: clr = [session identityRating:identBob]; dirk@420: XCTAssertEqual(clr, PEP_rating_trusted); andreas@392: andreas@392: // Let' say we undo handshake andreas@392: [session keyResetTrust:identBob]; andreas@392: andreas@392: // Yellow ? andreas@392: clr = [session outgoingColorForMessage:msg]; dirk@420: XCTAssertEqual(clr, PEP_rating_reliable); andreas@392: andreas@392: // mistrust Bob andreas@392: [session keyMistrusted:identBob]; andreas@392: dirk@444: identBob.fingerPrint = nil; dirk@441: [session updateIdentity:identBob]; dirk@441: XCTAssertNil(identBob.fingerPrint); dirk@441: andreas@392: // Gray == PEP_rating_unencrypted andreas@392: clr = [session outgoingColorForMessage:msg]; dirk@420: XCTAssertEqual(clr, PEP_rating_unencrypted); andreas@392: dirk@444: // Undo dirk@443: [session undoLastMistrust]; dirk@444: [session updateIdentity:identBob]; dirk@444: XCTAssertNotNil(identBob.fingerPrint); andreas@392: andreas@392: // Back to yellow andreas@392: clr = [session outgoingColorForMessage:msg]; dirk@420: XCTAssertEqual(clr, PEP_rating_reliable); dirk@444: XCTAssertEqual([session identityRating:identBob], PEP_rating_reliable); andreas@392: andreas@392: // Trust again andreas@392: [session trustPersonalKey:identBob]; andreas@392: andreas@392: // Back to green andreas@392: clr = [session outgoingColorForMessage:msg]; dirk@420: XCTAssertEqual(clr, PEP_rating_trusted); andreas@392: andreas@392: // Now let see if it turns back yellow if we add an unconfirmed folk. andreas@392: // pEp Test John (test key, don't use) andreas@392: // AA2E4BEB93E5FE33DEFD8BE1135CD6D170DCF575 andreas@392: [PEPTestUtils importBundledKey:@"0x70DCF575.asc"]; andreas@392: andreas@392: PEPIdentity *identJohn = [[PEPIdentity alloc] andreas@392: initWithAddress:@"pep.test.john@pep-project.org" andreas@392: userID:@"101" userName:@"pEp Test John" andreas@392: isOwn:NO andreas@392: fingerPrint:@"AA2E4BEB93E5FE33DEFD8BE1135CD6D170DCF575"]; andreas@392: andreas@392: [session updateIdentity:identJohn]; andreas@392: andreas@411: msg.cc = @[[PEPTestUtils foreignPepIdentityWithAddress:@"pep.test.john@pep-project.org" andreas@411: userName:@"pEp Test John"]]; andreas@392: // Yellow ? andreas@392: clr = [session outgoingColorForMessage:msg]; dirk@420: XCTAssertEqual(clr, PEP_rating_reliable); andreas@392: andreas@392: PEPMessage *encmsg; andreas@392: PEP_STATUS status = [session encryptMessage:msg extra:@[] dest:&encmsg]; andreas@392: andreas@392: XCTAssertNotNil(encmsg); andreas@392: XCTAssertEqualObjects(encmsg.shortMessage, @"p≡p"); andreas@392: XCTAssertTrue([encmsg.longMessage containsString:@"p≡p"]); andreas@392: dirk@420: XCTAssertEqual(status, PEP_STATUS_OK); andreas@392: } andreas@392: andreas@392: andreas@392: - (void)testOutgoingBccColors andreas@392: { andreas@392: PEPSession *session = [PEPSession new]; andreas@392: andreas@392: // Our test user : andreas@392: // pEp Test Alice (test key don't use) andreas@392: // 4ABE3AAF59AC32CFE4F86500A9411D176FF00E97 andreas@392: [PEPTestUtils importBundledKey:@"6FF00E97_sec.asc"]; andreas@392: andreas@392: PEPIdentity *identAlice = [[PEPIdentity alloc] andreas@392: initWithAddress:@"pep.test.alice@pep-project.org" andreas@392: userID:ownUserId andreas@392: userName:@"pEp Test Alice" andreas@392: isOwn:YES andreas@392: fingerPrint:@"4ABE3AAF59AC32CFE4F86500A9411D176FF00E97"]; andreas@392: andreas@392: [session mySelf:identAlice]; andreas@392: andreas@392: PEPMessage *msg = [PEPMessage new]; andreas@392: msg.from = identAlice; andreas@392: msg.to = @[[[PEPIdentity alloc] initWithAddress:@"pep.test.bob@pep-project.org" andreas@392: userID:@"42" userName:@"pEp Test Bob" isOwn:NO]]; andreas@392: msg.shortMessage = @"All Green Test"; andreas@392: msg.longMessage = @"This is a text content"; andreas@392: msg.direction = PEP_dir_outgoing; andreas@392: andreas@392: // Test with unknown Bob andreas@392: PEP_rating clr = [session outgoingColorForMessage:msg]; dirk@420: XCTAssertEqual(clr, PEP_rating_unencrypted); andreas@392: andreas@392: // Now let see with bob's pubkey already known andreas@392: // pEp Test Bob (test key, don't use) andreas@392: // BFCDB7F301DEEEBBF947F29659BFF488C9C2EE39 andreas@392: [PEPTestUtils importBundledKey:@"0xC9C2EE39.asc"]; andreas@392: andreas@392: PEPIdentity *identBob = [[PEPIdentity alloc] andreas@392: initWithAddress:@"pep.test.bob@pep-project.org" andreas@392: userID:@"42" userName:@"pEp Test Bob" andreas@392: isOwn:NO andreas@392: fingerPrint:@"BFCDB7F301DEEEBBF947F29659BFF488C9C2EE39"]; andreas@392: andreas@392: [session updateIdentity:identBob]; andreas@392: andreas@392: // Should be yellow, since no handshake happened. andreas@392: clr = [session outgoingColorForMessage:msg]; dirk@420: XCTAssertEqual(clr, PEP_rating_reliable); andreas@392: andreas@392: clr = [session identityRating:identBob]; dirk@420: XCTAssertEqual(clr, PEP_rating_reliable); andreas@392: andreas@392: // Let' say we got that handshake, set PEP_ct_confirmed in Bob's identity andreas@392: [session trustPersonalKey:identBob]; andreas@392: andreas@392: // This time it should be green andreas@392: clr = [session outgoingColorForMessage:msg]; dirk@420: XCTAssertEqual(clr, PEP_rating_trusted); andreas@392: andreas@392: clr = [session identityRating:identBob]; dirk@420: XCTAssertEqual(clr, PEP_rating_trusted); andreas@392: andreas@392: // Now let see if it turns back yellow if we add an unconfirmed folk. andreas@392: // pEp Test John (test key, don't use) andreas@392: // AA2E4BEB93E5FE33DEFD8BE1135CD6D170DCF575 andreas@392: [PEPTestUtils importBundledKey:@"0x70DCF575.asc"]; andreas@392: andreas@392: PEPIdentity *identJohn = [[PEPIdentity alloc] andreas@392: initWithAddress:@"pep.test.john@pep-project.org" andreas@392: userID:@"101" userName:@"pEp Test John" andreas@392: isOwn:NO andreas@392: fingerPrint:@"AA2E4BEB93E5FE33DEFD8BE1135CD6D170DCF575"]; andreas@392: andreas@392: [session updateIdentity:identJohn]; andreas@392: andreas@392: msg.bcc = @[[[PEPIdentity alloc] initWithAddress:@"pep.test.john@pep-project.org" andreas@392: userID:@"101" userName:@"pEp Test John" isOwn:NO]]; andreas@392: andreas@392: // Yellow ? andreas@392: clr = [session outgoingColorForMessage:msg]; dirk@420: XCTAssertEqual(clr, PEP_rating_reliable); andreas@392: andreas@392: [session trustPersonalKey:identJohn]; andreas@392: andreas@392: // This time it should be green andreas@392: clr = [session outgoingColorForMessage:msg]; dirk@420: XCTAssertEqual(clr, PEP_rating_trusted); andreas@392: andreas@392: clr = [session identityRating:identJohn]; dirk@420: XCTAssertEqual(clr, PEP_rating_trusted); andreas@392: } andreas@392: andreas@392: - (void)testDontEncryptForMistrusted andreas@392: { andreas@392: PEPSession *session = [PEPSession new]; andreas@392: andreas@392: // Our test user : andreas@392: // pEp Test Alice (test key don't use) andreas@392: // 4ABE3AAF59AC32CFE4F86500A9411D176FF00E97 andreas@392: [PEPTestUtils importBundledKey:@"6FF00E97_sec.asc"]; andreas@392: andreas@392: PEPIdentity *identAlice = [[PEPIdentity alloc] andreas@392: initWithAddress:@"pep.test.alice@pep-project.org" andreas@392: userID:ownUserId andreas@392: userName:@"pEp Test Alice" andreas@392: isOwn:YES andreas@392: fingerPrint:@"4ABE3AAF59AC32CFE4F86500A9411D176FF00E97"]; andreas@392: andreas@392: [session mySelf:identAlice]; andreas@392: andreas@392: // pEp Test Bob (test key, don't use) andreas@392: // BFCDB7F301DEEEBBF947F29659BFF488C9C2EE39 andreas@392: [PEPTestUtils importBundledKey:@"0xC9C2EE39.asc"]; andreas@392: andreas@392: PEPIdentity *identBob = [[PEPIdentity alloc] andreas@392: initWithAddress:@"pep.test.bob@pep-project.org" andreas@392: userID:@"42" userName:@"pEp Test Bob" andreas@392: isOwn:NO andreas@392: fingerPrint:@"BFCDB7F301DEEEBBF947F29659BFF488C9C2EE39"]; andreas@392: andreas@392: [session updateIdentity:identBob]; andreas@392: andreas@392: // mistrust Bob andreas@392: [session keyMistrusted:identBob]; andreas@392: andreas@392: PEPMessage *msg = [PEPMessage new]; andreas@392: msg.from = identAlice; andreas@392: msg.to = @[[[PEPIdentity alloc] initWithAddress:@"pep.test.bob@pep-project.org" userID:@"42" andreas@392: userName:@"pEp Test Bob" isOwn:NO]]; andreas@392: msg.shortMessage = @"All Green Test"; andreas@392: msg.longMessage = @"This is a text content"; andreas@392: msg.direction = PEP_dir_outgoing; andreas@392: andreas@392: // Gray == PEP_rating_unencrypted andreas@392: PEP_rating clr = [session outgoingColorForMessage:msg]; dirk@420: XCTAssertEqual(clr, PEP_rating_unencrypted); andreas@392: andreas@392: PEPMessage *encmsg; andreas@392: PEP_STATUS status = [session encryptMessage:msg extra:@[] dest:&encmsg]; andreas@392: dirk@420: XCTAssertEqual(status, PEP_UNENCRYPTED); andreas@392: andreas@392: XCTAssertNotEqualObjects(encmsg.attachments[0][@"mimeType"], @"application/pgp-encrypted"); andreas@392: andreas@392: [self pEpCleanUp]; andreas@392: } andreas@392: andreas@392: - (void)testRenewExpired andreas@392: { andreas@392: PEPSession *session = [PEPSession new]; andreas@392: andreas@392: // Our expired test user : andreas@392: // pEp Test Hector (old test key don't use) andreas@392: [PEPTestUtils importBundledKey:@"5CB2C182_sec.asc"]; andreas@392: andreas@392: PEPIdentity *identHector = [[PEPIdentity alloc] andreas@392: initWithAddress:@"pep.test.hector@pep-project.org" andreas@392: userID:@"fc2d33" userName:@"pEp Test Hector" andreas@392: isOwn:NO andreas@392: fingerPrint:@"EEA655839E347EC9E10A5DE2E80CB3FD5CB2C182"]; andreas@392: andreas@392: // Check that this key is indeed expired andreas@392: [session updateIdentity:identHector]; andreas@392: XCTAssertEqual(PEP_ct_key_expired, identHector.commType); andreas@392: andreas@392: PEPIdentity *identHectorOwn = [[PEPIdentity alloc] andreas@392: initWithAddress:@"pep.test.hector@pep-project.org" andreas@392: userID:ownUserId userName:@"pEp Test Hector" andreas@392: isOwn:YES andreas@392: fingerPrint:@"EEA655839E347EC9E10A5DE2E80CB3FD5CB2C182"]; andreas@392: andreas@392: // Myself automatically renew expired key. andreas@392: [session mySelf:identHectorOwn]; andreas@392: XCTAssertEqual(PEP_ct_pEp, identHectorOwn.commType); andreas@392: andreas@392: [self pEpCleanUpRestoringBackupNamed:@"Bob"]; andreas@392: andreas@392: andreas@392: [self pEpSetUp:@"Bob"]; andreas@392: andreas@392: PEPIdentity *_identHector = [[PEPIdentity alloc] andreas@392: initWithAddress:@"pep.test.hector@pep-project.org" andreas@392: userID:@"khkhkh" userName:@"pEp Test Hector" andreas@392: isOwn:NO andreas@392: fingerPrint:@"EEA655839E347EC9E10A5DE2E80CB3FD5CB2C182"]; andreas@392: andreas@392: [session updateIdentity:_identHector]; andreas@392: XCTAssertEqual(PEP_ct_OpenPGP_unconfirmed, _identHector.commType); andreas@392: } andreas@392: andreas@392: - (void)testRevoke andreas@392: { andreas@392: PEPSession *session = [PEPSession new]; andreas@392: andreas@392: // Our test user : andreas@392: // pEp Test Alice (test key don't use) andreas@392: // 4ABE3AAF59AC32CFE4F86500A9411D176FF00E97 andreas@392: [PEPTestUtils importBundledKey:@"6FF00E97_sec.asc"]; andreas@392: NSString *fpr = @"4ABE3AAF59AC32CFE4F86500A9411D176FF00E97"; andreas@392: andreas@392: PEPIdentity *identAlice = [[PEPIdentity alloc] andreas@392: initWithAddress:@"pep.test.alice@pep-project.org" andreas@392: userID:ownUserId andreas@392: userName:@"pEp Test Alice" andreas@392: isOwn:YES andreas@392: fingerPrint:fpr]; andreas@392: andreas@392: [session mySelf:identAlice]; andreas@392: andreas@392: PEPIdentity *identAlice2 = [identAlice mutableCopy]; andreas@392: andreas@392: // This will revoke key andreas@392: [session keyMistrusted:identAlice2]; andreas@416: identAlice2.fingerPrint = nil; andreas@416: [session mySelf:identAlice]; andreas@416: andreas@392: andreas@392: // Check fingerprint is different andreas@392: XCTAssertNotEqualObjects(identAlice2.fingerPrint, fpr); andreas@392: } andreas@392: andreas@392: - (void)testMailToMyself andreas@392: { andreas@392: PEPSession *session = [PEPSession new]; andreas@392: andreas@392: // Our test user : andreas@392: // pEp Test Alice (test key don't use) andreas@392: // 4ABE3AAF59AC32CFE4F86500A9411D176FF00E97 andreas@392: [PEPTestUtils importBundledKey:@"6FF00E97_sec.asc"]; andreas@392: andreas@392: PEPIdentity *identAlice = [[PEPIdentity alloc] andreas@392: initWithAddress:@"pep.test.alice@pep-project.org" andreas@392: userID:ownUserId andreas@392: userName:@"pEp Test Alice" andreas@392: isOwn:YES andreas@392: fingerPrint:@"4ABE3AAF59AC32CFE4F86500A9411D176FF00E97"]; andreas@392: andreas@392: [session mySelf:identAlice]; andreas@392: andreas@392: PEPMessage *msg = [PEPMessage new]; andreas@392: msg.from = identAlice; andreas@392: msg.to = @[identAlice]; andreas@392: msg.shortMessage = @"Mail to Myself"; andreas@392: msg.longMessage = @"This is a text content"; andreas@392: msg.direction = PEP_dir_outgoing; andreas@392: andreas@392: PEP_rating clr = [session outgoingColorForMessage:msg]; dirk@420: XCTAssertEqual(clr, PEP_rating_trusted_and_anonymized); andreas@392: andreas@392: PEPMessage *encmsg; andreas@392: PEP_STATUS status = [session encryptMessage:msg extra:@[] dest:&encmsg]; andreas@392: dirk@420: XCTAssertEqual(status, PEP_STATUS_OK); andreas@392: andreas@392: NSArray* keys; andreas@392: PEPMessage *decmsg; andreas@392: andreas@392: clr = [session decryptMessage:encmsg dest:&decmsg keys:&keys]; dirk@420: XCTAssertEqual(clr, PEP_rating_trusted_and_anonymized); andreas@392: } andreas@392: andreas@392: - (void)testEncryptedMailFromMutt andreas@392: { andreas@392: PEPSession *session = [PEPSession new]; andreas@392: andreas@392: // This is the public key for test001@peptest.ch andreas@392: [PEPTestUtils importBundledKey:@"A3FC7F0A.asc"]; andreas@392: andreas@392: // This is the secret key for test001@peptest.ch andreas@392: [PEPTestUtils importBundledKey:@"A3FC7F0A_sec.asc"]; andreas@392: andreas@392: // Mail from mutt, already processed into message dict by the app. dirk@434: NSMutableDictionary *msgDict = [PEPTestUtils dirk@434: unarchiveDictionary:@"msg_to_A3FC7F0A_from_mutt.ser"].mutableCopy; andreas@392: [msgDict removeObjectForKey:kPepLongMessage]; andreas@392: [msgDict removeObjectForKey:kPepLongMessageFormatted]; andreas@392: andreas@392: // Also extracted "live" from the app. dirk@434: NSMutableDictionary *accountDict = [PEPTestUtils dirk@434: unarchiveDictionary:@"account_A3FC7F0A.ser"].mutableCopy; andreas@392: [accountDict removeObjectForKey:kPepCommType]; andreas@392: [accountDict removeObjectForKey:kPepFingerprint]; andreas@392: PEPIdentity *identMe = [[PEPIdentity alloc] initWithDictionary:accountDict]; andreas@392: andreas@392: [session mySelf:identMe]; andreas@392: XCTAssertNotNil(identMe.fingerPrint); andreas@392: andreas@392: NSArray* keys; andreas@392: PEPMessage *msg = [PEPMessage new]; andreas@392: [msg setValuesForKeysWithDictionary:msgDict]; andreas@392: PEPMessage *pepDecryptedMail; andreas@392: [session decryptMessage:msg dest:&pepDecryptedMail keys:&keys]; andreas@392: XCTAssertNotNil(pepDecryptedMail.longMessage); andreas@392: } andreas@392: andreas@392: - (void)testOutgoingContactColor andreas@392: { andreas@392: PEPSession *session = [PEPSession new]; andreas@392: andreas@411: PEPIdentity *partner1Orig = [PEPTestUtils foreignPepIdentityWithAddress:@"partner1@dontcare.me" andreas@411: userName:@"Partner 1"]; andreas@392: NSString *pubKeyPartner1 = [PEPTestUtils loadResourceByName:@"partner1_F2D281C2789DD7F6_pub.asc"]; andreas@392: XCTAssertNotNil(pubKeyPartner1); andreas@392: [session importKey:pubKeyPartner1]; andreas@392: andreas@392: PEP_rating color = [session identityRating:partner1Orig]; andreas@392: XCTAssertEqual(color, PEP_rating_reliable); andreas@392: } andreas@392: andreas@392: - (void)testMessageTrustwordsWithMySelf andreas@392: { andreas@392: PEPSession *session = [PEPSession new]; andreas@392: andreas@392: PEPStringList *keys = nil; andreas@392: PEPMessage *decryptedDict = [self internalEncryptToMySelfKeys:&keys]; andreas@392: XCTAssertNotNil(keys); andreas@392: XCTAssert(keys.count > 0); andreas@392: andreas@392: PEPIdentity *receiver = decryptedDict.to[0]; andreas@392: [session updateIdentity:receiver]; andreas@392: XCTAssertNotNil(receiver); andreas@392: PEP_STATUS trustwordsStatus; andreas@392: andreas@392: NSString *trustwords = [session getTrustwordsForMessage:decryptedDict andreas@392: receiver:receiver andreas@392: keysArray:keys language:@"en" andreas@392: full:YES andreas@392: resultingStatus: &trustwordsStatus]; andreas@392: // No trustwords with yourself andreas@392: XCTAssertEqual(trustwordsStatus, PEP_TRUSTWORDS_DUPLICATE_FPR); andreas@392: XCTAssertNil(trustwords); andreas@392: } andreas@392: andreas@392: - (void)testGetTrustwords andreas@392: { andreas@392: PEPSession *session = [PEPSession new]; andreas@392: andreas@392: PEPIdentity *partner1Orig = [[PEPIdentity alloc] andreas@392: initWithAddress:@"partner1@dontcare.me" userID:@"partner1" andreas@392: userName:@"partner1" andreas@392: isOwn:NO fingerPrint:@"F0CD3F7B422E5D587ABD885BF2D281C2789DD7F6"]; andreas@392: andreas@392: PEPIdentity *meOrig = [[PEPIdentity alloc] andreas@392: initWithAddress:@"me@dontcare.me" userID:@"me" andreas@392: userName:@"me" andreas@392: isOwn:NO fingerPrint:@"CC1F73F6FB774BF08B197691E3BFBCA9248FC681"]; andreas@392: andreas@392: NSString *pubKeyPartner1 = [PEPTestUtils loadResourceByName:@"partner1_F2D281C2789DD7F6_pub.asc"]; andreas@392: XCTAssertNotNil(pubKeyPartner1); andreas@392: NSString *pubKeyMe = [PEPTestUtils loadResourceByName:@"meATdontcare_E3BFBCA9248FC681_pub.asc"]; andreas@392: XCTAssertNotNil(pubKeyMe); andreas@392: NSString *secKeyMe = [PEPTestUtils loadResourceByName:@"meATdontcare_E3BFBCA9248FC681_sec.asc"]; andreas@392: XCTAssertNotNil(secKeyMe); andreas@392: andreas@392: NSString *trustwordsFull = [session getTrustwordsIdentity1:meOrig identity2:partner1Orig andreas@392: language:nil full:YES]; andreas@392: XCTAssertEqualObjects(trustwordsFull, andreas@392: @"EMERSON GASPER TOKENISM BOLUS COLLAGE DESPISE BEDDED ENCRYPTION IMAGINE BEDFORD"); andreas@392: andreas@392: NSString *trustwordsFullEnglish = [session getTrustwordsIdentity1:meOrig identity2:partner1Orig andreas@392: language:@"en" full:YES]; andreas@392: XCTAssertEqualObjects(trustwordsFullEnglish, trustwordsFull); andreas@392: andreas@392: NSString *trustwordsUndefined = [session getTrustwordsIdentity1:meOrig identity2:partner1Orig andreas@392: language:@"ZZ" full:YES]; andreas@392: XCTAssertNil(trustwordsUndefined); andreas@392: } andreas@392: andreas@416: #pragma mark - configUnencryptedSubject andreas@416: andreas@416: - (void)testConfigUnencryptedSubject andreas@416: { andreas@416: // Setup Config to encrypt subject andreas@416: [PEPObjCAdapter setUnecryptedSubjectEnabled:NO]; andreas@416: andreas@416: // Write mail to yourself ... andreas@416: PEPMessage *encMessage = [self mailWrittenToMySelf]; andreas@416: andreas@416: // ... and assert subject is encrypted andreas@416: XCTAssertEqualObjects(encMessage.shortMessage, @"p≡p", @"Subject should be encrypted"); andreas@416: } andreas@416: andreas@416: - (void)testConfigUnencryptedSubject_encryptedSubjectDisabled andreas@416: { andreas@416: // Setup Config to not encrypt subject andreas@416: [PEPObjCAdapter setUnecryptedSubjectEnabled:YES]; andreas@416: andreas@416: // Write mail to yourself ... andreas@416: PEPMessage *encMessage = [self mailWrittenToMySelf]; andreas@416: andreas@416: // ... and assert the subject is not encrypted andreas@416: XCTAssertNotEqualObjects(encMessage.shortMessage, @"p≡p", @"Subject should not be encrypted"); andreas@416: } andreas@416: dirk@418: - (void)testStringToRating dirk@418: { dirk@418: PEPSession *session = [PEPSession new]; dirk@418: XCTAssertEqual([session ratingFromString:@"cannot_decrypt"], PEP_rating_cannot_decrypt); dirk@418: XCTAssertEqual([session ratingFromString:@"have_no_key"], PEP_rating_have_no_key); dirk@418: XCTAssertEqual([session ratingFromString:@"unencrypted"], PEP_rating_unencrypted); dirk@418: XCTAssertEqual([session ratingFromString:@"unencrypted_for_some"], dirk@418: PEP_rating_unencrypted_for_some); dirk@418: XCTAssertEqual([session ratingFromString:@"unreliable"], PEP_rating_unreliable); dirk@418: XCTAssertEqual([session ratingFromString:@"reliable"], PEP_rating_reliable); dirk@418: XCTAssertEqual([session ratingFromString:@"trusted"], PEP_rating_trusted); dirk@418: XCTAssertEqual([session ratingFromString:@"trusted_and_anonymized"], dirk@418: PEP_rating_trusted_and_anonymized); dirk@418: XCTAssertEqual([session ratingFromString:@"fully_anonymous"], PEP_rating_fully_anonymous); dirk@418: XCTAssertEqual([session ratingFromString:@"mistrust"], PEP_rating_mistrust); dirk@418: XCTAssertEqual([session ratingFromString:@"b0rken"], PEP_rating_b0rken); dirk@418: XCTAssertEqual([session ratingFromString:@"under_attack"], PEP_rating_under_attack); dirk@418: XCTAssertEqual([session ratingFromString:@"undefined"], PEP_rating_undefined); dirk@418: XCTAssertEqual([session ratingFromString:@"does not exist111"], PEP_rating_undefined); dirk@418: } dirk@418: dirk@418: - (void)testRatingToString dirk@418: { dirk@418: PEPSession *session = [PEPSession new]; dirk@418: XCTAssertEqualObjects([session stringFromRating:PEP_rating_cannot_decrypt], @"cannot_decrypt"); dirk@418: XCTAssertEqualObjects([session stringFromRating:PEP_rating_have_no_key], @"have_no_key"); dirk@418: XCTAssertEqualObjects([session stringFromRating:PEP_rating_unencrypted], @"unencrypted"); dirk@418: XCTAssertEqualObjects([session stringFromRating:PEP_rating_unencrypted_for_some], dirk@418: @"unencrypted_for_some"); dirk@418: XCTAssertEqualObjects([session stringFromRating:PEP_rating_unreliable], @"unreliable"); dirk@418: XCTAssertEqualObjects([session stringFromRating:PEP_rating_reliable], @"reliable"); dirk@418: XCTAssertEqualObjects([session stringFromRating:PEP_rating_trusted], @"trusted"); dirk@418: XCTAssertEqualObjects([session stringFromRating:PEP_rating_trusted_and_anonymized], dirk@418: @"trusted_and_anonymized"); dirk@418: XCTAssertEqualObjects([session stringFromRating:PEP_rating_fully_anonymous], dirk@418: @"fully_anonymous"); dirk@418: XCTAssertEqualObjects([session stringFromRating:PEP_rating_mistrust], @"mistrust"); dirk@418: XCTAssertEqualObjects([session stringFromRating:PEP_rating_b0rken], @"b0rken"); dirk@418: XCTAssertEqualObjects([session stringFromRating:PEP_rating_under_attack], @"under_attack"); dirk@418: XCTAssertEqualObjects([session stringFromRating:PEP_rating_undefined], @"undefined"); dirk@418: XCTAssertEqualObjects([session stringFromRating:500], @"undefined"); dirk@418: } dirk@418: dirk@431: - (void)testIsPEPUser dirk@431: { dirk@431: PEPSession *session = [PEPSession new]; dirk@431: dirk@431: PEPIdentity *identMe = [[PEPIdentity alloc] dirk@431: initWithAddress:@"me-myself-and-i@pep-project.org" dirk@431: userID:@"me-myself-and-i" dirk@431: userName:@"pEp Test Alice" dirk@431: isOwn:YES]; dirk@431: [session mySelf:identMe]; dirk@431: XCTAssertNotNil(identMe.fingerPrint); dirk@432: dirk@432: // PEP_CANNOT_FIND_PERSON == 902 dirk@431: NSError *error; dirk@431: XCTAssertTrue([session isPEPUser:identMe error:&error]); dirk@431: XCTAssertNil(error); dirk@431: } dirk@431: andreas@392: #pragma mark - Helpers andreas@392: dirk@439: - (PEPIdentity *)checkImportingKeyFilePath:(NSString *)filePath address:(NSString *)address dirk@439: userID:(NSString *)userID dirk@439: fingerPrint:(NSString *)fingerPrint dirk@437: { dirk@437: PEPSession *session = [PEPSession new]; dirk@437: dirk@437: [PEPTestUtils importBundledKey:filePath]; dirk@437: dirk@437: // Our test user: dirk@437: PEPIdentity *identTest = [[PEPIdentity alloc] dirk@437: initWithAddress:address dirk@437: userID:userID dirk@439: userName:[NSString stringWithFormat:@"Some User Name %@", userID] dirk@437: isOwn:NO]; dirk@437: dirk@437: [session updateIdentity:identTest]; dirk@437: XCTAssertNotNil(identTest.fingerPrint); dirk@437: XCTAssertEqualObjects(identTest.fingerPrint, fingerPrint); dirk@439: dirk@439: return identTest; dirk@439: } dirk@439: dirk@439: - (PEPIdentity *)checkMySelfImportingKeyFilePath:(NSString *)filePath address:(NSString *)address dirk@439: userID:(NSString *)userID dirk@439: fingerPrint:(NSString *)fingerPrint dirk@439: { dirk@439: PEPSession *session = [PEPSession new]; dirk@439: dirk@439: [PEPTestUtils importBundledKey:filePath]; dirk@439: dirk@439: // Our test user: dirk@439: PEPIdentity *identTest = [[PEPIdentity alloc] dirk@439: initWithAddress:address dirk@439: userID:userID dirk@439: userName:[NSString stringWithFormat:@"Some User Name %@", userID] dirk@439: isOwn:YES dirk@439: fingerPrint: fingerPrint]; dirk@439: dirk@439: [session mySelf:identTest]; dirk@439: XCTAssertNotNil(identTest.fingerPrint); dirk@439: XCTAssertEqualObjects(identTest.fingerPrint, fingerPrint); dirk@439: dirk@439: return identTest; dirk@437: } dirk@437: dirk@433: /** dirk@433: Verifies that a partner ID is really a correct Identity. dirk@433: Usually used on identities imported as keys, since the engine has problems with them. dirk@433: */ dirk@433: - (void)updateAndVerifyPartnerIdentity:(PEPIdentity *)partnerIdentity session:(PEPSession *)session dirk@433: { dirk@433: XCTAssertNotNil(partnerIdentity.fingerPrint); dirk@433: [session updateIdentity:partnerIdentity]; dirk@433: XCTAssertNotNil(partnerIdentity.fingerPrint); dirk@433: NSString *fingerprint = partnerIdentity.fingerPrint; dirk@433: partnerIdentity.fingerPrint = nil; dirk@433: [session updateIdentity:partnerIdentity]; dirk@433: XCTAssertNotNil(partnerIdentity.fingerPrint); dirk@433: XCTAssertEqualObjects(partnerIdentity.fingerPrint, fingerprint); dirk@433: } dirk@433: andreas@416: - (PEPMessage *)mailWrittenToMySelf andreas@416: { andreas@416: PEPSession *session = [PEPSession new]; andreas@416: andreas@416: // Write a e-mail to yourself ... andreas@416: PEPIdentity *me = [PEPTestUtils ownPepIdentityWithAddress:@"me@peptest.ch" andreas@416: userName:@"userName"]; andreas@416: [session mySelf:me]; andreas@416: andreas@416: NSString *shortMessage = @"Subject"; andreas@416: NSString *longMessage = @"Oh, this is a long body text!"; andreas@416: PEPMessage *mail = [PEPTestUtils mailFrom:me andreas@416: toIdent:me andreas@416: shortMessage:shortMessage andreas@416: longMessage:longMessage andreas@416: outgoing:YES]; andreas@416: PEPMessage *encMessage; andreas@416: [session encryptMessage:mail identity:me dest:&encMessage]; andreas@416: andreas@416: return encMessage; andreas@416: } andreas@416: andreas@392: - (PEPMessage *)internalEncryptToMySelfKeys:(PEPStringList **)keys andreas@392: { andreas@392: PEPSession *session = [PEPSession new]; andreas@411: andreas@411: PEPIdentity *me = [PEPTestUtils ownPepIdentityWithAddress:@"me@peptest.ch" andreas@411: userName:@"userName"]; andreas@392: [session mySelf:me]; andreas@392: XCTAssertNotNil(me.fingerPrint); andreas@392: andreas@392: // Create draft andreas@392: NSString *shortMessage = @"Subject"; andreas@392: NSString *longMessage = @"Oh, this is a long body text!"; andreas@392: PEPMessage *mail = [PEPTestUtils mailFrom:me toIdent:me shortMessage:shortMessage longMessage:longMessage outgoing:YES]; andreas@392: andreas@392: PEPMessage *encMessage; andreas@392: PEP_STATUS status = [session encryptMessage:mail identity:me dest:&encMessage]; andreas@392: XCTAssertEqual(status, 0); andreas@392: XCTAssertEqualObjects(encMessage.shortMessage, @"p≡p"); andreas@392: andreas@392: PEPMessage *unencDict; andreas@392: PEP_rating rating = [session decryptMessage:encMessage dest:&unencDict keys:keys]; andreas@392: XCTAssertGreaterThanOrEqual(rating, PEP_rating_reliable); andreas@392: andreas@392: XCTAssertEqualObjects(unencDict.shortMessage, shortMessage); andreas@392: XCTAssertEqualObjects(unencDict.longMessage, longMessage); andreas@392: andreas@392: return unencDict; andreas@392: } andreas@392: andreas@392: - (void)pEpCleanUpRestoringBackupNamed:(NSString *)backup { andreas@392: [PEPTestUtils deleteWorkFilesAfterBackingUpWithBackupName:backup]; andreas@392: } andreas@392: andreas@392: - (void)pEpCleanUp andreas@392: { andreas@392: [PEPSession cleanup]; andreas@392: [self pEpCleanUpRestoringBackupNamed:NULL]; andreas@392: } andreas@392: andreas@392: - (void)pEpSetUp:(NSString *)restore andreas@392: { andreas@392: // Must be the first thing you do before using anything pEp-related andreas@392: // ... but this is now done in session, with a "dispatch_once" andreas@392: // [PEPObjCAdapter setupTrustWordsDB:[NSBundle bundleForClass:[self class]]]; andreas@392: andreas@392: [PEPTestUtils deleteWorkFilesAfterBackingUpWithBackupName:nil]; andreas@392: [PEPTestUtils restoreWorkFilesFromBackupNamed:restore]; andreas@392: } andreas@392: andreas@392: - (void)pEpSetUp andreas@392: { andreas@392: [self pEpSetUp:NULL]; andreas@392: } andreas@392: dirk@424: - (void)helperXEncStatusForOutgoingEncryptdMailToSelf:(BOOL)toSelf dirk@424: expectedRating:(PEP_rating)expectedRating dirk@422: { dirk@422: PEPSession *session = [PEPSession new]; dirk@422: dirk@422: // Partner pubkey for the test: dirk@422: // pEp Test Alice (test key don't use) dirk@422: // 4ABE3AAF59AC32CFE4F86500A9411D176FF00E97 dirk@422: [PEPTestUtils importBundledKey:@"0x6FF00E97.asc"]; dirk@422: dirk@422: PEPIdentity *identAlice = [[PEPIdentity alloc] dirk@422: initWithAddress:@"pep.test.alice@pep-project.org" dirk@422: userID:ownUserId dirk@422: userName:@"pEp Test Alice" dirk@422: isOwn:NO dirk@433: fingerPrint:@"4ABE3AAF59AC32CFE4F86500A9411D176FF00E97"]; dirk@433: [self updateAndVerifyPartnerIdentity:identAlice session:session]; dirk@422: dirk@422: PEPIdentity *identMe = [[PEPIdentity alloc] dirk@422: initWithAddress:@"me-myself-and-i@pep-project.org" dirk@422: userID:@"me-myself-and-i" dirk@422: userName:@"pEp Test Alice" dirk@422: isOwn:YES]; dirk@422: [session mySelf:identMe]; dirk@422: XCTAssertNotNil(identMe.fingerPrint); dirk@422: dirk@422: PEPMessage *msg = [PEPMessage new]; dirk@422: msg.from = identMe; dirk@422: msg.to = @[identAlice]; dirk@422: msg.shortMessage = @"Mail to Alice"; dirk@422: msg.longMessage = @"Alice?"; dirk@422: msg.direction = PEP_dir_outgoing; dirk@422: dirk@422: PEP_rating clr = [session outgoingColorForMessage:msg]; dirk@424: XCTAssertEqual(clr, PEP_rating_reliable); dirk@422: dirk@423: PEPMessage *encMsg; dirk@424: dirk@424: PEP_STATUS statusEnc = PEP_VERSION_MISMATCH; dirk@424: if (toSelf) { dirk@424: statusEnc = [session encryptMessage:msg identity:identMe dest:&encMsg]; dirk@424: } else { dirk@424: statusEnc = [session encryptMessage:msg extra:@[] dest:&encMsg]; dirk@424: } dirk@422: dirk@423: XCTAssertEqual(statusEnc, PEP_STATUS_OK); dirk@423: dirk@423: XCTAssertNotNil(encMsg); dirk@423: dirk@423: PEPMessage *decMsg; dirk@423: PEPStringList *keys; dirk@423: PEP_rating pEpRating = [session decryptMessage:encMsg dest:&decMsg keys:&keys]; dirk@424: XCTAssertEqual(pEpRating, expectedRating); dirk@423: XCTAssertNotNil(decMsg); dirk@423: dirk@423: NSArray * encStatusField = nil; dirk@423: for (NSArray *field in decMsg.optionalFields) { dirk@423: NSString *header = [field[0] lowercaseString]; dirk@423: if ([header isEqualToString:@"x-encstatus"]) { dirk@423: encStatusField = field; dirk@423: } dirk@423: } dirk@423: XCTAssertNotNil(encStatusField); dirk@423: if (encStatusField) { dirk@423: PEP_rating outgoingRating = [session ratingFromString:encStatusField[1]]; dirk@424: XCTAssertEqual(outgoingRating, expectedRating); dirk@423: } dirk@422: } dirk@422: dirk@424: - (void)testXEncStatusForOutgoingEncryptedMail dirk@424: { dirk@424: [self helperXEncStatusForOutgoingEncryptdMailToSelf:NO expectedRating:PEP_rating_reliable]; dirk@424: } dirk@424: dirk@424: - (void)testXEncStatusForOutgoingSelfEncryptedMail dirk@424: { dirk@424: [self helperXEncStatusForOutgoingEncryptdMailToSelf:YES dirk@424: expectedRating:PEP_rating_trusted_and_anonymized]; dirk@424: } dirk@424: andreas@392: @end