pEpObjCTests/PEPSessionTest.m
author buff <andreas@pep-project.org>
Thu, 18 Jan 2018 16:41:32 +0100
changeset 392 3810cea03bc2
child 393 6f8fa4c7b897
permissions -rw-r--r--
IOSAD-55 seperates tests
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@392
    27
    [self pEpCleanUp];
andreas@392
    28
}
andreas@392
    29
andreas@392
    30
- (void)tearDown {
andreas@392
    31
    [self pEpCleanUp];
andreas@392
    32
    [super tearDown];
andreas@392
    33
}
andreas@392
    34
andreas@392
    35
- (void)testSyncSession
andreas@392
    36
{
andreas@392
    37
    PEPSession *session = [PEPSession new];
andreas@392
    38
    PEPTestSyncDelegate *syncDelegate = [[PEPTestSyncDelegate alloc] init];
andreas@392
    39
andreas@392
    40
    // This should attach session just created
andreas@392
    41
    [PEPObjCAdapter startSync:syncDelegate];
andreas@392
    42
andreas@392
    43
    PEPIdentity *identMe = [[PEPIdentity alloc]
andreas@392
    44
                            initWithAddress:@"pep.test.iosgenkey@pep-project.org"
andreas@392
    45
                            userID:@"Me"
andreas@392
    46
                            userName:@"pEp Test iOS GenKey"
andreas@392
    47
                            isOwn:YES];
andreas@392
    48
andreas@392
    49
    [session mySelf:identMe];
andreas@392
    50
andreas@392
    51
    bool res = [syncDelegate waitUntilSent:1];
andreas@392
    52
andreas@392
    53
    // Can't currently work, engine doesn't contain sync.
andreas@392
    54
    XCTAssertFalse(res);
andreas@392
    55
andreas@392
    56
    // This should detach session just created
andreas@392
    57
    [PEPObjCAdapter stopSync];
andreas@392
    58
}
andreas@392
    59
andreas@392
    60
- (void)testTrustWords
andreas@392
    61
{
andreas@392
    62
    PEPSession *session = [PEPSession new];
andreas@392
    63
andreas@392
    64
    NSArray *trustwords = [session trustwords:@"DB47DB47DB47DB47DB47DB47DB47DB47DB47DB47"
andreas@392
    65
                                  forLanguage:@"en" shortened:false];
andreas@392
    66
    XCTAssertEqual([trustwords count], 10);
andreas@392
    67
andreas@392
    68
    for(id word in trustwords)
andreas@392
    69
        XCTAssertEqualObjects(word, @"BAPTISMAL");
andreas@392
    70
}
andreas@392
    71
andreas@392
    72
- (void)testGenKey
andreas@392
    73
{
andreas@392
    74
    PEPSession *session = [PEPSession new];
andreas@392
    75
andreas@392
    76
    PEPIdentity *identMe = [[PEPIdentity alloc]
andreas@392
    77
                            initWithAddress:@"pep.test.iosgenkey@pep-project.org"
andreas@392
    78
                            userID:@"Me"
andreas@392
    79
                            userName:@"pEp Test iOS GenKey"
andreas@392
    80
                            isOwn:YES];
andreas@392
    81
andreas@392
    82
    [session mySelf:identMe];
andreas@392
    83
andreas@392
    84
    XCTAssertNotNil(identMe.fingerPrint);
andreas@392
    85
    XCTAssertNotEqual(identMe.commType, PEP_ct_unknown);
andreas@392
    86
andreas@392
    87
    // check that the comm type is not a PGP one
andreas@392
    88
    XCTAssertFalse([identMe containsPGPCommType]);
andreas@392
    89
}
andreas@392
    90
andreas@392
    91
- (void)testMySelfCommType
andreas@392
    92
{
andreas@392
    93
    PEPSession *session = [PEPSession new];
andreas@392
    94
andreas@392
    95
    PEPIdentity *identMe = [[PEPIdentity alloc]
andreas@392
    96
                            initWithAddress:@"pep.test.iosgenkey@pep-project.org"
andreas@392
    97
                            userID:@"Me"
andreas@392
    98
                            userName:@"pEp Test iOS GenKey"
andreas@392
    99
                            isOwn:YES];
andreas@392
   100
andreas@392
   101
    [session mySelf:identMe];
andreas@392
   102
andreas@392
   103
    XCTAssertNotNil(identMe.fingerPrint);
andreas@392
   104
    XCTAssertNotEqual(identMe.commType, PEP_ct_unknown);
andreas@392
   105
andreas@392
   106
    // check that the comm type is not a PGP one
andreas@392
   107
    XCTAssertFalse([identMe containsPGPCommType]);
andreas@392
   108
andreas@392
   109
    dispatch_queue_t queue = dispatch_get_global_queue(QOS_CLASS_USER_INITIATED, 0);
andreas@392
   110
    dispatch_sync(queue, ^{
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];
andreas@392
   120
        [session2 mySelf:identMe2];
andreas@392
   121
        XCTAssertNotNil(identMe2.fingerPrint);
andreas@392
   122
        XCTAssertFalse([identMe2 containsPGPCommType]);
andreas@392
   123
        XCTAssertEqualObjects(identMe2.fingerPrint, identMe.fingerPrint);
andreas@392
   124
andreas@392
   125
        // Now pretend the app only knows kPepUsername and kPepAddress
andreas@392
   126
        PEPIdentity *identMe3 = [[PEPIdentity alloc]
andreas@392
   127
                                 initWithAddress:identMe.address
andreas@392
   128
                                 userName:identMe.userName
andreas@392
   129
                                 isOwn:NO];
andreas@392
   130
        [session2 mySelf:identMe3];
andreas@392
   131
        XCTAssertNotNil(identMe3.fingerPrint);
andreas@392
   132
        XCTAssertFalse([identMe3 containsPGPCommType]);
andreas@392
   133
        XCTAssertEqualObjects(identMe3.fingerPrint, identMe.fingerPrint);
andreas@392
   134
andreas@392
   135
        XCTAssertEqualObjects(identMe.address, identMe2.address);
andreas@392
   136
        XCTAssertEqualObjects(identMe.address, identMe3.address);
andreas@392
   137
        XCTAssertEqual(identMe.commType, identMe2.commType);
andreas@392
   138
        XCTAssertEqual(identMe.commType, identMe3.commType);
andreas@392
   139
    });
