pEpObjCTests/PEPSessionTest.m
author Dirk Zimmermann <dz@pep.security>
Fri, 27 Nov 2020 18:20:10 +0100
branchIOSAD-185
changeset 2391 1d8448f5267b
parent 2237 a6f4300cbf63
permissions -rw-r--r--
IOSAD-185 Guards for all headers
     1 //
     2 //  PEPSessionTest.m
     3 //  pEpObjCAdapterTests
     4 //
     5 //  Created by Dirk Zimmermann on 18.07.20.
     6 //  Copyright © 2020 p≡p. All rights reserved.
     7 //
     8 
     9 #import <XCTest/XCTest.h>
    10 
    11 #import "PEPObjCAdapterFramework.h"
    12 
    13 #import "PEPTestUtils.h"
    14 #import "PEPSessionProvider.h"
    15 #import "PEPInternalSession.h"
    16 
    17 @interface PEPSessionTest : XCTestCase
    18 
    19 @end
    20 
    21 @implementation PEPSessionTest
    22 
    23 - (void)setUp
    24 {
    25     [super setUp];
    26 
    27     [self pEpCleanUp];
    28 
    29     [PEPObjCAdapter setUnEncryptedSubjectEnabled:NO];
    30 
    31     NSError *error = nil;
    32     XCTAssertTrue([PEPObjCAdapter configurePassphraseForNewKeys:nil error:&error]);
    33     XCTAssertNil(error);
    34 }
    35 
    36 - (void)tearDown
    37 {
    38     [self pEpCleanUp];
    39     [super tearDown];
    40 }
    41 
    42 - (void)pEpCleanUp
    43 {
    44     [PEPTestUtils cleanUp];
    45 }
    46 
    47 - (void)testMailToMyself
    48 {
    49     // Our test user:
    50     // pEp Test Alice (test key don't use) <pep.test.alice@pep-project.org>
    51     // 4ABE3AAF59AC32CFE4F86500A9411D176FF00E97
    52     XCTAssertTrue([self importBundledKey:@"6FF00E97_sec.asc"]);
    53 
    54     PEPIdentity *identAlice = [[PEPIdentity alloc]
    55                                initWithAddress:@"pep.test.alice@pep-project.org"
    56                                userID:ownUserId
    57                                userName:@"pEp Test Alice"
    58                                isOwn:YES
    59                                fingerPrint:@"4ABE3AAF59AC32CFE4F86500A9411D176FF00E97"];
    60 
    61     PEPSession *asyncSession = [PEPSession new];
    62 
    63     NSError *error = nil;
    64     PEPIdentity *identAliceMyselfed = [self mySelf:identAlice error:&error];
    65     XCTAssertNotNil(identAliceMyselfed);
    66     XCTAssertNil(error);
    67 
    68     PEPMessage *msg = [PEPMessage new];
    69     msg.from = identAlice;
    70     msg.to = @[identAlice];
    71     msg.shortMessage = @"Mail to Myself";
    72     msg.longMessage = @"This is a text content";
    73     msg.direction = PEPMsgDirectionOutgoing;
    74 
    75     error = nil;
    76     NSNumber *numRating = [self testOutgoingRatingForMessage:msg error:&error];
    77     XCTAssertNotNil(numRating);
    78     XCTAssertNil(error);
    79     XCTAssertEqual(numRating.pEpRating, PEPRatingTrustedAndAnonymized);
    80 
    81     for (NSNumber *boolNumWithEncFormat in @[@YES, @NO]) {
    82         error = nil;
    83         PEPMessage *encryptedMessage = [PEPMessage new];
    84         if (boolNumWithEncFormat.boolValue) {
    85             encryptedMessage = [self
    86                                 encryptMessage:msg
    87                                 extraKeys:nil
    88                                 encFormat:PEPEncFormatPEP
    89                                 status:nil
    90                                 error:&error];
    91             XCTAssertNotNil(encryptedMessage);
    92             XCTAssertNil(error);
    93         } else {
    94             encryptedMessage = [self encryptMessage:msg extraKeys:nil status:nil error:&error];
    95             XCTAssertNotNil(encryptedMessage);
    96             XCTAssertNil(error);
    97         }
    98 
    99         XCTestExpectation *expectationDec = [self expectationWithDescription:@"expectationDec"];
   100         [asyncSession
   101          decryptMessage:encryptedMessage
   102          flags:0
   103          extraKeys:nil
   104          errorCallback:^(NSError *error) {
   105             XCTFail();
   106             [expectationDec fulfill];
   107         }
   108          successCallback:^(PEPMessage * srcMessage,
   109                            PEPMessage * dstMessage,
   110                            PEPStringList * keyList,
   111                            PEPRating rating,
   112                            PEPDecryptFlags flags,
   113                            BOOL isFormerlyEncryptedReuploadedMessage) {
   114             XCTAssertNotNil(dstMessage);
   115             XCTAssertEqual(rating, PEPRatingTrustedAndAnonymized);
   116             [expectationDec fulfill];
   117         }];
   118         [self waitForExpectations:@[expectationDec] timeout:PEPTestInternalSyncTimeout];
   119     }
   120 }
   121 
   122 - (void)testEncryptToSelf
   123 {
   124     // Write mail to yourself ...
   125     PEPMessage *encMessage = [self mailWrittenToMySelf];
   126 
   127     // ... and assert subject is encrypted
   128     XCTAssertEqualObjects(encMessage.shortMessage, @"p≡p");
   129 }
   130 
   131 - (void)testEncryptAndAttachPrivateKeyIllegalValue
   132 {
   133     PEPIdentity *identMe = [[PEPIdentity alloc]
   134                             initWithAddress:@"me-myself-and-i@pep-project.org"
   135                             userID:@"me-myself-and-i"
   136                             userName:@"pEp Me"
   137                             isOwn:YES];
   138 
   139     NSError *error = nil;
   140     identMe = [self mySelf:identMe error:&error];
   141     XCTAssertNotNil(identMe);
   142     XCTAssertNil(error);
   143 
   144     XCTAssertNotNil(identMe.fingerPrint);
   145 
   146     NSString *fprAlice = @"4ABE3AAF59AC32CFE4F86500A9411D176FF00E97";
   147     PEPIdentity *identAlice = [self
   148                                checkImportingKeyFilePath:@"6FF00E97_sec.asc"
   149                                address:@"pep.test.alice@pep-project.org"
   150                                userID:@"alice_user_id"
   151                                fingerPrint:fprAlice];
   152     XCTAssertNotNil(identAlice);
   153     XCTAssertEqualObjects(identAlice.fingerPrint, fprAlice);
   154 
   155     NSString *shortMessage = @"whatever it may be";
   156     NSString *longMessage = [NSString stringWithFormat:@"%@ %@", shortMessage, shortMessage];
   157     PEPMessage *message = [PEPMessage new];
   158     message.from = identMe;
   159     message.to = @[identAlice];
   160     message.shortMessage = shortMessage;
   161     message.longMessage = longMessage;
   162 
   163     XCTestExpectation *expectationEnc = [self expectationWithDescription:@"expectationEnc"];
   164 
   165     PEPSession *asyncSession = [PEPSession new];
   166 
   167     [asyncSession
   168      encryptMessage:message
   169      toFpr:fprAlice
   170      encFormat:PEPEncFormatPEP
   171      flags:0
   172      errorCallback:^(NSError * _Nonnull error) {
   173         [expectationEnc fulfill];
   174     } successCallback:^(PEPMessage * _Nonnull srcMessage, PEPMessage * _Nonnull destMessage) {
   175         XCTFail();
   176         [expectationEnc fulfill];
   177     }];
   178 
   179     [self waitForExpectations:@[expectationEnc] timeout:PEPTestInternalSyncTimeout];
   180 }
   181 
   182 - (void)testRatingForIdentity
   183 {
   184     PEPIdentity *me = [self
   185                        checkMySelfImportingKeyFilePath:@"6FF00E97_sec.asc"
   186                        address:@"pep.test.alice@pep-project.org"
   187                        userID:@"Alice_User_ID"
   188                        fingerPrint:@"4ABE3AAF59AC32CFE4F86500A9411D176FF00E97"];
   189     XCTAssertNotNil(me);
   190     XCTAssertEqual([self ratingForIdentity:me], PEPRatingTrustedAndAnonymized);
   191 
   192     PEPIdentity *alice = [self
   193                           checkImportingKeyFilePath:@"6FF00E97_sec.asc"
   194                           address:@"pep.test.alice@pep-project.org"
   195                           userID:@"This Is Alice"
   196                           fingerPrint:@"4ABE3AAF59AC32CFE4F86500A9411D176FF00E97"];
   197     XCTAssertNotNil(alice);
   198 
   199     XCTAssertEqual([self ratingForIdentity:alice], PEPRatingReliable);
   200 }
   201 
   202 - (void)testTrustWords
   203 {
   204     NSError *error = nil;
   205     NSArray *trustwords = [self
   206                            trustwordsForFingerprint:@"DB47DB47DB47DB47DB47DB47DB47DB47DB47DB47"
   207                            languageID:@"en"
   208                            shortened:false
   209                            error:&error];
   210     XCTAssertNil(error);
   211     XCTAssertEqual([trustwords count], 10);
   212 
   213     for(id word in trustwords) {
   214         XCTAssertEqualObjects(word, @"BAPTISMAL");
   215     }
   216 }
   217 
   218 - (void)testIdentityRatingTrustResetMistrustUndo
   219 {
   220     PEPIdentity *me = [[PEPIdentity alloc]
   221                        initWithAddress:@"me@example.org"
   222                        userID:@"me_myself"
   223                        userName:@"Me Me"
   224                        isOwn:YES];
   225 
   226     NSError *error = nil;
   227     me = [self mySelf:me error:&error];
   228     XCTAssertNotNil(me);
   229     XCTAssertNil(error);
   230 
   231     XCTAssertNotNil(me.fingerPrint);
   232     XCTAssertEqual([self ratingForIdentity:me], PEPRatingTrustedAndAnonymized);
   233 
   234     PEPIdentity *alice = [self
   235                           checkImportingKeyFilePath:@"6FF00E97_sec.asc"
   236                           address:@"pep.test.alice@pep-project.org"
   237                           userID:@"This Is Alice"
   238                           fingerPrint:@"4ABE3AAF59AC32CFE4F86500A9411D176FF00E97"];
   239     XCTAssertNotNil(alice);
   240     XCTAssertEqual([self ratingForIdentity:alice], PEPRatingReliable);
   241 
   242     XCTAssertTrue([self trustPersonalKey:alice error:&error]);
   243     XCTAssertNil(error);
   244     XCTAssertEqual([self ratingForIdentity:alice], PEPRatingTrusted);
   245 
   246     XCTAssertTrue([self keyResetTrust:alice error:&error]);
   247     XCTAssertNil(error);
   248     XCTAssertEqual([self ratingForIdentity:alice], PEPRatingReliable);
   249 
   250     XCTAssertTrue([self keyMistrusted:alice error:&error]);
   251     XCTAssertNil(error);
   252     XCTAssertEqual([self ratingForIdentity:alice], PEPRatingHaveNoKey);
   253 }
   254 
   255 - (void)testQueryKeySyncOnOwnIdentityInALoop
   256 {
   257     PEPIdentity *identMe = [[PEPIdentity alloc]
   258                             initWithAddress:@"me-myself-and-i@pep-project.org"
   259                             userID:@"me-myself-and-i"
   260                             userName:@"pEp Me"
   261                             isOwn:YES];
   262     NSError *error = nil;
   263     identMe = [self mySelf:identMe error:&error];
   264     XCTAssertNotNil(identMe);
   265     XCTAssertNil(error);
   266 
   267     for (NSNumber *numBool in @[@YES, @NO]) {
   268         error = nil;
   269         if ([numBool boolValue]) {
   270             XCTAssertTrue([self enableSyncForIdentity:identMe error:&error]);
   271         } else {
   272             XCTAssertTrue([self disableSyncForIdentity:identMe error:&error]);
   273         }
   274         XCTAssertNil(error);
   275 
   276         for (int i = 0; i < 10; ++i) {
   277             NSNumber *numQuery = [self queryKeySyncEnabledForIdentity:identMe error:&error];
   278             XCTAssertNotNil(numQuery);
   279             XCTAssertEqualObjects(numBool, numQuery);
   280             XCTAssertNil(error);
   281         }
   282     }
   283 }
   284 
   285 - (void)testGetLogWithError
   286 {
   287     NSError *error = nil;
   288     NSString *log = [self getLogWithError:&error];
   289     XCTAssertGreaterThan(log.length, 0);
   290     XCTAssertNotNil(log);
   291     XCTAssertNil(error);
   292 }
   293 
   294 - (void)testGetTrustwords
   295 {
   296     PEPIdentity *partner1Orig = [[PEPIdentity alloc]
   297                                  initWithAddress:@"partner1@dontcare.me" userID:@"partner1"
   298                                  userName:@"partner1"
   299                                  isOwn:NO fingerPrint:@"F0CD3F7B422E5D587ABD885BF2D281C2789DD7F6"];
   300 
   301     PEPIdentity *meOrig = [[PEPIdentity alloc]
   302                            initWithAddress:@"me@dontcare.me" userID:@"me"
   303                            userName:@"me"
   304                            isOwn:NO fingerPrint:@"CC1F73F6FB774BF08B197691E3BFBCA9248FC681"];
   305 
   306     NSError *error = nil;
   307     NSString *trustwordsFull = [self getTrustwordsIdentity1:meOrig identity2:partner1Orig
   308                                                    language:@"en" full:YES error:&error];
   309     XCTAssertNil(error);
   310     XCTAssertEqualObjects(trustwordsFull,
   311                           @"EMERSON GASPER TOKENISM BOLUS COLLAGE DESPISE BEDDED ENCRYPTION IMAGINE BEDFORD");
   312 
   313     NSString *trustwordsUndefined = [self getTrustwordsIdentity1:meOrig identity2:partner1Orig
   314                                                         language:@"ZZ" full:YES error:&error];
   315     XCTAssertNotNil(error);
   316     XCTAssertNil(trustwordsUndefined);
   317 }
   318 
   319 - (void)testGenKey
   320 {
   321     PEPIdentity *identMe = [[PEPIdentity alloc]
   322                             initWithAddress:@"pep.test.iosgenkey@pep-project.org"
   323                             userID:@"Me"
   324                             userName:@"pEp Test iOS GenKey"
   325                             isOwn:YES];
   326 
   327     NSError *error = nil;
   328     identMe = [self mySelf:identMe error:&error];
   329     XCTAssertNotNil(identMe);
   330     XCTAssertNil(error);
   331 
   332     XCTAssertNotNil(identMe.fingerPrint);
   333     XCTAssertNotEqual(identMe.commType, PEPCommTypeUnknown);
   334 
   335     NSNumber *boolNum = [self isPEPUser:identMe error:&error];
   336     XCTAssertNil(error);
   337     XCTAssertNotNil(boolNum);
   338     XCTAssertTrue(boolNum.boolValue);
   339 }
   340 
   341 - (void)testTrustOwnKey
   342 {
   343     PEPIdentity *me = [PEPTestUtils ownPepIdentityWithAddress:@"me@peptest.ch"
   344                                                      userName:@"userName"];
   345     NSError *error = nil;
   346     me = [self mySelf:me error:&error];
   347     XCTAssertNotNil(me);
   348     XCTAssertNil(error);
   349 
   350     XCTAssertTrue([self trustOwnKeyIdentity:me error:&error]);
   351     XCTAssertNil(error);
   352 }
   353 
   354 - (void)testKeyResetIdentityOnOwnKeyIsIllegal
   355 {
   356     PEPIdentity *me = [PEPTestUtils ownPepIdentityWithAddress:@"me@peptest.ch"
   357                                                      userName:@"userName"];
   358 
   359     NSError *error = nil;
   360     me = [self mySelf:me error:&error];
   361     XCTAssertNotNil(me);
   362     XCTAssertNil(error);
   363 
   364     NSString *fprOriginal = me.fingerPrint;
   365     XCTAssertNotNil(fprOriginal);
   366 
   367     // Cannot reset all _own_ keys with this method, as documented
   368     XCTAssertFalse([self keyReset:me fingerprint:nil error:&error]);
   369     XCTAssertNotNil(error);
   370 
   371     me = [self mySelf:me error:&error];
   372     XCTAssertNotNil(me);
   373     XCTAssertNil(error);
   374 
   375     NSString *fprAfterReset = me.fingerPrint;
   376     XCTAssertNotNil(fprAfterReset);
   377 
   378     XCTAssertNotEqual(fprOriginal, fprAfterReset);
   379 }
   380 
   381 #pragma mark - Helpers
   382 
   383 - (PEPMessage *)mailWrittenToMySelf
   384 {
   385     // Write a e-mail to yourself ...
   386     PEPIdentity *me = [PEPTestUtils ownPepIdentityWithAddress:@"me@peptest.ch"
   387                                                      userName:@"userName"];
   388 
   389     NSError *error = nil;
   390     me = [self mySelf:me error:&error];
   391     XCTAssertNotNil(me);
   392     XCTAssertNil(error);
   393 
   394     NSString *shortMessage = @"Subject";
   395     NSString *longMessage = @"Oh, this is a long body text!";
   396     PEPMessage *mail = [PEPTestUtils mailFrom:me
   397                                       toIdent:me
   398                                  shortMessage:shortMessage
   399                                   longMessage:longMessage
   400                                      outgoing:YES];
   401 
   402     PEPSession *asyncSession = [PEPSession new];
   403 
   404     XCTestExpectation *expectationEnc = [self expectationWithDescription:@"expectationEnc"];
   405 
   406     __block PEPMessage *encryptedMessage = [PEPMessage new];
   407 
   408     [asyncSession
   409      encryptMessage:mail
   410      forSelf:me
   411      extraKeys:nil
   412      errorCallback:^(NSError * _Nonnull error) {
   413         XCTFail();
   414         [expectationEnc fulfill];
   415     } successCallback:^(PEPMessage * _Nonnull srcMessage, PEPMessage * _Nonnull destMessage) {
   416         encryptedMessage = destMessage;
   417         [expectationEnc fulfill];
   418     }];
   419 
   420     [self waitForExpectations:@[expectationEnc] timeout:PEPTestInternalSyncTimeout];
   421 
   422     return encryptedMessage;
   423 }
   424 
   425 - (NSNumber * _Nullable)testOutgoingRatingForMessage:(PEPMessage * _Nonnull)theMessage
   426                                                error:(NSError * _Nullable * _Nullable)error
   427 {
   428     NSError *theError = nil;
   429     NSNumber *ratingOriginal = [self outgoingRatingForMessage:theMessage error:&theError];
   430     XCTAssertNotNil(ratingOriginal);
   431     XCTAssertNil(theError);
   432 
   433     if (ratingOriginal == nil) {
   434         return nil;
   435     }
   436 
   437     NSNumber *ratingPreview = [[PEPSessionProvider session]
   438                                outgoingRatingPreviewForMessage:theMessage
   439                                error:error];
   440     XCTAssertEqual(ratingOriginal, ratingPreview);
   441 
   442     return ratingOriginal;
   443 }
   444 
   445 - (PEPIdentity *)checkImportingKeyFilePath:(NSString *)filePath address:(NSString *)address
   446                                     userID:(NSString *)userID
   447                                fingerPrint:(NSString *)fingerPrint
   448 {
   449     BOOL success = [self importBundledKey:filePath];
   450     XCTAssertTrue(success);
   451 
   452     if (success) {
   453         // Our test user:
   454         PEPIdentity *identTest = [[PEPIdentity alloc]
   455                                   initWithAddress:address
   456                                   userID:userID
   457                                   userName:[NSString stringWithFormat:@"Some User Name %@", userID]
   458                                   isOwn:NO];
   459 
   460         NSError *error = nil;
   461         PEPIdentity *identTestUpdated = [self updateIdentity:identTest error:&error];
   462 
   463         XCTAssertNil(error);
   464         XCTAssertNotNil(identTestUpdated);
   465         XCTAssertNotNil(identTestUpdated.fingerPrint);
   466         XCTAssertEqualObjects(identTestUpdated.fingerPrint, fingerPrint);
   467 
   468         return identTestUpdated;
   469     } else {
   470         return nil;
   471     }
   472 }
   473 
   474 - (BOOL)importBundledKey:(NSString *)item
   475 {
   476     PEPSession *asyncSession = [PEPSession new];
   477 
   478     NSString *txtFileContents = [PEPTestUtils loadStringFromFileName:item];
   479     if (!txtFileContents) {
   480         XCTFail();
   481     }
   482 
   483     __block BOOL success = YES;
   484 
   485     XCTestExpectation *expImport = [self expectationWithDescription:@"expImport"];
   486     [asyncSession importKey:txtFileContents
   487               errorCallback:^(NSError * _Nonnull error) {
   488         XCTFail();
   489         success = NO;
   490         [expImport fulfill];
   491     } successCallback:^(NSArray<PEPIdentity *> * _Nonnull identities) {
   492         [expImport fulfill];
   493         success = YES;
   494     }];
   495 
   496     [self waitForExpectations:@[expImport] timeout:PEPTestInternalSyncTimeout];
   497 
   498     return success;
   499 }
   500 
   501 - (PEPIdentity * _Nullable)checkMySelfImportingKeyFilePath:(NSString *)filePath
   502                                                    address:(NSString *)address
   503                                                     userID:(NSString *)userID
   504                                                fingerPrint:(NSString *)fingerPrint
   505 {
   506     PEPSession *asyncSession = [PEPSession new];
   507 
   508     XCTAssertTrue([self importBundledKey:filePath]);
   509 
   510     // Our test user:
   511     PEPIdentity *identTest = [[PEPIdentity alloc]
   512                               initWithAddress:address
   513                               userID:userID
   514                               userName:[NSString stringWithFormat:@"Some User Name %@", userID]
   515                               isOwn:YES
   516                               fingerPrint: fingerPrint];
   517 
   518     __block BOOL success = NO;
   519     XCTestExpectation *expSetOwnKey = [self expectationWithDescription:@"expSetOwnKey"];
   520     [asyncSession setOwnKey:identTest
   521                 fingerprint:fingerPrint
   522               errorCallback:^(NSError * _Nonnull error) {
   523         XCTFail();
   524         success = NO;
   525         [expSetOwnKey fulfill];
   526     } successCallback:^{
   527         success = YES;
   528         [expSetOwnKey fulfill];
   529     }];
   530 
   531     [self waitForExpectations:@[expSetOwnKey] timeout:PEPTestInternalSyncTimeout];
   532 
   533     if (success) {
   534         return identTest;
   535     } else {
   536         return nil;
   537     }
   538 }
   539 
   540 #pragma mark - Normal session to async
   541 
   542 - (PEPRating)ratingForIdentity:(PEPIdentity *)identity
   543 {
   544     PEPSession *asyncSession = [PEPSession new];
   545 
   546     __block PEPRating resultingRating = PEPRatingB0rken;
   547 
   548     XCTestExpectation *expRated = [self expectationWithDescription:@"expRated"];
   549     [asyncSession ratingForIdentity:identity
   550                       errorCallback:^(NSError * _Nonnull error) {
   551         XCTFail();
   552         [expRated fulfill];
   553     } successCallback:^(PEPRating rating) {
   554         resultingRating = rating;
   555         [expRated fulfill];
   556     }];
   557     [self waitForExpectations:@[expRated] timeout:PEPTestInternalSyncTimeout];
   558 
   559     return resultingRating;
   560 }
   561 
   562 - (PEPIdentity * _Nullable)mySelf:(PEPIdentity * _Nonnull)identity
   563                             error:(NSError * _Nullable * _Nullable)error
   564 {
   565     PEPSession *asyncSession = [PEPSession new];
   566 
   567     XCTestExpectation *expMyself = [self expectationWithDescription:@"expMyself"];
   568     __block PEPIdentity *identityMyselfed = nil;
   569     __block NSError *errorMyself = nil;
   570     [asyncSession mySelf:identity
   571            errorCallback:^(NSError * _Nonnull theError) {
   572         errorMyself = theError;
   573         [expMyself fulfill];
   574     } successCallback:^(PEPIdentity * _Nonnull identity) {
   575         identityMyselfed = identity;
   576         [expMyself fulfill];
   577     }];
   578     [self waitForExpectations:@[expMyself] timeout:PEPTestInternalSyncTimeout];
   579 
   580     *error = errorMyself;
   581 
   582     XCTAssertNotNil(identityMyselfed);
   583 
   584     if (error) {
   585         *error = errorMyself;
   586     }
   587 
   588     return identityMyselfed;
   589 }
   590 
   591 - (NSArray<NSString *> * _Nullable)trustwordsForFingerprint:(NSString * _Nonnull)fingerprint
   592                                                  languageID:(NSString * _Nonnull)languageID
   593                                                   shortened:(BOOL)shortened
   594                                                       error:(NSError * _Nullable * _Nullable)error
   595 {
   596     PEPSession *asyncSession = [PEPSession new];
   597     XCTestExpectation *exp = [self expectationWithDescription:@"exp"];
   598     __block NSArray<NSString *> *result = nil;
   599     __block NSError *theError = nil;
   600     [asyncSession trustwordsForFingerprint:fingerprint
   601                                 languageID:languageID
   602                                  shortened:shortened
   603                              errorCallback:^(NSError * _Nonnull error) {
   604         theError = error;
   605         [exp fulfill];
   606     } successCallback:^(NSArray<NSString *> * _Nonnull trustwords) {
   607         [exp fulfill];
   608         result = trustwords;
   609     }];
   610     [self waitForExpectations:@[exp] timeout:PEPTestInternalSyncTimeout];
   611     if (error) {
   612         *error = theError;
   613     }
   614     return result;
   615 }
   616 
   617 - (PEPIdentity * _Nullable)updateIdentity:(PEPIdentity * _Nonnull)identity
   618                                     error:(NSError * _Nullable * _Nullable)error
   619 {
   620     PEPSession *asyncSession = [PEPSession new];
   621     XCTestExpectation *expUpdateIdent = [self expectationWithDescription:@"expUpdateIdent"];
   622     __block PEPIdentity *identTestUpdated = nil;
   623     __block NSError *theError = nil;
   624     [asyncSession updateIdentity:identity
   625                    errorCallback:^(NSError * _Nonnull error) {
   626         theError = error;
   627         [expUpdateIdent fulfill];
   628     } successCallback:^(PEPIdentity * _Nonnull identity) {
   629         identTestUpdated = identity;
   630         [expUpdateIdent fulfill];
   631     }];
   632     [self waitForExpectations:@[expUpdateIdent] timeout:PEPTestInternalSyncTimeout];
   633     if (error) {
   634         *error = theError;
   635     }
   636     return identTestUpdated;
   637 }
   638 
   639 - (NSNumber * _Nullable)outgoingRatingForMessage:(PEPMessage * _Nonnull)theMessage
   640                                            error:(NSError * _Nullable * _Nullable)error
   641 {
   642     PEPSession *asyncSession = [PEPSession new];
   643     XCTestExpectation *exp = [self expectationWithDescription:@"exp"];
   644     __block NSNumber *result = nil;
   645     __block NSError *theError = nil;
   646     [asyncSession outgoingRatingForMessage:theMessage
   647                              errorCallback:^(NSError * _Nonnull error) {
   648         theError = error;
   649         [exp fulfill];
   650     } successCallback:^(PEPRating rating) {
   651         result = [NSNumber numberWithPEPRating:rating];
   652         [exp fulfill];
   653     }];
   654     [self waitForExpectations:@[exp] timeout:PEPTestInternalSyncTimeout];
   655     if (error) {
   656         *error = theError;
   657     }
   658     return result;
   659 }
   660 
   661 - (PEPMessage * _Nullable)encryptMessage:(PEPMessage * _Nonnull)message
   662                                extraKeys:(PEPStringList * _Nullable)extraKeys
   663                                encFormat:(PEPEncFormat)encFormat
   664                                   status:(PEPStatus * _Nullable)status
   665                                    error:(NSError * _Nullable * _Nullable)error
   666 {
   667     PEPSession *asyncSession = [PEPSession new];
   668     XCTestExpectation *exp = [self expectationWithDescription:@"exp"];
   669     __block PEPMessage *result = nil;
   670     __block NSError *theError = nil;
   671     [asyncSession encryptMessage:message
   672                        extraKeys:extraKeys
   673                        encFormat:encFormat
   674                    errorCallback:^(NSError * _Nonnull error) {
   675         theError = error;
   676         [exp fulfill];
   677     } successCallback:^(PEPMessage * _Nonnull srcMessage, PEPMessage * _Nonnull destMessage) {
   678         result = destMessage;
   679         [exp fulfill];
   680     }];
   681     [self waitForExpectations:@[exp] timeout:PEPTestInternalSyncTimeout];
   682     if (error) {
   683         *error = theError;
   684     }
   685     return result;
   686 }
   687 
   688 - (PEPMessage * _Nullable)encryptMessage:(PEPMessage * _Nonnull)message
   689                                extraKeys:(PEPStringList * _Nullable)extraKeys
   690                                   status:(PEPStatus * _Nullable)status
   691                                    error:(NSError * _Nullable * _Nullable)error
   692 {
   693     PEPSession *asyncSession = [PEPSession new];
   694     XCTestExpectation *exp = [self expectationWithDescription:@"exp"];
   695     __block PEPMessage *result = nil;
   696     __block NSError *theError = nil;
   697     [asyncSession encryptMessage:message
   698                        extraKeys:extraKeys
   699                    errorCallback:^(NSError * _Nonnull error) {
   700         theError = error;
   701         [exp fulfill];
   702     } successCallback:^(PEPMessage * _Nonnull srcMessage, PEPMessage * _Nonnull destMessage) {
   703         result = destMessage;
   704         [exp fulfill];
   705     }];
   706     [self waitForExpectations:@[exp] timeout:PEPTestInternalSyncTimeout];
   707     if (error) {
   708         *error = theError;
   709     }
   710     return result;
   711 }
   712 
   713 - (BOOL)trustPersonalKey:(PEPIdentity * _Nonnull)identity
   714                    error:(NSError * _Nullable * _Nullable)error
   715 {
   716     PEPSession *asyncSession = [PEPSession new];
   717     XCTestExpectation *exp = [self expectationWithDescription:@"exp"];
   718     __block BOOL result = NO;
   719     __block NSError *theError = nil;
   720     [asyncSession trustPersonalKey:identity
   721                      errorCallback:^(NSError * _Nonnull error) {
   722         result = NO;
   723         theError = error;
   724         [exp fulfill];
   725     } successCallback:^{
   726         result = YES;
   727         [exp fulfill];
   728     }];
   729     [self waitForExpectations:@[exp] timeout:PEPTestInternalSyncTimeout];
   730     if (error) {
   731         *error = theError;
   732     }
   733     return result;
   734 }
   735 
   736 - (BOOL)keyResetTrust:(PEPIdentity * _Nonnull)identity
   737                 error:(NSError * _Nullable * _Nullable)error
   738 {
   739     PEPSession *asyncSession = [PEPSession new];
   740     XCTestExpectation *exp = [self expectationWithDescription:@"exp"];
   741     __block BOOL result = NO;
   742     __block NSError *theError = nil;
   743     [asyncSession keyResetTrust:identity
   744                   errorCallback:^(NSError * _Nonnull error) {
   745         result = NO;
   746         theError = error;
   747         [exp fulfill];
   748     } successCallback:^{
   749         result = YES;
   750         [exp fulfill];
   751     }];
   752     [self waitForExpectations:@[exp] timeout:PEPTestInternalSyncTimeout];
   753     if (error) {
   754         *error = theError;
   755     }
   756     return result;
   757 }
   758 
   759 - (BOOL)keyMistrusted:(PEPIdentity *)identity error:(NSError * _Nullable * _Nullable)error
   760 {
   761     PEPSession *asyncSession = [PEPSession new];
   762     XCTestExpectation *exp = [self expectationWithDescription:@"exp"];
   763     __block BOOL result = NO;
   764     __block NSError *theError = nil;
   765     [asyncSession keyMistrusted:identity
   766                   errorCallback:^(NSError * _Nonnull error) {
   767         result = NO;
   768         theError = error;
   769         [exp fulfill];
   770     } successCallback:^{
   771         result = YES;
   772         [exp fulfill];
   773     }];
   774     [self waitForExpectations:@[exp] timeout:PEPTestInternalSyncTimeout];
   775     if (error) {
   776         *error = theError;
   777     }
   778     return result;
   779 }
   780 
   781 - (BOOL)enableSyncForIdentity:(PEPIdentity * _Nonnull)identity
   782                         error:(NSError * _Nullable * _Nullable)error
   783 {
   784     PEPSession *asyncSession = [PEPSession new];
   785     XCTestExpectation *exp = [self expectationWithDescription:@"exp"];
   786     __block BOOL result = NO;
   787     __block NSError *theError = nil;
   788     [asyncSession enableSyncForIdentity:identity
   789                   errorCallback:^(NSError * _Nonnull error) {
   790         result = NO;
   791         theError = error;
   792         [exp fulfill];
   793     } successCallback:^{
   794         result = YES;
   795         [exp fulfill];
   796     }];
   797     [self waitForExpectations:@[exp] timeout:PEPTestInternalSyncTimeout];
   798     if (error) {
   799         *error = theError;
   800     }
   801     return result;
   802 }
   803 
   804 - (NSNumber * _Nullable)queryKeySyncEnabledForIdentity:(PEPIdentity * _Nonnull)identity
   805                                                  error:(NSError * _Nullable * _Nullable)error
   806 {
   807     PEPSession *asyncSession = [PEPSession new];
   808     XCTestExpectation *exp = [self expectationWithDescription:@"exp"];
   809     __block NSNumber *result = nil;
   810     __block NSError *theError = nil;
   811     [asyncSession queryKeySyncEnabledForIdentity:identity
   812                                    errorCallback:^(NSError * _Nonnull error) {
   813         result = nil;
   814         theError = error;
   815         [exp fulfill];
   816     } successCallback:^(BOOL enabled) {
   817         result = [NSNumber numberWithBool:enabled];
   818         [exp fulfill];
   819     }];
   820     [self waitForExpectations:@[exp] timeout:PEPTestInternalSyncTimeout];
   821     if (error) {
   822         *error = theError;
   823     }
   824     return result;
   825 }
   826 
   827 - (BOOL)disableSyncForIdentity:(PEPIdentity * _Nonnull)identity
   828                          error:(NSError * _Nullable * _Nullable)error
   829 {
   830     PEPSession *asyncSession = [PEPSession new];
   831     XCTestExpectation *exp = [self expectationWithDescription:@"exp"];
   832     __block BOOL result = NO;
   833     __block NSError *theError = nil;
   834     [asyncSession disableSyncForIdentity:identity
   835                            errorCallback:^(NSError * _Nonnull error) {
   836         result = NO;
   837         theError = error;
   838         [exp fulfill];
   839     } successCallback:^{
   840         result = YES;
   841         [exp fulfill];
   842     }];
   843     [self waitForExpectations:@[exp] timeout:PEPTestInternalSyncTimeout];
   844     if (error) {
   845         *error = theError;
   846     }
   847     return result;
   848 }
   849 
   850 - (NSString * _Nullable)getLogWithError:(NSError * _Nullable * _Nullable)error
   851 {
   852     PEPSession *asyncSession = [PEPSession new];
   853     XCTestExpectation *exp = [self expectationWithDescription:@"exp"];
   854     __block NSString *result = nil;
   855     __block NSError *theError = nil;
   856     [asyncSession getLog:^(NSError * _Nonnull error) {
   857         result = nil;
   858         theError = error;
   859         [exp fulfill];
   860     } successCallback:^(NSString *theLog) {
   861         result = theLog;
   862         [exp fulfill];
   863     }];
   864     [self waitForExpectations:@[exp] timeout:PEPTestInternalSyncTimeout];
   865     if (error) {
   866         *error = theError;
   867     }
   868     return result;
   869 }
   870 
   871 - (NSString * _Nullable)getTrustwordsIdentity1:(PEPIdentity * _Nonnull)identity1
   872                                      identity2:(PEPIdentity * _Nonnull)identity2
   873                                       language:(NSString * _Nullable)language
   874                                           full:(BOOL)full
   875                                          error:(NSError * _Nullable * _Nullable)error
   876 {
   877     PEPSession *asyncSession = [PEPSession new];
   878     XCTestExpectation *exp = [self expectationWithDescription:@"exp"];
   879     __block NSString *result = nil;
   880     __block NSError *theError = nil;
   881     [asyncSession getTrustwordsIdentity1:identity1
   882                                identity2:identity2
   883                                 language:language
   884                                     full:full
   885                            errorCallback:^(NSError * _Nonnull error) {
   886         result = nil;
   887         theError = error;
   888         [exp fulfill];
   889     } successCallback:^(NSString * _Nonnull trustwords) {
   890         result = trustwords;
   891         [exp fulfill];
   892     }];
   893     [self waitForExpectations:@[exp] timeout:PEPTestInternalSyncTimeout];
   894     if (error) {
   895         *error = theError;
   896     }
   897     return result;
   898 }
   899 
   900 - (NSNumber * _Nullable)isPEPUser:(PEPIdentity * _Nonnull)identity
   901                             error:(NSError * _Nullable * _Nullable)error
   902 {
   903     PEPSession *asyncSession = [PEPSession new];
   904     XCTestExpectation *exp = [self expectationWithDescription:@"exp"];
   905     __block NSNumber *result = nil;
   906     __block NSError *theError = nil;
   907     [asyncSession isPEPUser:identity
   908               errorCallback:^(NSError * _Nonnull error) {
   909         result = nil;
   910         theError = error;
   911         [exp fulfill];
   912     } successCallback:^(BOOL enabled) {
   913         result = [NSNumber numberWithBool:enabled];
   914         [exp fulfill];
   915     }];
   916     [self waitForExpectations:@[exp] timeout:PEPTestInternalSyncTimeout];
   917     if (error) {
   918         *error = theError;
   919     }
   920     return result;
   921 }
   922 
   923 - (BOOL)trustOwnKeyIdentity:(PEPIdentity * _Nonnull)identity
   924                       error:(NSError * _Nullable * _Nullable)error
   925 {
   926     PEPSession *asyncSession = [PEPSession new];
   927     XCTestExpectation *exp = [self expectationWithDescription:@"exp"];
   928     __block BOOL result = NO;
   929     __block NSError *theError = nil;
   930     [asyncSession trustOwnKeyIdentity:identity
   931                         errorCallback:^(NSError * _Nonnull error) {
   932         result = NO;
   933         theError = error;
   934         [exp fulfill];
   935     } successCallback:^{
   936         result = YES;
   937         [exp fulfill];
   938     }];
   939     [self waitForExpectations:@[exp] timeout:PEPTestInternalSyncTimeout];
   940     if (error) {
   941         *error = theError;
   942     }
   943     return result;
   944 }
   945 
   946 - (BOOL)keyReset:(PEPIdentity * _Nonnull)identity
   947      fingerprint:(NSString * _Nullable)fingerprint
   948            error:(NSError * _Nullable * _Nullable)error
   949 {
   950     PEPSession *asyncSession = [PEPSession new];
   951     XCTestExpectation *exp = [self expectationWithDescription:@"exp"];
   952     __block BOOL result = NO;
   953     __block NSError *theError = nil;
   954     [asyncSession keyReset:identity
   955                fingerprint:fingerprint
   956              errorCallback:^(NSError * _Nonnull error) {
   957         result = NO;
   958         theError = error;
   959         [exp fulfill];
   960     } successCallback:^{
   961         result = YES;
   962         [exp fulfill];
   963     }];
   964     [self waitForExpectations:@[exp] timeout:PEPTestInternalSyncTimeout];
   965     if (error) {
   966         *error = theError;
   967     }
   968     return result;
   969 }
   970 
   971 @end