pEpObjCTests/PEPSessionTest.m
author Dirk Zimmermann <dirk@pep-project.org>
Wed, 21 Feb 2018 12:05:19 +0100
changeset 491 721c4077e76d
parent 490 d5d089b07164
child 494 6f45696ae8b3
permissions -rw-r--r--
IOSAD-76 use existing session
andreas@392
     1
//
andreas@392
     2
//  PEPSessionTest.m
andreas@392
     3
//  pEpObjCAdapterTests
andreas@392
     4
//
andreas@392
     5
//  Created by Andreas Buff on 18.01.18.
andreas@392
     6
//  Copyright © 2018 p≡p. All rights reserved.
andreas@392
     7
//
andreas@392
     8
andreas@392
     9
#import <XCTest/XCTest.h>
andreas@392
    10
andreas@392
    11
#import "PEPObjCAdapter.h"
andreas@392
    12
#import "NSDictionary+Extension.h"
andreas@392
    13
#import "PEPIdentity.h"
andreas@392
    14
#import "PEPMessage.h"
andreas@392
    15
andreas@392
    16
#import "PEPTestUtils.h"
andreas@392
    17
#import "PEPTestSyncDelegate.h"
andreas@392
    18
andreas@392
    19
@interface PEPSessionTest : XCTestCase
andreas@392
    20
@end
andreas@392
    21
andreas@392
    22
@implementation PEPSessionTest
andreas@392
    23
andreas@392
    24
- (void)setUp
andreas@392
    25
{
andreas@392
    26
    [super setUp];
andreas@416
    27
    [PEPObjCAdapter setUnecryptedSubjectEnabled:NO];
andreas@416
    28
andreas@392
    29
    [self pEpCleanUp];
andreas@392
    30
}
andreas@392
    31
andreas@392
    32
- (void)tearDown {
andreas@392
    33
    [self pEpCleanUp];
andreas@392
    34
    [super tearDown];
andreas@392
    35
}
andreas@392
    36
andreas@392
    37
- (void)testSyncSession
andreas@392
    38
{
andreas@392
    39
    PEPSession *session = [PEPSession new];
dirk@474
    40
dirk@474
    41
    // Dummy to set up the DB, since this is currenty only triggered by session use,
dirk@474
    42
    // which PEPObjCAdapter.startSync does not trigger.
dirk@474
    43
    [session getLog];
dirk@474
    44
andreas@392
    45
    PEPTestSyncDelegate *syncDelegate = [[PEPTestSyncDelegate alloc] init];
andreas@392
    46
andreas@392
    47
    // This should attach session just created
andreas@392
    48
    [PEPObjCAdapter startSync:syncDelegate];
andreas@392
    49
andreas@392
    50
    PEPIdentity *identMe = [[PEPIdentity alloc]
andreas@392
    51
                            initWithAddress:@"pep.test.iosgenkey@pep-project.org"
andreas@392
    52
                            userID:@"Me"
andreas@392
    53
                            userName:@"pEp Test iOS GenKey"
andreas@392
    54
                            isOwn:YES];
andreas@392
    55
andreas@392
    56
    [session mySelf:identMe];
andreas@392
    57
andreas@392
    58
    bool res = [syncDelegate waitUntilSent:1];
andreas@392
    59
andreas@392
    60
    // Can't currently work, engine doesn't contain sync.
andreas@392
    61
    XCTAssertFalse(res);
andreas@392
    62
andreas@392
    63
    // This should detach session just created
andreas@392
    64
    [PEPObjCAdapter stopSync];
andreas@392
    65
}
andreas@392
    66
andreas@392
    67
- (void)testTrustWords
andreas@392
    68
{
andreas@392
    69
    PEPSession *session = [PEPSession new];
andreas@392
    70
andreas@392
    71
    NSArray *trustwords = [session trustwords:@"DB47DB47DB47DB47DB47DB47DB47DB47DB47DB47"
andreas@392
    72
                                  forLanguage:@"en" shortened:false];
andreas@392
    73
    XCTAssertEqual([trustwords count], 10);
andreas@392
    74
andreas@392
    75
    for(id word in trustwords)
andreas@392
    76
        XCTAssertEqualObjects(word, @"BAPTISMAL");
andreas@392
    77
}
andreas@392
    78
andreas@392
    79
- (void)testGenKey
andreas@392
    80
{
andreas@392
    81
    PEPSession *session = [PEPSession new];
andreas@392
    82
andreas@392
    83
    PEPIdentity *identMe = [[PEPIdentity alloc]
andreas@392
    84
                            initWithAddress:@"pep.test.iosgenkey@pep-project.org"
andreas@392
    85
                            userID:@"Me"
andreas@392
    86
                            userName:@"pEp Test iOS GenKey"
andreas@392
    87
                            isOwn:YES];
andreas@392
    88
andreas@392
    89
    [session mySelf:identMe];
andreas@392
    90
andreas@392
    91
    XCTAssertNotNil(identMe.fingerPrint);
andreas@392
    92
    XCTAssertNotEqual(identMe.commType, PEP_ct_unknown);
andreas@392
    93
andreas@392
    94
    // check that the comm type is not a PGP one
andreas@392
    95
    XCTAssertFalse([identMe containsPGPCommType]);
andreas@392
    96
}
andreas@392
    97
andreas@392
    98
- (void)testMySelfCommType
andreas@392
    99
{
andreas@392
   100
    PEPSession *session = [PEPSession new];
andreas@392
   101
andreas@392
   102
    PEPIdentity *identMe = [[PEPIdentity alloc]
andreas@392
   103
                            initWithAddress:@"pep.test.iosgenkey@pep-project.org"
andreas@392
   104
                            userID:@"Me"
andreas@392
   105
                            userName:@"pEp Test iOS GenKey"
andreas@392
   106
                            isOwn:YES];
andreas@392
   107
andreas@392
   108
    [session mySelf:identMe];
andreas@392
   109
andreas@392
   110
    XCTAssertNotNil(identMe.fingerPrint);
andreas@392
   111
    XCTAssertNotEqual(identMe.commType, PEP_ct_unknown);
andreas@392
   112
andreas@392
   113
    // check that the comm type is not a PGP one
andreas@392
   114
    XCTAssertFalse([identMe containsPGPCommType]);
andreas@392
   115
andreas@392
   116
    dispatch_queue_t queue = dispatch_get_global_queue(QOS_CLASS_USER_INITIATED, 0);
andreas@392
   117
    dispatch_sync(queue, ^{
andreas@392
   118
        PEPSession *session2 = [PEPSession new];
andreas@392
   119
andreas@392
   120
        // Now simulate an update from the app, which usually only caches
andreas@392
   121
        // kPepUsername, kPepAddress and optionally kPepUserID.
andreas@392
   122
        PEPIdentity *identMe2 = [[PEPIdentity alloc]
andreas@392
   123
                                 initWithAddress:identMe.address
andreas@392
   124
                                 userID:identMe.userID
andreas@392
   125
                                 userName:identMe.userName
andreas@392
   126
                                 isOwn:NO];
andreas@392
   127
        [session2 mySelf:identMe2];
andreas@392
   128
        XCTAssertNotNil(identMe2.fingerPrint);
andreas@392
   129
        XCTAssertFalse([identMe2 containsPGPCommType]);
andreas@392
   130
        XCTAssertEqualObjects(identMe2.fingerPrint, identMe.fingerPrint);
andreas@392
   131
andreas@392
   132
        // Now pretend the app only knows kPepUsername and kPepAddress
andreas@411
   133
        PEPIdentity *identMe3 = [PEPTestUtils foreignPepIdentityWithAddress:identMe.address
andreas@411
   134
                                                                   userName:identMe.userName];
andreas@392
   135
        [session2 mySelf:identMe3];
andreas@392
   136
        XCTAssertNotNil(identMe3.fingerPrint);
andreas@392
   137
        XCTAssertFalse([identMe3 containsPGPCommType]);
andreas@392
   138
        XCTAssertEqualObjects(identMe3.fingerPrint, identMe.fingerPrint);
andreas@392
   139
andreas@392
   140
        XCTAssertEqualObjects(identMe.address, identMe2.address);
andreas@392
   141
        XCTAssertEqualObjects(identMe.address, identMe3.address);
andreas@392
   142
        XCTAssertEqual(identMe.commType, identMe2.commType);
andreas@392
   143
        XCTAssertEqual(identMe.commType, identMe3.commType);
andreas@392
   144
    });
andreas@392
   145
}
andreas@392
   146
dirk@435
   147
- (void)testPartnerWithoutFingerPrint
dirk@435
   148
{
dirk@435
   149
    PEPSession *session = [PEPSession new];
dirk@435
   150
dirk@435
   151
    PEPIdentity *identRandom = [[PEPIdentity alloc]
dirk@435
   152
                                initWithAddress:@"does_not_exist@example.com"
dirk@435
   153
                                userID:@"got_out"
dirk@435
   154
                                userName:@"No Way Not Even Alice"
dirk@435
   155
                                isOwn:NO];
dirk@435
   156
dirk@435
   157
    [session updateIdentity:identRandom];
dirk@435
   158
    XCTAssertNil(identRandom.fingerPrint);
dirk@435
   159
}
dirk@435
   160
dirk@437
   161