andreas@392
   140
}
andreas@392
   141
andreas@392
   142
- (void)testOutgoingColors
andreas@392
   143
{
andreas@392
   144
    PEPSession *session = [PEPSession new];
andreas@392
   145
andreas@392
   146
    // Our test user :
andreas@392
   147
    // pEp Test Alice (test key don't use) <pep.test.alice@pep-project.org>
andreas@392
   148
    // 4ABE3AAF59AC32CFE4F86500A9411D176FF00E97
andreas@392
   149
    [PEPTestUtils importBundledKey:@"6FF00E97_sec.asc"];
andreas@392
   150
andreas@392
   151
    // Our test user :
andreas@392
   152
    PEPIdentity *identAlice = [[PEPIdentity alloc]
andreas@392
   153
                               initWithAddress:@"pep.test.alice@pep-project.org"
andreas@392
   154
                               userID:ownUserId
andreas@392
   155
                               userName:@"pEp Test Alice"
andreas@392
   156
                               isOwn:YES
andreas@392
   157
                               fingerPrint:@"4ABE3AAF59AC32CFE4F86500A9411D176FF00E97"];
andreas@392
   158
andreas@392
   159
    [session mySelf:identAlice];
andreas@392
   160
andreas@392
   161
    //Message
andreas@392
   162
andreas@392
   163
    PEPMessage *msg = [PEPMessage new];
andreas@392
   164
    msg.from = identAlice;
andreas@392
   165
    msg.to = @[[[PEPIdentity alloc] initWithAddress:@"pep.test.bob@pep-project.org"
andreas@392
   166
                                             userID: @"42"
andreas@392
   167
                                           userName:@"pEp Test Bob"
andreas@392
   168
                                              isOwn:NO]];
andreas@392
   169
    msg.shortMessage = @"All Green Test";
andreas@392
   170
    msg.longMessage = @"This is a text content";
andreas@392
   171
    msg.direction = PEP_dir_outgoing;
andreas@392
   172
andreas@392
   173
    // Test with unknown Bob
andreas@392
   174
    PEP_rating clr = [session outgoingColorForMessage:msg];
andreas@392
   175
    XCTAssert( clr == PEP_rating_unencrypted);
andreas@392
   176
andreas@392
   177
    // Now let see with bob's pubkey already known
andreas@392
   178
    // pEp Test Bob (test key, don't use) <pep.test.bob@pep-project.org>
andreas@392
   179
    // BFCDB7F301DEEEBBF947F29659BFF488C9C2EE39
andreas@392
   180
    [PEPTestUtils importBundledKey:@"0xC9C2EE39.asc"];
andreas@392
   181
andreas@392
   182
    PEPIdentity *identBob = [[PEPIdentity alloc]
andreas@392
   183
                             initWithAddress:@"pep.test.bob@pep-project.org"
andreas@392
   184
                             userID:@"42" userName:@"pEp Test Bob"
andreas@392
   185
                             isOwn:NO
andreas@392
   186
                             fingerPrint:@"BFCDB7F301DEEEBBF947F29659BFF488C9C2EE39"];
andreas@392
   187
andreas@392
   188
    [session updateIdentity:identBob];
andreas@392
   189
andreas@392
   190
    // Should be yellow, since no handshake happened.
andreas@392
   191
    clr = [session outgoingColorForMessage:msg];
andreas@392
   192
    XCTAssert( clr == PEP_rating_reliable);
andreas@392
   193
andreas@392
   194
    clr = [session identityRating:identBob];
andreas@392
   195
    XCTAssert( clr == PEP_rating_reliable);
andreas@392
   196
andreas@392
   197
    // Let' say we got that handshake, set PEP_ct_confirmed in Bob's identity
andreas@392
   198
    [session trustPersonalKey:identBob];
andreas@392
   199
andreas@392
   200
    // This time it should be green
andreas@392
   201
    clr = [session outgoingColorForMessage:msg];
andreas@392
   202
    XCTAssert( clr == PEP_rating_trusted);
andreas@392
   203
andreas@392
   204
    clr = [session identityRating:identBob];
andreas@392
   205
    XCTAssert( clr == PEP_rating_trusted);
andreas@392
   206
andreas@392
   207
    // Let' say we undo handshake
andreas@392
   208
    [session keyResetTrust:identBob];
andreas@392
   209
andreas@392
   210
    // Yellow ?
andreas@392
   211
    clr = [session outgoingColorForMessage:msg];
andreas@392
   212
    XCTAssert( clr == PEP_rating_reliable);
andreas@392
   213
andreas@392
   214
    // mistrust Bob
andreas@392
   215
    [session keyMistrusted:identBob];
andreas@392
   216
andreas@392
   217
    // Gray == PEP_rating_unencrypted
andreas@392
   218
    clr = [session outgoingColorForMessage:msg];
andreas@392
   219
    XCTAssert( clr == PEP_rating_unencrypted);
andreas@392
   220
andreas@392
   221
    // Forget
andreas@392
   222
    [session keyResetTrust:identBob];
andreas@392
   223
andreas@392
   224
    // Back to yellow
andreas@392
   225
    clr = [session outgoingColorForMessage:msg];
andreas@392
   226
    XCTAssert( clr == PEP_rating_reliable);
andreas@392
   227
andreas@392
   228
    // Trust again
andreas@392
   229
    [session trustPersonalKey:identBob];
andreas@392
   230
andreas@392
   231
    // Back to green
andreas@392
   232
    clr = [session outgoingColorForMessage:msg];
andreas@392
   233
    XCTAssert( clr == PEP_rating_trusted);
andreas@392
   234
andreas@392
   235
    // Now let see if it turns back yellow if we add an unconfirmed folk.
andreas@392
   236
    // pEp Test John (test key, don't use) <pep.test.john@pep-project.org>
andreas@392
   237
    // AA2E4BEB93E5FE33DEFD8BE1135CD6D170DCF575
andreas@392
   238
    [PEPTestUtils importBundledKey:@"0x70DCF575.asc"];
andreas@392
   239
andreas@392
   240
    PEPIdentity *identJohn = [[PEPIdentity alloc]
andreas@392
   241
                              initWithAddress:@"pep.test.john@pep-project.org"
andreas@392
   242
                              userID:@"101" userName:@"pEp Test John"
andreas@392
   243
                              isOwn:NO
andreas@392
   244
                              fingerPrint:@"AA2E4BEB93E5FE33DEFD8BE1135CD6D170DCF575"];
andreas@392
   245
andreas@392
   246
    [session updateIdentity:identJohn];
andreas@392
   247
andreas@392
   248
    msg.cc = @[[[PEPIdentity alloc] initWithAddress:@"pep.test.john@pep-project.org"
andreas@392
   249
                                           userName:@"pEp Test John" isOwn:NO]];
andreas@392
   250
andreas@392
   251
    // Yellow ?
andreas@392
   252
    clr = [session outgoingColorForMessage:msg];
andreas@392
   253
    XCTAssert( clr == PEP_rating_reliable);
andreas@392
   254
andreas@392
   255
    PEPMessage *encmsg;
andreas@392
   256
    PEP_STATUS status = [session encryptMessage:msg extra:@[] dest:&encmsg];
andreas@392
   257
andreas@392
   258
    XCTAssertNotNil(encmsg);
andreas@392
   259
    XCTAssertEqualObjects(encmsg.shortMessage, @"p≡p");
andreas@392
   260
    XCTAssertTrue([encmsg.longMessage containsString:@"p≡p"]);
andreas@392
   261
andreas@392
   262
    XCTAssert(status == PEP_STATUS_OK);
andreas@392
   263
}
andreas@392
   264
