pEpObjCTests/PEPSessionTest.m
author Dirk Zimmermann <dirk@pep-project.org>
Mon, 05 Nov 2018 17:36:09 +0100
branchIOSAD-103
changeset 763 b4abd1a328fb
parent 762 379d410cfdfc
child 764 a6a8de86841f
permissions -rw-r--r--
IOSAD-103 re-use sync start
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"
dirk@577
    15
#import "PEPAttachment.h"
andreas@392
    16
#import "PEPTestUtils.h"
dirk@706
    17
#import "PEPSync.h"
dirk@732
    18
#import "PEPSendMessageDelegate.h"
dirk@706
    19
dirk@711
    20
#import "PEPSessionTestNotifyHandshakeDelegate.h"
dirk@711
    21
#import "PEPSessionTestSendMessageDelegate.h"
andreas@392
    22
andreas@392
    23
@interface PEPSessionTest : XCTestCase
dirk@706
    24
dirk@706
    25
@property (nonatomic) PEPSync *sync;
dirk@711
    26
@property (nonatomic) PEPSessionTestSendMessageDelegate *sendMessageDelegate;
dirk@711
    27
@property (nonatomic) PEPSessionTestNotifyHandshakeDelegate *notifyHandshakeDelegate;
dirk@706
    28
andreas@392
    29
@end
andreas@392
    30
andreas@392
    31
@implementation PEPSessionTest
andreas@392
    32
andreas@392
    33
- (void)setUp
andreas@392
    34
{
andreas@392
    35
    [super setUp];
dirk@706
    36
dirk@739
    37
    [self pEpCleanUp];
dirk@739
    38
dirk@763
    39
    [self startSync];
dirk@706
    40
dirk@601
    41
    [PEPObjCAdapter setUnEncryptedSubjectEnabled:NO];
andreas@392
    42
}
andreas@392
    43
dirk@525
    44
- (void)tearDown
dirk@525
    45
{
dirk@706
    46
    [self.sync shutdown];
dirk@706
    47
andreas@392
    48
    [self pEpCleanUp];
andreas@392
    49
    [super tearDown];
andreas@392
    50
}
andreas@392
    51
andreas@392
    52
- (void)testTrustWords
andreas@392
    53
{
andreas@392
    54
    PEPSession *session = [PEPSession new];
andreas@392
    55
dirk@531
    56
    NSError *error = nil;
dirk@531
    57
    NSArray *trustwords = [session
dirk@531
    58
                           trustwordsForFingerprint:@"DB47DB47DB47DB47DB47DB47DB47DB47DB47DB47"
dirk@531
    59
                           languageID:@"en"
dirk@531
    60
                           shortened:false
dirk@531
    61
                           error:&error];
dirk@531
    62
    XCTAssertNil(error);
andreas@392
    63
    XCTAssertEqual([trustwords count], 10);
andreas@392
    64
andreas@392
    65
    for(id word in trustwords)
andreas@392
    66
        XCTAssertEqualObjects(word, @"BAPTISMAL");
andreas@392
    67
}
andreas@392
    68
andreas@392
    69
- (void)testGenKey
andreas@392
    70
{
andreas@392
    71
    PEPSession *session = [PEPSession new];
andreas@392
    72
andreas@392
    73
    PEPIdentity *identMe = [[PEPIdentity alloc]
andreas@392
    74
                            initWithAddress:@"pep.test.iosgenkey@pep-project.org"
andreas@392
    75
                            userID:@"Me"
andreas@392
    76
                            userName:@"pEp Test iOS GenKey"
andreas@392
    77
                            isOwn:YES];
andreas@392
    78
dirk@532
    79
    NSError *error = nil;
dirk@532
    80
    XCTAssertTrue([session mySelf:identMe error:&error]);
dirk@532
    81
    XCTAssertNil(error);
andreas@392
    82
andreas@392
    83
    XCTAssertNotNil(identMe.fingerPrint);
andreas@392
    84
    XCTAssertNotEqual(identMe.commType, PEP_ct_unknown);
andreas@392
    85
dirk@567
    86
    XCTAssertTrue([identMe isPEPUser:session error:&error]);
andreas@392
    87
}
andreas@392
    88
andreas@392
    89
- (void)testMySelfCommType
andreas@392
    90
{
andreas@392
    91
    PEPSession *session = [PEPSession new];
andreas@392
    92
andreas@392
    93
    PEPIdentity *identMe = [[PEPIdentity alloc]
andreas@392
    94
                            initWithAddress:@"pep.test.iosgenkey@pep-project.org"
dirk@533
    95
                            userID:@"pep.test.iosgenkey@pep-project.org_userID"
andreas@392
    96
                            userName:@"pEp Test iOS GenKey"
andreas@392
    97
                            isOwn:YES];
andreas@392
    98
dirk@532
    99
    NSError *error = nil;
dirk@532
   100
    XCTAssertTrue([session mySelf:identMe error:&error]);
dirk@532
   101
    XCTAssertNil(error);
andreas@392
   102
andreas@392
   103
    XCTAssertNotNil(identMe.fingerPrint);
andreas@392
   104
    XCTAssertNotEqual(identMe.commType, PEP_ct_unknown);
andreas@392
   105
dirk@567
   106
    XCTAssertTrue([identMe isPEPUser:session error:&error]);
andreas@392
   107
andreas@392
   108
    dispatch_queue_t queue = dispatch_get_global_queue(QOS_CLASS_USER_INITIATED, 0);
andreas@392
   109
    dispatch_sync(queue, ^{
dirk@532
   110
        NSError *innerError = nil;
andreas@392
   111
        PEPSession *session2 = [PEPSession new];
andreas@392
   112
andreas@392
   113
        // Now simulate an update from the app, which usually only caches
andreas@392
   114
        // kPepUsername, kPepAddress and optionally kPepUserID.
andreas@392
   115
        PEPIdentity *identMe2 = [[PEPIdentity alloc]
andreas@392
   116
                                 initWithAddress:identMe.address
andreas@392
   117
                                 userID:identMe.userID
andreas@392
   118
                                 userName:identMe.userName
andreas@392
   119
                                 isOwn:NO];
dirk@532
   120
dirk@532
   121
        XCTAssertTrue([session2 mySelf:identMe2 error:&innerError]);
dirk@532
   122
        XCTAssertNil(innerError);
dirk@532
   123
andreas@392
   124
        XCTAssertNotNil(identMe2.fingerPrint);
dirk@567
   125
        XCTAssertTrue([identMe2 isPEPUser:session error:&innerError]);
andreas@392
   126
        XCTAssertEqualObjects(identMe2.fingerPrint, identMe.fingerPrint);
andreas@392
   127
andreas@392
   128
        // Now pretend the app only knows kPepUsername and kPepAddress
andreas@411
   129
        PEPIdentity *identMe3 = [PEPTestUtils foreignPepIdentityWithAddress:identMe.address
andreas@411
   130
                                                                   userName:identMe.userName];
dirk@532
   131
        XCTAssertTrue([session2 mySelf:identMe3 error:&innerError]);
dirk@532
   132
        XCTAssertNil(innerError);
dirk@532
   133
andreas@392
   134
        XCTAssertNotNil(identMe3.fingerPrint);
dirk@567
   135
        XCTAssertTrue([identMe3 isPEPUser:session error:&innerError]);
andreas@392
   136
        XCTAssertEqualObjects(identMe3.fingerPrint, identMe.fingerPrint);
andreas@392
   137
andreas@392
   138
        XCTAssertEqualObjects(identMe.address, identMe2.address);
andreas@392
   139
        XCTAssertEqualObjects(identMe.address, identMe3.address);
andreas@392
   140
        XCTAssertEqual(identMe.commType, identMe2.commType);
andreas@392
   141
        XCTAssertEqual(identMe.commType, identMe3.commType);
andreas@392
   142
    });
andreas@392
   143
}
andreas@392
   144
dirk@435
   145