- (void)testImportPartnerKeys
dirk@436
   162
{
dirk@488
   163
    XCTAssertNotNil([self checkImportingKeyFilePath:@"6FF00E97_sec.asc"
dirk@488
   164
                                            address:@"pep.test.alice@pep-project.org"
dirk@488
   165
                                             userID:@"This Is Alice"
dirk@488
   166
                                        fingerPrint:@"4ABE3AAF59AC32CFE4F86500A9411D176FF00E97"
dirk@488
   167
                                            session: nil]);
dirk@436
   168
dirk@488
   169
    XCTAssertNotNil([self checkImportingKeyFilePath:@"0xC9C2EE39.asc"
dirk@488
   170
                                            address:@"pep.test.bob@pep-project.org"
dirk@488
   171
                                             userID:@"This Is Bob"
dirk@488
   172
                                        fingerPrint:@"BFCDB7F301DEEEBBF947F29659BFF488C9C2EE39"
dirk@488
   173
                                            session: nil]);
dirk@436
   174
}
dirk@436
   175
dirk@439
   176
- (void)testIdentityRating
dirk@439
   177
{
dirk@439
   178
    PEPSession *session = [PEPSession new];
dirk@439
   179
dirk@439
   180
    PEPIdentity *me = [self
dirk@439
   181
                       checkMySelfImportingKeyFilePath:@"6FF00E97_sec.asc"
dirk@439
   182
                       address:@"pep.test.alice@pep-project.org"
dirk@439
   183
                       userID:@"Alice_User_ID"
dirk@491
   184
                       fingerPrint:@"4ABE3AAF59AC32CFE4F86500A9411D176FF00E97"
dirk@491
   185
                       session:session];
dirk@439
   186
    XCTAssertEqual([session identityRating:me], PEP_rating_trusted_and_anonymized);
dirk@439
   187
dirk@439
   188
    PEPIdentity *alice = [self
dirk@439
   189
                          checkImportingKeyFilePath:@"6FF00E97_sec.asc"
dirk@439
   190
                          address:@"pep.test.alice@pep-project.org"
dirk@439
   191
                          userID:@"This Is Alice"
dirk@456
   192
                          fingerPrint:@"4ABE3AAF59AC32CFE4F86500A9411D176FF00E97"
dirk@456
   193
                          session: session];
dirk@488
   194
    XCTAssertNotNil(alice);
dirk@439
   195
    XCTAssertEqual([session identityRating:alice], PEP_rating_reliable);
dirk@439
   196
}
dirk@439
   197
dirk@446
   198
- (void)testIdentityRatingTrustResetMistrustUndo
dirk@445
   199
{
dirk@445
   200
    PEPSession *session = [PEPSession new];
dirk@445
   201
dirk@460
   202
    PEPIdentity *me = [[PEPIdentity alloc]
dirk@460
   203
                       initWithAddress:@"me@example.org"
dirk@460
   204
                       userID:@"me_myself"
dirk@460
   205
                       userName:@"Me Me"
dirk@460
   206
                       isOwn:YES];
dirk@460
   207
    [session mySelf:me];
dirk@460
   208
    XCTAssertNotNil(me.fingerPrint);
dirk@445
   209
    XCTAssertEqual([session identityRating:me], PEP_rating_trusted_and_anonymized);
dirk@445
   210
dirk@445
   211
    PEPIdentity *alice = [self
dirk@445
   212
                          checkImportingKeyFilePath:@"6FF00E97_sec.asc"
dirk@445
   213
                          address:@"pep.test.alice@pep-project.org"
dirk@445
   214
                          userID:@"This Is Alice"
dirk@456
   215
                          fingerPrint:@"4ABE3AAF59AC32CFE4F86500A9411D176FF00E97"
dirk@456
   216
                          session: session];
dirk@488
   217
    XCTAssertNotNil(alice);
dirk@445
   218
    XCTAssertEqual([session identityRating:alice], PEP_rating_reliable);
dirk@445
   219
dirk@446
   220
    [session trustPersonalKey:alice];
dirk@446
   221
    XCTAssertEqual([session identityRating:alice], PEP_rating_trusted);
dirk@446
   222
dirk@446
   223
    [session keyResetTrust:alice];
dirk@446
   224
    XCTAssertEqual([session identityRating:alice], PEP_rating_reliable);
dirk@446
   225
dirk@445
   226
    [session keyMistrusted:alice];
dirk@445
   227
    XCTAssertEqual([session identityRating:alice], PEP_rating_have_no_key);
dirk@445
   228
dirk@445
   229
    [session undoLastMistrust];
dirk@445
   230
    XCTAssertEqual([session identityRating:alice], PEP_rating_reliable);
dirk@446
   231
dirk@446
   232
    [session trustPersonalKey:alice];
dirk@446
   233
    XCTAssertEqual([session identityRating:alice], PEP_rating_trusted);
dirk@446
   234
dirk@446
   235
    [session keyResetTrust:alice];
dirk@450
   236
    XCTAssertEqual([session identityRating:alice], PEP_rating_have_no_key);
dirk@445
   237
}
dirk@445
   238
dirk@478
   239
/** ENGINE-384 */
dirk@472
   240
- (void)testIdentityRatingCrash
dirk@472
   241
{
dirk@472
   242
    PEPSession *session = [PEPSession new];
dirk@472
   243
dirk@472
   244
    PEPIdentity *me = [[PEPIdentity alloc]
dirk@472
   245
                       initWithAddress:@"me@example.org"
dirk@472
   246
                       userID:@"me_myself"
dirk@472
   247
                       userName:@"Me Me"
dirk@472
   248
                       isOwn:YES];
dirk@472
   249
    [session mySelf:me];
dirk@472
   250
    XCTAssertNotNil(me.fingerPrint);
dirk@472
   251
    XCTAssertEqual([session identityRating:me], PEP_rating_trusted_and_anonymized);
dirk@472
   252
dirk@472
   253
    PEPIdentity *alice = [self
dirk@472
   254
                          checkImportingKeyFilePath:@"6FF00E97_sec.asc"
dirk@472
   255
                          address:@"pep.test.alice@pep-project.org"
dirk@472
   256
                          userID:@"This Is Alice"
dirk@472
   257
                          fingerPrint:@"4ABE3AAF59AC32CFE4F86500A9411D176FF00E97"
dirk@472
   258
                          session: session];
dirk@488
   259
    XCTAssertNotNil(alice);
dirk@472
   260
    XCTAssertEqual([session identityRating:alice], PEP_rating_reliable);
dirk@472
   261
dirk@472
   262
    [session trustPersonalKey:alice];
dirk@472
   263
    XCTAssertEqual([session identityRating:alice], PEP_rating_trusted);
dirk@472
   264
dirk@472
   265
    [session keyResetTrust:alice];
dirk@472
   266
    XCTAssertEqual([session identityRating:alice], PEP_rating_reliable);
dirk@472
   267
dirk@472
   268
    [session keyMistrusted:alice];
dirk@472
   269
    XCTAssertEqual([session identityRating:alice], PEP_rating_have_no_key);
dirk@472
   270
dirk@472
   271
    [session undoLastMistrust];
dirk@472
   272
dirk@472
   273
    [session trustPersonalKey:alice];
dirk@472
   274
    XCTAssertEqual([session identityRating:alice], PEP_rating_trusted);
dirk@472
   275
dirk@472
   276
    [session keyResetTrust:alice];
dirk@472
   277
    XCTAssertEqual([session identityRating:alice], PEP_rating_have_no_key);
dirk@472
   278
dirk@478
   279
    // This line provoked the crash
dirk@472
   280
    [session trustPersonalKey:alice];
dirk@472
   281
}
dirk@472
   282
dirk@458
   283
/**
dirk@458
   284
 Try to provoke a SQLITE_BUSY (ENGINE-374)
dirk@458
   285
 */
dirk@458
   286
- (void)testIdentityRatingTrustResetMistrustUndoBusy
dirk@458
   287
{
dirk@458
   288
    PEPSession *session = [PEPSession new];
dirk@458
   289
dirk@459
   290
    PEPIdentity *me = [[PEPIdentity alloc]
dirk@459
   291
                       initWithAddress:@"me@example.org"
dirk@459
   292
                       userID:@"me_myself"
dirk@459
   293
                       userName:@"Me Me"
dirk@459
   294
                       isOwn:YES];
dirk@459
   295
    [session mySelf:me];
dirk@459
   296
    XCTAssertNotNil(me.fingerPrint);
dirk@458
   297
    XCTAssertEqual([session identityRating:me], PEP_rating_trusted_and_anonymized);
dirk@458
   298
dirk@458
   299
    PEPIdentity *alice = [self
dirk@458
   300
                          checkImportingKeyFilePath:@"6FF00E97_sec.asc"
dirk@458
   301
                          address:@"pep.test.alice@pep-project.org"
dirk@458
   302
                          userID:@"This Is Alice"
dirk@458
   303
                          fingerPrint:@"4ABE3AAF59AC32CFE4F86500A9411D176FF00E97"
dirk@458
   304
                          session: session];
dirk@488
   305
    XCTAssertNotNil(alice);
dirk@458
   306
    XCTAssertEqual([session identityRating:alice], PEP_rating_reliable);
dirk@458
   307
dirk@458
   308
    void (^encryptingBlock)(void) = ^{
dirk@458
   309
        PEPSession *innerSession = [PEPSession new];
dirk@458
   310
        PEPMessage *msg = [PEPMessage new];
dirk@458
   311
        msg.from = me;
dirk@458
   312
        msg.to = @[alice];
dirk@458
   313
        msg.shortMessage = @"The subject";
dirk@458
   314
        msg.longMessage = @"Lots and lots of text";
dirk@476
   315
        msg.direction = PEP_dir_outgoing;
dirk@458
   316
        PEPMessage *encMsg;
dirk@458
   317
        PEP_STATUS status = [innerSession encryptMessage:msg identity:me dest:&encMsg];
dirk@458
   318
        XCTAssertEqual(status, PEP_STATUS_OK);
dirk@458
   319
    };
dirk@458
   320
dirk@458
   321
    dispatch_group_t backgroundGroup = dispatch_group_create();
dirk@458
   322
    dispatch_group_async(backgroundGroup,
dirk@458
   323
                         dispatch_get_global_queue(QOS_CLASS_USER_INITIATED, 0), encryptingBlock);
dirk@458
   324
dirk@458
   325
    [session trustPersonalKey:alice];
dirk@458
   326
    XCTAssertEqual([session identityRating:alice], PEP_rating_trusted);
dirk@458
   327
dirk@458
   328
    [session keyResetTrust:alice];
dirk@458
   329
    XCTAssertEqual([session identityRating:alice], PEP_rating_reliable);
dirk@458
   330
dirk@458
   331
    [session keyMistrusted:alice];
dirk@458
   332
    XCTAssertEqual([session identityRating:alice], PEP_rating_have_no_key);
dirk@458
   333
dirk@458
   334
    [session undoLastMistrust];
dirk@458
   335
    XCTAssertEqual([session identityRating:alice], PEP_rating_reliable);
dirk@458
   336
dirk@458
   337
    [session trustPersonalKey:alice];
dirk@458
   338
    XCTAssertEqual([session identityRating:alice], PEP_rating_trusted);
dirk@458
   339
dirk@458
   340
    [session keyResetTrust:alice];
dirk@458
   341
    XCTAssertEqual([session identityRating:alice], PEP_rating_have_no_key);
dirk@458
   342
dirk@458
   343
    dispatch_group_wait(backgroundGroup, DISPATCH_TIME_FOREVER);
dirk@458
   344
}
dirk@458
   345