andreas@392
   265
andreas@392
   266
- (void)testOutgoingBccColors
andreas@392
   267
{
andreas@392
   268
    PEPSession *session = [PEPSession new];
andreas@392
   269
andreas@392
   270
    // Our test user :
andreas@392
   271
    // pEp Test Alice (test key don't use) <pep.test.alice@pep-project.org>
andreas@392
   272
    // 4ABE3AAF59AC32CFE4F86500A9411D176FF00E97
andreas@392
   273
    [PEPTestUtils importBundledKey:@"6FF00E97_sec.asc"];
andreas@392
   274
andreas@392
   275
    PEPIdentity *identAlice = [[PEPIdentity alloc]
andreas@392
   276
                               initWithAddress:@"pep.test.alice@pep-project.org"
andreas@392
   277
                               userID:ownUserId
andreas@392
   278
                               userName:@"pEp Test Alice"
andreas@392
   279
                               isOwn:YES
andreas@392
   280
                               fingerPrint:@"4ABE3AAF59AC32CFE4F86500A9411D176FF00E97"];
andreas@392
   281
andreas@392
   282
    [session mySelf:identAlice];
andreas@392
   283
andreas@392
   284
    PEPMessage *msg = [PEPMessage new];
andreas@392
   285
    msg.from = identAlice;
andreas@392
   286
    msg.to = @[[[PEPIdentity alloc] initWithAddress:@"pep.test.bob@pep-project.org"
andreas@392
   287
                                             userID:@"42" userName:@"pEp Test Bob" isOwn:NO]];
andreas@392
   288
    msg.shortMessage = @"All Green Test";
andreas@392
   289
    msg.longMessage = @"This is a text content";
andreas@392
   290
    msg.direction = PEP_dir_outgoing;
andreas@392
   291
andreas@392
   292
    // Test with unknown Bob
andreas@392
   293
    PEP_rating clr = [session outgoingColorForMessage:msg];
andreas@392
   294
    XCTAssert( clr == PEP_rating_unencrypted);
andreas@392
   295
andreas@392
   296
    // Now let see with bob's pubkey already known
andreas@392
   297
    // pEp Test Bob (test key, don't use) <pep.test.bob@pep-project.org>
andreas@392
   298
    // BFCDB7F301DEEEBBF947F29659BFF488C9C2EE39
andreas@392
   299
    [PEPTestUtils importBundledKey:@"0xC9C2EE39.asc"];
andreas@392
   300
andreas@392
   301
    PEPIdentity *identBob = [[PEPIdentity alloc]
andreas@392
   302
                             initWithAddress:@"pep.test.bob@pep-project.org"
andreas@392
   303
                             userID:@"42" userName:@"pEp Test Bob"
andreas@392
   304
                             isOwn:NO
andreas@392
   305
                             fingerPrint:@"BFCDB7F301DEEEBBF947F29659BFF488C9C2EE39"];
andreas@392
   306
andreas@392
   307
    [session updateIdentity:identBob];
andreas@392
   308
andreas@392
   309
    // Should be yellow, since no handshake happened.
andreas@392
   310
    clr = [session outgoingColorForMessage:msg];
andreas@392
   311
    XCTAssert( clr == PEP_rating_reliable);
andreas@392
   312
andreas@392
   313
    clr = [session identityRating:identBob];
andreas@392
   314
    XCTAssert( clr == PEP_rating_reliable);
andreas@392
   315
andreas@392
   316
    // Let' say we got that handshake, set PEP_ct_confirmed in Bob's identity
andreas@392
   317
    [session trustPersonalKey:identBob];
andreas@392
   318
andreas@392
   319
    // This time it should be green
andreas@392
   320
    clr = [session outgoingColorForMessage:msg];
andreas@392
   321
    XCTAssert( clr == PEP_rating_trusted);
andreas@392
   322
andreas@392
   323
    clr = [session identityRating:identBob];
andreas@392
   324
    XCTAssert( clr == PEP_rating_trusted);
andreas@392
   325
andreas@392
   326
    // Now let see if it turns back yellow if we add an unconfirmed folk.
andreas@392
   327
    // pEp Test John (test key, don't use) <pep.test.john@pep-project.org>
andreas@392
   328
    // AA2E4BEB93E5FE33DEFD8BE1135CD6D170DCF575
andreas@392
   329
    [PEPTestUtils importBundledKey:@"0x70DCF575.asc"];
andreas@392
   330
andreas@392
   331
    PEPIdentity *identJohn = [[PEPIdentity alloc]
andreas@392
   332
                              initWithAddress:@"pep.test.john@pep-project.org"
andreas@392
   333
                              userID:@"101" userName:@"pEp Test John"
andreas@392
   334
                              isOwn:NO
andreas@392
   335
                              fingerPrint:@"AA2E4BEB93E5FE33DEFD8BE1135CD6D170DCF575"];
andreas@392
   336
andreas@392
   337
    [session updateIdentity:identJohn];
andreas@392
   338
andreas@392
   339
    msg.bcc = @[[[PEPIdentity alloc] initWithAddress:@"pep.test.john@pep-project.org"
andreas@392
   340
                                              userID:@"101" userName:@"pEp Test John" isOwn:NO]];
andreas@392
   341
andreas@392
   342
    // Yellow ?
andreas@392
   343
    clr = [session outgoingColorForMessage:msg];
andreas@392
   344
    XCTAssert( clr == PEP_rating_reliable);
andreas@392
   345
andreas@392
   346
    [session trustPersonalKey:identJohn];
andreas@392
   347
andreas@392
   348
    // This time it should be green
andreas@392
   349
    clr = [session outgoingColorForMessage:msg];
andreas@392
   350
    XCTAssert( clr == PEP_rating_trusted);
andreas@392
   351
andreas@392
   352
    clr = [session identityRating:identJohn];
andreas@392
   353
    XCTAssert( clr == PEP_rating_trusted);
andreas@392
   354
}
andreas@392
   355