- (void)testPartnerWithoutFingerPrint
dirk@435
   146
{
dirk@435
   147
    PEPSession *session = [PEPSession new];
dirk@435
   148
dirk@435
   149
    PEPIdentity *identRandom = [[PEPIdentity alloc]
dirk@435
   150
                                initWithAddress:@"does_not_exist@example.com"
dirk@435
   151
                                userID:@"got_out"
dirk@435
   152
                                userName:@"No Way Not Even Alice"
dirk@435
   153
                                isOwn:NO];
dirk@435
   154
dirk@532
   155
    NSError *error = nil;
dirk@532
   156
    XCTAssertTrue([session updateIdentity:identRandom error:&error]);
dirk@532
   157
    XCTAssertNil(error);
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@529
   186
    XCTAssertEqual([self ratingForIdentity:me session:session], 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@529
   195
    XCTAssertEqual([self ratingForIdentity:alice session:session], PEP_rating_reliable);
dirk@439
   196
}
dirk@439
   197
dirk@546
   198
/** ENGINE-409 */
dirk@546
   199
- (void)testIdentityRatingMistrustReset
dirk@546
   200
{
dirk@546
   201
    PEPSession *session = [PEPSession new];
dirk@546
   202
dirk@546
   203
    PEPIdentity *me = [[PEPIdentity alloc]
dirk@546
   204
                       initWithAddress:@"me@example.org"
dirk@546
   205
                       userID:@"me_myself"
dirk@546
   206
                       userName:@"Me Me"
dirk@546
   207
                       isOwn:YES];
dirk@546
   208
dirk@546
   209
    NSError *error = nil;
dirk@546
   210
    XCTAssertTrue([session mySelf:me error:&error]);
dirk@546
   211
    XCTAssertNil(error);
dirk@546
   212
dirk@546
   213
    XCTAssertNotNil(me.fingerPrint);
dirk@546
   214
    XCTAssertEqual([self ratingForIdentity:me session:session], PEP_rating_trusted_and_anonymized);
dirk@546
   215
dirk@546
   216
    PEPIdentity *alice = [self
dirk@546
   217
                          checkImportingKeyFilePath:@"6FF00E97_sec.asc"
dirk@546
   218
                          address:@"pep.test.alice@pep-project.org"
dirk@546
   219
                          userID:@"This Is Alice"
dirk@546
   220
                          fingerPrint:@"4ABE3AAF59AC32CFE4F86500A9411D176FF00E97"
dirk@546
   221
                          session: session];
dirk@546
   222
    XCTAssertNotNil(alice);
dirk@546
   223
    XCTAssertEqual([self ratingForIdentity:alice session:session], PEP_rating_reliable);
dirk@546
   224
dirk@546
   225
    XCTAssertTrue([session keyMistrusted:alice error:&error]);
dirk@546
   226
    XCTAssertNil(error);
dirk@546
   227
    XCTAssertEqual([self ratingForIdentity:alice session:session], PEP_rating_have_no_key);
dirk@546
   228
}
dirk@546
   229
dirk@446
   230
- (void)testIdentityRatingTrustResetMistrustUndo
dirk@445
   231
{
dirk@445
   232
    PEPSession *session = [PEPSession new];
dirk@445
   233
dirk@460
   234
    PEPIdentity *me = [[PEPIdentity alloc]
dirk@460
   235
                       initWithAddress:@"me@example.org"
dirk@460
   236
                       userID:@"me_myself"
dirk@460
   237
                       userName:@"Me Me"
dirk@460
   238
                       isOwn:YES];
dirk@532
   239
dirk@532
   240
    NSError *error = nil;
dirk@532
   241
    XCTAssertTrue([session mySelf:me error:&error]);
dirk@532
   242
    XCTAssertNil(error);
dirk@532
   243
dirk@460
   244
    XCTAssertNotNil(me.fingerPrint);
dirk@529
   245
    XCTAssertEqual([self ratingForIdentity:me session:session], PEP_rating_trusted_and_anonymized);
dirk@445
   246
dirk@445
   247
    PEPIdentity *alice = [self
dirk@445
   248
                          checkImportingKeyFilePath:@"6FF00E97_sec.asc"
dirk@445
   249
                          address:@"pep.test.alice@pep-project.org"
dirk@445
   250
                          userID:@"This Is Alice"
dirk@456
   251
                          fingerPrint:@"4ABE3AAF59AC32CFE4F86500A9411D176FF00E97"
dirk@456
   252
                          session: session];
dirk@488
   253
    XCTAssertNotNil(alice);
dirk@529
   254
    XCTAssertEqual([self ratingForIdentity:alice session:session], PEP_rating_reliable);
dirk@445
   255
dirk@534
   256
    XCTAssertTrue([session trustPersonalKey:alice error:&error]);
dirk@534
   257
    XCTAssertNil(error);
dirk@529
   258
    XCTAssertEqual([self ratingForIdentity:alice session:session], PEP_rating_trusted);
dirk@446
   259
dirk@545
   260
    XCTAssertTrue([session keyResetTrust:alice error:&error]);
dirk@545
   261
    XCTAssertNil(error);
dirk@529
   262
    XCTAssertEqual([self ratingForIdentity:alice session:session], PEP_rating_reliable);
dirk@446
   263
dirk@536
   264
    XCTAssertTrue([session keyMistrusted:alice error:&error]);
dirk@536
   265
    XCTAssertNil(error);
dirk@529
   266
    XCTAssertEqual([self ratingForIdentity:alice session:session], PEP_rating_have_no_key);
dirk@445
   267
}
dirk@445
   268
dirk@478
   269
/** ENGINE-384 */
dirk@472
   270
- (void)testIdentityRatingCrash
dirk@472
   271
{
dirk@472
   272
    PEPSession *session = [PEPSession new];
dirk@472
   273
dirk@472
   274
    PEPIdentity *me = [[PEPIdentity alloc]
dirk@472
   275
                       initWithAddress:@"me@example.org"
dirk@472
   276
                       userID:@"me_myself"
dirk@472
   277
                       userName:@"Me Me"
dirk@472
   278
                       isOwn:YES];
dirk@532
   279
    NSError *error = nil;
dirk@532
   280
    XCTAssertTrue([session mySelf:me error:&error]);
dirk@532
   281
    XCTAssertNil(error);
dirk@532
   282
dirk@472
   283
    XCTAssertNotNil(me.fingerPrint);
dirk@529
   284
    XCTAssertEqual([self ratingForIdentity:me session:session], PEP_rating_trusted_and_anonymized);
dirk@472
   285
dirk@472
   286
    PEPIdentity *alice = [self
dirk@472
   287
                          checkImportingKeyFilePath:@"6FF00E97_sec.asc"
dirk@472
   288
                          address:@"pep.test.alice@pep-project.org"
dirk@472
   289
                          userID:@"This Is Alice"
dirk@472
   290
                          fingerPrint:@"4ABE3AAF59AC32CFE4F86500A9411D176FF00E97"
dirk@472
   291
                          session: session];
dirk@488
   292
    XCTAssertNotNil(alice);
dirk@529
   293
    XCTAssertEqual([self ratingForIdentity:alice session:session], PEP_rating_reliable);
dirk@472
   294
dirk@534
   295
    XCTAssertTrue([session trustPersonalKey:alice error:&error]);
dirk@534
   296
    XCTAssertNil(error);
dirk@529
   297
    XCTAssertEqual([self ratingForIdentity:alice session:session], PEP_rating_trusted);
dirk@472
   298
dirk@545
   299
    XCTAssertTrue([session keyResetTrust:alice error:&error]);
dirk@545
   300
    XCTAssertNil(error);
dirk@529
   301
    XCTAssertEqual([self ratingForIdentity:alice session:session], PEP_rating_reliable);
dirk@472
   302
dirk@536
   303
    XCTAssertTrue([session keyMistrusted:alice error:&error]);
dirk@536
   304
    XCTAssertNil(error);
dirk@529
   305
    XCTAssertEqual([self ratingForIdentity:alice session:session], PEP_rating_have_no_key);
dirk@472
   306
}
dirk@472
   307
dirk@458
   308
/**
dirk@458
   309
 Try to provoke a SQLITE_BUSY (ENGINE-374)
dirk@458
   310
 */
dirk@458
   311
- (void)testIdentityRatingTrustResetMistrustUndoBusy
dirk@458
   312
{
dirk@458
   313
    PEPSession *session = [PEPSession new];
dirk@458
   314
dirk@459
   315
    PEPIdentity *me = [[PEPIdentity alloc]
dirk@459
   316
                       initWithAddress:@"me@example.org"
dirk@459
   317
                       userID:@"me_myself"
dirk@459
   318
                       userName:@"Me Me"
dirk@459
   319
                       isOwn:YES];
dirk@532
   320
    NSError *error = nil;
dirk@532
   321
    XCTAssertTrue([session mySelf:me error:&error]);
dirk@532
   322
    XCTAssertNil(error);
dirk@532
   323
dirk@459
   324
    XCTAssertNotNil(me.fingerPrint);
dirk@529
   325
    XCTAssertEqual([self ratingForIdentity:me session:session], PEP_rating_trusted_and_anonymized);
dirk@458
   326
dirk@458
   327
    PEPIdentity *alice = [self
dirk@458
   328
                          checkImportingKeyFilePath:@"6FF00E97_sec.asc"
dirk@458
   329
                          address:@"pep.test.alice@pep-project.org"
dirk@458
   330
                          userID:@"This Is Alice"
dirk@458
   331
                          fingerPrint:@"4ABE3AAF59AC32CFE4F86500A9411D176FF00E97"
dirk@458
   332
                          session: session];
dirk@488
   333
    XCTAssertNotNil(alice);
dirk@529
   334
    XCTAssertEqual([self ratingForIdentity:alice session:session], PEP_rating_reliable);
dirk@458
   335
dirk@458
   336
    void (^encryptingBlock)(void) = ^{
dirk@458
   337
        PEPSession *innerSession = [PEPSession new];
dirk@458
   338
        PEPMessage *msg = [PEPMessage new];
dirk@458
   339
        msg.from = me;
dirk@458
   340
        msg.to = @[alice];
dirk@458
   341
        msg.shortMessage = @"The subject";
dirk@458
   342
        msg.longMessage = @"Lots and lots of text";
dirk@476
   343
        msg.direction = PEP_dir_outgoing;
dirk@526
   344
dirk@526
   345
        PEP_STATUS status;
dirk@526
   346
        NSError *error = nil;
dirk@526
   347
        PEPMessage *encMsg = [innerSession
dirk@526
   348
                              encryptMessage:msg
dirk@557
   349
                              forSelf:me
dirk@556
   350
                              extraKeys:nil
dirk@526
   351
                              status:&status error:&error];
dirk@458
   352
        XCTAssertEqual(status, PEP_STATUS_OK);
dirk@526
   353
        XCTAssertNotNil(encMsg);
dirk@458
   354
    };
dirk@458
   355
dirk@458
   356
    dispatch_group_t backgroundGroup = dispatch_group_create();
dirk@458
   357
    dispatch_group_async(backgroundGroup,
dirk@458
   358
                         dispatch_get_global_queue(QOS_CLASS_USER_INITIATED, 0), encryptingBlock);
dirk@458
   359
dirk@534
   360
    XCTAssertTrue([session trustPersonalKey:alice error:&error]);
dirk@534
   361
    XCTAssertNil(error);
dirk@529
   362
    XCTAssertEqual([self ratingForIdentity:alice session:session], PEP_rating_trusted);
dirk@458
   363
dirk@545
   364
    XCTAssertTrue([session keyResetTrust:alice error:&error]);
dirk@545
   365
    XCTAssertNil(error);
dirk@529
   366
    XCTAssertEqual([self ratingForIdentity:alice session:session], PEP_rating_reliable);
dirk@458
   367
dirk@536
   368
    XCTAssertTrue([session keyMistrusted:alice error:&error]);
dirk@536
   369
    XCTAssertNil(error);
dirk@529
   370
    XCTAssertEqual([self ratingForIdentity:alice session:session], PEP_rating_have_no_key);
dirk@458
   371
}
dirk@458
   372
andreas@392
   373
- (void)testOutgoingColors
andreas@392
   374
{
andreas@392
   375
    PEPSession *session = [PEPSession new];
andreas@392
   376
andreas@392
   377
    // Our test user :
andreas@392
   378
    // pEp Test Alice (test key don't use) <pep.test.alice@pep-project.org>
andreas@392
   379
    // 4ABE3AAF59AC32CFE4F86500A9411D176FF00E97
dirk@488
   380
    XCTAssertTrue([PEPTestUtils importBundledKey:@"6FF00E97_sec.asc" session:session]);
andreas@392
   381
andreas@392
   382
    // Our test user :
dirk@440
   383
    PEPIdentity *identAlice = [self
dirk@440
   384
                               checkMySelfImportingKeyFilePath:@"6FF00E97_sec.asc"
dirk@440
   385
                               address:@"pep.test.alice@pep-project.org"
dirk@440
   386
                               userID:@"Alice_User_ID"
dirk@491
   387
                               fingerPrint:@"4ABE3AAF59AC32CFE4F86500A9411D176FF00E97"
dirk@491
   388
                               session:session];
andreas@392
   389
andreas@392
   390
    //Message
andreas@392
   391
dirk@441
   392
    {
dirk@441
   393
        PEPIdentity *identUnknownBob = [[PEPIdentity alloc]
dirk@441
   394
                                        initWithAddress:@"pep.test.unknown.bob@pep-project.org"
dirk@441
   395
                                        userID:@"4242" userName:@"pEp Test Bob Unknown"
dirk@441
   396
                                        isOwn:NO];
dirk@441
   397
dirk@441
   398
        PEPMessage *msgGray = [PEPMessage new];
dirk@441
   399
        msgGray.from = identAlice;
dirk@441
   400
        msgGray.to = @[identUnknownBob];
dirk@441
   401
        msgGray.shortMessage = @"All Gray Test";
dirk@441
   402
        msgGray.longMessage = @"This is a text content";
dirk@441
   403
        msgGray.direction = PEP_dir_outgoing;
dirk@441
   404
dirk@528
   405
        NSError *error = nil;
dirk@528
   406
dirk@441
   407
        // Test with unknown Bob
dirk@653
   408
        NSNumber *numRating = [self
dirk@653
   409
                               testOutgoingRatingForMessage:msgGray
dirk@653
   410
                               session:session
dirk@653
   411
                               error:&error];
dirk@573
   412
        XCTAssertNotNil(numRating);
dirk@573
   413
        XCTAssertNil(error);
dirk@573
   414
        XCTAssertEqual(numRating.pEpRating, PEP_rating_unencrypted);
dirk@441
   415
    }
dirk@441
   416
dirk@441
   417
    PEPIdentity *identBob = [self
dirk@441
   418
                             checkImportingKeyFilePath:@"0xC9C2EE39.asc"
dirk@441
   419
                             address:@"pep.test.bob@pep-project.org"
dirk@441
   420
                             userID:@"42"
dirk@456
   421
                             fingerPrint:@"BFCDB7F301DEEEBBF947F29659BFF488C9C2EE39"
dirk@456
   422
                             session: session];
dirk@488
   423
    XCTAssertNotNil(identBob);
dirk@438
   424
andreas@392
   425
    PEPMessage *msg = [PEPMessage new];
andreas@392
   426
    msg.from = identAlice;
dirk@438
   427
    msg.to = @[identBob];
dirk@441
   428
    msg.shortMessage = @"All Gray Test";
andreas@392
   429
    msg.longMessage = @"This is a text content";
andreas@392
   430
    msg.direction = PEP_dir_outgoing;
andreas@392
   431
dirk@528
   432
    NSError *error = nil;
dirk@528
   433
dirk@441
   434
    // Should be yellow, since no handshake happened.
dirk@653
   435
    NSNumber *numRating = [self testOutgoingRatingForMessage:msg session:session error:&error];
dirk@573
   436
    XCTAssertNotNil(numRating);
dirk@528
   437
    XCTAssertNil(error);
dirk@573
   438
    XCTAssertEqual(numRating.pEpRating, PEP_rating_reliable);
andreas@392
   439
dirk@573
   440
    PEP_rating rating = [self ratingForIdentity:identBob session:session];
dirk@528
   441
    XCTAssertEqual(rating, PEP_rating_reliable);
andreas@392
   442
andreas@392
   443
    // Let' say we got that handshake, set PEP_ct_confirmed in Bob's identity
dirk@534
   444
    XCTAssertTrue([session trustPersonalKey:identBob error:&error]);
dirk@534
   445
    XCTAssertNil(error);
andreas@392
   446
andreas@392
   447
    // This time it should be green
dirk@653
   448
    numRating = [self testOutgoingRatingForMessage:msg session:session error:&error];
dirk@573
   449
    XCTAssertNotNil(numRating);
dirk@573
   450
    XCTAssertNil(error);
dirk@573
   451
    XCTAssertEqual(numRating.pEpRating, PEP_rating_trusted);
andreas@392
   452
dirk@529
   453
    rating = [self ratingForIdentity:identBob session:session];
dirk@528
   454
    XCTAssertEqual(rating, PEP_rating_trusted);
andreas@392
   455
andreas@392
   456
    // Let' say we undo handshake
dirk@545
   457
    XCTAssertTrue([session keyResetTrust:identBob error:&error]);
dirk@545
   458
    XCTAssertNil(error);
andreas@392
   459
andreas@392
   460
    // Yellow ?
dirk@653
   461
    numRating = [self testOutgoingRatingForMessage:msg session:session error:&error];
dirk@573
   462
    XCTAssertNotNil(numRating);
dirk@573
   463
    XCTAssertNil(error);
dirk@573
   464
    XCTAssertEqual(numRating.pEpRating, PEP_rating_reliable);
andreas@392
   465
andreas@392
   466
    // mistrust Bob
dirk@536
   467
    XCTAssertTrue([session keyMistrusted:identBob error:&error]);
dirk@536
   468
    XCTAssertNil(error);
andreas@392
   469
dirk@444
   470
    identBob.fingerPrint = nil;
dirk@532
   471
    XCTAssertTrue([session updateIdentity:identBob error:&error]);
dirk@532
   472
    XCTAssertNil(error);
dirk@441
   473
    XCTAssertNil(identBob.fingerPrint);
dirk@441
   474
andreas@392
   475
    // Gray == PEP_rating_unencrypted
dirk@653
   476
    numRating = [self testOutgoingRatingForMessage:msg session:session error:&error];
dirk@573
   477
    XCTAssertNotNil(numRating);
dirk@573
   478
    XCTAssertNil(error);
dirk@573
   479
    XCTAssertEqual(numRating.pEpRating, PEP_rating_unencrypted);
andreas@392
   480
}
andreas@392
   481
andreas@392
   482
andreas@392
   483
- (void)testOutgoingBccColors
andreas@392
   484
{
andreas@392
   485
    PEPSession *session = [PEPSession new];
andreas@392
   486
andreas@392
   487
    // Our test user :
andreas@392
   488
    // pEp Test Alice (test key don't use) <pep.test.alice@pep-project.org>
andreas@392
   489
    // 4ABE3AAF59AC32CFE4F86500A9411D176FF00E97
dirk@488
   490
    XCTAssertTrue([PEPTestUtils importBundledKey:@"6FF00E97_sec.asc" session:session]);
andreas@392
   491
andreas@392
   492
    PEPIdentity *identAlice = [[PEPIdentity alloc]
andreas@392
   493
                               initWithAddress:@"pep.test.alice@pep-project.org"
andreas@392
   494
                               userID:ownUserId
andreas@392
   495
                               userName:@"pEp Test Alice"
andreas@392
   496
                               isOwn:YES
andreas@392
   497
                               fingerPrint:@"4ABE3AAF59AC32CFE4F86500A9411D176FF00E97"];
andreas@392
   498
dirk@532
   499
    NSError *error = nil;
dirk@532
   500
    XCTAssertTrue([session mySelf:identAlice error:&error]);
dirk@532
   501
    XCTAssertNil(error);
andreas@392
   502
andreas@392
   503
    PEPMessage *msg = [PEPMessage new];
andreas@392
   504
    msg.from = identAlice;
andreas@392
   505
    msg.to = @[[[PEPIdentity alloc] initWithAddress:@"pep.test.bob@pep-project.org"
andreas@392
   506
                                             userID:@"42" userName:@"pEp Test Bob" isOwn:NO]];
andreas@392
   507
    msg.shortMessage = @"All Green Test";
andreas@392
   508
    msg.longMessage = @"This is a text content";
andreas@392
   509
    msg.direction = PEP_dir_outgoing;
andreas@392
   510
andreas@392
   511
    // Test with unknown Bob
dirk@528
   512
    PEP_rating rating;
dirk@653
   513
    NSNumber *numRating = [self testOutgoingRatingForMessage:msg session:session error:&error];
dirk@573
   514
    XCTAssertNotNil(numRating);
dirk@573
   515
    XCTAssertNil(error);
dirk@573
   516
    XCTAssertEqual(numRating.pEpRating, PEP_rating_unencrypted);
andreas@392
   517
andreas@392
   518
    // Now let see with bob's pubkey already known
andreas@392
   519
    // pEp Test Bob (test key, don't use) <pep.test.bob@pep-project.org>
andreas@392
   520
    // BFCDB7F301DEEEBBF947F29659BFF488C9C2EE39
dirk@488
   521
    XCTAssertTrue([PEPTestUtils importBundledKey:@"0xC9C2EE39.asc" session:session]);
andreas@392
   522
andreas@392
   523
    PEPIdentity *identBob = [[PEPIdentity alloc]
andreas@392
   524
                             initWithAddress:@"pep.test.bob@pep-project.org"
andreas@392
   525
                             userID:@"42" userName:@"pEp Test Bob"
andreas@392
   526
                             isOwn:NO
andreas@392
   527
                             fingerPrint:@"BFCDB7F301DEEEBBF947F29659BFF488C9C2EE39"];
andreas@392
   528
dirk@532
   529
    XCTAssertTrue([session updateIdentity:identBob error:&error]);
dirk@532
   530
    XCTAssertNil(error);
andreas@392
   531
andreas@392
   532
    // Should be yellow, since no handshake happened.
dirk@653
   533
    numRating = [self testOutgoingRatingForMessage:msg session:session error:&error];
dirk@573
   534
    XCTAssertNotNil(numRating);
dirk@573
   535
    XCTAssertNil(error);
dirk@573
   536
    XCTAssertEqual(numRating.pEpRating, PEP_rating_reliable);
andreas@392
   537
dirk@529
   538
    rating = [self ratingForIdentity:identBob session:session];
dirk@528
   539
    XCTAssertEqual(rating, PEP_rating_reliable);
andreas@392
   540
andreas@392
   541
    // Let' say we got that handshake, set PEP_ct_confirmed in Bob's identity
dirk@534
   542
    XCTAssertTrue([session trustPersonalKey:identBob error:&error]);
dirk@534
   543
    XCTAssertNil(error);
andreas@392
   544
andreas@392
   545
    // This time it should be green
dirk@653
   546
    numRating = [self testOutgoingRatingForMessage:msg session:session error:&error];
dirk@573
   547
    XCTAssertNotNil(numRating);
dirk@573
   548
    XCTAssertNil(error);
dirk@573
   549
    XCTAssertEqual(numRating.pEpRating, PEP_rating_trusted);
andreas@392
   550
dirk@529
   551
    rating = [self ratingForIdentity:identBob session:session];
dirk@528
   552
    XCTAssertEqual(rating, PEP_rating_trusted);
andreas@392
   553
andreas@392
   554
    // Now let see if it turns back yellow if we add an unconfirmed folk.
andreas@392
   555
    // pEp Test John (test key, don't use) <pep.test.john@pep-project.org>
andreas@392
   556
    // AA2E4BEB93E5FE33DEFD8BE1135CD6D170DCF575
dirk@488
   557
    XCTAssertTrue([PEPTestUtils importBundledKey:@"0x70DCF575.asc" session:session]);
andreas@392
   558
andreas@392
   559
    PEPIdentity *identJohn = [[PEPIdentity alloc]
andreas@392
   560
                              initWithAddress:@"pep.test.john@pep-project.org"
andreas@392
   561
                              userID:@"101" userName:@"pEp Test John"
andreas@392
   562
                              isOwn:NO
andreas@392
   563
                              fingerPrint:@"AA2E4BEB93E5FE33DEFD8BE1135CD6D170DCF575"];
andreas@392
   564
dirk@532
   565
    XCTAssertTrue([session updateIdentity:identJohn error:&error]);
dirk@532
   566
    XCTAssertNil(error);
andreas@392
   567
andreas@392
   568
    msg.bcc = @[[[PEPIdentity alloc] initWithAddress:@"pep.test.john@pep-project.org"
andreas@392
   569
                                              userID:@"101" userName:@"pEp Test John" isOwn:NO]];
andreas@392
   570
andreas@392
   571
    // Yellow ?
dirk@653
   572
    numRating = [self testOutgoingRatingForMessage:msg session:session error:&error];
dirk@573
   573
    XCTAssertNotNil(numRating);
dirk@573
   574
    XCTAssertNil(error);
dirk@573
   575
    XCTAssertEqual(numRating.pEpRating, PEP_rating_reliable);
andreas@392
   576
dirk@534
   577
    XCTAssertTrue([session trustPersonalKey:identJohn error:&error]);
dirk@534
   578
    XCTAssertNil(error);
andreas@392
   579
andreas@392
   580
    // This time it should be green
dirk@653
   581
    numRating = [self testOutgoingRatingForMessage:msg session:session error:&error];
dirk@573
   582
    XCTAssertNotNil(numRating);
dirk@573
   583
    XCTAssertNil(error);
dirk@573
   584
    XCTAssertEqual(numRating.pEpRating, PEP_rating_trusted);
andreas@392
   585
dirk@529
   586
    rating = [self ratingForIdentity:identJohn session:session];
dirk@528
   587
    XCTAssertEqual(rating, PEP_rating_trusted);
andreas@392
   588
}
andreas@392
   589
andreas@392
   590
- (void)testDontEncryptForMistrusted
andreas@392
   591
{
andreas@392
   592
    PEPSession *session = [PEPSession new];
andreas@392
   593
andreas@392
   594
    // Our test user :
andreas@392
   595
    // pEp Test Alice (test key don't use) <pep.test.alice@pep-project.org>
andreas@392
   596
    // 4ABE3AAF59AC32CFE4F86500A9411D176FF00E97
dirk@488
   597
    XCTAssertTrue([PEPTestUtils importBundledKey:@"6FF00E97_sec.asc" session:session]);
andreas@392
   598
andreas@392
   599
    PEPIdentity *identAlice = [[PEPIdentity alloc]
andreas@392
   600
                               initWithAddress:@"pep.test.alice@pep-project.org"
andreas@392
   601
                               userID:ownUserId
andreas@392
   602
                               userName:@"pEp Test Alice"
andreas@392
   603
                               isOwn:YES
andreas@392
   604
                               fingerPrint:@"4ABE3AAF59AC32CFE4F86500A9411D176FF00E97"];
andreas@392
   605
dirk@532
   606
    NSError *error = nil;
dirk@532
   607
    XCTAssertTrue([session mySelf:identAlice error:&error]);
dirk@532
   608
    XCTAssertNil(error);
andreas@392
   609
andreas@392
   610
    // pEp Test Bob (test key, don't use) <pep.test.bob@pep-project.org>
andreas@392
   611
    // BFCDB7F301DEEEBBF947F29659BFF488C9C2EE39
dirk@488
   612
    XCTAssertTrue([PEPTestUtils importBundledKey:@"0xC9C2EE39.asc" session:session]);
andreas@392
   613
andreas@392
   614
    PEPIdentity *identBob = [[PEPIdentity alloc]
andreas@392
   615
                             initWithAddress:@"pep.test.bob@pep-project.org"
andreas@392
   616
                             userID:@"42" userName:@"pEp Test Bob"
andreas@392
   617
                             isOwn:NO
andreas@392
   618
                             fingerPrint:@"BFCDB7F301DEEEBBF947F29659BFF488C9C2EE39"];
andreas@392
   619
dirk@532
   620
    XCTAssertTrue([session updateIdentity:identBob error:&error]);
dirk@532
   621
    XCTAssertNil(error);
andreas@392
   622
andreas@392
   623
    // mistrust Bob
dirk@536
   624
    XCTAssertTrue([session keyMistrusted:identBob error:&error]);
dirk@536
   625
    XCTAssertNil(error);
andreas@392
   626
andreas@392
   627
    PEPMessage *msg = [PEPMessage new];
andreas@392
   628
    msg.from = identAlice;
andreas@392
   629
    msg.to = @[[[PEPIdentity alloc] initWithAddress:@"pep.test.bob@pep-project.org" userID:@"42"
andreas@392
   630
                                           userName:@"pEp Test Bob" isOwn:NO]];
andreas@392
   631
    msg.shortMessage = @"All Green Test";
andreas@392
   632
    msg.longMessage = @"This is a text content";
andreas@392
   633
    msg.direction = PEP_dir_outgoing;
andreas@392
   634
andreas@392
   635
    // Gray == PEP_rating_unencrypted
dirk@653
   636
    NSNumber *numRating = [self testOutgoingRatingForMessage:msg session:session error:&error];
dirk@573
   637
    XCTAssertNotNil(numRating);
dirk@573
   638
    XCTAssertNil(error);
dirk@573
   639
    XCTAssertEqual(numRating.pEpRating, PEP_rating_unencrypted);
andreas@392
   640
dirk@524
   641
    PEPMessage *encMsg = [session encryptMessage:msg extraKeys:nil status:nil error:&error];
dirk@522
   642
    XCTAssertNotNil(encMsg);
dirk@522
   643
    XCTAssertNil(error);
andreas@392
   644
dirk@577
   645
    XCTAssertNotEqualObjects(encMsg.attachments[0].mimeType, @"application/pgp-encrypted");
andreas@392
   646
andreas@392
   647
    [self pEpCleanUp];
andreas@392
   648
}
andreas@392
   649
andreas@392
   650
- (void)testRevoke
andreas@392
   651
{
andreas@392
   652
    PEPSession *session = [PEPSession new];
andreas@392
   653
andreas@392
   654
    // Our test user :
andreas@392
   655
    // pEp Test Alice (test key don't use) <pep.test.alice@pep-project.org>
andreas@392
   656
    // 4ABE3AAF59AC32CFE4F86500A9411D176FF00E97
dirk@488
   657
    XCTAssertTrue([PEPTestUtils importBundledKey:@"6FF00E97_sec.asc" session:session]);
andreas@392
   658
    NSString *fpr = @"4ABE3AAF59AC32CFE4F86500A9411D176FF00E97";
andreas@392
   659
andreas@392
   660
    PEPIdentity *identAlice = [[PEPIdentity alloc]
andreas@392
   661
                               initWithAddress:@"pep.test.alice@pep-project.org"
andreas@392
   662
                               userID:ownUserId
andreas@392
   663
                               userName:@"pEp Test Alice"
andreas@392
   664
                               isOwn:YES
andreas@392
   665
                               fingerPrint:fpr];
andreas@392
   666
dirk@532
   667
    NSError *error = nil;
dirk@532
   668
    XCTAssertTrue([session mySelf:identAlice error:&error]);
dirk@532
   669
    XCTAssertNil(error);
andreas@392
   670
andreas@392
   671
    PEPIdentity *identAlice2 = [identAlice mutableCopy];
andreas@392
   672
andreas@392
   673
    // This will revoke key
dirk@536
   674
    XCTAssertTrue([session keyMistrusted:identAlice2 error:&error]);
dirk@536
   675
    XCTAssertNil(error);
andreas@416
   676
    identAlice2.fingerPrint = nil;
dirk@532
   677
dirk@532
   678
    XCTAssertTrue([session mySelf:identAlice error:&error]);
dirk@532
   679
    XCTAssertNil(error);
andreas@416
   680
andreas@392
   681
    // Check fingerprint is different
andreas@392
   682
    XCTAssertNotEqualObjects(identAlice2.fingerPrint, fpr);
andreas@392
   683
}
andreas@392
   684
andreas@392
   685
- (void)testMailToMyself
andreas@392
   686
{
andreas@392
   687
    PEPSession *session = [PEPSession new];
andreas@392
   688
andreas@392
   689
    // Our test user :
andreas@392
   690
    // pEp Test Alice (test key don't use) <pep.test.alice@pep-project.org>
andreas@392
   691
    // 4ABE3AAF59AC32CFE4F86500A9411D176FF00E97
dirk@488
   692
    XCTAssertTrue([PEPTestUtils importBundledKey:@"6FF00E97_sec.asc" session:session]);
andreas@392
   693
andreas@392
   694
    PEPIdentity *identAlice = [[PEPIdentity alloc]
andreas@392
   695
                               initWithAddress:@"pep.test.alice@pep-project.org"
andreas@392
   696
                               userID:ownUserId
andreas@392
   697
                               userName:@"pEp Test Alice"
andreas@392
   698
                               isOwn:YES
andreas@392
   699
                               fingerPrint:@"4ABE3AAF59AC32CFE4F86500A9411D176FF00E97"];
andreas@392
   700
dirk@532
   701
    NSError *error = nil;
dirk@532
   702
    XCTAssertTrue([session mySelf:identAlice error:&error]);
dirk@532
   703
    XCTAssertNil(error);
andreas@392
   704
andreas@392
   705
    PEPMessage *msg = [PEPMessage new];
andreas@392
   706
    msg.from = identAlice;
andreas@392
   707
    msg.to = @[identAlice];
andreas@392
   708
    msg.shortMessage = @"Mail to Myself";
andreas@392
   709
    msg.longMessage = @"This is a text content";
andreas@392
   710
    msg.direction = PEP_dir_outgoing;
andreas@392
   711
dirk@653
   712
    NSNumber *numRating = [self testOutgoingRatingForMessage:msg session:session error:&error];
dirk@573
   713
    XCTAssertNotNil(numRating);
dirk@573
   714
    XCTAssertNil(error);
dirk@573
   715
    XCTAssertEqual(numRating.pEpRating, PEP_rating_trusted_and_anonymized);
dirk@528
   716
dirk@524
   717
    PEPMessage *encMsg = [session encryptMessage:msg extraKeys:nil status:nil error:&error];
dirk@522
   718
    XCTAssertNotNil(encMsg);
dirk@522
   719
    XCTAssertNil(error);
andreas@392
   720
dirk@522
   721
    NSArray *keys;
andreas@392
   722
dirk@522
   723
    error = nil;
dirk@600
   724
    PEP_rating rating = PEP_rating_undefined;
dirk@517
   725
    PEPMessage *decmsg = [session
dirk@522
   726
                          decryptMessage:encMsg
dirk@583
   727
                          flags:nil
dirk@528
   728
                          rating:&rating
dirk@523
   729
                          extraKeys:&keys
dirk@524
   730
                          status:nil
dirk@517
   731
                          error:&error];
dirk@517
   732
    XCTAssertNotNil(decmsg);
dirk@514
   733
    XCTAssertNil(error);
dirk@528
   734
    XCTAssertEqual(rating, PEP_rating_trusted_and_anonymized);
andreas@392
   735
}
andreas@392
   736
dirk@632
   737
- (void)testEncryptedMailFromMuttWithReencryption
andreas@392
   738
{
andreas@392
   739
    PEPSession *session = [PEPSession new];
andreas@392
   740
andreas@392
   741
    // This is the public key for test001@peptest.ch
dirk@488
   742
    XCTAssertTrue([PEPTestUtils importBundledKey:@"A3FC7F0A.asc" session:session]);
andreas@392
   743
andreas@392
   744
    // This is the secret key for test001@peptest.ch
dirk@488
   745
    XCTAssertTrue([PEPTestUtils importBundledKey:@"A3FC7F0A_sec.asc" session:session]);
andreas@392
   746
andreas@392
   747
    // Mail from mutt, already processed into message dict by the app.
dirk@465
   748
    NSMutableDictionary *msgDict = [[PEPTestUtils
dirk@465
   749
                                     unarchiveDictionary:@"msg_to_A3FC7F0A_from_mutt.ser"]
dirk@465
   750
                                    mutableCopy];
dirk@579
   751
    [PEPTestUtils migrateUnarchivedMessageDictionary:msgDict];
andreas@392
   752
    [msgDict removeObjectForKey:kPepLongMessage];
andreas@392
   753
    [msgDict removeObjectForKey:kPepLongMessageFormatted];
andreas@392
   754
andreas@392
   755
    // Also extracted "live" from the app.
dirk@465
   756
    NSMutableDictionary *accountDict = [[PEPTestUtils
dirk@465
   757
                                         unarchiveDictionary:@"account_A3FC7F0A.ser"]
dirk@465
   758
                                        mutableCopy];
andreas@392
   759
    [accountDict removeObjectForKey:kPepCommType];
andreas@392
   760
    [accountDict removeObjectForKey:kPepFingerprint];
andreas@392
   761
    PEPIdentity *identMe = [[PEPIdentity alloc] initWithDictionary:accountDict];
andreas@392
   762
dirk@532
   763
    NSError *error = nil;
dirk@532
   764
    XCTAssertTrue([session mySelf:identMe error:&error]);
dirk@532
   765
    XCTAssertNil(error);
dirk@532
   766
andreas@392
   767
    XCTAssertNotNil(identMe.fingerPrint);
andreas@392
   768
andreas@392
   769
    NSArray* keys;
andreas@392
   770
    PEPMessage *msg = [PEPMessage new];
andreas@392
   771
    [msg setValuesForKeysWithDictionary:msgDict];
dirk@590
   772
    PEPMessage *msgOriginal = [PEPMessage new];
dirk@590
   773
    [msgOriginal setValuesForKeysWithDictionary:msgDict];
dirk@514
   774
dirk@590
   775
    XCTAssertEqualObjects(msg, msgOriginal);
dirk@590
   776
dirk@600
   777
    PEP_rating rating = PEP_rating_undefined;
dirk@590
   778
    PEP_decrypt_flags flags = PEP_decrypt_flag_untrusted_server;
dirk@590
   779
dirk@517
   780
    PEPMessage *pepDecryptedMail = [session
dirk@517
   781
                                    decryptMessage:msg
dirk@590
   782
                                    flags:&flags
dirk@590
   783
                                    rating:&rating
dirk@523
   784
                                    extraKeys:&keys
dirk@524
   785
                                    status:nil
dirk@517
   786
                                    error:&error];
dirk@517
   787
    XCTAssertNotNil(pepDecryptedMail);
dirk@514
   788
    XCTAssertNil(error);
dirk@514
   789
dirk@590
   790
    // Technically, the mail is encrypted, but the signatures don't match
dirk@590
   791
    XCTAssertEqual(rating, PEP_rating_unreliable);
dirk@590
   792
dirk@632
   793
    // Since we're requesting re-encryption, src should have been changed
dirk@632
   794
    XCTAssertNotEqualObjects(msg, msgOriginal);
dirk@590
   795
andreas@392
   796
    XCTAssertNotNil(pepDecryptedMail.longMessage);
andreas@392
   797
}
andreas@392
   798
andreas@392
   799
- (void)testOutgoingContactColor
andreas@392
   800
{
andreas@392
   801
    PEPSession *session = [PEPSession new];
andreas@392
   802
andreas@411
   803
    PEPIdentity *partner1Orig = [PEPTestUtils foreignPepIdentityWithAddress:@"partner1@dontcare.me"
andreas@411
   804
                                                                   userName:@"Partner 1"];
andreas@392
   805
    NSString *pubKeyPartner1 = [PEPTestUtils loadResourceByName:@"partner1_F2D281C2789DD7F6_pub.asc"];
andreas@392
   806
    XCTAssertNotNil(pubKeyPartner1);
dirk@551
   807
dirk@551
   808
    NSError *error = nil;
dirk@551
   809
    XCTAssertTrue([session importKey:pubKeyPartner1 error:&error]);
dirk@551
   810
    XCTAssertNil(error);
andreas@392
   811
dirk@529
   812
    PEP_rating color = [self ratingForIdentity:partner1Orig session:session];
andreas@392
   813
    XCTAssertEqual(color, PEP_rating_reliable);
andreas@392
   814
}
andreas@392
   815
andreas@392
   816
- (void)testGetTrustwords
andreas@392
   817
{
andreas@392
   818
    PEPSession *session = [PEPSession new];
andreas@392
   819
andreas@392
   820
    PEPIdentity *partner1Orig = [[PEPIdentity alloc]
andreas@392
   821
                                 initWithAddress:@"partner1@dontcare.me" userID:@"partner1"
andreas@392
   822
                                 userName:@"partner1"
andreas@392
   823
                                 isOwn:NO fingerPrint:@"F0CD3F7B422E5D587ABD885BF2D281C2789DD7F6"];
andreas@392
   824
andreas@392
   825
    PEPIdentity *meOrig = [[PEPIdentity alloc]
andreas@392
   826
                           initWithAddress:@"me@dontcare.me" userID:@"me"
andreas@392
   827
                           userName:@"me"
andreas@392
   828
                           isOwn:NO fingerPrint:@"CC1F73F6FB774BF08B197691E3BFBCA9248FC681"];
andreas@392
   829
andreas@392
   830
    NSString *pubKeyPartner1 = [PEPTestUtils loadResourceByName:@"partner1_F2D281C2789DD7F6_pub.asc"];
andreas@392
   831
    XCTAssertNotNil(pubKeyPartner1);
andreas@392
   832
    NSString *pubKeyMe = [PEPTestUtils loadResourceByName:@"meATdontcare_E3BFBCA9248FC681_pub.asc"];
andreas@392
   833
    XCTAssertNotNil(pubKeyMe);
andreas@392
   834
    NSString *secKeyMe = [PEPTestUtils loadResourceByName:@"meATdontcare_E3BFBCA9248FC681_sec.asc"];
andreas@392
   835
    XCTAssertNotNil(secKeyMe);
andreas@392
   836
dirk@558
   837
    NSError *error = nil;
andreas@392
   838
    NSString *trustwordsFull = [session getTrustwordsIdentity1:meOrig identity2:partner1Orig
dirk@558
   839
                                                      language:nil full:YES error:&error];
dirk@558
   840
    XCTAssertNil(error);
andreas@392
   841
    XCTAssertEqualObjects(trustwordsFull,
andreas@392
   842
                          @"EMERSON GASPER TOKENISM BOLUS COLLAGE DESPISE BEDDED ENCRYPTION IMAGINE BEDFORD");
andreas@392
   843
andreas@392
   844
    NSString *trustwordsFullEnglish = [session getTrustwordsIdentity1:meOrig identity2:partner1Orig
dirk@558
   845
                                                             language:@"en" full:YES error:&error];
dirk@558
   846
    XCTAssertNil(error);
andreas@392
   847
    XCTAssertEqualObjects(trustwordsFullEnglish, trustwordsFull);
andreas@392
   848
andreas@392
   849
    NSString *trustwordsUndefined = [session getTrustwordsIdentity1:meOrig identity2:partner1Orig
dirk@558
   850
                                                           language:@"ZZ" full:YES error:&error];
dirk@558
   851
    XCTAssertNotNil(error);
andreas@392
   852
    XCTAssertNil(trustwordsUndefined);
andreas@392
   853
}
andreas@392
   854
dirk@418
   855
- (void)testStringToRating
dirk@418
   856
{
dirk@418
   857
    PEPSession *session = [PEPSession new];
dirk@418
   858
    XCTAssertEqual([session ratingFromString:@"cannot_decrypt"], PEP_rating_cannot_decrypt);
dirk@418
   859
    XCTAssertEqual([session ratingFromString:@"have_no_key"], PEP_rating_have_no_key);
dirk@418
   860
    XCTAssertEqual([session ratingFromString:@"unencrypted"], PEP_rating_unencrypted);
dirk@418
   861
    XCTAssertEqual([session ratingFromString:@"unencrypted_for_some"],
dirk@418
   862
                   PEP_rating_unencrypted_for_some);
dirk@418
   863
    XCTAssertEqual([session ratingFromString:@"unreliable"], PEP_rating_unreliable);
dirk@418
   864
    XCTAssertEqual([session ratingFromString:@"reliable"], PEP_rating_reliable);
dirk@418
   865
    XCTAssertEqual([session ratingFromString:@"trusted"], PEP_rating_trusted);
dirk@418
   866
    XCTAssertEqual([session ratingFromString:@"trusted_and_anonymized"],
dirk@418
   867
                   PEP_rating_trusted_and_anonymized);
dirk@418
   868
    XCTAssertEqual([session ratingFromString:@"fully_anonymous"], PEP_rating_fully_anonymous);
dirk@418
   869
    XCTAssertEqual([session ratingFromString:@"mistrust"], PEP_rating_mistrust);
dirk@418
   870
    XCTAssertEqual([session ratingFromString:@"b0rken"], PEP_rating_b0rken);
dirk@418
   871
    XCTAssertEqual([session ratingFromString:@"under_attack"], PEP_rating_under_attack);
dirk@418
   872
    XCTAssertEqual([session ratingFromString:@"undefined"], PEP_rating_undefined);
dirk@418
   873
    XCTAssertEqual([session ratingFromString:@"does not exist111"], PEP_rating_undefined);
dirk@418
   874
}
dirk@418
   875
dirk@418
   876
- (void)testRatingToString
dirk@418
   877
{
dirk@418
   878
    PEPSession *session = [PEPSession new];
dirk@418
   879
    XCTAssertEqualObjects([session stringFromRating:PEP_rating_cannot_decrypt], @"cannot_decrypt");
dirk@418
   880
    XCTAssertEqualObjects([session stringFromRating:PEP_rating_have_no_key], @"have_no_key");
dirk@418
   881
    XCTAssertEqualObjects([session stringFromRating:PEP_rating_unencrypted], @"unencrypted");
dirk@418
   882
    XCTAssertEqualObjects([session stringFromRating:PEP_rating_unencrypted_for_some],
dirk@418
   883
                          @"unencrypted_for_some");
dirk@418
   884
    XCTAssertEqualObjects([session stringFromRating:PEP_rating_unreliable], @"unreliable");
dirk@418
   885
    XCTAssertEqualObjects([session stringFromRating:PEP_rating_reliable], @"reliable");
dirk@418
   886
    XCTAssertEqualObjects([session stringFromRating:PEP_rating_trusted], @"trusted");
dirk@418
   887
    XCTAssertEqualObjects([session stringFromRating:PEP_rating_trusted_and_anonymized],
dirk@418
   888
                          @"trusted_and_anonymized");
dirk@418
   889
    XCTAssertEqualObjects([session stringFromRating:PEP_rating_fully_anonymous],
dirk@418
   890
                          @"fully_anonymous");
dirk@418
   891
    XCTAssertEqualObjects([session stringFromRating:PEP_rating_mistrust], @"mistrust");
dirk@418
   892
    XCTAssertEqualObjects([session stringFromRating:PEP_rating_b0rken], @"b0rken");
dirk@418
   893
    XCTAssertEqualObjects([session stringFromRating:PEP_rating_under_attack], @"under_attack");
dirk@418
   894
    XCTAssertEqualObjects([session stringFromRating:PEP_rating_undefined], @"undefined");
dirk@418
   895
    XCTAssertEqualObjects([session stringFromRating:500], @"undefined");
dirk@418
   896
}
dirk@418
   897
dirk@431
   898
- (void)testIsPEPUser
dirk@431
   899
{
dirk@431
   900
    PEPSession *session = [PEPSession new];
dirk@431
   901
dirk@431
   902
    PEPIdentity *identMe = [[PEPIdentity alloc]
dirk@431
   903
                            initWithAddress:@"me-myself-and-i@pep-project.org"
dirk@431
   904
                            userID:@"me-myself-and-i"
dirk@452
   905
                            userName:@"pEp Me"
dirk@431
   906
                            isOwn:YES];
dirk@532
   907
    NSError *error = nil;
dirk@532
   908
    XCTAssertTrue([session mySelf:identMe error:&error]);
dirk@532
   909
    XCTAssertNil(error);
dirk@532
   910
dirk@431
   911
    XCTAssertNotNil(identMe.fingerPrint);
dirk@432
   912
dirk@432
   913
    // PEP_CANNOT_FIND_PERSON == 902
dirk@567
   914
    XCTAssertTrue([session isPEPUser:identMe error:&error]);
dirk@431
   915
}
dirk@431
   916
dirk@449
   917
- (void)testXEncStatusForOutgoingEncryptedMail
dirk@449
   918
{
dirk@449
   919
    [self helperXEncStatusForOutgoingEncryptdMailToSelf:NO expectedRating:PEP_rating_reliable];
dirk@449
   920
}
dirk@449
   921
dirk@449
   922
- (void)testXEncStatusForOutgoingSelfEncryptedMail
dirk@449
   923
{
dirk@449
   924
    [self helperXEncStatusForOutgoingEncryptdMailToSelf:YES
dirk@449
   925
                                         expectedRating:PEP_rating_trusted_and_anonymized];
dirk@449
   926
}
dirk@449
   927
dirk@456
   928
- (void)testEncryptMessagesWithoutKeys
dirk@456
   929
{
dirk@456
   930
    PEPSession *session = [PEPSession new];
dirk@456
   931
dirk@456
   932
    PEPIdentity *identMe = [[PEPIdentity alloc]
dirk@456
   933
                            initWithAddress:@"me-myself-and-i@pep-project.org"
dirk@456
   934
                            userID:@"me-myself-and-i"
dirk@456
   935
                            userName:@"pEp Me"
dirk@456
   936
                            isOwn:YES];
dirk@532
   937
    NSError *error = nil;
dirk@532
   938
    XCTAssertTrue([session mySelf:identMe error:&error]);
dirk@532
   939
    XCTAssertNil(error);
dirk@532
   940
dirk@456
   941
    XCTAssertNotNil(identMe.fingerPrint);
dirk@456
   942
dirk@456
   943
    PEPIdentity *identAlice = [[PEPIdentity alloc]
dirk@456
   944
                               initWithAddress:@"alice@pep-project.org"
dirk@456
   945
                               userID:@"alice"
dirk@456
   946
                               userName:@"pEp Test Alice"
dirk@456
   947
                               isOwn:NO];
dirk@456
   948
dirk@456
   949
    PEPMessage *msg = [PEPMessage new];
dirk@456
   950
    msg.from = identMe;
dirk@456
   951
    msg.to = @[identAlice];
dirk@456
   952
    msg.shortMessage = @"Mail to Alice";
dirk@456
   953
    msg.longMessage = @"Alice?";
dirk@456
   954
    msg.direction = PEP_dir_outgoing;
dirk@456
   955
dirk@653
   956
    NSNumber *numRating = [self testOutgoingRatingForMessage:msg session:session error:&error];
dirk@573
   957
    XCTAssertNotNil(numRating);
dirk@573
   958
    XCTAssertNil(error);
dirk@573
   959
    XCTAssertEqual(numRating.pEpRating, PEP_rating_unencrypted);
dirk@528
   960
dirk@524
   961
    PEPMessage *encMsg = [session encryptMessage:msg extraKeys:nil status:nil error:&error];
dirk@522
   962
    XCTAssertNotNil(encMsg);
dirk@522
   963
    XCTAssertNil(error);
dirk@456
   964
dirk@456
   965
    XCTAssertNotNil(encMsg);
dirk@456
   966
dirk@456
   967
    PEPStringList *keys;
dirk@514
   968
    PEP_rating pEpRating;
dirk@522
   969
    error = nil;
dirk@517
   970
    PEPMessage *decMsg = [session
dirk@517
   971
                          decryptMessage:encMsg
dirk@583
   972
                          flags:nil
dirk@517
   973
                          rating:&pEpRating
dirk@523
   974
                          extraKeys:&keys
dirk@524
   975
                          status:nil
dirk@517
   976
                          error:&error];
dirk@517
   977
    XCTAssertNotNil(decMsg);
dirk@514
   978
    XCTAssertNil(error);
dirk@514
   979
dirk@456
   980
    XCTAssertEqual(pEpRating, PEP_rating_unencrypted);
dirk@456
   981
    XCTAssertNotNil(decMsg);
dirk@456
   982
}
dirk@456
   983
dirk@456
   984
/**
dirk@456
   985
 ENGINE-364. Tries to invoke trustPersonalKey on an identity without key,
dirk@456
   986
 giving it a fake fingerprint.
dirk@456
   987
 */
dirk@456
   988
- (void)testTrustPersonalKey
dirk@456
   989
{
dirk@456
   990
    PEPSession *session = [PEPSession new];
dirk@456
   991
dirk@456
   992
    PEPIdentity *identMe = [[PEPIdentity alloc]
dirk@456
   993
                            initWithAddress:@"me-myself-and-i@pep-project.org"
dirk@456
   994
                            userID:@"me-myself-and-i"
dirk@456
   995
                            userName:@"pEp Me"
dirk@456
   996
                            isOwn:YES];
dirk@532
   997
    NSError *error = nil;
dirk@532
   998
    XCTAssertTrue([session mySelf:identMe error:&error]);
dirk@532
   999
    XCTAssertNil(error);
dirk@532
  1000
dirk@456
  1001
    XCTAssertNotNil(identMe.fingerPrint);
dirk@456
  1002
dirk@456
  1003
    // The fingerprint is definitely wrong, we don't have a key
dirk@456
  1004
    PEPIdentity *identAlice = [[PEPIdentity alloc]
dirk@456
  1005
                               initWithAddress:@"alice@pep-project.org"
dirk@456
  1006
                               userID:@"alice"
dirk@456
  1007
                               userName:@"pEp Test Alice"
dirk@456
  1008
                               isOwn:NO
dirk@456
  1009
                               fingerPrint:@"4ABE3AAF59AC32CFE4F86500A9411D176FF00E97"];
dirk@456
  1010
dirk@534
  1011
    XCTAssertFalse([session trustPersonalKey:identAlice error:&error]);
dirk@534
  1012
    XCTAssertNotNil(error);
dirk@456
  1013
}
dirk@456
  1014
dirk@457
  1015
/**
dirk@457
  1016
 ENGINE-381
dirk@457
  1017
 */
dirk@457
  1018
- (void)testVolatileIdentityRating
dirk@457
  1019
{
dirk@457
  1020
    PEPSession *session = [PEPSession new];
dirk@457
  1021
dirk@457
  1022
    PEPIdentity *identMe = [[PEPIdentity alloc]
dirk@457
  1023
                            initWithAddress:@"me-myself-and-i@pep-project.org"
dirk@457
  1024
                            userID:@"me-myself-and-i"
dirk@457
  1025
                            userName:@"pEp Me"
dirk@457
  1026
                            isOwn:YES];
dirk@532
  1027
    NSError *error = nil;
dirk@532
  1028
    XCTAssertTrue([session mySelf:identMe error:&error]);
dirk@532
  1029
    XCTAssertNil(error);
dirk@532
  1030
dirk@457
  1031
    XCTAssertNotNil(identMe.fingerPrint);
dirk@457
  1032
dirk@457
  1033
    PEPIdentity *identAlice = [self
dirk@457
  1034
                               checkImportingKeyFilePath:@"6FF00E97_sec.asc"
dirk@457
  1035
                               address:@"pep.test.alice@pep-project.org"
dirk@457
  1036
                               userID:@"alice_user_id"
dirk@457
  1037
                               fingerPrint:@"4ABE3AAF59AC32CFE4F86500A9411D176FF00E97"
dirk@457
  1038
                               session: session];
dirk@488
  1039
    XCTAssertNotNil(identAlice);
dirk@457
  1040
dirk@457
  1041
    dispatch_group_t identityRatingGroup = dispatch_group_create();
dirk@457
  1042
dirk@457
  1043
    void (^ratingBlock)(void) = ^{
dirk@457
  1044
        PEPSession *innerSession = [PEPSession new];
dirk@529
  1045
        PEP_rating rating = [self ratingForIdentity:identAlice session:innerSession];
dirk@457
  1046
        XCTAssertEqual(rating, PEP_rating_reliable);
dirk@457
  1047
    };
dirk@457
  1048
dirk@479
  1049
    for (int i = 0; i < 4; ++i) {
dirk@457
  1050
        dispatch_group_async(identityRatingGroup,
dirk@457
  1051
                             dispatch_get_global_queue(QOS_CLASS_USER_INITIATED, 0),
dirk@457
  1052
                             ratingBlock);
dirk@457
  1053
    }
dirk@457
  1054
dirk@479
  1055
    for (int i = 0; i < 4; ++i) {
dirk@457
  1056
        ratingBlock();
dirk@457
  1057
    }
dirk@457
  1058
dirk@457
  1059
    dispatch_group_wait(identityRatingGroup, DISPATCH_TIME_FOREVER);
dirk@457
  1060
}
dirk@457
  1061
dirk@612
  1062
/**
dirk@615
  1063
 IOSAD-93, testing for easy error case.
dirk@612
  1064
 */
dirk@618
  1065
- (void)testEncryptAndAttachPrivateKeyIllegalValue
dirk@612
  1066
{
dirk@612
  1067
    PEPSession *session = [PEPSession new];
dirk@612
  1068
dirk@612
  1069
    PEPIdentity *identMe = [[PEPIdentity alloc]
dirk@612
  1070
                            initWithAddress:@"me-myself-and-i@pep-project.org"
dirk@612
  1071
                            userID:@"me-myself-and-i"
dirk@612
  1072
                            userName:@"pEp Me"
dirk@612
  1073
                            isOwn:YES];
dirk@612
  1074
    NSError *error = nil;
dirk@612
  1075
    XCTAssertTrue([session mySelf:identMe error:&error]);
dirk@612
  1076
    XCTAssertNil(error);
dirk@612
  1077
dirk@612
  1078
    XCTAssertNotNil(identMe.fingerPrint);
dirk@612
  1079
dirk@612
  1080
    NSString *fprAlice = @"4ABE3AAF59AC32CFE4F86500A9411D176FF00E97";
dirk@612
  1081
    PEPIdentity *identAlice = [self
dirk@612
  1082
                               checkImportingKeyFilePath:@"6FF00E97_sec.asc"
dirk@612
  1083
                               address:@"pep.test.alice@pep-project.org"
dirk@612
  1084
                               userID:@"alice_user_id"
dirk@612
  1085
                               fingerPrint:fprAlice
dirk@612
  1086
                               session: session];
dirk@612
  1087
    XCTAssertNotNil(identAlice);
dirk@612
  1088
dirk@612
  1089
    NSString *shortMessage = @"whatever it may be";
dirk@612
  1090
    NSString *longMessage = [NSString stringWithFormat:@"%@ %@", shortMessage, shortMessage];
dirk@612
  1091
    PEPMessage *message = [PEPMessage new];
dirk@612
  1092
    message.from = identMe;
dirk@612
  1093
    message.to = @[identAlice];
dirk@612
  1094
    message.shortMessage = shortMessage;
dirk@612
  1095
    message.longMessage = longMessage;
dirk@612
  1096
dirk@612
  1097
    PEP_STATUS status = PEP_KEY_NOT_FOUND;
dirk@612
  1098
    error = nil;
dirk@612
  1099
    PEPMessage *encrypted = [session
dirk@612
  1100
                             encryptMessage:message
dirk@612
  1101
                             toFpr:fprAlice
dirk@612
  1102
                             encFormat:PEP_enc_PEP
dirk@612
  1103
                             flags:0
dirk@612
  1104
                             status:&status error:&error];
dirk@613
  1105
    XCTAssertEqual(status, PEP_ILLEGAL_VALUE);
dirk@613
  1106
    XCTAssertNotNil(error);
dirk@612
  1107
    XCTAssertNil(encrypted);
dirk@612
  1108
}
dirk@612
  1109
dirk@449
  1110
#pragma mark - configUnencryptedSubject
dirk@449
  1111
dirk@449
  1112
- (void)testConfigUnencryptedSubject
dirk@449
  1113
{
dirk@449
  1114
    // Setup Config to encrypt subject
dirk@601
  1115
    [PEPObjCAdapter setUnEncryptedSubjectEnabled:NO];
dirk@449
  1116
dirk@449
  1117
    // Write mail to yourself ...
dirk@449
  1118
    PEPMessage *encMessage = [self mailWrittenToMySelf];
dirk@449
  1119
dirk@449
  1120
    // ... and assert subject is encrypted
dirk@449
  1121
    XCTAssertEqualObjects(encMessage.shortMessage, @"p≡p", @"Subject should be encrypted");
dirk@449
  1122
}
dirk@449
  1123
dirk@602
  1124
- (void)testConfigUnencryptedSubjectEncryptedSubjectDisabled
dirk@449
  1125
{
dirk@449
  1126
    // Setup Config to not encrypt subject
dirk@601
  1127
    [PEPObjCAdapter setUnEncryptedSubjectEnabled:YES];
dirk@449
  1128
dirk@449
  1129
    // Write mail to yourself ...
dirk@449
  1130
    PEPMessage *encMessage = [self mailWrittenToMySelf];
dirk@449
  1131
dirk@602
  1132
    // pEp to pEp uses message 2.0, which always encrypts subjects (ENGINE-429)
dirk@602
  1133
    XCTAssertEqualObjects(encMessage.shortMessage, @"p≡p", @"Subject should be encrypted");
dirk@449
  1134
}
dirk@449
  1135
dirk@628
  1136
#pragma mark - Passive mode
dirk@628
  1137
dirk@628
  1138
- (void)testPassiveMode
dirk@628
  1139
{
dirk@628
  1140
    [self testPassiveModeEnabled:NO];
dirk@628
  1141
    [self testPassiveModeEnabled:YES];
dirk@628
  1142
}
dirk@628
  1143
dirk@646
  1144
#pragma mark - Decryption
dirk@646
  1145
dirk@646
  1146
- (void)testDecryptionOfUnencryptedMessageWithOdtAttachmentContainingSpace
dirk@646
  1147
{
dirk@646
  1148
    PEPSession *session = [PEPSession new];
dirk@646
  1149
dirk@646
  1150
    PEPIdentity *me = [PEPTestUtils ownPepIdentityWithAddress:@"me@peptest.ch"
dirk@646
  1151
                                                     userName:@"userName"];
dirk@646
  1152
    NSError *error = nil;
dirk@646
  1153
    XCTAssertTrue([session mySelf:me error:&error]);
dirk@646
  1154
    XCTAssertNil(error);
dirk@646
  1155
dirk@646
  1156
    const char *dataString = "blahblah";
dirk@646
  1157
    const size_t dataSize = strlen(dataString);
dirk@646
  1158
    char *rawData = strndup(dataString, dataSize);
dirk@646
  1159
dirk@646
  1160
    PEPAttachment *attachment = [[PEPAttachment alloc]
dirk@646
  1161
                                 initWithData:[NSData
dirk@646
  1162
                                               dataWithBytesNoCopy:rawData length:dataSize]];
dirk@646
  1163
    attachment.filename = @"Someone andTextIncludingTheSpace.odt";
dirk@646
  1164
    attachment.mimeType = @"application/vnd.oasis.opendocument.text";
dirk@646
  1165
dirk@646
  1166
    NSString *shortMessage = @"Subject";
dirk@646
  1167
    NSString *longMessage = @"Oh, this is a long body text!";
dirk@646
  1168
    PEPMessage *mail = [PEPTestUtils mailFrom:me
dirk@646
  1169
                                      toIdent:me
dirk@646
  1170
                                 shortMessage:shortMessage
dirk@646
  1171
                                  longMessage:longMessage
dirk@646
  1172
                                     outgoing:YES];
dirk@646
  1173
dirk@646
  1174
    mail.attachments = @[attachment];
dirk@646
  1175
dirk@646
  1176
    error = nil;
dirk@646
  1177
    PEPStringList *keys;
dirk@646
  1178
    PEP_rating rating = PEP_rating_undefined;
dirk@646
  1179
    PEPMessage *decmsg = [session
dirk@646
  1180
                          decryptMessage:mail
dirk@646
  1181
                          flags:nil
dirk@646
  1182
                          rating:&rating
dirk@646
  1183
                          extraKeys:&keys
dirk@646
  1184
                          status:nil
dirk@646
  1185
                          error:&error];
dirk@646
  1186
    XCTAssertNotNil(decmsg);
dirk@646
  1187
    XCTAssertNil(error);
dirk@646
  1188
    XCTAssertEqual(rating, PEP_rating_unencrypted);
dirk@646
  1189
dirk@646
  1190
    PEPAttachment *decryptedAttachment = [decmsg.attachments objectAtIndex:0];
dirk@646
  1191
    XCTAssertEqualObjects(decryptedAttachment.mimeType, attachment.mimeType);
dirk@646
  1192
    XCTAssertEqualObjects(decryptedAttachment.filename, attachment.filename);
dirk@646
  1193
}
dirk@646
  1194
dirk@749
  1195
#pragma mark - Send Message
dirk@749
  1196
dirk@749
  1197
/**
dirk@749
  1198
 Prove that mySelf triggers a message to be sent.
dirk@749
  1199
 */
dirk@749
  1200
- (void)testBasicSendMessage
dirk@749
  1201
{
dirk@749
  1202
    PEPSession *session = [PEPSession new];
dirk@749
  1203
dirk@749
  1204
    XCTAssertEqual(self.sendMessageDelegate.messages.count, 0);
dirk@760
  1205
    XCTAssertNil(self.sendMessageDelegate.lastMessage);
dirk@749
  1206
dirk@749
  1207
    XCTKVOExpectation *expHaveMessage = [[XCTKVOExpectation alloc]
dirk@749
  1208
                                         initWithKeyPath:@"lastMessage"
dirk@749
  1209
                                         object:self.sendMessageDelegate];
dirk@749
  1210
dirk@749
  1211
    PEPIdentity *identMe = [[PEPIdentity alloc]
dirk@749
  1212
                            initWithAddress:@"me-myself-and-i@pep-project.org"
dirk@749
  1213
                            userID:@"me-myself-and-i"
dirk@749
  1214
                            userName:@"pEp Me"
dirk@749
  1215
                            isOwn:YES];
dirk@749
  1216
    NSError *error = nil;
dirk@749
  1217
    XCTAssertTrue([session mySelf:identMe error:&error]);
dirk@749
  1218
    XCTAssertNil(error);
dirk@749
  1219
dirk@749
  1220
    XCTAssertNotNil(identMe.fingerPrint);
dirk@749
  1221
dirk@762
  1222
    [self waitForExpectations:@[expHaveMessage] timeout:PEPTestInternalSyncTimeout];
dirk@760
  1223
    XCTAssertNotNil(self.sendMessageDelegate.lastMessage);
dirk@749
  1224
dirk@749
  1225
    XCTAssertEqual(self.sendMessageDelegate.messages.count, 1);
dirk@749
  1226
}
dirk@749
  1227
dirk@719
  1228
#pragma mark - Key Reset
dirk@719
  1229
dirk@741
  1230
- (void)testBasicKeyResetTrust
dirk@719
  1231
{
dirk@719
  1232
    PEPSession *session = [PEPSession new];
dirk@719
  1233
dirk@742
  1234
    XCTAssertEqual(self.sendMessageDelegate.messages.count, 0);
dirk@742
  1235
dirk@754
  1236
    XCTKVOExpectation *expHaveMessage = [[XCTKVOExpectation alloc]
dirk@754
  1237
                                         initWithKeyPath:@"lastMessage"
dirk@754
  1238
                                         object:self.sendMessageDelegate];
dirk@754
  1239
dirk@719
  1240
    PEPIdentity *identMe = [[PEPIdentity alloc]
dirk@719
  1241
                            initWithAddress:@"me-myself-and-i@pep-project.org"
dirk@719
  1242
                            userID:@"me-myself-and-i"
dirk@719
  1243
                            userName:@"pEp Me"
dirk@719
  1244
                            isOwn:YES];
dirk@719
  1245
    NSError *error = nil;
dirk@719
  1246
    XCTAssertTrue([session mySelf:identMe error:&error]);
dirk@719
  1247
    XCTAssertNil(error);
dirk@719
  1248
dirk@763
  1249
    [self.sync shutdown];
dirk@763
  1250
dirk@719
  1251
    XCTAssertNotNil(identMe.fingerPrint);
dirk@719
  1252
    NSString *fpr1 = identMe.fingerPrint;
dirk@719
  1253
dirk@719
  1254
    XCTAssertTrue([session keyResetTrust:identMe error:&error]);
dirk@719
  1255
    XCTAssertNil(error);
dirk@719
  1256
dirk@719
  1257
    identMe.fingerPrint = nil;
dirk@719
  1258
    XCTAssertTrue([session updateIdentity:identMe error:&error]);
dirk@719
  1259
    XCTAssertNotNil(identMe.fingerPrint);
dirk@719
  1260
    XCTAssertNotEqual(identMe.fingerPrint, fpr1);
dirk@742
  1261
dirk@754
  1262
    [self waitForExpectations:@[expHaveMessage] timeout:PEPTestInternalSyncTimeout];
dirk@745
  1263
dirk@742
  1264
    XCTAssertEqual(self.sendMessageDelegate.messages.count, 1);
dirk@719
  1265
}
dirk@719
  1266
andreas@392
  1267
#pragma mark - Helpers
andreas@392
  1268
dirk@763
  1269
- (void)reStartSync
dirk@763
  1270
{
dirk@763
  1271
    [self.sync shutdown];
dirk@763
  1272
    [self startSync];
dirk@763
  1273
}
dirk@763
  1274
dirk@763
  1275
- (void)startSync
dirk@763
  1276
{
dirk@763
  1277
    self.sendMessageDelegate = [PEPSessionTestSendMessageDelegate new];
dirk@763
  1278
    self.notifyHandshakeDelegate = [PEPSessionTestNotifyHandshakeDelegate new];
dirk@763
  1279
dirk@763
  1280
    self.sync = [[PEPSync alloc]
dirk@763
  1281
                 initWithSendMessageDelegate:self.sendMessageDelegate
dirk@763
  1282
                 notifyHandshakeDelegate:self.notifyHandshakeDelegate];
dirk@763
  1283
    [self.sync startup];
dirk@763
  1284
}
dirk@763
  1285
dirk@653
  1286
- (NSNumber * _Nullable)testOutgoingRatingForMessage:(PEPMessage * _Nonnull)theMessage
dirk@653
  1287
                                             session:(PEPSession *)session
dirk@653
  1288
                                               error:(NSError * _Nullable * _Nullable)error
dirk@653
  1289
{
dirk@653
  1290
    NSNumber *ratingOriginal = [session outgoingRatingForMessage:theMessage error:error];
dirk@653
  1291
    NSNumber *ratingPreview = [session outgoingRatingPreviewForMessage:theMessage error:nil];
dirk@653
  1292
    XCTAssertEqual(ratingOriginal, ratingPreview);
dirk@653
  1293
    return ratingOriginal;
dirk@653
  1294
}
dirk@653
  1295
dirk@628
  1296
- (void)testPassiveModeEnabled:(BOOL)passiveModeEnabled
dirk@628
  1297
{
dirk@628
  1298
    [PEPObjCAdapter setPassiveModeEnabled:passiveModeEnabled];
dirk@628
  1299
    PEPSession *session = [PEPSession new];
dirk@628
  1300
dirk@628
  1301
    PEPIdentity *identMe = [[PEPIdentity alloc]
dirk@628
  1302
                            initWithAddress:@"me-myself-and-i@pep-project.org"
dirk@628
  1303
                            userID:@"me-myself-and-i"
dirk@628
  1304
                            userName:@"pEp Me"
dirk@628
  1305
                            isOwn:YES];
dirk@628
  1306
    NSError *error = nil;
dirk@628
  1307
    XCTAssertTrue([session mySelf:identMe error:&error]);
dirk@628
  1308
    XCTAssertNil(error);
dirk@628
  1309
dirk@628
  1310
    XCTAssertNotNil(identMe.fingerPrint);
dirk@628
  1311
dirk@628
  1312
    PEPIdentity *identAlice = [[PEPIdentity alloc]
dirk@628
  1313
                               initWithAddress:@"pep.test.alice@pep-project.org"
dirk@628
  1314
                               userID:@"alice_user_id"
dirk@628
  1315
                               userName:@"Alice"
dirk@628
  1316
                               isOwn:NO];
dirk@628
  1317
dirk@628
  1318
    NSString *shortMessage = @"whatever it may be";
dirk@628
  1319
    NSString *longMessage = [NSString stringWithFormat:@"%@ %@", shortMessage, shortMessage];
dirk@628
  1320
    PEPMessage *message = [PEPMessage new];
dirk@628
  1321
    message.direction = PEP_dir_outgoing;
dirk@628
  1322
    message.from = identMe;
dirk@628
  1323
    message.to = @[identAlice];
dirk@628
  1324
    message.shortMessage = shortMessage;
dirk@628
  1325
    message.longMessage = longMessage;
dirk@628
  1326
dirk@628
  1327
    PEP_STATUS status = PEP_KEY_NOT_FOUND;
dirk@628
  1328
    PEPMessage *encryptedMessage =  [session encryptMessage:message
dirk@628
  1329
                                                  extraKeys:@[]
dirk@628
  1330
                                                     status:&status
dirk@628
  1331
                                                      error:&error];
dirk@628
  1332
    XCTAssertNil(error);
dirk@628
  1333
    XCTAssertEqual(status, PEP_UNENCRYPTED);
dirk@628
  1334
dirk@628
  1335
    if (passiveModeEnabled) {
dirk@628
  1336
        XCTAssertNil(encryptedMessage.attachments);
dirk@628
  1337
    } else {
dirk@628
  1338
        XCTAssertEqual(encryptedMessage.attachments.count, 1);
dirk@628
  1339
    }
dirk@628
  1340
}
dirk@628
  1341
dirk@529
  1342
/**
dirk@529
  1343
 Determines the rating for the given identity.
dirk@529
  1344
 @return PEP_rating_undefined on error
dirk@529
  1345
 */
dirk@529
  1346
- (PEP_rating)ratingForIdentity:(PEPIdentity *)identity session:(PEPSession *)session
dirk@529
  1347
{
dirk@529
  1348
    NSError *error;
dirk@574
  1349
    NSNumber *numRating = [session ratingForIdentity:identity error:&error];
dirk@529
  1350
    XCTAssertNil(error);
dirk@574
  1351
    return numRating.pEpRating;
dirk@529
  1352
}
dirk@529
  1353
dirk@439
  1354
- (PEPIdentity *)checkImportingKeyFilePath:(NSString *)filePath address:(NSString *)address
dirk@439
  1355
                                    userID:(NSString *)userID
dirk@439
  1356
                               fingerPrint:(NSString *)fingerPrint
dirk@456
  1357
                                   session:(PEPSession *)session
dirk@437
  1358
{
dirk@456
  1359
    if (!session) {
dirk@456
  1360
        session = [PEPSession new];
dirk@456
  1361
    }
dirk@437
  1362
dirk@488
  1363
    BOOL success = [PEPTestUtils importBundledKey:filePath session:session];
dirk@488
  1364
    XCTAssertTrue(success);
dirk@437
  1365
dirk@488
  1366
    if (success) {
dirk@488
  1367
        // Our test user:
dirk@488
  1368
        PEPIdentity *identTest = [[PEPIdentity alloc]
dirk@488
  1369
                                  initWithAddress:address
dirk@488
  1370
                                  userID:userID
dirk@488
  1371
                                  userName:[NSString stringWithFormat:@"Some User Name %@", userID]
dirk@488
  1372
                                  isOwn:NO];
dirk@437
  1373
dirk@532
  1374
        NSError *error = nil;
dirk@532
  1375
        XCTAssertTrue([session updateIdentity:identTest error:&error]);
dirk@532
  1376
        XCTAssertNil(error);
dirk@488
  1377
        XCTAssertNotNil(identTest.fingerPrint);
dirk@488
  1378
        XCTAssertEqualObjects(identTest.fingerPrint, fingerPrint);
dirk@439
  1379
dirk@488
  1380
        return identTest;
dirk@488
  1381
    } else {
dirk@488
  1382
        return nil;
dirk@488
  1383
    }
dirk@439
  1384
}
dirk@439
  1385
dirk@439
  1386
- (PEPIdentity *)checkMySelfImportingKeyFilePath:(NSString *)filePath address:(NSString *)address
dirk@439
  1387
                                          userID:(NSString *)userID
dirk@439
  1388
                                     fingerPrint:(NSString *)fingerPrint
dirk@491
  1389
                                         session:(PEPSession *)session
dirk@439
  1390
{
dirk@494
  1391
    XCTAssertTrue([PEPTestUtils importBundledKey:filePath session:session]);
dirk@439
  1392
dirk@439
  1393
    // Our test user:
dirk@439
  1394
    PEPIdentity *identTest = [[PEPIdentity alloc]
dirk@439
  1395
                              initWithAddress:address
dirk@439
  1396
                              userID:userID
dirk@439
  1397
                              userName:[NSString stringWithFormat:@"Some User Name %@", userID]
dirk@439
  1398
                              isOwn:YES
dirk@439
  1399
                              fingerPrint: fingerPrint];
dirk@439
  1400
dirk@502
  1401
    NSError *error;
dirk@502
  1402
    XCTAssertTrue([session setOwnKey:identTest fingerprint:fingerPrint error:&error]);
dirk@502
  1403
    XCTAssertNil(error);
dirk@439
  1404
    XCTAssertNotNil(identTest.fingerPrint);
dirk@439
  1405
    XCTAssertEqualObjects(identTest.fingerPrint, fingerPrint);
dirk@439
  1406
dirk@439
  1407
    return identTest;
dirk@437
  1408
}
dirk@437
  1409
dirk@433
  1410
/**
dirk@433
  1411
 Verifies that a partner ID is really a correct Identity.
dirk@433
  1412
 Usually used on identities imported as keys, since the engine has problems with them.
dirk@433
  1413
 */
dirk@433
  1414
- (void)updateAndVerifyPartnerIdentity:(PEPIdentity *)partnerIdentity session:(PEPSession *)session
dirk@433
  1415
{
dirk@532
  1416
    NSError *error = nil;
dirk@532
  1417
dirk@433
  1418
    XCTAssertNotNil(partnerIdentity.fingerPrint);
dirk@532
  1419
    XCTAssertTrue([session updateIdentity:partnerIdentity error:&error]);
dirk@532
  1420
    XCTAssertNil(error);
dirk@433
  1421
    XCTAssertNotNil(partnerIdentity.fingerPrint);
dirk@433
  1422
    NSString *fingerprint = partnerIdentity.fingerPrint;
dirk@433
  1423
    partnerIdentity.fingerPrint = nil;
dirk@532
  1424
    XCTAssertTrue([session updateIdentity:partnerIdentity error:&error]);
dirk@532
  1425
    XCTAssertNil(error);
dirk@433
  1426
    XCTAssertNotNil(partnerIdentity.fingerPrint);
dirk@433
  1427
    XCTAssertEqualObjects(partnerIdentity.fingerPrint, fingerprint);
dirk@433
  1428
}
dirk@433
  1429
andreas@416
  1430
- (PEPMessage *)mailWrittenToMySelf
andreas@416
  1431
{
andreas@416
  1432
    PEPSession *session = [PEPSession new];
andreas@416
  1433
andreas@416
  1434
    // Write a e-mail to yourself ...
andreas@416
  1435
    PEPIdentity *me = [PEPTestUtils ownPepIdentityWithAddress:@"me@peptest.ch"
andreas@416
  1436
                                                     userName:@"userName"];
dirk@532
  1437
    NSError *error = nil;
dirk@532
  1438
    XCTAssertTrue([session mySelf:me error:&error]);
dirk@532
  1439
    XCTAssertNil(error);
andreas@416
  1440
andreas@416
  1441
    NSString *shortMessage = @"Subject";
andreas@416
  1442
    NSString *longMessage = @"Oh, this is a long body text!";
andreas@416
  1443
    PEPMessage *mail = [PEPTestUtils mailFrom:me
andreas@416
  1444
                                      toIdent:me
andreas@416
  1445
                                 shortMessage:shortMessage
andreas@416
  1446
                                  longMessage:longMessage
andreas@416
  1447
                                     outgoing:YES];
dirk@526
  1448
    PEP_STATUS status = PEP_UNKNOWN_ERROR;
dirk@556
  1449
    PEPMessage *encMessage = [session
dirk@556
  1450
                              encryptMessage:mail
dirk@557
  1451
                              forSelf:me
dirk@556
  1452
                              extraKeys:nil
dirk@556
  1453
                              status:&status
dirk@556
  1454
                              error:&error];
dirk@526
  1455
    XCTAssertNil(error);
andreas@416
  1456
andreas@416
  1457
    return encMessage;
andreas@416
  1458
}
andreas@416
  1459
andreas@392
  1460
- (PEPMessage *)internalEncryptToMySelfKeys:(PEPStringList **)keys
andreas@392
  1461
{
andreas@392
  1462
    PEPSession *session = [PEPSession new];
andreas@411
  1463
    
andreas@411
  1464
    PEPIdentity *me = [PEPTestUtils ownPepIdentityWithAddress:@"me@peptest.ch"
andreas@411
  1465
                                                     userName:@"userName"];
dirk@532
  1466
    NSError *error = nil;
dirk@532
  1467
    XCTAssertTrue([session mySelf:me error:&error]);
dirk@532
  1468
    XCTAssertNil(error);
dirk@532
  1469
andreas@392
  1470
    XCTAssertNotNil(me.fingerPrint);
andreas@392
  1471
andreas@392
  1472
    // Create draft
andreas@392
  1473
    NSString *shortMessage = @"Subject";
andreas@392
  1474
    NSString *longMessage = @"Oh, this is a long body text!";
andreas@392
  1475
    PEPMessage *mail = [PEPTestUtils mailFrom:me toIdent:me shortMessage:shortMessage longMessage:longMessage outgoing:YES];
andreas@392
  1476
dirk@526
  1477
    PEP_STATUS status;
dirk@556
  1478
    PEPMessage *encMessage = [session
dirk@556
  1479
                              encryptMessage:mail
dirk@557
  1480
                              forSelf:me
dirk@556
  1481
                              extraKeys:nil
dirk@556
  1482
                              status:&status
dirk@556
  1483
                              error:&error];
andreas@392
  1484
    XCTAssertEqual(status, 0);
andreas@392
  1485
    XCTAssertEqualObjects(encMessage.shortMessage, @"p≡p");
andreas@392
  1486
dirk@514
  1487
    PEP_rating rating;
dirk@526
  1488
    error = nil;
dirk@517
  1489
    PEPMessage *unencDict = [session
dirk@517
  1490
                             decryptMessage:encMessage
dirk@583
  1491
                             flags:nil
dirk@517
  1492
                             rating:&rating
dirk@523
  1493
                             extraKeys:keys
dirk@524
  1494
                             status:nil
dirk@517
  1495
                             error:&error];
dirk@517
  1496
    XCTAssertNotNil(unencDict);
dirk@514
  1497
    XCTAssertNil(error);
dirk@514
  1498
andreas@392
  1499
    XCTAssertGreaterThanOrEqual(rating, PEP_rating_reliable);
andreas@392
  1500
andreas@392
  1501
    XCTAssertEqualObjects(unencDict.shortMessage, shortMessage);
andreas@392
  1502
    XCTAssertEqualObjects(unencDict.longMessage, longMessage);
andreas@392
  1503
andreas@392
  1504
    return unencDict;
andreas@392
  1505
}
andreas@392
  1506
andreas@392
  1507
- (void)pEpCleanUp
andreas@392
  1508
{
dirk@470
  1509
    [PEPTestUtils cleanUp];
andreas@392
  1510
}
andreas@392
  1511
dirk@424
  1512
- (void)helperXEncStatusForOutgoingEncryptdMailToSelf:(BOOL)toSelf
dirk@424
  1513
                                       expectedRating:(PEP_rating)expectedRating
dirk@422
  1514
{
dirk@422
  1515
    PEPSession *session = [PEPSession new];
dirk@422
  1516
dirk@422
  1517
    // Partner pubkey for the test:
dirk@422
  1518
    // pEp Test Alice (test key don't use) <pep.test.alice@pep-project.org>
dirk@422
  1519
    // 4ABE3AAF59AC32CFE4F86500A9411D176FF00E97
dirk@617
  1520
    XCTAssertTrue([PEPTestUtils importBundledKey:@"6FF00E97.asc" session:session]);
dirk@422
  1521
dirk@422
  1522
    PEPIdentity *identAlice = [[PEPIdentity alloc]
dirk@422
  1523
                               initWithAddress:@"pep.test.alice@pep-project.org"
dirk@422
  1524
                               userID:ownUserId
dirk@422
  1525
                               userName:@"pEp Test Alice"
dirk@422
  1526
                               isOwn:NO
dirk@433
  1527
                               fingerPrint:@"4ABE3AAF59AC32CFE4F86500A9411D176FF00E97"];
dirk@433
  1528
    [self updateAndVerifyPartnerIdentity:identAlice session:session];
dirk@422
  1529
dirk@422
  1530
    PEPIdentity *identMe = [[PEPIdentity alloc]
dirk@422
  1531
                               initWithAddress:@"me-myself-and-i@pep-project.org"
dirk@422
  1532
                               userID:@"me-myself-and-i"
dirk@452
  1533
                               userName:@"pEp Me"
dirk@422
  1534
                               isOwn:YES];
dirk@532
  1535
    NSError *error = nil;
dirk@532
  1536
    XCTAssertTrue([session mySelf:identMe error:&error]);
dirk@532
  1537
    XCTAssertNil(error);
dirk@532
  1538
dirk@422
  1539
    XCTAssertNotNil(identMe.fingerPrint);
dirk@422
  1540
dirk@422
  1541
    PEPMessage *msg = [PEPMessage new];
dirk@422
  1542
    msg.from = identMe;
dirk@422
  1543
    msg.to = @[identAlice];
dirk@422
  1544
    msg.shortMessage = @"Mail to Alice";
dirk@422
  1545
    msg.longMessage = @"Alice?";
dirk@422
  1546
    msg.direction = PEP_dir_outgoing;
dirk@422
  1547
dirk@653
  1548
    NSNumber *numRating = [self testOutgoingRatingForMessage:msg session:session error:&error];
dirk@573
  1549
    XCTAssertNotNil(numRating);
dirk@573
  1550
    XCTAssertNil(error);
dirk@573
  1551
    XCTAssertEqual(numRating.pEpRating, PEP_rating_reliable);
dirk@422
  1552
dirk@423
  1553
    PEPMessage *encMsg;
dirk@424
  1554
dirk@424
  1555
    PEP_STATUS statusEnc = PEP_VERSION_MISMATCH;
dirk@424
  1556
    if (toSelf) {
dirk@556
  1557
        encMsg = [session
dirk@556
  1558
                  encryptMessage:msg
dirk@557
  1559
                  forSelf:identMe
dirk@556
  1560
                  extraKeys:nil
dirk@556
  1561
                  status:&statusEnc
dirk@556
  1562
                  error:&error];
dirk@522
  1563
        XCTAssertEqual(statusEnc, PEP_STATUS_OK);
dirk@424
  1564
    } else {
dirk@524
  1565
        encMsg = [session encryptMessage:msg extraKeys:nil status:nil error:&error];
dirk@522
  1566
        XCTAssertNotNil(encMsg);
dirk@522
  1567
        XCTAssertNil(error);
dirk@424
  1568
    }
dirk@423
  1569
    XCTAssertNotNil(encMsg);
dirk@423
  1570
dirk@423
  1571
    PEPStringList *keys;
dirk@514
  1572
    PEP_rating pEpRating;
dirk@526
  1573
    error = nil;
dirk@517
  1574
    PEPMessage *decMsg = [session
dirk@517
  1575
                          decryptMessage:encMsg
dirk@583
  1576
                          flags:nil
dirk@517
  1577
                          rating:&pEpRating
dirk@523
  1578
                          extraKeys:&keys
dirk@524
  1579
                          status:nil
dirk@517
  1580
                          error:&error];
dirk@514
  1581
    XCTAssertNil(error);
dirk@517
  1582
    XCTAssertNotNil(decMsg);
dirk@514
  1583
dirk@424
  1584
    XCTAssertEqual(pEpRating, expectedRating);
dirk@423
  1585
dirk@423
  1586
    NSArray * encStatusField = nil;
dirk@423
  1587
    for (NSArray *field in decMsg.optionalFields) {
dirk@423
  1588
        NSString *header = [field[0] lowercaseString];
dirk@423
  1589
        if ([header isEqualToString:@"x-encstatus"]) {
dirk@423
  1590
            encStatusField = field;
dirk@423
  1591
        }
dirk@423
  1592
    }
dirk@423
  1593
    XCTAssertNotNil(encStatusField);
dirk@423
  1594
    if (encStatusField) {
dirk@423
  1595
        PEP_rating outgoingRating = [session ratingFromString:encStatusField[1]];
dirk@424
  1596
        XCTAssertEqual(outgoingRating, expectedRating);
dirk@423
  1597
    }
dirk@422
  1598
}
dirk@422
  1599
andreas@392
  1600
@end