andreas@392
   346
- (void)testOutgoingColors
andreas@392
   347
{
andreas@392
   348
    PEPSession *session = [PEPSession new];
andreas@392
   349
andreas@392
   350
    // Our test user :
andreas@392
   351
    // pEp Test Alice (test key don't use) <pep.test.alice@pep-project.org>
andreas@392
   352
    // 4ABE3AAF59AC32CFE4F86500A9411D176FF00E97
dirk@488
   353
    XCTAssertTrue([PEPTestUtils importBundledKey:@"6FF00E97_sec.asc" session:session]);
andreas@392
   354
andreas@392
   355
    // Our test user :
dirk@440
   356
    PEPIdentity *identAlice = [self
dirk@440
   357
                               checkMySelfImportingKeyFilePath:@"6FF00E97_sec.asc"
dirk@440
   358
                               address:@"pep.test.alice@pep-project.org"
dirk@440
   359
                               userID:@"Alice_User_ID"
dirk@491
   360
                               fingerPrint:@"4ABE3AAF59AC32CFE4F86500A9411D176FF00E97"
dirk@491
   361
                               session:session];
andreas@392
   362
andreas@392
   363
    //Message
andreas@392
   364
dirk@441
   365
    {
dirk@441
   366
        PEPIdentity *identUnknownBob = [[PEPIdentity alloc]
dirk@441
   367
                                        initWithAddress:@"pep.test.unknown.bob@pep-project.org"
dirk@441
   368
                                        userID:@"4242" userName:@"pEp Test Bob Unknown"
dirk@441
   369
                                        isOwn:NO];
dirk@441
   370
dirk@441
   371
        PEPMessage *msgGray = [PEPMessage new];
dirk@441
   372
        msgGray.from = identAlice;
dirk@441
   373
        msgGray.to = @[identUnknownBob];
dirk@441
   374
        msgGray.shortMessage = @"All Gray Test";
dirk@441
   375
        msgGray.longMessage = @"This is a text content";
dirk@441
   376
        msgGray.direction = PEP_dir_outgoing;
dirk@441
   377
dirk@441
   378
        // Test with unknown Bob
dirk@441
   379
        PEP_rating clr = [session outgoingColorForMessage:msgGray];
dirk@441
   380
        XCTAssertEqual(clr, PEP_rating_unencrypted);
dirk@441
   381
    }
dirk@441
   382
dirk@441
   383
    PEPIdentity *identBob = [self
dirk@441
   384
                             checkImportingKeyFilePath:@"0xC9C2EE39.asc"
dirk@441
   385
                             address:@"pep.test.bob@pep-project.org"
dirk@441
   386
                             userID:@"42"
dirk@456
   387
                             fingerPrint:@"BFCDB7F301DEEEBBF947F29659BFF488C9C2EE39"
dirk@456
   388
                             session: session];
dirk@488
   389
    XCTAssertNotNil(identBob);
dirk@438
   390
andreas@392
   391
    PEPMessage *msg = [PEPMessage new];
andreas@392
   392
    msg.from = identAlice;
dirk@438
   393
    msg.to = @[identBob];
dirk@441
   394
    msg.shortMessage = @"All Gray Test";
andreas@392
   395
    msg.longMessage = @"This is a text content";
andreas@392
   396
    msg.direction = PEP_dir_outgoing;
andreas@392
   397
dirk@441
   398
    // Should be yellow, since no handshake happened.
andreas@392
   399
    PEP_rating clr = [session outgoingColorForMessage:msg];
dirk@420
   400
    XCTAssertEqual(clr, PEP_rating_reliable);
andreas@392
   401
andreas@392
   402
    clr = [session identityRating:identBob];
dirk@420
   403
    XCTAssertEqual(clr, PEP_rating_reliable);
andreas@392
   404
andreas@392
   405
    // Let' say we got that handshake, set PEP_ct_confirmed in Bob's identity
andreas@392
   406
    [session trustPersonalKey:identBob];
andreas@392
   407
andreas@392
   408
    // This time it should be green
andreas@392
   409
    clr = [session outgoingColorForMessage:msg];
dirk@420
   410
    XCTAssertEqual(clr, PEP_rating_trusted);
andreas@392
   411
andreas@392
   412
    clr = [session identityRating:identBob];
dirk@420
   413
    XCTAssertEqual(clr, PEP_rating_trusted);
andreas@392
   414
andreas@392
   415
    // Let' say we undo handshake
andreas@392
   416
    [session keyResetTrust:identBob];
andreas@392
   417
andreas@392
   418
    // Yellow ?
andreas@392
   419
    clr = [session outgoingColorForMessage:msg];
dirk@420
   420
    XCTAssertEqual(clr, PEP_rating_reliable);
andreas@392
   421
andreas@392
   422
    // mistrust Bob
andreas@392
   423
    [session keyMistrusted:identBob];
andreas@392
   424
dirk@444
   425
    identBob.fingerPrint = nil;
dirk@441
   426
    [session updateIdentity:identBob];
dirk@441
   427
    XCTAssertNil(identBob.fingerPrint);
dirk@441
   428
andreas@392
   429
    // Gray == PEP_rating_unencrypted
andreas@392
   430
    clr = [session outgoingColorForMessage:msg];
dirk@420
   431
    XCTAssertEqual(clr, PEP_rating_unencrypted);
andreas@392
   432
dirk@444
   433
    // Undo
dirk@443
   434
    [session undoLastMistrust];
dirk@444
   435
    [session updateIdentity:identBob];
dirk@444
   436
    XCTAssertNotNil(identBob.fingerPrint);
andreas@392
   437
andreas@392
   438
    // Back to yellow
andreas@392
   439
    clr = [session outgoingColorForMessage:msg];
dirk@420
   440
    XCTAssertEqual(clr, PEP_rating_reliable);
dirk@444
   441
    XCTAssertEqual([session identityRating:identBob], PEP_rating_reliable);
andreas@392
   442
andreas@392
   443
    // Trust again
andreas@392
   444
    [session trustPersonalKey:identBob];
andreas@392
   445
andreas@392
   446
    // Back to green
andreas@392
   447
    clr = [session outgoingColorForMessage:msg];
dirk@420
   448
    XCTAssertEqual(clr, PEP_rating_trusted);
andreas@392
   449
andreas@392
   450
    // Now let see if it turns back yellow if we add an unconfirmed folk.
andreas@392
   451
    // pEp Test John (test key, don't use) <pep.test.john@pep-project.org>
andreas@392
   452
    // AA2E4BEB93E5FE33DEFD8BE1135CD6D170DCF575
dirk@488
   453
    XCTAssertTrue([PEPTestUtils importBundledKey:@"0x70DCF575.asc" session:session]);
andreas@392
   454
andreas@392
   455
    PEPIdentity *identJohn = [[PEPIdentity alloc]
andreas@392
   456
                              initWithAddress:@"pep.test.john@pep-project.org"
andreas@392
   457
                              userID:@"101" userName:@"pEp Test John"
andreas@392
   458
                              isOwn:NO
andreas@392
   459
                              fingerPrint:@"AA2E4BEB93E5FE33DEFD8BE1135CD6D170DCF575"];
andreas@392
   460
andreas@392
   461
    [session updateIdentity:identJohn];
andreas@392
   462
andreas@411
   463
    msg.cc = @[[PEPTestUtils foreignPepIdentityWithAddress:@"pep.test.john@pep-project.org"
andreas@411
   464
                                                  userName:@"pEp Test John"]];
andreas@392
   465
    // Yellow ?
andreas@392
   466
    clr = [session outgoingColorForMessage:msg];
dirk@420
   467
    XCTAssertEqual(clr, PEP_rating_reliable);
andreas@392
   468
andreas@392
   469
    PEPMessage *encmsg;
andreas@392
   470
    PEP_STATUS status = [session encryptMessage:msg extra:@[] dest:&encmsg];
andreas@392
   471
andreas@392
   472
    XCTAssertNotNil(encmsg);
andreas@392
   473
    XCTAssertEqualObjects(encmsg.shortMessage, @"p≡p");
andreas@392
   474
    XCTAssertTrue([encmsg.longMessage containsString:@"p≡p"]);
andreas@392
   475
dirk@420
   476
    XCTAssertEqual(status, PEP_STATUS_OK);
andreas@392
   477
}
andreas@392
   478