andreas@392
   356
- (void)testDontEncryptForMistrusted
andreas@392
   357
{
andreas@392
   358
    PEPSession *session = [PEPSession new];
andreas@392
   359
andreas@392
   360
    // Our test user :
andreas@392
   361
    // pEp Test Alice (test key don't use) <pep.test.alice@pep-project.org>
andreas@392
   362
    // 4ABE3AAF59AC32CFE4F86500A9411D176FF00E97
andreas@392
   363
    [PEPTestUtils importBundledKey:@"6FF00E97_sec.asc"];
andreas@392
   364
andreas@392
   365
    PEPIdentity *identAlice = [[PEPIdentity alloc]
andreas@392
   366
                               initWithAddress:@"pep.test.alice@pep-project.org"
andreas@392
   367
                               userID:ownUserId
andreas@392
   368
                               userName:@"pEp Test Alice"
andreas@392
   369
                               isOwn:YES
andreas@392
   370
                               fingerPrint:@"4ABE3AAF59AC32CFE4F86500A9411D176FF00E97"];
andreas@392
   371
andreas@392
   372
    [session mySelf:identAlice];
andreas@392
   373
andreas@392
   374
    // pEp Test Bob (test key, don't use) <pep.test.bob@pep-project.org>
andreas@392
   375
    // BFCDB7F301DEEEBBF947F29659BFF488C9C2EE39
andreas@392
   376
    [PEPTestUtils importBundledKey:@"0xC9C2EE39.asc"];
andreas@392
   377
andreas@392
   378
    PEPIdentity *identBob = [[PEPIdentity alloc]
andreas@392
   379
                             initWithAddress:@"pep.test.bob@pep-project.org"
andreas@392
   380
                             userID:@"42" userName:@"pEp Test Bob"
andreas@392
   381
                             isOwn:NO
andreas@392
   382
                             fingerPrint:@"BFCDB7F301DEEEBBF947F29659BFF488C9C2EE39"];
andreas@392
   383
andreas@392
   384
    [session updateIdentity:identBob];
andreas@392
   385
andreas@392
   386
    // mistrust Bob
andreas@392
   387
    [session keyMistrusted:identBob];
andreas@392
   388
andreas@392
   389
    PEPMessage *msg = [PEPMessage new];
andreas@392
   390
    msg.from = identAlice;
andreas@392
   391
    msg.to = @[[[PEPIdentity alloc] initWithAddress:@"pep.test.bob@pep-project.org" userID:@"42"
andreas@392
   392
                                           userName:@"pEp Test Bob" isOwn:NO]];
andreas@392
   393
    msg.shortMessage = @"All Green Test";
andreas@392
   394
    msg.longMessage = @"This is a text content";
andreas@392
   395
    msg.direction = PEP_dir_outgoing;
andreas@392
   396
andreas@392
   397
    // Gray == PEP_rating_unencrypted
andreas@392
   398
    PEP_rating clr = [session outgoingColorForMessage:msg];
andreas@392
   399
    XCTAssert( clr == PEP_rating_unencrypted);
andreas@392
   400
andreas@392
   401
    PEPMessage *encmsg;
andreas@392
   402
    PEP_STATUS status = [session encryptMessage:msg extra:@[] dest:&encmsg];
andreas@392
   403
andreas@392
   404
    XCTAssert(status == PEP_UNENCRYPTED);
andreas@392
   405
andreas@392
   406
    XCTAssertNotEqualObjects(encmsg.attachments[0][@"mimeType"], @"application/pgp-encrypted");
andreas@392
   407
andreas@392
   408
    [self pEpCleanUp];
andreas@392
   409
}
andreas@392
   410
andreas@392
   411
- (void)testRenewExpired
andreas@392
   412
{
andreas@392
   413
    PEPSession *session = [PEPSession new];
andreas@392
   414
andreas@392
   415
    // Our expired test user :
andreas@392
   416
    // pEp Test Hector (old test key don't use) <pep.test.hector@pep-project.org>
andreas@392
   417
    [PEPTestUtils importBundledKey:@"5CB2C182_sec.asc"];
andreas@392
   418
andreas@392
   419
    PEPIdentity *identHector = [[PEPIdentity alloc]
andreas@392
   420
                                initWithAddress:@"pep.test.hector@pep-project.org"
andreas@392
   421
                                userID:@"fc2d33" userName:@"pEp Test Hector"
andreas@392
   422
                                isOwn:NO
andreas@392
   423
                                fingerPrint:@"EEA655839E347EC9E10A5DE2E80CB3FD5CB2C182"];
andreas@392
   424
andreas@392
   425
    // Check that this key is indeed expired
andreas@392
   426
    [session updateIdentity:identHector];
andreas@392
   427
    XCTAssertEqual(PEP_ct_key_expired, identHector.commType);
andreas@392
   428
andreas@392
   429
    PEPIdentity *identHectorOwn = [[PEPIdentity alloc]
andreas@392
   430
                                   initWithAddress:@"pep.test.hector@pep-project.org"
andreas@392
   431
                                   userID:ownUserId userName:@"pEp Test Hector"
andreas@392
   432
                                   isOwn:YES
andreas@392
   433
                                   fingerPrint:@"EEA655839E347EC9E10A5DE2E80CB3FD5CB2C182"];
andreas@392
   434
andreas@392
   435
    // Myself automatically renew expired key.
andreas@392
   436
    [session mySelf:identHectorOwn];
andreas@392
   437
    XCTAssertEqual(PEP_ct_pEp, identHectorOwn.commType);
andreas@392
   438
andreas@392
   439
    [self pEpCleanUpRestoringBackupNamed:@"Bob"];
andreas@392
   440
andreas@392
   441
andreas@392
   442
    [self pEpSetUp:@"Bob"];
andreas@392
   443
andreas@392
   444
    PEPIdentity *_identHector = [[PEPIdentity alloc]
andreas@392
   445
                                 initWithAddress:@"pep.test.hector@pep-project.org"
andreas@392
   446
                                 userID:@"khkhkh" userName:@"pEp Test Hector"
andreas@392
   447
                                 isOwn:NO
andreas@392
   448
                                 fingerPrint:@"EEA655839E347EC9E10A5DE2E80CB3FD5CB2C182"];
andreas@392
   449
andreas@392
   450
    [session updateIdentity:_identHector];
andreas@392
   451
    XCTAssertEqual(PEP_ct_OpenPGP_unconfirmed, _identHector.commType);
andreas@392
   452
}
andreas@392
   453
