pEpObjCTests/PEPSessionTest.m
changeset 532 775c55945da1
parent 531 8bd62764f284
child 533 79edad305d94
     1.1 --- a/pEpObjCTests/PEPSessionTest.m	Thu Mar 15 08:04:31 2018 +0100
     1.2 +++ b/pEpObjCTests/PEPSessionTest.m	Thu Mar 15 08:04:32 2018 +0100
     1.3 @@ -54,7 +54,9 @@
     1.4                              userName:@"pEp Test iOS GenKey"
     1.5                              isOwn:YES];
     1.6  
     1.7 -    [session mySelf:identMe];
     1.8 +    NSError *error = nil;
     1.9 +    XCTAssertTrue([session mySelf:identMe error:&error]);
    1.10 +    XCTAssertNil(error);
    1.11  
    1.12      bool res = [syncDelegate waitUntilSent:1];
    1.13  
    1.14 @@ -92,7 +94,9 @@
    1.15                              userName:@"pEp Test iOS GenKey"
    1.16                              isOwn:YES];
    1.17  
    1.18 -    [session mySelf:identMe];
    1.19 +    NSError *error = nil;
    1.20 +    XCTAssertTrue([session mySelf:identMe error:&error]);
    1.21 +    XCTAssertNil(error);
    1.22  
    1.23      XCTAssertNotNil(identMe.fingerPrint);
    1.24      XCTAssertNotEqual(identMe.commType, PEP_ct_unknown);
    1.25 @@ -110,7 +114,9 @@
    1.26                              userName:@"pEp Test iOS GenKey"
    1.27                              isOwn:YES];
    1.28  
    1.29 -    [session mySelf:identMe];
    1.30 +    NSError *error = nil;
    1.31 +    XCTAssertTrue([session mySelf:identMe error:&error]);
    1.32 +    XCTAssertNil(error);
    1.33  
    1.34      XCTAssertNotNil(identMe.fingerPrint);
    1.35      XCTAssertNotEqual(identMe.commType, PEP_ct_unknown);
    1.36 @@ -119,6 +125,7 @@
    1.37  
    1.38      dispatch_queue_t queue = dispatch_get_global_queue(QOS_CLASS_USER_INITIATED, 0);
    1.39      dispatch_sync(queue, ^{
    1.40 +        NSError *innerError = nil;
    1.41          PEPSession *session2 = [PEPSession new];
    1.42  
    1.43          // Now simulate an update from the app, which usually only caches
    1.44 @@ -128,7 +135,10 @@
    1.45                                   userID:identMe.userID
    1.46                                   userName:identMe.userName
    1.47                                   isOwn:NO];
    1.48 -        [session2 mySelf:identMe2];
    1.49 +
    1.50 +        XCTAssertTrue([session2 mySelf:identMe2 error:&innerError]);
    1.51 +        XCTAssertNil(innerError);
    1.52 +
    1.53          XCTAssertNotNil(identMe2.fingerPrint);
    1.54          XCTAssertTrue([identMe2 isPEPUser:session]);
    1.55          XCTAssertEqualObjects(identMe2.fingerPrint, identMe.fingerPrint);
    1.56 @@ -136,7 +146,9 @@
    1.57          // Now pretend the app only knows kPepUsername and kPepAddress
    1.58          PEPIdentity *identMe3 = [PEPTestUtils foreignPepIdentityWithAddress:identMe.address
    1.59                                                                     userName:identMe.userName];
    1.60 -        [session2 mySelf:identMe3];
    1.61 +        XCTAssertTrue([session2 mySelf:identMe3 error:&innerError]);
    1.62 +        XCTAssertNil(innerError);
    1.63 +
    1.64          XCTAssertNotNil(identMe3.fingerPrint);
    1.65          XCTAssertFalse([identMe3 isPEPUser:session]);
    1.66          XCTAssertEqualObjects(identMe3.fingerPrint, identMe.fingerPrint);
    1.67 @@ -158,7 +170,9 @@
    1.68                                  userName:@"No Way Not Even Alice"
    1.69                                  isOwn:NO];
    1.70  
    1.71 -    [session updateIdentity:identRandom];
    1.72 +    NSError *error = nil;
    1.73 +    XCTAssertTrue([session updateIdentity:identRandom error:&error]);
    1.74 +    XCTAssertNil(error);
    1.75      XCTAssertNil(identRandom.fingerPrint);
    1.76  }
    1.77  
    1.78 @@ -208,7 +222,11 @@
    1.79                         userID:@"me_myself"
    1.80                         userName:@"Me Me"
    1.81                         isOwn:YES];
    1.82 -    [session mySelf:me];
    1.83 +
    1.84 +    NSError *error = nil;
    1.85 +    XCTAssertTrue([session mySelf:me error:&error]);
    1.86 +    XCTAssertNil(error);
    1.87 +
    1.88      XCTAssertNotNil(me.fingerPrint);
    1.89      XCTAssertEqual([self ratingForIdentity:me session:session], PEP_rating_trusted_and_anonymized);
    1.90  
    1.91 @@ -252,7 +270,10 @@
    1.92                         userID:@"me_myself"
    1.93                         userName:@"Me Me"
    1.94                         isOwn:YES];
    1.95 -    [session mySelf:me];
    1.96 +    NSError *error = nil;
    1.97 +    XCTAssertTrue([session mySelf:me error:&error]);
    1.98 +    XCTAssertNil(error);
    1.99 +
   1.100      XCTAssertNotNil(me.fingerPrint);
   1.101      XCTAssertEqual([self ratingForIdentity:me session:session], PEP_rating_trusted_and_anonymized);
   1.102  
   1.103 @@ -298,7 +319,10 @@
   1.104                         userID:@"me_myself"
   1.105                         userName:@"Me Me"
   1.106                         isOwn:YES];
   1.107 -    [session mySelf:me];
   1.108 +    NSError *error = nil;
   1.109 +    XCTAssertTrue([session mySelf:me error:&error]);
   1.110 +    XCTAssertNil(error);
   1.111 +
   1.112      XCTAssertNotNil(me.fingerPrint);
   1.113      XCTAssertEqual([self ratingForIdentity:me session:session], PEP_rating_trusted_and_anonymized);
   1.114  
   1.115 @@ -444,7 +468,8 @@
   1.116      [session keyMistrusted:identBob];
   1.117  
   1.118      identBob.fingerPrint = nil;
   1.119 -    [session updateIdentity:identBob];
   1.120 +    XCTAssertTrue([session updateIdentity:identBob error:&error]);
   1.121 +    XCTAssertNil(error);
   1.122      XCTAssertNil(identBob.fingerPrint);
   1.123  
   1.124      // Gray == PEP_rating_unencrypted
   1.125 @@ -453,7 +478,8 @@
   1.126  
   1.127      // Undo
   1.128      [session undoLastMistrust];
   1.129 -    [session updateIdentity:identBob];
   1.130 +    XCTAssertTrue([session updateIdentity:identBob error:&error]);
   1.131 +    XCTAssertNil(error);
   1.132      XCTAssertNotNil(identBob.fingerPrint);
   1.133  
   1.134      // Back to yellow
   1.135 @@ -481,7 +507,8 @@
   1.136                                isOwn:NO
   1.137                                fingerPrint:@"AA2E4BEB93E5FE33DEFD8BE1135CD6D170DCF575"];
   1.138  
   1.139 -    [session updateIdentity:identJohn];
   1.140 +    XCTAssertTrue([session updateIdentity:identJohn error:&error]);
   1.141 +    XCTAssertNil(error);
   1.142  
   1.143      msg.cc = @[[PEPTestUtils foreignPepIdentityWithAddress:@"pep.test.john@pep-project.org"
   1.144                                                    userName:@"pEp Test John"]];
   1.145 @@ -514,7 +541,9 @@
   1.146                                 isOwn:YES
   1.147                                 fingerPrint:@"4ABE3AAF59AC32CFE4F86500A9411D176FF00E97"];
   1.148  
   1.149 -    [session mySelf:identAlice];
   1.150 +    NSError *error = nil;
   1.151 +    XCTAssertTrue([session mySelf:identAlice error:&error]);
   1.152 +    XCTAssertNil(error);
   1.153  
   1.154      PEPMessage *msg = [PEPMessage new];
   1.155      msg.from = identAlice;
   1.156 @@ -524,8 +553,6 @@
   1.157      msg.longMessage = @"This is a text content";
   1.158      msg.direction = PEP_dir_outgoing;
   1.159  
   1.160 -    NSError *error = nil;
   1.161 -
   1.162      // Test with unknown Bob
   1.163      PEP_rating rating;
   1.164      XCTAssertTrue([session outgoingRating:&rating forMessage:msg error:&error]);
   1.165 @@ -542,7 +569,8 @@
   1.166                               isOwn:NO
   1.167                               fingerPrint:@"BFCDB7F301DEEEBBF947F29659BFF488C9C2EE39"];
   1.168  
   1.169 -    [session updateIdentity:identBob];
   1.170 +    XCTAssertTrue([session updateIdentity:identBob error:&error]);
   1.171 +    XCTAssertNil(error);
   1.172  
   1.173      // Should be yellow, since no handshake happened.
   1.174      XCTAssertTrue([session outgoingRating:&rating forMessage:msg error:&error]);
   1.175 @@ -572,7 +600,8 @@
   1.176                                isOwn:NO
   1.177                                fingerPrint:@"AA2E4BEB93E5FE33DEFD8BE1135CD6D170DCF575"];
   1.178  
   1.179 -    [session updateIdentity:identJohn];
   1.180 +    XCTAssertTrue([session updateIdentity:identJohn error:&error]);
   1.181 +    XCTAssertNil(error);
   1.182  
   1.183      msg.bcc = @[[[PEPIdentity alloc] initWithAddress:@"pep.test.john@pep-project.org"
   1.184                                                userID:@"101" userName:@"pEp Test John" isOwn:NO]];
   1.185 @@ -607,7 +636,9 @@
   1.186                                 isOwn:YES
   1.187                                 fingerPrint:@"4ABE3AAF59AC32CFE4F86500A9411D176FF00E97"];
   1.188  
   1.189 -    [session mySelf:identAlice];
   1.190 +    NSError *error = nil;
   1.191 +    XCTAssertTrue([session mySelf:identAlice error:&error]);
   1.192 +    XCTAssertNil(error);
   1.193  
   1.194      // pEp Test Bob (test key, don't use) <pep.test.bob@pep-project.org>
   1.195      // BFCDB7F301DEEEBBF947F29659BFF488C9C2EE39
   1.196 @@ -619,7 +650,8 @@
   1.197                               isOwn:NO
   1.198                               fingerPrint:@"BFCDB7F301DEEEBBF947F29659BFF488C9C2EE39"];
   1.199  
   1.200 -    [session updateIdentity:identBob];
   1.201 +    XCTAssertTrue([session updateIdentity:identBob error:&error]);
   1.202 +    XCTAssertNil(error);
   1.203  
   1.204      // mistrust Bob
   1.205      [session keyMistrusted:identBob];
   1.206 @@ -632,8 +664,6 @@
   1.207      msg.longMessage = @"This is a text content";
   1.208      msg.direction = PEP_dir_outgoing;
   1.209  
   1.210 -    NSError *error = nil;
   1.211 -
   1.212      // Gray == PEP_rating_unencrypted
   1.213      PEP_rating rating;
   1.214      XCTAssertTrue([session outgoingRating:&rating forMessage:msg error:&error]);
   1.215 @@ -665,14 +695,18 @@
   1.216                                 isOwn:YES
   1.217                                 fingerPrint:fpr];
   1.218  
   1.219 -    [session mySelf:identAlice];
   1.220 +    NSError *error = nil;
   1.221 +    XCTAssertTrue([session mySelf:identAlice error:&error]);
   1.222 +    XCTAssertNil(error);
   1.223  
   1.224      PEPIdentity *identAlice2 = [identAlice mutableCopy];
   1.225  
   1.226      // This will revoke key
   1.227      [session keyMistrusted:identAlice2];
   1.228      identAlice2.fingerPrint = nil;
   1.229 -    [session mySelf:identAlice];
   1.230 +
   1.231 +    XCTAssertTrue([session mySelf:identAlice error:&error]);
   1.232 +    XCTAssertNil(error);
   1.233  
   1.234      // Check fingerprint is different
   1.235      XCTAssertNotEqualObjects(identAlice2.fingerPrint, fpr);
   1.236 @@ -694,7 +728,9 @@
   1.237                                 isOwn:YES
   1.238                                 fingerPrint:@"4ABE3AAF59AC32CFE4F86500A9411D176FF00E97"];
   1.239  
   1.240 -    [session mySelf:identAlice];
   1.241 +    NSError *error = nil;
   1.242 +    XCTAssertTrue([session mySelf:identAlice error:&error]);
   1.243 +    XCTAssertNil(error);
   1.244  
   1.245      PEPMessage *msg = [PEPMessage new];
   1.246      msg.from = identAlice;
   1.247 @@ -703,8 +739,6 @@
   1.248      msg.longMessage = @"This is a text content";
   1.249      msg.direction = PEP_dir_outgoing;
   1.250  
   1.251 -    NSError *error = nil;
   1.252 -
   1.253      PEP_rating rating;
   1.254      XCTAssertTrue([session outgoingRating:&rating forMessage:msg error:&error]);
   1.255      XCTAssertEqual(rating, PEP_rating_trusted_and_anonymized);
   1.256 @@ -752,7 +786,10 @@
   1.257      [accountDict removeObjectForKey:kPepFingerprint];
   1.258      PEPIdentity *identMe = [[PEPIdentity alloc] initWithDictionary:accountDict];
   1.259  
   1.260 -    [session mySelf:identMe];
   1.261 +    NSError *error = nil;
   1.262 +    XCTAssertTrue([session mySelf:identMe error:&error]);
   1.263 +    XCTAssertNil(error);
   1.264 +
   1.265      XCTAssertNotNil(identMe.fingerPrint);
   1.266  
   1.267      NSArray* keys;
   1.268 @@ -760,7 +797,6 @@
   1.269      [msg setValuesForKeysWithDictionary:msgDict];
   1.270  
   1.271      // Technically, the mail is encrypted, but the signatures don't match
   1.272 -    NSError *error;
   1.273      PEPMessage *pepDecryptedMail = [session
   1.274                                      decryptMessage:msg
   1.275                                      rating:nil
   1.276 @@ -874,7 +910,10 @@
   1.277                              userID:@"me-myself-and-i"
   1.278                              userName:@"pEp Me"
   1.279                              isOwn:YES];
   1.280 -    [session mySelf:identMe];
   1.281 +    NSError *error = nil;
   1.282 +    XCTAssertTrue([session mySelf:identMe error:&error]);
   1.283 +    XCTAssertNil(error);
   1.284 +
   1.285      XCTAssertNotNil(identMe.fingerPrint);
   1.286  
   1.287      // PEP_CANNOT_FIND_PERSON == 902
   1.288 @@ -901,7 +940,10 @@
   1.289                              userID:@"me-myself-and-i"
   1.290                              userName:@"pEp Me"
   1.291                              isOwn:YES];
   1.292 -    [session mySelf:identMe];
   1.293 +    NSError *error = nil;
   1.294 +    XCTAssertTrue([session mySelf:identMe error:&error]);
   1.295 +    XCTAssertNil(error);
   1.296 +
   1.297      XCTAssertNotNil(identMe.fingerPrint);
   1.298  
   1.299      PEPIdentity *identAlice = [[PEPIdentity alloc]
   1.300 @@ -917,8 +959,6 @@
   1.301      msg.longMessage = @"Alice?";
   1.302      msg.direction = PEP_dir_outgoing;
   1.303  
   1.304 -    NSError *error = nil;
   1.305 -
   1.306      PEP_rating rating;
   1.307      XCTAssertTrue([session outgoingRating:&rating forMessage:msg error:&error]);
   1.308      XCTAssertEqual(rating, PEP_rating_unencrypted);
   1.309 @@ -958,7 +998,10 @@
   1.310                              userID:@"me-myself-and-i"
   1.311                              userName:@"pEp Me"
   1.312                              isOwn:YES];
   1.313 -    [session mySelf:identMe];
   1.314 +    NSError *error = nil;
   1.315 +    XCTAssertTrue([session mySelf:identMe error:&error]);
   1.316 +    XCTAssertNil(error);
   1.317 +
   1.318      XCTAssertNotNil(identMe.fingerPrint);
   1.319  
   1.320      // The fingerprint is definitely wrong, we don't have a key
   1.321 @@ -984,7 +1027,10 @@
   1.322                              userID:@"me-myself-and-i"
   1.323                              userName:@"pEp Me"
   1.324                              isOwn:YES];
   1.325 -    [session mySelf:identMe];
   1.326 +    NSError *error = nil;
   1.327 +    XCTAssertTrue([session mySelf:identMe error:&error]);
   1.328 +    XCTAssertNil(error);
   1.329 +
   1.330      XCTAssertNotNil(identMe.fingerPrint);
   1.331  
   1.332      PEPIdentity *identAlice = [self
   1.333 @@ -1077,7 +1123,9 @@
   1.334                                    userName:[NSString stringWithFormat:@"Some User Name %@", userID]
   1.335                                    isOwn:NO];
   1.336  
   1.337 -        [session updateIdentity:identTest];
   1.338 +        NSError *error = nil;
   1.339 +        XCTAssertTrue([session updateIdentity:identTest error:&error]);
   1.340 +        XCTAssertNil(error);
   1.341          XCTAssertNotNil(identTest.fingerPrint);
   1.342          XCTAssertEqualObjects(identTest.fingerPrint, fingerPrint);
   1.343  
   1.344 @@ -1117,12 +1165,16 @@
   1.345   */
   1.346  - (void)updateAndVerifyPartnerIdentity:(PEPIdentity *)partnerIdentity session:(PEPSession *)session
   1.347  {
   1.348 +    NSError *error = nil;
   1.349 +
   1.350      XCTAssertNotNil(partnerIdentity.fingerPrint);
   1.351 -    [session updateIdentity:partnerIdentity];
   1.352 +    XCTAssertTrue([session updateIdentity:partnerIdentity error:&error]);
   1.353 +    XCTAssertNil(error);
   1.354      XCTAssertNotNil(partnerIdentity.fingerPrint);
   1.355      NSString *fingerprint = partnerIdentity.fingerPrint;
   1.356      partnerIdentity.fingerPrint = nil;
   1.357 -    [session updateIdentity:partnerIdentity];
   1.358 +    XCTAssertTrue([session updateIdentity:partnerIdentity error:&error]);
   1.359 +    XCTAssertNil(error);
   1.360      XCTAssertNotNil(partnerIdentity.fingerPrint);
   1.361      XCTAssertEqualObjects(partnerIdentity.fingerPrint, fingerprint);
   1.362  }
   1.363 @@ -1134,7 +1186,9 @@
   1.364      // Write a e-mail to yourself ...
   1.365      PEPIdentity *me = [PEPTestUtils ownPepIdentityWithAddress:@"me@peptest.ch"
   1.366                                                       userName:@"userName"];
   1.367 -    [session mySelf:me];
   1.368 +    NSError *error = nil;
   1.369 +    XCTAssertTrue([session mySelf:me error:&error]);
   1.370 +    XCTAssertNil(error);
   1.371  
   1.372      NSString *shortMessage = @"Subject";
   1.373      NSString *longMessage = @"Oh, this is a long body text!";
   1.374 @@ -1143,7 +1197,6 @@
   1.375                                   shortMessage:shortMessage
   1.376                                    longMessage:longMessage
   1.377                                       outgoing:YES];
   1.378 -    NSError *error = nil;
   1.379      PEP_STATUS status = PEP_UNKNOWN_ERROR;
   1.380      PEPMessage *encMessage = [session encryptMessage:mail identity:me status:&status error:&error];
   1.381      XCTAssertNil(error);
   1.382 @@ -1157,7 +1210,10 @@
   1.383      
   1.384      PEPIdentity *me = [PEPTestUtils ownPepIdentityWithAddress:@"me@peptest.ch"
   1.385                                                       userName:@"userName"];
   1.386 -    [session mySelf:me];
   1.387 +    NSError *error = nil;
   1.388 +    XCTAssertTrue([session mySelf:me error:&error]);
   1.389 +    XCTAssertNil(error);
   1.390 +
   1.391      XCTAssertNotNil(me.fingerPrint);
   1.392  
   1.393      // Create draft
   1.394 @@ -1166,7 +1222,6 @@
   1.395      PEPMessage *mail = [PEPTestUtils mailFrom:me toIdent:me shortMessage:shortMessage longMessage:longMessage outgoing:YES];
   1.396  
   1.397      PEP_STATUS status;
   1.398 -    NSError *error = nil;
   1.399      PEPMessage *encMessage = [session encryptMessage:mail identity:me status:&status error:&error];
   1.400      XCTAssertEqual(status, 0);
   1.401      XCTAssertEqualObjects(encMessage.shortMessage, @"p≡p");
   1.402 @@ -1218,7 +1273,10 @@
   1.403                                 userID:@"me-myself-and-i"
   1.404                                 userName:@"pEp Me"
   1.405                                 isOwn:YES];
   1.406 -    [session mySelf:identMe];
   1.407 +    NSError *error = nil;
   1.408 +    XCTAssertTrue([session mySelf:identMe error:&error]);
   1.409 +    XCTAssertNil(error);
   1.410 +
   1.411      XCTAssertNotNil(identMe.fingerPrint);
   1.412  
   1.413      PEPMessage *msg = [PEPMessage new];
   1.414 @@ -1228,8 +1286,6 @@
   1.415      msg.longMessage = @"Alice?";
   1.416      msg.direction = PEP_dir_outgoing;
   1.417  
   1.418 -    NSError *error = nil;
   1.419 -
   1.420      PEP_rating rating;
   1.421      XCTAssertTrue([session outgoingRating:&rating forMessage:msg error:&error]);
   1.422      XCTAssertEqual(rating, PEP_rating_reliable);