andreas@392
   479
andreas@392
   480
- (void)testOutgoingBccColors
andreas@392
   481
{
andreas@392
   482
    PEPSession *session = [PEPSession new];
andreas@392
   483
andreas@392
   484
    // Our test user :
andreas@392
   485
    // pEp Test Alice (test key don't use) <pep.test.alice@pep-project.org>
andreas@392
   486
    // 4ABE3AAF59AC32CFE4F86500A9411D176FF00E97
dirk@488
   487
    XCTAssertTrue([PEPTestUtils importBundledKey:@"6FF00E97_sec.asc" session:session]);
andreas@392
   488
andreas@392
   489
    PEPIdentity *identAlice = [[PEPIdentity alloc]
andreas@392
   490
                               initWithAddress:@"pep.test.alice@pep-project.org"
andreas@392
   491
                               userID:ownUserId
andreas@392
   492
                               userName:@"pEp Test Alice"
andreas@392
   493
                               isOwn:YES
andreas@392
   494
                               fingerPrint:@"4ABE3AAF59AC32CFE4F86500A9411D176FF00E97"];
andreas@392
   495
andreas@392
   496
    [session mySelf:identAlice];
andreas@392
   497
andreas@392
   498
    PEPMessage *msg = [PEPMessage new];
andreas@392
   499
    msg.from = identAlice;
andreas@392
   500
    msg.to = @[[[PEPIdentity alloc] initWithAddress:@"pep.test.bob@pep-project.org"
andreas@392
   501
                                             userID:@"42" userName:@"pEp Test Bob" isOwn:NO]];
andreas@392
   502
    msg.shortMessage = @"All Green Test";
andreas@392
   503
    msg.longMessage = @"This is a text content";
andreas@392
   504
    msg.direction = PEP_dir_outgoing;
andreas@392
   505
andreas@392
   506
    // Test with unknown Bob
andreas@392
   507
    PEP_rating clr = [session outgoingColorForMessage:msg];
dirk@420
   508
    XCTAssertEqual(clr, PEP_rating_unencrypted);
andreas@392
   509
andreas@392
   510
    // Now let see with bob's pubkey already known
andreas@392
   511
    // pEp Test Bob (test key, don't use) <pep.test.bob@pep-project.org>
andreas@392
   512
    // BFCDB7F301DEEEBBF947F29659BFF488C9C2EE39
dirk@488
   513
    XCTAssertTrue([PEPTestUtils importBundledKey:@"0xC9C2EE39.asc" session:session]);
andreas@392
   514
andreas@392
   515
    PEPIdentity *identBob = [[PEPIdentity alloc]
andreas@392
   516
                             initWithAddress:@"pep.test.bob@pep-project.org"
andreas@392
   517
                             userID:@"42" userName:@"pEp Test Bob"
andreas@392
   518
                             isOwn:NO
andreas@392
   519
                             fingerPrint:@"BFCDB7F301DEEEBBF947F29659BFF488C9C2EE39"];
andreas@392
   520
andreas@392
   521
    [session updateIdentity:identBob];
andreas@392
   522
andreas@392
   523
    // Should be yellow, since no handshake happened.
andreas@392
   524
    clr = [session outgoingColorForMessage:msg];
dirk@420
   525
    XCTAssertEqual(clr, PEP_rating_reliable);
andreas@392
   526
andreas@392
   527
    clr = [session identityRating:identBob];
dirk@420
   528
    XCTAssertEqual(clr, PEP_rating_reliable);
andreas@392
   529
andreas@392
   530
    // Let' say we got that handshake, set PEP_ct_confirmed in Bob's identity
andreas@392
   531
    [session trustPersonalKey:identBob];
andreas@392
   532
andreas@392
   533
    // This time it should be green
andreas@392
   534
    clr = [session outgoingColorForMessage:msg];
dirk@420
   535
    XCTAssertEqual(clr, PEP_rating_trusted);
andreas@392
   536
andreas@392
   537
    clr = [session identityRating:identBob];
dirk@420
   538
    XCTAssertEqual(clr, PEP_rating_trusted);
andreas@392
   539
andreas@392
   540
    // Now let see if it turns back yellow if we add an unconfirmed folk.
andreas@392
   541
    // pEp Test John (test key, don't use) <pep.test.john@pep-project.org>
andreas@392
   542
    // AA2E4BEB93E5FE33DEFD8BE1135CD6D170DCF575
dirk@488
   543
    XCTAssertTrue([PEPTestUtils importBundledKey:@"0x70DCF575.asc" session:session]);
andreas@392
   544
andreas@392
   545
    PEPIdentity *identJohn = [[PEPIdentity alloc]
andreas@392
   546
                              initWithAddress:@"pep.test.john@pep-project.org"
andreas@392
   547
                              userID:@"101" userName:@"pEp Test John"
andreas@392
   548
                              isOwn:NO
andreas@392
   549
                              fingerPrint:@"AA2E4BEB93E5FE33DEFD8BE1135CD6D170DCF575"];
andreas@392
   550
andreas@392
   551
    [session updateIdentity:identJohn];
andreas@392
   552
andreas@392
   553
    msg.bcc = @[[[PEPIdentity alloc] initWithAddress:@"pep.test.john@pep-project.org"
andreas@392
   554
                                              userID:@"101" userName:@"pEp Test John" isOwn:NO]];
andreas@392
   555
andreas@392
   556
    // Yellow ?
andreas@392
   557
    clr = [session outgoingColorForMessage:msg];
dirk@420
   558
    XCTAssertEqual(clr, PEP_rating_reliable);
andreas@392
   559
andreas@392
   560
    [session trustPersonalKey:identJohn];
andreas@392
   561
andreas@392
   562
    // This time it should be green
andreas@392
   563
    clr = [session outgoingColorForMessage:msg];
dirk@420
   564
    XCTAssertEqual(clr, PEP_rating_trusted);
andreas@392
   565
andreas@392
   566
    clr = [session identityRating:identJohn];
dirk@420
   567
    XCTAssertEqual(clr, PEP_rating_trusted);
andreas@392
   568
}
andreas@392
   569
andreas@392
   570
- (void)testDontEncryptForMistrusted
andreas@392
   571
{
andreas@392
   572
    PEPSession *session = [PEPSession new];
andreas@392
   573
andreas@392
   574
    // Our test user :
andreas@392
   575
    // pEp Test Alice (test key don't use) <pep.test.alice@pep-project.org>
andreas@392
   576
    // 4ABE3AAF59AC32CFE4F86500A9411D176FF00E97
dirk@488
   577
    XCTAssertTrue([PEPTestUtils importBundledKey:@"6FF00E97_sec.asc" session:session]);
andreas@392
   578
andreas@392
   579
    PEPIdentity *identAlice = [[PEPIdentity alloc]
andreas@392
   580
                               initWithAddress:@"pep.test.alice@pep-project.org"
andreas@392
   581
                               userID:ownUserId
andreas@392
   582
                               userName:@"pEp Test Alice"
andreas@392
   583
                               isOwn:YES
andreas@392
   584
                               fingerPrint:@"4ABE3AAF59AC32CFE4F86500A9411D176FF00E97"];
andreas@392
   585
andreas@392
   586
    [session mySelf:identAlice];
andreas@392
   587
andreas@392
   588
    // pEp Test Bob (test key, don't use) <pep.test.bob@pep-project.org>
andreas@392
   589
    // BFCDB7F301DEEEBBF947F29659BFF488C9C2EE39
dirk@488
   590
    XCTAssertTrue([PEPTestUtils importBundledKey:@"0xC9C2EE39.asc" session:session]);
andreas@392
   591
andreas@392
   592
    PEPIdentity *identBob = [[PEPIdentity alloc]
andreas@392
   593
                             initWithAddress:@"pep.test.bob@pep-project.org"
andreas@392
   594
                             userID:@"42" userName:@"pEp Test Bob"
andreas@392
   595
                             isOwn:NO
andreas@392
   596
                             fingerPrint:@"BFCDB7F301DEEEBBF947F29659BFF488C9C2EE39"];
andreas@392
   597
andreas@392
   598
    [session updateIdentity:identBob];
andreas@392
   599
andreas@392
   600
    // mistrust Bob
andreas@392
   601
    [session keyMistrusted:identBob];
andreas@392
   602
andreas@392
   603
    PEPMessage *msg = [PEPMessage new];
andreas@392
   604
    msg.from = identAlice;
andreas@392
   605
    msg.to = @[[[PEPIdentity alloc] initWithAddress:@"pep.test.bob@pep-project.org" userID:@"42"
andreas@392
   606
                                           userName:@"pEp Test Bob" isOwn:NO]];
andreas@392
   607
    msg.shortMessage = @"All Green Test";
andreas@392
   608
    msg.longMessage = @"This is a text content";
andreas@392
   609
    msg.direction = PEP_dir_outgoing;
andreas@392
   610
andreas@392
   611
    // Gray == PEP_rating_unencrypted
andreas@392
   612
    PEP_rating clr = [session outgoingColorForMessage:msg];
dirk@420
   613
    XCTAssertEqual(clr, PEP_rating_unencrypted);
andreas@392
   614
andreas@392
   615
    PEPMessage *encmsg;
andreas@392
   616
    PEP_STATUS status = [session encryptMessage:msg extra:@[] dest:&encmsg];
andreas@392
   617
dirk@420
   618
    XCTAssertEqual(status, PEP_UNENCRYPTED);
andreas@392
   619
andreas@392
   620
    XCTAssertNotEqualObjects(encmsg.attachments[0][@"mimeType"], @"application/pgp-encrypted");
andreas@392
   621
andreas@392
   622
    [self pEpCleanUp];
andreas@392
   623
}
andreas@392
   624