andreas@392
   454
- (void)testRevoke
andreas@392
   455
{
andreas@392
   456
    PEPSession *session = [PEPSession new];
andreas@392
   457
andreas@392
   458
    // Our test user :
andreas@392
   459
    // pEp Test Alice (test key don't use) <pep.test.alice@pep-project.org>
andreas@392
   460
    // 4ABE3AAF59AC32CFE4F86500A9411D176FF00E97
andreas@392
   461
    [PEPTestUtils importBundledKey:@"6FF00E97_sec.asc"];
andreas@392
   462
    NSString *fpr = @"4ABE3AAF59AC32CFE4F86500A9411D176FF00E97";
andreas@392
   463
andreas@392
   464
    PEPIdentity *identAlice = [[PEPIdentity alloc]
andreas@392
   465
                               initWithAddress:@"pep.test.alice@pep-project.org"
andreas@392
   466
                               userID:ownUserId
andreas@392
   467
                               userName:@"pEp Test Alice"
andreas@392
   468
                               isOwn:YES
andreas@392
   469
                               fingerPrint:fpr];
andreas@392
   470
andreas@392
   471
    [session mySelf:identAlice];
andreas@392
   472
andreas@392
   473
    PEPIdentity *identAlice2 = [identAlice mutableCopy];
andreas@392
   474
andreas@392
   475
    // This will revoke key
andreas@392
   476
    [session keyMistrusted:identAlice2];
andreas@392
   477
andreas@392
   478
    // Check fingerprint is different
andreas@392
   479
    XCTAssertNotEqualObjects(identAlice2.fingerPrint, fpr);
andreas@392
   480
}
andreas@392
   481
andreas@392
   482
- (void)testMailToMyself
andreas@392
   483
{
andreas@392
   484
    PEPSession *session = [PEPSession new];
andreas@392
   485
andreas@392
   486
    // Our test user :
andreas@392
   487
    // pEp Test Alice (test key don't use) <pep.test.alice@pep-project.org>
andreas@392
   488
    // 4ABE3AAF59AC32CFE4F86500A9411D176FF00E97
andreas@392
   489
    [PEPTestUtils importBundledKey:@"6FF00E97_sec.asc"];
andreas@392
   490
andreas@392
   491
    PEPIdentity *identAlice = [[PEPIdentity alloc]
andreas@392
   492
                               initWithAddress:@"pep.test.alice@pep-project.org"
andreas@392
   493
                               userID:ownUserId
andreas@392
   494
                               userName:@"pEp Test Alice"
andreas@392
   495
                               isOwn:YES
andreas@392
   496
                               fingerPrint:@"4ABE3AAF59AC32CFE4F86500A9411D176FF00E97"];
andreas@392
   497
andreas@392
   498
    [session mySelf:identAlice];
andreas@392
   499
andreas@392
   500
    PEPMessage *msg = [PEPMessage new];
andreas@392
   501
    msg.from = identAlice;
andreas@392
   502
    msg.to = @[identAlice];
andreas@392
   503
    msg.shortMessage = @"Mail to Myself";
andreas@392
   504
    msg.longMessage = @"This is a text content";
andreas@392
   505
    msg.direction = PEP_dir_outgoing;
andreas@392
   506
andreas@392
   507
    // Test with unknown Bob
andreas@392
   508
    PEP_rating clr = [session outgoingColorForMessage:msg];
andreas@392
   509
    XCTAssert( clr == PEP_rating_trusted_and_anonymized);
andreas@392
   510
andreas@392
   511
    PEPMessage *encmsg;
andreas@392
   512
    PEP_STATUS status = [session encryptMessage:msg extra:@[] dest:&encmsg];
andreas@392
   513
andreas@392
   514
    XCTAssert(status == PEP_STATUS_OK);
andreas@392
   515
andreas@392
   516
    NSArray* keys;
andreas@392
   517
    PEPMessage *decmsg;
andreas@392
   518
andreas@392
   519
    clr = [session decryptMessage:encmsg dest:&decmsg keys:&keys];
andreas@392
   520
    XCTAssert( clr == PEP_rating_trusted_and_anonymized);
andreas@392
   521
}
andreas@392
   522
andreas@392
   523
////// test fails. IOSAD-59
andreas@392
   524
////// See testTwoNewUsers.
andreas@392
   525
//////
andreas@392
   526
//- (void)testTwoNewUsers
andreas@392
   527
//{
andreas@392
   528
//    PEPSession *session = [PEPSession new];
andreas@392
   529
//
andreas@392
   530
//    PEPMessage* petrasMsg;
andreas@392
   531
//
andreas@392
   532
//    PEPIdentity *identMiroAtPetra = [[PEPIdentity alloc]
andreas@392
   533
//                                     initWithAddress:@"pep.test.miro@pep-project.org"
andreas@392
   534
//                                     userID:@"not_me"
andreas@392
   535
//                                     userName:@"Miro"
andreas@392
   536
//                                     isOwn:NO];
andreas@392
   537
//    {
andreas@392
   538
//        PEPIdentity *identPetra = [[PEPIdentity alloc]
andreas@392
   539
//                                   initWithAddress:@"pep.test.petra@pep-project.org"
andreas@392
   540
//                                   userID:ownUserId
andreas@392
   541
//                                   userName:@"Petra"
andreas@392
   542
//                                   isOwn:YES];
andreas@392
   543
//
andreas@392
   544
