pEpObjCTests/PEPSessionTest.m
changeset 456 76a427a44a2b
parent 455 70a3329df5e2
child 457 6919513e72af
     1.1 --- a/pEpObjCTests/PEPSessionTest.m	Thu Feb 15 09:31:34 2018 +0100
     1.2 +++ b/pEpObjCTests/PEPSessionTest.m	Thu Feb 15 12:04:39 2018 +0100
     1.3 @@ -157,11 +157,13 @@
     1.4  {
     1.5      [self checkImportingKeyFilePath:@"6FF00E97_sec.asc" address:@"pep.test.alice@pep-project.org"
     1.6                               userID:@"This Is Alice"
     1.7 -                        fingerPrint:@"4ABE3AAF59AC32CFE4F86500A9411D176FF00E97"];
     1.8 +                        fingerPrint:@"4ABE3AAF59AC32CFE4F86500A9411D176FF00E97"
     1.9 +                            session: nil];
    1.10  
    1.11      [self checkImportingKeyFilePath:@"0xC9C2EE39.asc" address:@"pep.test.bob@pep-project.org"
    1.12                               userID:@"This Is Bob"
    1.13 -                        fingerPrint:@"BFCDB7F301DEEEBBF947F29659BFF488C9C2EE39"];
    1.14 +                        fingerPrint:@"BFCDB7F301DEEEBBF947F29659BFF488C9C2EE39"
    1.15 +                            session: nil];
    1.16  }
    1.17  
    1.18  - (void)testIdentityRating
    1.19 @@ -179,7 +181,8 @@
    1.20                            checkImportingKeyFilePath:@"6FF00E97_sec.asc"
    1.21                            address:@"pep.test.alice@pep-project.org"
    1.22                            userID:@"This Is Alice"
    1.23 -                          fingerPrint:@"4ABE3AAF59AC32CFE4F86500A9411D176FF00E97"];
    1.24 +                          fingerPrint:@"4ABE3AAF59AC32CFE4F86500A9411D176FF00E97"
    1.25 +                          session: session];
    1.26      XCTAssertEqual([session identityRating:alice], PEP_rating_reliable);
    1.27  }
    1.28  
    1.29 @@ -198,7 +201,8 @@
    1.30                            checkImportingKeyFilePath:@"6FF00E97_sec.asc"
    1.31                            address:@"pep.test.alice@pep-project.org"
    1.32                            userID:@"This Is Alice"
    1.33 -                          fingerPrint:@"4ABE3AAF59AC32CFE4F86500A9411D176FF00E97"];
    1.34 +                          fingerPrint:@"4ABE3AAF59AC32CFE4F86500A9411D176FF00E97"
    1.35 +                          session: session];
    1.36      XCTAssertEqual([session identityRating:alice], PEP_rating_reliable);
    1.37  
    1.38      [session trustPersonalKey:alice];
    1.39 @@ -260,7 +264,8 @@
    1.40                               checkImportingKeyFilePath:@"0xC9C2EE39.asc"
    1.41                               address:@"pep.test.bob@pep-project.org"
    1.42                               userID:@"42"
    1.43 -                             fingerPrint:@"BFCDB7F301DEEEBBF947F29659BFF488C9C2EE39"];
    1.44 +                             fingerPrint:@"BFCDB7F301DEEEBBF947F29659BFF488C9C2EE39"
    1.45 +                             session: session];
    1.46  
    1.47      PEPMessage *msg = [PEPMessage new];
    1.48      msg.from = identAlice;
    1.49 @@ -787,6 +792,76 @@
    1.50                                           expectedRating:PEP_rating_trusted_and_anonymized];
    1.51  }
    1.52  
    1.53 +- (void)testEncryptMessagesWithoutKeys
    1.54 +{
    1.55 +    PEPSession *session = [PEPSession new];
    1.56 +
    1.57 +    PEPIdentity *identMe = [[PEPIdentity alloc]
    1.58 +                            initWithAddress:@"me-myself-and-i@pep-project.org"
    1.59 +                            userID:@"me-myself-and-i"
    1.60 +                            userName:@"pEp Me"
    1.61 +                            isOwn:YES];
    1.62 +    [session mySelf:identMe];
    1.63 +    XCTAssertNotNil(identMe.fingerPrint);
    1.64 +
    1.65 +    PEPIdentity *identAlice = [[PEPIdentity alloc]
    1.66 +                               initWithAddress:@"alice@pep-project.org"
    1.67 +                               userID:@"alice"
    1.68 +                               userName:@"pEp Test Alice"
    1.69 +                               isOwn:NO];
    1.70 +
    1.71 +    PEPMessage *msg = [PEPMessage new];
    1.72 +    msg.from = identMe;
    1.73 +    msg.to = @[identAlice];
    1.74 +    msg.shortMessage = @"Mail to Alice";
    1.75 +    msg.longMessage = @"Alice?";
    1.76 +    msg.direction = PEP_dir_outgoing;
    1.77 +
    1.78 +    PEP_rating clr = [session outgoingColorForMessage:msg];
    1.79 +    XCTAssertEqual(clr, PEP_rating_unencrypted);
    1.80 +
    1.81 +    PEPMessage *encMsg;
    1.82 +
    1.83 +    PEP_STATUS statusEnc = statusEnc = [session encryptMessage:msg extra:@[] dest:&encMsg];
    1.84 +
    1.85 +    XCTAssertEqual(statusEnc, PEP_UNENCRYPTED);
    1.86 +
    1.87 +    XCTAssertNotNil(encMsg);
    1.88 +
    1.89 +    PEPMessage *decMsg;
    1.90 +    PEPStringList *keys;
    1.91 +    PEP_rating pEpRating = [session decryptMessage:encMsg dest:&decMsg keys:&keys];
    1.92 +    XCTAssertEqual(pEpRating, PEP_rating_unencrypted);
    1.93 +    XCTAssertNotNil(decMsg);
    1.94 +}
    1.95 +
    1.96 +/**
    1.97 + ENGINE-364. Tries to invoke trustPersonalKey on an identity without key,
    1.98 + giving it a fake fingerprint.
    1.99 + */
   1.100 +- (void)testTrustPersonalKey
   1.101 +{
   1.102 +    PEPSession *session = [PEPSession new];
   1.103 +
   1.104 +    PEPIdentity *identMe = [[PEPIdentity alloc]
   1.105 +                            initWithAddress:@"me-myself-and-i@pep-project.org"
   1.106 +                            userID:@"me-myself-and-i"
   1.107 +                            userName:@"pEp Me"
   1.108 +                            isOwn:YES];
   1.109 +    [session mySelf:identMe];
   1.110 +    XCTAssertNotNil(identMe.fingerPrint);
   1.111 +
   1.112 +    // The fingerprint is definitely wrong, we don't have a key
   1.113 +    PEPIdentity *identAlice = [[PEPIdentity alloc]
   1.114 +                               initWithAddress:@"alice@pep-project.org"
   1.115 +                               userID:@"alice"
   1.116 +                               userName:@"pEp Test Alice"
   1.117 +                               isOwn:NO
   1.118 +                               fingerPrint:@"4ABE3AAF59AC32CFE4F86500A9411D176FF00E97"];
   1.119 +
   1.120 +    [session trustPersonalKey:identAlice];
   1.121 +}
   1.122 +
   1.123  #pragma mark - configUnencryptedSubject
   1.124  
   1.125  - (void)testConfigUnencryptedSubject
   1.126 @@ -818,8 +893,11 @@
   1.127  - (PEPIdentity *)checkImportingKeyFilePath:(NSString *)filePath address:(NSString *)address
   1.128                                      userID:(NSString *)userID
   1.129                                 fingerPrint:(NSString *)fingerPrint
   1.130 +                                   session:(PEPSession *)session
   1.131  {
   1.132 -    PEPSession *session = [PEPSession new];
   1.133 +    if (!session) {
   1.134 +        session = [PEPSession new];
   1.135 +    }
   1.136  
   1.137      [PEPTestUtils importBundledKey:filePath];
   1.138  
   1.139 @@ -1021,74 +1099,4 @@
   1.140      }
   1.141  }
   1.142  
   1.143 -- (void)testEncryptMessagesWithoutKeys
   1.144 -{
   1.145 -    PEPSession *session = [PEPSession new];
   1.146 -
   1.147 -    PEPIdentity *identMe = [[PEPIdentity alloc]
   1.148 -                            initWithAddress:@"me-myself-and-i@pep-project.org"
   1.149 -                            userID:@"me-myself-and-i"
   1.150 -                            userName:@"pEp Me"
   1.151 -                            isOwn:YES];
   1.152 -    [session mySelf:identMe];
   1.153 -    XCTAssertNotNil(identMe.fingerPrint);
   1.154 -
   1.155 -    PEPIdentity *identAlice = [[PEPIdentity alloc]
   1.156 -                               initWithAddress:@"alice@pep-project.org"
   1.157 -                               userID:@"alice"
   1.158 -                               userName:@"pEp Test Alice"
   1.159 -                               isOwn:NO];
   1.160 -
   1.161 -    PEPMessage *msg = [PEPMessage new];
   1.162 -    msg.from = identMe;
   1.163 -    msg.to = @[identAlice];
   1.164 -    msg.shortMessage = @"Mail to Alice";
   1.165 -    msg.longMessage = @"Alice?";
   1.166 -    msg.direction = PEP_dir_outgoing;
   1.167 -
   1.168 -    PEP_rating clr = [session outgoingColorForMessage:msg];
   1.169 -    XCTAssertEqual(clr, PEP_rating_unencrypted);
   1.170 -
   1.171 -    PEPMessage *encMsg;
   1.172 -
   1.173 -    PEP_STATUS statusEnc = statusEnc = [session encryptMessage:msg extra:@[] dest:&encMsg];
   1.174 -
   1.175 -    XCTAssertEqual(statusEnc, PEP_UNENCRYPTED);
   1.176 -
   1.177 -    XCTAssertNotNil(encMsg);
   1.178 -
   1.179 -    PEPMessage *decMsg;
   1.180 -    PEPStringList *keys;
   1.181 -    PEP_rating pEpRating = [session decryptMessage:encMsg dest:&decMsg keys:&keys];
   1.182 -    XCTAssertEqual(pEpRating, PEP_rating_unencrypted);
   1.183 -    XCTAssertNotNil(decMsg);
   1.184 -}
   1.185 -
   1.186 -/**
   1.187 - ENGINE-364. Tries to invoke trustPersonalKey on an identity without key,
   1.188 - giving it a fake fingerprint.
   1.189 - */
   1.190 -- (void)testTrustPersonalKey
   1.191 -{
   1.192 -    PEPSession *session = [PEPSession new];
   1.193 -
   1.194 -    PEPIdentity *identMe = [[PEPIdentity alloc]
   1.195 -                            initWithAddress:@"me-myself-and-i@pep-project.org"
   1.196 -                            userID:@"me-myself-and-i"
   1.197 -                            userName:@"pEp Me"
   1.198 -                            isOwn:YES];
   1.199 -    [session mySelf:identMe];
   1.200 -    XCTAssertNotNil(identMe.fingerPrint);
   1.201 -
   1.202 -    // The fingerprint is definitely wrong, we don't have a key
   1.203 -    PEPIdentity *identAlice = [[PEPIdentity alloc]
   1.204 -                               initWithAddress:@"alice@pep-project.org"
   1.205 -                               userID:@"alice"
   1.206 -                               userName:@"pEp Test Alice"
   1.207 -                               isOwn:NO
   1.208 -                               fingerPrint:@"4ABE3AAF59AC32CFE4F86500A9411D176FF00E97"];
   1.209 -
   1.210 -    [session trustPersonalKey:identAlice];
   1.211 -}
   1.212 -
   1.213  @end