andreas@392
   625
- (void)testRevoke
andreas@392
   626
{
andreas@392
   627
    PEPSession *session = [PEPSession new];
andreas@392
   628
andreas@392
   629
    // Our test user :
andreas@392
   630
    // pEp Test Alice (test key don't use) <pep.test.alice@pep-project.org>
andreas@392
   631
    // 4ABE3AAF59AC32CFE4F86500A9411D176FF00E97
dirk@488
   632
    XCTAssertTrue([PEPTestUtils importBundledKey:@"6FF00E97_sec.asc" session:session]);
andreas@392
   633
    NSString *fpr = @"4ABE3AAF59AC32CFE4F86500A9411D176FF00E97";
andreas@392
   634
andreas@392
   635
    PEPIdentity *identAlice = [[PEPIdentity alloc]
andreas@392
   636
                               initWithAddress:@"pep.test.alice@pep-project.org"
andreas@392
   637
                               userID:ownUserId
andreas@392
   638
                               userName:@"pEp Test Alice"
andreas@392
   639
                               isOwn:YES
andreas@392
   640
                               fingerPrint:fpr];
andreas@392
   641
andreas@392
   642
    [session mySelf:identAlice];
andreas@392
   643
andreas@392
   644
    PEPIdentity *identAlice2 = [identAlice mutableCopy];
andreas@392
   645
andreas@392
   646
    // This will revoke key
andreas@392
   647
    [session keyMistrusted:identAlice2];
andreas@416
   648
    identAlice2.fingerPrint = nil;
andreas@416
   649
    [session mySelf:identAlice];
andreas@416
   650
andreas@392
   651
    // Check fingerprint is different
andreas@392
   652
    XCTAssertNotEqualObjects(identAlice2.fingerPrint, fpr);
andreas@392
   653
}
andreas@392
   654
andreas@392
   655
- (void)testMailToMyself
andreas@392
   656
{
andreas@392
   657
    PEPSession *session = [PEPSession new];
andreas@392
   658
andreas@392
   659
    // Our test user :
andreas@392
   660
    // pEp Test Alice (test key don't use) <pep.test.alice@pep-project.org>
andreas@392
   661
    // 4ABE3AAF59AC32CFE4F86500A9411D176FF00E97
dirk@488
   662
    XCTAssertTrue([PEPTestUtils importBundledKey:@"6FF00E97_sec.asc" session:session]);
andreas@392
   663
andreas@392
   664
    PEPIdentity *identAlice = [[PEPIdentity alloc]
andreas@392
   665
                               initWithAddress:@"pep.test.alice@pep-project.org"
andreas@392
   666
                               userID:ownUserId
andreas@392
   667
                               userName:@"pEp Test Alice"
andreas@392
   668
                               isOwn:YES
andreas@392
   669
                               fingerPrint:@"4ABE3AAF59AC32CFE4F86500A9411D176FF00E97"];
andreas@392
   670
andreas@392
   671
    [session mySelf:identAlice];
andreas@392
   672
andreas@392
   673
    PEPMessage *msg = [PEPMessage new];
andreas@392
   674
    msg.from = identAlice;
andreas@392
   675
    msg.to = @[identAlice];
andreas@392
   676
    msg.shortMessage = @"Mail to Myself";
andreas@392
   677
    msg.longMessage = @"This is a text content";
andreas@392
   678
    msg.direction = PEP_dir_outgoing;
andreas@392
   679
andreas@392
   680
    PEP_rating clr = [session outgoingColorForMessage:msg];
dirk@420
   681
    XCTAssertEqual(clr, PEP_rating_trusted_and_anonymized);
andreas@392
   682
andreas@392
   683
    PEPMessage *encmsg;
andreas@392
   684
    PEP_STATUS status = [session encryptMessage:msg extra:@[] dest:&encmsg];
andreas@392
   685
dirk@420
   686
    XCTAssertEqual(status, PEP_STATUS_OK);
andreas@392
   687
andreas@392
   688
    NSArray* keys;
andreas@392
   689
    PEPMessage *decmsg;
andreas@392
   690
andreas@392
   691
    clr = [session decryptMessage:encmsg dest:&decmsg keys:&keys];
dirk@420
   692
    XCTAssertEqual(clr, PEP_rating_trusted_and_anonymized);
andreas@392
   693
}
andreas@392
   694
andreas@392
   695
- (void)testEncryptedMailFromMutt
andreas@392
   696
{
andreas@392
   697
    PEPSession *session = [PEPSession new];
andreas@392
   698
andreas@392
   699
    // This is the public key for test001@peptest.ch
dirk@488
   700
    XCTAssertTrue([PEPTestUtils importBundledKey:@"A3FC7F0A.asc" session:session]);
andreas@392
   701
andreas@392
   702
    // This is the secret key for test001@peptest.ch
dirk@488
   703
    XCTAssertTrue([PEPTestUtils importBundledKey:@"A3FC7F0A_sec.asc" session:session]);
andreas@392
   704
andreas@392
   705
    // Mail from mutt, already processed into message dict by the app.
dirk@465
   706
    NSMutableDictionary *msgDict = [[PEPTestUtils
dirk@465
   707
                                     unarchiveDictionary:@"msg_to_A3FC7F0A_from_mutt.ser"]
dirk@465
   708
                                    mutableCopy];
andreas@392
   709
    [msgDict removeObjectForKey:kPepLongMessage];
andreas@392
   710
    [msgDict removeObjectForKey:kPepLongMessageFormatted];
andreas@392
   711
andreas@392
   712
    // Also extracted "live" from the app.
dirk@465
   713
    NSMutableDictionary *accountDict = [[PEPTestUtils
dirk@465
   714
                                         unarchiveDictionary:@"account_A3FC7F0A.ser"]
dirk@465
   715
                                        mutableCopy];
andreas@392
   716
    [accountDict removeObjectForKey:kPepCommType];
andreas@392
   717
    [accountDict removeObjectForKey:kPepFingerprint];
andreas@392
   718
    PEPIdentity *identMe = [[PEPIdentity alloc] initWithDictionary:accountDict];
andreas@392
   719
andreas@392
   720
    [session mySelf:identMe];
andreas@392
   721
    XCTAssertNotNil(identMe.fingerPrint);
andreas@392
   722
andreas@392
   723
    NSArray* keys;
andreas@392
   724
    PEPMessage *msg = [PEPMessage new];
andreas@392
   725
    [msg setValuesForKeysWithDictionary:msgDict];
andreas@392
   726
    PEPMessage *pepDecryptedMail;
dirk@471
   727
    [session decryptMessage:msg dest:&pepDecryptedMail keys:&keys];
andreas@392
   728
    XCTAssertNotNil(pepDecryptedMail.longMessage);
andreas@392
   729
}
andreas@392
   730
andreas@392
   731
- (void)testOutgoingContactColor
andreas@392
   732
{
andreas@392
   733
    PEPSession *session = [PEPSession new];
andreas@392
   734
andreas@411
   735
    PEPIdentity *partner1Orig = [PEPTestUtils foreignPepIdentityWithAddress:@"partner1@dontcare.me"
andreas@411
   736
                                                                   userName:@"Partner 1"];
andreas@392
   737
    NSString *pubKeyPartner1 = [PEPTestUtils loadResourceByName:@"partner1_F2D281C2789DD7F6_pub.asc"];
andreas@392
   738
    XCTAssertNotNil(pubKeyPartner1);
andreas@392
   739
    [session importKey:pubKeyPartner1];
andreas@392
   740
andreas@392
   741
    PEP_rating color = [session identityRating:partner1Orig];
andreas@392
   742
    XCTAssertEqual(color, PEP_rating_reliable);
andreas@392
   743
}
andreas@392
   744
andreas@392
   745