//        [session mySelf:identPetra];
andreas@392
   545
//        XCTAssert(identPetra.fingerPrint);
andreas@392
   546
//
andreas@392
   547
//        PEPMessage *msg = [PEPMessage new];
andreas@392
   548
//        msg.from = identPetra;
andreas@392
   549
//        msg.to = @[identMiroAtPetra];
andreas@392
   550
//        msg.shortMessage = @"Lets use pEp";
andreas@392
   551
//        msg.longMessage = @"Dear, I just installed pEp, you should do the same !";
andreas@392
   552
//        msg.direction = PEP_dir_outgoing;
andreas@392
   553
//
andreas@392
   554
//        PEP_STATUS status = [session encryptMessage:msg extra:@[] dest:&petrasMsg];
andreas@392
   555
//        XCTAssert(status == PEP_UNENCRYPTED);
andreas@392
   556
//    }
andreas@392
   557
//
andreas@392
   558
//    [PEPSession cleanup];
andreas@392
   559
//    [self pEpCleanUpRestoringBackupNamed:@"Petra"];
andreas@392
   560
//
andreas@392
   561
//    // Meanwhile, Petra's outgoing message goes through the Internet,
andreas@392
   562
//    // and becomes incomming message to Miro
andreas@392
   563
//    petrasMsg.direction = PEP_dir_incoming;
andreas@392
   564
//
andreas@392
   565
//    PEPMessage* mirosMsg;
andreas@392
   566
//
andreas@392
   567
//    [self pEpSetUp];
andreas@392
   568
//
andreas@392
   569
//    NSString *longMessage = @"That was so easy";
andreas@392
   570
//    {
andreas@392
   571
//        PEPIdentity *identMiro = [[PEPIdentity alloc]
andreas@392
   572
//                                  initWithAddress:@"pep.test.miro@pep-project.org"
andreas@392
   573
//                                  userID:ownUserId
andreas@392
   574
//                                  userName:@"Miro"
andreas@392
   575
//                                  isOwn:YES];
andreas@392
   576
//
andreas@392
   577
//        [session mySelf:identMiro];
andreas@392
   578
//        XCTAssert(identMiro.fingerPrint);
andreas@392
   579
//
andreas@392
   580
//        PEPMessage *decmsg;
andreas@392
   581
//        NSArray* keys;
andreas@392
   582
//        PEP_rating clr = [session decryptMessage:petrasMsg dest:&decmsg keys:&keys];
andreas@392
   583
//        XCTAssert(clr == PEP_rating_unencrypted);
andreas@392
   584
//
andreas@392
   585
//        PEPMessage *msg = [PEPMessage new];
andreas@392
   586
//        msg.from = identMiro;
andreas@392
   587
//        msg.to = @[[[PEPIdentity alloc] initWithAddress:@"pep.test.petra@pep-project.org"
andreas@392
   588
//                                               userName:@"Petra" isOwn:NO]];
andreas@392
   589
//        msg.shortMessage = @"Re: Lets use pEp";
andreas@392
   590
//        msg.longMessage = longMessage;
andreas@392
   591
//        msg.direction = PEP_dir_outgoing;
andreas@392
   592
//
andreas@392
   593
//        PEP_STATUS status = [session encryptMessage:msg extra:@[] dest:&mirosMsg];
andreas@392
   594
//        XCTAssert(status == PEP_STATUS_OK);
andreas@392
   595
//    }
andreas@392
   596
//
andreas@392
   597
//    [PEPSession cleanup];
andreas@392
   598
//    [self pEpCleanUpRestoringBackupNamed:@"Miro"];
andreas@392
   599
//
andreas@392
   600
//    // Again, outgoing flips into incoming
andreas@392
   601
//    mirosMsg.direction = PEP_dir_incoming;
andreas@392
   602
//
andreas@392
   603
//    [self pEpSetUp:@"Petra"];
andreas@392
   604
//    {
andreas@392
   605
//        PEPMessage *decmsg;
andreas@392
   606
//        NSArray* keys;
andreas@392
   607
//        PEPMessage *encmsg = mirosMsg.mutableCopy;
andreas@392
   608
//        encmsg.from = identMiroAtPetra.mutableCopy;
andreas@392
   609
//
andreas@392
   610
//        PEP_rating clr = [session decryptMessage:encmsg dest:&decmsg keys:&keys];
andreas@392
   611
//
andreas@392
   612
//        XCTAssertEqual(clr, PEP_rating_reliable);
andreas@392
   613
//
andreas@392
   614
//        PEP_rating secondclr = [session reEvaluateRatingForMessage:decmsg];
andreas@392
   615
//
andreas@392
   616
//        XCTAssertEqual(secondclr, PEP_rating_reliable);
andreas@392
   617
//
andreas@392
   618
//        // Check Miro is in DB
andreas@392
   619
//        [session updateIdentity:identMiroAtPetra];
andreas@392
   620
//
andreas@392
   621
//        XCTAssertNotNil(identMiroAtPetra.fingerPrint);
andreas@392
   622
//
andreas@392
   623
//        // Trust to that identity
andreas@392
   624
//        [session trustPersonalKey:identMiroAtPetra];
andreas@392
   625
//
andreas@392
   626
//        secondclr = [session reEvaluateRatingForMessage:decmsg];
andreas@392
   627
//        XCTAssertEqual(secondclr, PEP_rating_trusted_and_anonymized, @"Not trusted"); //is PEP_rating_reliable here. Should be PEP_rating_trusted imo.. In this case trustPersonalKey would not work plus the expection is wrong
andreas@392
   628
//
andreas@392
   629
//        clr = [session decryptMessage:encmsg dest:&decmsg keys:&keys];
andreas@392
   630
//        XCTAssertEqual(clr, PEP_rating_trusted_and_anonymized, @"Not trusted"); //is PEP_rating_reliable here. Should be PEP_rating_trusted imo.. In this case trustPersonalKey would not work plus the expection is wrong
andreas@392
   631
//
andreas@392
   632
//        // Undo trust
andreas@392
   633
//        [session keyResetTrust:identMiroAtPetra];
andreas@392
   634
//
andreas@392
   635
//        clr = [session decryptMessage:encmsg dest:&decmsg keys:&keys];
andreas@392
   636
//        XCTAssertEqual(clr, PEP_rating_reliable, @"keyResetTrust didn't work?");
andreas@392
   637