- (void)testGetTrustwords
andreas@392
   746
{
andreas@392
   747
    PEPSession *session = [PEPSession new];
andreas@392
   748
andreas@392
   749
    PEPIdentity *partner1Orig = [[PEPIdentity alloc]
andreas@392
   750
                                 initWithAddress:@"partner1@dontcare.me" userID:@"partner1"
andreas@392
   751
                                 userName:@"partner1"
andreas@392
   752
                                 isOwn:NO fingerPrint:@"F0CD3F7B422E5D587ABD885BF2D281C2789DD7F6"];
andreas@392
   753
andreas@392
   754
    PEPIdentity *meOrig = [[PEPIdentity alloc]
andreas@392
   755
                           initWithAddress:@"me@dontcare.me" userID:@"me"
andreas@392
   756
                           userName:@"me"
andreas@392
   757
                           isOwn:NO fingerPrint:@"CC1F73F6FB774BF08B197691E3BFBCA9248FC681"];
andreas@392
   758
andreas@392
   759
    NSString *pubKeyPartner1 = [PEPTestUtils loadResourceByName:@"partner1_F2D281C2789DD7F6_pub.asc"];
andreas@392
   760
    XCTAssertNotNil(pubKeyPartner1);
andreas@392
   761
    NSString *pubKeyMe = [PEPTestUtils loadResourceByName:@"meATdontcare_E3BFBCA9248FC681_pub.asc"];
andreas@392
   762
    XCTAssertNotNil(pubKeyMe);
andreas@392
   763
    NSString *secKeyMe = [PEPTestUtils loadResourceByName:@"meATdontcare_E3BFBCA9248FC681_sec.asc"];
andreas@392
   764
    XCTAssertNotNil(secKeyMe);
andreas@392
   765
andreas@392
   766
    NSString *trustwordsFull = [session getTrustwordsIdentity1:meOrig identity2:partner1Orig
andreas@392
   767
                                                      language:nil full:YES];
andreas@392
   768
    XCTAssertEqualObjects(trustwordsFull,
andreas@392
   769
                          @"EMERSON GASPER TOKENISM BOLUS COLLAGE DESPISE BEDDED ENCRYPTION IMAGINE BEDFORD");
andreas@392
   770
andreas@392
   771
    NSString *trustwordsFullEnglish = [session getTrustwordsIdentity1:meOrig identity2:partner1Orig
andreas@392
   772
                                                             language:@"en" full:YES];
andreas@392
   773
    XCTAssertEqualObjects(trustwordsFullEnglish, trustwordsFull);
andreas@392
   774
andreas@392
   775
    NSString *trustwordsUndefined = [session getTrustwordsIdentity1:meOrig identity2:partner1Orig
andreas@392
   776
                                                           language:@"ZZ" full:YES];
andreas@392
   777
    XCTAssertNil(trustwordsUndefined);
andreas@392
   778
}
andreas@392
   779
dirk@418
   780
- (void)testStringToRating
dirk@418
   781
{
dirk@418
   782
    PEPSession *session = [PEPSession new];
dirk@418
   783
    XCTAssertEqual([session ratingFromString:@"cannot_decrypt"], PEP_rating_cannot_decrypt);
dirk@418
   784
    XCTAssertEqual([session ratingFromString:@"have_no_key"], PEP_rating_have_no_key);
dirk@418
   785
    XCTAssertEqual([session ratingFromString:@"unencrypted"], PEP_rating_unencrypted);
dirk@418
   786
    XCTAssertEqual([session ratingFromString:@"unencrypted_for_some"],
dirk@418
   787
                   PEP_rating_unencrypted_for_some);
dirk@418
   788
    XCTAssertEqual([session ratingFromString:@"unreliable"], PEP_rating_unreliable);
dirk@418
   789
    XCTAssertEqual([session ratingFromString:@"reliable"], PEP_rating_reliable);
dirk@418
   790
    XCTAssertEqual([session ratingFromString:@"trusted"], PEP_rating_trusted);
dirk@418
   791
    XCTAssertEqual([session ratingFromString:@"trusted_and_anonymized"],
dirk@418
   792
                   PEP_rating_trusted_and_anonymized);
dirk@418
   793
    XCTAssertEqual([session ratingFromString:@"fully_anonymous"], PEP_rating_fully_anonymous);
dirk@418
   794
    XCTAssertEqual([session ratingFromString:@"mistrust"], PEP_rating_mistrust);
dirk@418
   795
    XCTAssertEqual([session ratingFromString:@"b0rken"], PEP_rating_b0rken);
dirk@418
   796
    XCTAssertEqual([session ratingFromString:@"under_attack"], PEP_rating_under_attack);
dirk@418
   797
    XCTAssertEqual([session ratingFromString:@"undefined"], PEP_rating_undefined);
dirk@418
   798
    XCTAssertEqual([session ratingFromString:@"does not exist111"], PEP_rating_undefined);
dirk@418
   799
}
dirk@418
   800
dirk@418
   801
- (void)testRatingToString
dirk@418
   802
{
dirk@418
   803
    PEPSession *session = [PEPSession new];
dirk@418
   804
    XCTAssertEqualObjects([session stringFromRating:PEP_rating_cannot_decrypt], @"cannot_decrypt");
dirk@418
   805
    XCTAssertEqualObjects([session stringFromRating:PEP_rating_have_no_key], @"have_no_key");
dirk@418
   806
    XCTAssertEqualObjects([session stringFromRating:PEP_rating_unencrypted], @"unencrypted");
dirk@418
   807
    XCTAssertEqualObjects([session stringFromRating:PEP_rating_unencrypted_for_some],
dirk@418
   808
                          @"unencrypted_for_some");
dirk@418
   809
    XCTAssertEqualObjects([session stringFromRating:PEP_rating_unreliable], @"unreliable");
dirk@418
   810
    XCTAssertEqualObjects([session stringFromRating:PEP_rating_reliable], @"reliable");
dirk@418
   811
    XCTAssertEqualObjects([session stringFromRating:PEP_rating_trusted], @"trusted");
dirk@418
   812
    XCTAssertEqualObjects([session stringFromRating:PEP_rating_trusted_and_anonymized],
dirk@418
   813
                          @"trusted_and_anonymized");
dirk@418
   814
    XCTAssertEqualObjects([session stringFromRating:PEP_rating_fully_anonymous],
dirk@418
   815
                          @"fully_anonymous");
dirk@418
   816
    XCTAssertEqualObjects([session stringFromRating:PEP_rating_mistrust], @"mistrust");
dirk@418
   817
    XCTAssertEqualObjects([session stringFromRating:PEP_rating_b0rken], @"b0rken");
dirk@418
   818
    XCTAssertEqualObjects([session stringFromRating:PEP_rating_under_attack], @"under_attack");
dirk@418
   819
    XCTAssertEqualObjects([session stringFromRating:PEP_rating_undefined], @"undefined");
dirk@418
   820
    XCTAssertEqualObjects([session stringFromRating:500], @"undefined");
dirk@418
   821
}
dirk@418
   822
dirk@431
   823
- (void)testIsPEPUser
dirk@431
   824
{
dirk@431
   825
    PEPSession *session = [PEPSession new];
dirk@431
   826
dirk@431
   827
    PEPIdentity *identMe = [[PEPIdentity alloc]
dirk@431
   828
                            initWithAddress:@"me-myself-and-i@pep-project.org"
dirk@431
   829
                            userID:@"me-myself-and-i"
dirk@452
   830
                            userName:@"pEp Me"
dirk@431
   831
                            isOwn:YES];
dirk@431
   832
    [session mySelf:identMe];
dirk@431
   833
    XCTAssertNotNil(identMe.fingerPrint);
dirk@432
   834
dirk@432
   835
    // PEP_CANNOT_FIND_PERSON == 902
dirk@453
   836
    XCTAssertTrue([session isPEPUser:identMe]);
dirk@431
   837
}
dirk@431
   838
dirk@449
   839
- (void)testXEncStatusForOutgoingEncryptedMail
dirk@449
   840
{
dirk@449
   841
    [self helperXEncStatusForOutgoingEncryptdMailToSelf:NO expectedRating:PEP_rating_reliable];
dirk@449
   842
}
dirk@449
   843
dirk@449
   844
- (void)testXEncStatusForOutgoingSelfEncryptedMail
dirk@449
   845
{
dirk@449
   846
    [self helperXEncStatusForOutgoingEncryptdMailToSelf:YES
dirk@449
   847
                                         expectedRating:PEP_rating_trusted_and_anonymized];
dirk@449
   848
}
dirk@449
   849
dirk@456
   850
- (void)testEncryptMessagesWithoutKeys
dirk@456
   851
{
dirk@456
   852
    PEPSession *session = [PEPSession new];
dirk@456
   853
dirk@456
   854
    PEPIdentity *identMe = [[PEPIdentity alloc]
dirk@456
   855
                            initWithAddress:@"me-myself-and-i@pep-project.org"
dirk@456
   856
                            userID:@"me-myself-and-i"
dirk@456
   857
                            userName:@"pEp Me"
dirk@456
   858
                            isOwn:YES];
dirk@456
   859
    [session mySelf:identMe];
dirk@456
   860
    XCTAssertNotNil(identMe.fingerPrint);
dirk@456
   861
dirk@456
   862
    PEPIdentity *identAlice = [[PEPIdentity alloc]
dirk@456
   863
                               initWithAddress:@"alice@pep-project.org"
dirk@456
   864
                               userID:@"alice"
dirk@456
   865
                               userName:@"pEp Test Alice"
dirk@456
   866
                               isOwn:NO];
dirk@456
   867
dirk@456
   868
    PEPMessage *msg = [PEPMessage new];
dirk@456
   869
    msg.from = identMe;
dirk@456
   870
    msg.to = @[identAlice];
dirk@456
   871
    msg.shortMessage = @"Mail to Alice";
dirk@456
   872
    msg.longMessage = @"Alice?";
dirk@456
   873
    msg.direction = PEP_dir_outgoing;
dirk@456
   874
dirk@456
   875
    PEP_rating clr = [session outgoingColorForMessage:msg];
dirk@456
   876
    XCTAssertEqual(clr, PEP_rating_unencrypted);
dirk@456
   877
dirk@456
   878
    PEPMessage *encMsg;
dirk@456
   879
dirk@456
   880
    PEP_STATUS statusEnc = statusEnc = [session encryptMessage:msg extra:@[] dest:&encMsg];
dirk@456
   881
dirk@456
   882
    XCTAssertEqual(statusEnc, PEP_UNENCRYPTED);
dirk@456
   883
dirk@456
   884
    XCTAssertNotNil(encMsg);
dirk@456
   885
dirk@456
   886
    PEPMessage *decMsg;
dirk@456
   887
    PEPStringList *keys;
dirk@456
   888
    PEP_rating pEpRating = [session decryptMessage:encMsg dest:&decMsg keys:&keys];
dirk@456
   889
    XCTAssertEqual(pEpRating, PEP_rating_unencrypted);
dirk@456
   890
    XCTAssertNotNil(decMsg);
dirk@456
   891
}
dirk@456
   892