//
andreas@392
   638
//        // Try compromized
andreas@392
   639
//        [session keyMistrusted:identMiroAtPetra];
andreas@392
   640
//
andreas@392
   641
//        clr = [session decryptMessage:encmsg dest:&decmsg keys:&keys];
andreas@392
   642
//        XCTAssertEqual(clr, PEP_rating_mistrust, @"Not mistrusted");
andreas@392
   643
//
andreas@392
   644
//        // Regret
andreas@392
   645
//        [session keyResetTrust:identMiroAtPetra];
andreas@392
   646
//
andreas@392
   647
//        clr = [session decryptMessage:encmsg dest:&decmsg keys:&keys];
andreas@392
   648
//        XCTAssertEqual(clr, PEP_rating_reliable, @"keyResetTrust didn't work?"); //clr still mistrusted after resetting trust
andreas@392
   649
//
andreas@392
   650
//        // Trust again.
andreas@392
   651
//        [session trustPersonalKey:identMiroAtPetra];
andreas@392
   652
//
andreas@392
   653
//        clr = [session decryptMessage:encmsg dest:&decmsg keys:&keys];
andreas@392
   654
//        XCTAssertEqual(clr, PEP_rating_trusted_and_anonymized, @"Not trusted");
andreas@392
   655
//
andreas@392
   656
//        XCTAssertEqualObjects(decmsg.longMessage, longMessage);
andreas@392
   657
//    }
andreas@392
   658
//    [PEPSession cleanup];
andreas@392
   659
//    [self pEpCleanUpRestoringBackupNamed:@"Petra"];
andreas@392
   660
//}
andreas@392
   661
andreas@392
   662
- (void)testEncryptedMailFromMutt
andreas@392
   663
{
andreas@392
   664
    PEPSession *session = [PEPSession new];
andreas@392
   665
andreas@392
   666
    // This is the public key for test001@peptest.ch
andreas@392
   667
    [PEPTestUtils importBundledKey:@"A3FC7F0A.asc"];
andreas@392
   668
andreas@392
   669
    // This is the secret key for test001@peptest.ch
andreas@392
   670
    [PEPTestUtils importBundledKey:@"A3FC7F0A_sec.asc"];
andreas@392
   671
andreas@392
   672
    // Mail from mutt, already processed into message dict by the app.
andreas@392
   673
    NSMutableDictionary *msgDict = [PEPTestUtils unarchiveDictionary:@"msg_to_A3FC7F0A_from_mutt.ser"].mutableCopy;
andreas@392
   674
    [msgDict removeObjectForKey:kPepLongMessage];
andreas@392
   675
    [msgDict removeObjectForKey:kPepLongMessageFormatted];
andreas@392
   676
andreas@392
   677
    // Also extracted "live" from the app.
andreas@392
   678
    NSMutableDictionary *accountDict = [PEPTestUtils unarchiveDictionary:@"account_A3FC7F0A.ser"].mutableCopy;
andreas@392
   679
    [accountDict removeObjectForKey:kPepCommType];
andreas@392
   680
    [accountDict removeObjectForKey:kPepFingerprint];
andreas@392
   681
    PEPIdentity *identMe = [[PEPIdentity alloc] initWithDictionary:accountDict];
andreas@392
   682
andreas@392
   683
    [session mySelf:identMe];
andreas@392
   684
    XCTAssertNotNil(identMe.fingerPrint);
andreas@392
   685
andreas@392
   686
    NSArray* keys;
andreas@392
   687
    PEPMessage *msg = [PEPMessage new];
andreas@392
   688
    [msg setValuesForKeysWithDictionary:msgDict];
andreas@392
   689
    PEPMessage *pepDecryptedMail;
andreas@392
   690
    [session decryptMessage:msg dest:&pepDecryptedMail keys:&keys];
andreas@392
   691
    XCTAssertNotNil(pepDecryptedMail.longMessage);
andreas@392
   692
}
andreas@392
   693
andreas@392
   694
- (void)testOutgoingContactColor
andreas@392
   695
{
andreas@392
   696
    PEPSession *session = [PEPSession new];
andreas@392
   697
andreas@392
   698
    PEPIdentity *partner1Orig = [[PEPIdentity alloc] initWithAddress:@"partner1@dontcare.me"
andreas@392
   699
                                                            userName:@"Partner 1" isOwn:NO];
andreas@392
   700
    NSString *pubKeyPartner1 = [PEPTestUtils loadResourceByName:@"partner1_F2D281C2789DD7F6_pub.asc"];
andreas@392
   701
    XCTAssertNotNil(pubKeyPartner1);
andreas@392
   702
    [session importKey:pubKeyPartner1];
andreas@392
   703
andreas@392
   704
    PEP_rating color = [session identityRating:partner1Orig];
andreas@392
   705
    XCTAssertEqual(color, PEP_rating_reliable);
andreas@392
   706
}
andreas@392
   707
andreas@392
   708
- (void)testMessageTrustwordsWithMySelf
andreas@392
   709
{
andreas@392
   710
    PEPSession *session = [PEPSession new];
andreas@392
   711
andreas@392
   712
    PEPStringList *keys = nil;
andreas@392
   713
    PEPMessage *decryptedDict = [self internalEncryptToMySelfKeys:&keys];
andreas@392
   714
    XCTAssertNotNil(keys);
andreas@392
   715
    XCTAssert(keys.count > 0);
andreas@392
   716
andreas@392
   717
    PEPIdentity *receiver = decryptedDict.to[0];
andreas@392
   718
    [session updateIdentity:receiver];
andreas@392
   719
    XCTAssertNotNil(receiver);
andreas@392
   720
    PEP_STATUS trustwordsStatus;
andreas@392
   721
andreas@392
   722
    NSString *trustwords = [session getTrustwordsForMessage:decryptedDict
andreas@392
   723
                                                   receiver:receiver
andreas@392
   724
                                                  keysArray:keys language:@"en"
andreas@392
   725
                                                       full:YES
andreas@392
   726
                                            resultingStatus: &trustwordsStatus];
andreas@392
   727
    // No trustwords with yourself
andreas@392
   728
    XCTAssertEqual(trustwordsStatus, PEP_TRUSTWORDS_DUPLICATE_FPR);
andreas@392
   729
    XCTAssertNil(trustwords);
andreas@392
   730
}
andreas@392
   731
andreas@392
   732