dirk@456
   893
/**
dirk@456
   894
 ENGINE-364. Tries to invoke trustPersonalKey on an identity without key,
dirk@456
   895
 giving it a fake fingerprint.
dirk@456
   896
 */
dirk@456
   897
- (void)testTrustPersonalKey
dirk@456
   898
{
dirk@456
   899
    PEPSession *session = [PEPSession new];
dirk@456
   900
dirk@456
   901
    PEPIdentity *identMe = [[PEPIdentity alloc]
dirk@456
   902
                            initWithAddress:@"me-myself-and-i@pep-project.org"
dirk@456
   903
                            userID:@"me-myself-and-i"
dirk@456
   904
                            userName:@"pEp Me"
dirk@456
   905
                            isOwn:YES];
dirk@456
   906
    [session mySelf:identMe];
dirk@456
   907
    XCTAssertNotNil(identMe.fingerPrint);
dirk@456
   908
dirk@456
   909
    // The fingerprint is definitely wrong, we don't have a key
dirk@456
   910
    PEPIdentity *identAlice = [[PEPIdentity alloc]
dirk@456
   911
                               initWithAddress:@"alice@pep-project.org"
dirk@456
   912
                               userID:@"alice"
dirk@456
   913
                               userName:@"pEp Test Alice"
dirk@456
   914
                               isOwn:NO
dirk@456
   915
                               fingerPrint:@"4ABE3AAF59AC32CFE4F86500A9411D176FF00E97"];
dirk@456
   916
dirk@456
   917
    [session trustPersonalKey:identAlice];
dirk@456
   918
}
dirk@456
   919
dirk@457
   920
/**
dirk@457
   921
 ENGINE-381
dirk@457
   922
 */
dirk@457
   923
- (void)testVolatileIdentityRating
dirk@457
   924
{
dirk@457
   925
    PEPSession *session = [PEPSession new];
dirk@457
   926
dirk@457
   927
    PEPIdentity *identMe = [[PEPIdentity alloc]
dirk@457
   928
                            initWithAddress:@"me-myself-and-i@pep-project.org"
dirk@457
   929
                            userID:@"me-myself-and-i"
dirk@457
   930
                            userName:@"pEp Me"
dirk@457
   931
                            isOwn:YES];
dirk@457
   932
    [session mySelf:identMe];
dirk@457
   933
    XCTAssertNotNil(identMe.fingerPrint);
dirk@457
   934
dirk@457
   935
    PEPIdentity *identAlice = [self
dirk@457
   936
                               checkImportingKeyFilePath:@"6FF00E97_sec.asc"
dirk@457
   937
                               address:@"pep.test.alice@pep-project.org"
dirk@457
   938
                               userID:@"alice_user_id"
dirk@457
   939
                               fingerPrint:@"4ABE3AAF59AC32CFE4F86500A9411D176FF00E97"
dirk@457
   940
                               session: session];
dirk@488
   941
    XCTAssertNotNil(identAlice);
dirk@457
   942
dirk@457
   943
    dispatch_group_t identityRatingGroup = dispatch_group_create();
dirk@457
   944
dirk@457
   945
    void (^ratingBlock)(void) = ^{
dirk@457
   946
        PEPSession *innerSession = [PEPSession new];
dirk@457
   947
        PEP_rating rating = [innerSession identityRating:identAlice];
dirk@457
   948
        XCTAssertEqual(rating, PEP_rating_reliable);
dirk@457
   949
    };
dirk@457
   950
dirk@479
   951
    for (int i = 0; i < 4; ++i) {
dirk@457
   952
        dispatch_group_async(identityRatingGroup,
dirk@457
   953
                             dispatch_get_global_queue(QOS_CLASS_USER_INITIATED, 0),
dirk@457
   954
                             ratingBlock);
dirk@457
   955
    }
dirk@457
   956
dirk@479
   957
    for (int i = 0; i < 4; ++i) {
dirk@457
   958
        ratingBlock();
dirk@457
   959
    }
dirk@457
   960
dirk@457
   961
    dispatch_group_wait(identityRatingGroup, DISPATCH_TIME_FOREVER);
dirk@457
   962
}
dirk@457
   963
dirk@485
   964
/** ENGINE-319 */
dirk@485
   965
- (void)testEncryptedMailFromTrustedIdentity
dirk@485
   966
{
dirk@485
   967
    PEPSession *session = [PEPSession new];
dirk@485
   968
dirk@485
   969
    PEPIdentity *identTest001 =
dirk@485
   970
    [self
dirk@490
   971
     checkImportingKeyFilePath:@"iOS Test 001 iostest001@peptest.ch (0x467E45F8) pub.asc"
dirk@485
   972
     address:@"iostest001@peptest.ch"
dirk@485
   973
     userID:@"iOS_Test_001"
dirk@485
   974
     fingerPrint:@"118DD76CC408888101300A0D10807027467E45F8"
dirk@485
   975
     session: session];
dirk@488
   976
    XCTAssertNotNil(identTest001);
dirk@485
   977
}
dirk@485
   978
dirk@449
   979
#pragma mark - configUnencryptedSubject
dirk@449
   980
dirk@449
   981
- (void)testConfigUnencryptedSubject
dirk@449
   982
{
dirk@449
   983
    // Setup Config to encrypt subject
dirk@449
   984
    [PEPObjCAdapter setUnecryptedSubjectEnabled:NO];
dirk@449
   985
dirk@449
   986
    // Write mail to yourself ...
dirk@449
   987
    PEPMessage *encMessage = [self mailWrittenToMySelf];
dirk@449
   988
dirk@449
   989
    // ... and assert subject is encrypted
dirk@449
   990
    XCTAssertEqualObjects(encMessage.shortMessage, @"p≡p", @"Subject should be encrypted");
dirk@449
   991
}
dirk@449
   992
dirk@449
   993
- (void)testConfigUnencryptedSubject_encryptedSubjectDisabled
dirk@449
   994
{
dirk@449
   995
    // Setup Config to not encrypt subject
dirk@449
   996
    [PEPObjCAdapter setUnecryptedSubjectEnabled:YES];
dirk@449
   997
dirk@449
   998
    // Write mail to yourself ...
dirk@449
   999
    PEPMessage *encMessage = [self mailWrittenToMySelf];
dirk@449
  1000
dirk@449
  1001
    // ... and assert the subject is not encrypted
dirk@449
  1002
    XCTAssertNotEqualObjects(encMessage.shortMessage, @"p≡p", @"Subject should not be encrypted");
dirk@449
  1003
}
dirk@449
  1004
andreas@392
  1005
#pragma mark - Helpers
andreas@392
  1006
dirk@439
  1007
- (PEPIdentity *)checkImportingKeyFilePath:(NSString *)filePath address:(NSString *)address
dirk@439
  1008
                                    userID:(NSString *)userID
dirk@439
  1009
                               fingerPrint:(NSString *)fingerPrint
dirk@456
  1010
                                   session:(PEPSession *)session
dirk@437
  1011
{
dirk@456
  1012
    if (!session) {
dirk@456
  1013
        session = [PEPSession new];
dirk@456
  1014
    }
dirk@437
  1015
dirk@488
  1016
    BOOL success = [PEPTestUtils importBundledKey:filePath session:session];
dirk@488
  1017
    XCTAssertTrue(success);
dirk@437
  1018
dirk@488
  1019
    if (success) {
dirk@488
  1020
        // Our test user:
dirk@488
  1021
        PEPIdentity *identTest = [[PEPIdentity alloc]
dirk@488
  1022
                                  initWithAddress:address
dirk@488
  1023
                                  userID:userID
dirk@488
  1024
                                  userName:[NSString stringWithFormat:@"Some User Name %@", userID]
dirk@488
  1025
                                  isOwn:NO];
dirk@437
  1026
dirk@488
  1027
        [session updateIdentity:identTest];
dirk@488
  1028
        XCTAssertNotNil(identTest.fingerPrint);
dirk@488
  1029
        XCTAssertEqualObjects(identTest.fingerPrint, fingerPrint);
dirk@439
  1030
dirk@488
  1031
        return identTest;
dirk@488
  1032
    } else {
dirk@488
  1033
        return nil;
dirk@488
  1034
    }
dirk@439
  1035
}
dirk@439
  1036
dirk@439
  1037
- (PEPIdentity *)checkMySelfImportingKeyFilePath:(NSString *)filePath address:(NSString *)address
dirk@439
  1038
                                          userID:(NSString *)userID
dirk@439
  1039
                                     fingerPrint:(NSString *)fingerPrint
dirk@491
  1040
                                         session:(PEPSession *)session
dirk@439
  1041
{
dirk@488
  1042
    [PEPTestUtils importBundledKey:filePath session:session];
dirk@439
  1043
dirk@439
  1044
    // Our test user:
dirk@439
  1045
    PEPIdentity *identTest = [[PEPIdentity alloc]
dirk@439
  1046
                              initWithAddress:address
dirk@439
  1047
                              userID:userID
dirk@439
  1048
                              userName:[NSString stringWithFormat:@"Some User Name %@", userID]
dirk@439
  1049
                              isOwn:YES
dirk@439
  1050
                              fingerPrint: fingerPrint];
dirk@439
  1051
dirk@439
  1052
    [session mySelf:identTest];
dirk@439
  1053
    XCTAssertNotNil(identTest.fingerPrint);
dirk@439
  1054
    XCTAssertEqualObjects(identTest.fingerPrint, fingerPrint);
dirk@439
  1055
dirk@439
  1056
    return identTest;
dirk@437
  1057
}
dirk@437
  1058