- (void)testGetTrustwords
andreas@392
   733
{
andreas@392
   734
    PEPSession *session = [PEPSession new];
andreas@392
   735
andreas@392
   736
    PEPIdentity *partner1Orig = [[PEPIdentity alloc]
andreas@392
   737
                                 initWithAddress:@"partner1@dontcare.me" userID:@"partner1"
andreas@392
   738
                                 userName:@"partner1"
andreas@392
   739
                                 isOwn:NO fingerPrint:@"F0CD3F7B422E5D587ABD885BF2D281C2789DD7F6"];
andreas@392
   740
andreas@392
   741
    PEPIdentity *meOrig = [[PEPIdentity alloc]
andreas@392
   742
                           initWithAddress:@"me@dontcare.me" userID:@"me"
andreas@392
   743
                           userName:@"me"
andreas@392
   744
                           isOwn:NO fingerPrint:@"CC1F73F6FB774BF08B197691E3BFBCA9248FC681"];
andreas@392
   745
andreas@392
   746
    NSString *pubKeyPartner1 = [PEPTestUtils loadResourceByName:@"partner1_F2D281C2789DD7F6_pub.asc"];
andreas@392
   747
    XCTAssertNotNil(pubKeyPartner1);
andreas@392
   748
    NSString *pubKeyMe = [PEPTestUtils loadResourceByName:@"meATdontcare_E3BFBCA9248FC681_pub.asc"];
andreas@392
   749
    XCTAssertNotNil(pubKeyMe);
andreas@392
   750
    NSString *secKeyMe = [PEPTestUtils loadResourceByName:@"meATdontcare_E3BFBCA9248FC681_sec.asc"];
andreas@392
   751
    XCTAssertNotNil(secKeyMe);
andreas@392
   752
andreas@392
   753
    NSString *trustwordsFull = [session getTrustwordsIdentity1:meOrig identity2:partner1Orig
andreas@392
   754
                                                      language:nil full:YES];
andreas@392
   755
    XCTAssertEqualObjects(trustwordsFull,
andreas@392
   756
                          @"EMERSON GASPER TOKENISM BOLUS COLLAGE DESPISE BEDDED ENCRYPTION IMAGINE BEDFORD");
andreas@392
   757
andreas@392
   758
    NSString *trustwordsFullEnglish = [session getTrustwordsIdentity1:meOrig identity2:partner1Orig
andreas@392
   759
                                                             language:@"en" full:YES];
andreas@392
   760
    XCTAssertEqualObjects(trustwordsFullEnglish, trustwordsFull);
andreas@392
   761
andreas@392
   762
    NSString *trustwordsUndefined = [session getTrustwordsIdentity1:meOrig identity2:partner1Orig
andreas@392
   763
                                                           language:@"ZZ" full:YES];
andreas@392
   764
    XCTAssertNil(trustwordsUndefined);
andreas@392
   765
}
andreas@392
   766
andreas@392
   767
#pragma mark - Helpers
andreas@392
   768
andreas@392
   769
- (PEPMessage *)internalEncryptToMySelfKeys:(PEPStringList **)keys
andreas@392
   770
{
andreas@392
   771
    PEPSession *session = [PEPSession new];
andreas@392
   772
    PEPIdentity *me = [[PEPIdentity alloc]
andreas@392
   773
                       initWithAddress:@"me@peptest.ch" userName:@"userName"
andreas@392
   774
                       isOwn:YES];
andreas@392
   775
    [session mySelf:me];
andreas@392
   776
    XCTAssertNotNil(me.fingerPrint);
andreas@392
   777
andreas@392
   778
    // Create draft
andreas@392
   779
    NSString *shortMessage = @"Subject";
andreas@392
   780
    NSString *longMessage = @"Oh, this is a long body text!";
andreas@392
   781
    PEPMessage *mail = [PEPTestUtils mailFrom:me toIdent:me shortMessage:shortMessage longMessage:longMessage outgoing:YES];
andreas@392
   782
andreas@392
   783
    PEPMessage *encMessage;
andreas@392
   784
    PEP_STATUS status = [session encryptMessage:mail identity:me dest:&encMessage];
andreas@392
   785
    XCTAssertEqual(status, 0);
andreas@392
   786
    XCTAssertEqualObjects(encMessage.shortMessage, @"p≡p");
andreas@392
   787
andreas@392
   788
    PEPMessage *unencDict;
andreas@392
   789
    PEP_rating rating = [session decryptMessage:encMessage dest:&unencDict keys:keys];
andreas@392
   790
    XCTAssertGreaterThanOrEqual(rating, PEP_rating_reliable);
andreas@392
   791
andreas@392
   792
    XCTAssertEqualObjects(unencDict.shortMessage, shortMessage);
andreas@392
   793
    XCTAssertEqualObjects(unencDict.longMessage, longMessage);
andreas@392
   794
andreas@392
   795
    return unencDict;
andreas@392
   796
}
andreas@392
   797
andreas@392
   798
- (void)pEpCleanUpRestoringBackupNamed:(NSString *)backup {
andreas@392
   799
    [PEPTestUtils deleteWorkFilesAfterBackingUpWithBackupName:backup];
andreas@392
   800
}
andreas@392
   801
andreas@392
   802
- (void)pEpCleanUp
andreas@392
   803
{
andreas@392
   804
    [PEPSession cleanup];
andreas@392
   805
    [self pEpCleanUpRestoringBackupNamed:NULL];
andreas@392
   806
}
andreas@392
   807
andreas@392
   808
- (void)pEpSetUp:(NSString *)restore
andreas@392
   809
{
andreas@392
   810
    // Must be the first thing you do before using anything pEp-related
andreas@392
   811
    // ... but this is now done in session, with a "dispatch_once"
andreas@392
   812
    // [PEPObjCAdapter setupTrustWordsDB:[NSBundle bundleForClass:[self class]]];
andreas@392
   813
andreas@392
   814
    [PEPTestUtils deleteWorkFilesAfterBackingUpWithBackupName:nil];
andreas@392
   815
    [PEPTestUtils restoreWorkFilesFromBackupNamed:restore];
andreas@392
   816
}
andreas@392
   817
andreas@392
   818
- (void)pEpSetUp
andreas@392
   819
{
andreas@392
   820
    [self pEpSetUp:NULL];
andreas@392
   821
}
andreas@392
   822
andreas@392
   823
@end