dirk@433
  1059
/**
dirk@433
  1060
 Verifies that a partner ID is really a correct Identity.
dirk@433
  1061
 Usually used on identities imported as keys, since the engine has problems with them.
dirk@433
  1062
 */
dirk@433
  1063
- (void)updateAndVerifyPartnerIdentity:(PEPIdentity *)partnerIdentity session:(PEPSession *)session
dirk@433
  1064
{
dirk@433
  1065
    XCTAssertNotNil(partnerIdentity.fingerPrint);
dirk@433
  1066
    [session updateIdentity:partnerIdentity];
dirk@433
  1067
    XCTAssertNotNil(partnerIdentity.fingerPrint);
dirk@433
  1068
    NSString *fingerprint = partnerIdentity.fingerPrint;
dirk@433
  1069
    partnerIdentity.fingerPrint = nil;
dirk@433
  1070
    [session updateIdentity:partnerIdentity];
dirk@433
  1071
    XCTAssertNotNil(partnerIdentity.fingerPrint);
dirk@433
  1072
    XCTAssertEqualObjects(partnerIdentity.fingerPrint, fingerprint);
dirk@433
  1073
}
dirk@433
  1074
andreas@416
  1075
- (PEPMessage *)mailWrittenToMySelf
andreas@416
  1076
{
andreas@416
  1077
    PEPSession *session = [PEPSession new];
andreas@416
  1078
andreas@416
  1079
    // Write a e-mail to yourself ...
andreas@416
  1080
    PEPIdentity *me = [PEPTestUtils ownPepIdentityWithAddress:@"me@peptest.ch"
andreas@416
  1081
                                                     userName:@"userName"];
andreas@416
  1082
    [session mySelf:me];
andreas@416
  1083
andreas@416
  1084
    NSString *shortMessage = @"Subject";
andreas@416
  1085
    NSString *longMessage = @"Oh, this is a long body text!";
andreas@416
  1086
    PEPMessage *mail = [PEPTestUtils mailFrom:me
andreas@416
  1087
                                      toIdent:me
andreas@416
  1088
                                 shortMessage:shortMessage
andreas@416
  1089
                                  longMessage:longMessage
andreas@416
  1090
                                     outgoing:YES];
andreas@416
  1091
    PEPMessage *encMessage;
andreas@416
  1092
    [session encryptMessage:mail identity:me dest:&encMessage];
andreas@416
  1093
andreas@416
  1094
    return encMessage;
andreas@416
  1095
}
andreas@416
  1096
andreas@392
  1097
- (PEPMessage *)internalEncryptToMySelfKeys:(PEPStringList **)keys
andreas@392
  1098
{
andreas@392
  1099
    PEPSession *session = [PEPSession new];
andreas@411
  1100
    
andreas@411
  1101
    PEPIdentity *me = [PEPTestUtils ownPepIdentityWithAddress:@"me@peptest.ch"
andreas@411
  1102
                                                     userName:@"userName"];
andreas@392
  1103
    [session mySelf:me];
andreas@392
  1104
    XCTAssertNotNil(me.fingerPrint);
andreas@392
  1105
andreas@392
  1106
    // Create draft
andreas@392
  1107
    NSString *shortMessage = @"Subject";
andreas@392
  1108
    NSString *longMessage = @"Oh, this is a long body text!";
andreas@392
  1109
    PEPMessage *mail = [PEPTestUtils mailFrom:me toIdent:me shortMessage:shortMessage longMessage:longMessage outgoing:YES];
andreas@392
  1110
andreas@392
  1111
    PEPMessage *encMessage;
andreas@392
  1112
    PEP_STATUS status = [session encryptMessage:mail identity:me dest:&encMessage];
andreas@392
  1113
    XCTAssertEqual(status, 0);
andreas@392
  1114
    XCTAssertEqualObjects(encMessage.shortMessage, @"p≡p");
andreas@392
  1115
andreas@392
  1116
    PEPMessage *unencDict;
andreas@392
  1117
    PEP_rating rating = [session decryptMessage:encMessage dest:&unencDict keys:keys];
andreas@392
  1118
    XCTAssertGreaterThanOrEqual(rating, PEP_rating_reliable);
andreas@392
  1119
andreas@392
  1120
    XCTAssertEqualObjects(unencDict.shortMessage, shortMessage);
andreas@392
  1121
    XCTAssertEqualObjects(unencDict.longMessage, longMessage);
andreas@392
  1122
andreas@392
  1123
    return unencDict;
andreas@392
  1124
}
andreas@392
  1125
andreas@392
  1126
- (void)pEpCleanUp
andreas@392
  1127
{
dirk@470
  1128
    [PEPTestUtils cleanUp];
andreas@392
  1129
}
andreas@392
  1130
andreas@392
  1131
- (void)pEpSetUp
andreas@392
  1132
{
andreas@392
  1133
}
andreas@392
  1134
dirk@424
  1135
- (void)helperXEncStatusForOutgoingEncryptdMailToSelf:(BOOL)toSelf
dirk@424
  1136
                                       expectedRating:(PEP_rating)expectedRating
dirk@422
  1137
{
dirk@422
  1138
    PEPSession *session = [PEPSession new];
dirk@422
  1139
dirk@422
  1140
    // Partner pubkey for the test:
dirk@422
  1141
    // pEp Test Alice (test key don't use) <pep.test.alice@pep-project.org>
dirk@422
  1142
    // 4ABE3AAF59AC32CFE4F86500A9411D176FF00E97
dirk@488
  1143
    [PEPTestUtils importBundledKey:@"0x6FF00E97.asc" session:session];
dirk@422
  1144
dirk@422
  1145
    PEPIdentity *identAlice = [[PEPIdentity alloc]
dirk@422
  1146
                               initWithAddress:@"pep.test.alice@pep-project.org"
dirk@422
  1147
                               userID:ownUserId
dirk@422
  1148
                               userName:@"pEp Test Alice"
dirk@422
  1149
                               isOwn:NO
dirk@433
  1150
                               fingerPrint:@"4ABE3AAF59AC32CFE4F86500A9411D176FF00E97"];
dirk@433
  1151
    [self updateAndVerifyPartnerIdentity:identAlice session:session];
dirk@422
  1152
dirk@422
  1153
    PEPIdentity *identMe = [[PEPIdentity alloc]
dirk@422
  1154
                               initWithAddress:@"me-myself-and-i@pep-project.org"
dirk@422
  1155
                               userID:@"me-myself-and-i"
dirk@452
  1156
                               userName:@"pEp Me"
dirk@422
  1157
                               isOwn:YES];
dirk@422
  1158
    [session mySelf:identMe];
dirk@422
  1159
    XCTAssertNotNil(identMe.fingerPrint);
dirk@422
  1160
dirk@422
  1161
    PEPMessage *msg = [PEPMessage new];
dirk@422
  1162
    msg.from = identMe;
dirk@422
  1163
    msg.to = @[identAlice];
dirk@422
  1164
    msg.shortMessage = @"Mail to Alice";
dirk@422
  1165
    msg.longMessage = @"Alice?";
dirk@422
  1166
    msg.direction = PEP_dir_outgoing;
dirk@422
  1167
dirk@422
  1168
    PEP_rating clr = [session outgoingColorForMessage:msg];
dirk@424
  1169
    XCTAssertEqual(clr, PEP_rating_reliable);
dirk@422
  1170
dirk@423
  1171
    PEPMessage *encMsg;
dirk@424
  1172
dirk@424
  1173
    PEP_STATUS statusEnc = PEP_VERSION_MISMATCH;
dirk@424
  1174
    if (toSelf) {
dirk@424
  1175
        statusEnc = [session encryptMessage:msg identity:identMe dest:&encMsg];
dirk@424
  1176
    } else {
dirk@424
  1177
         statusEnc = [session encryptMessage:msg extra:@[] dest:&encMsg];
dirk@424
  1178
    }
dirk@422
  1179
dirk@423
  1180
    XCTAssertEqual(statusEnc, PEP_STATUS_OK);
dirk@423
  1181
dirk@423
  1182
    XCTAssertNotNil(encMsg);
dirk@423
  1183
dirk@423
  1184
    PEPMessage *decMsg;
dirk@423
  1185
    PEPStringList *keys;
dirk@423
  1186
    PEP_rating pEpRating = [session decryptMessage:encMsg dest:&decMsg keys:&keys];
dirk@424
  1187
    XCTAssertEqual(pEpRating, expectedRating);
dirk@423
  1188
    XCTAssertNotNil(decMsg);
dirk@423
  1189
dirk@423
  1190
    NSArray * encStatusField = nil;
dirk@423
  1191
    for (NSArray *field in decMsg.optionalFields) {
dirk@423
  1192
        NSString *header = [field[0] lowercaseString];
dirk@423
  1193
        if ([header isEqualToString:@"x-encstatus"]) {
dirk@423
  1194
            encStatusField = field;
dirk@423
  1195
        }
dirk@423
  1196
    }
dirk@423
  1197
    XCTAssertNotNil(encStatusField);
dirk@423
  1198
    if (encStatusField) {
dirk@423
  1199
        PEP_rating outgoingRating = [session ratingFromString:encStatusField[1]];
dirk@424
  1200
        XCTAssertEqual(outgoingRating, expectedRating);
dirk@423
  1201
    }
dirk@422
  1202
}
dirk@422
  1203
andreas@392
  1204
@end