pEpForiOSTests/PepAdapterTests.swift
author Xavier Algarra <xavier@pep-project.org>
Tue, 06 Jun 2017 07:49:23 +0200
changeset 2248 75013a586bfd
parent 2172 f8478979dd14
child 2840 706b1f6268fa
permissions -rw-r--r--
IOS-137 add multiple accounts option with the new login
     1 //
     2 //  PepAdapterTests.swift
     3 //  pEpForiOS
     4 //
     5 //  Created by hernani on 03/06/16.
     6 //  Copyright © 2016 p≡p Security S.A. All rights reserved.
     7 //
     8 
     9 import XCTest
    10 
    11 import pEpForiOS
    12 
    13 class PepAdapterTests: XCTestCase {
    14     let comp = "PepAdapterTests"
    15     let identity_me: NSMutableDictionary = [kPepAddress: "some@mail.com",
    16                                             kPepUsername: "This is me"]
    17     var pEpSession: PEPSession!
    18     
    19     override func setUp() {
    20         super.setUp()
    21         pEpSession = PEPSession()
    22     }
    23     
    24     override func tearDown() {
    25         pEpSession = nil
    26         super.tearDown()
    27     }
    28 
    29     func testPepSession() {
    30         XCTAssertNotNil(pEpSession)
    31     }
    32     
    33     func testMyself() {
    34         // This includes that a new key is generated.
    35         pEpSession.mySelf(identity_me)
    36         XCTAssertNotNil(identity_me[kPepUserID])
    37     }
    38     
    39     // XXX: Parts of this should be in PEPUtil module.
    40     func testKeyServerLookup() {
    41         let identity: NSMutableDictionary = [kPepUsername: "hernani",
    42                                              kPepAddress: "hernani@pep.foundation",
    43                                              kPepUserID: "2342"]
    44         PEPObjCAdapter.startKeyserverLookup()
    45         sleep(4)
    46         
    47         pEpSession.updateIdentity(identity)
    48         
    49         XCTAssertTrue(identity.count > 3,
    50                       "Identity dictionary was "
    51                         + "(successfully) modified by reference.")
    52 
    53         for key in identity.allKeys {
    54             Log.info(component: comp, content: "key = \(key)")
    55         }
    56         
    57         XCTAssertNotNil(identity[kPepFingerprint], "A fingerprint, there is!")
    58         
    59         PEPObjCAdapter.stopKeyserverLookup()
    60     }
    61     
    62     /**
    63      - See: https://cacert.pep.foundation/jira/browse/IOSAD-10
    64      https://cacert.pep.foundation/jira/browse/ENGINE-159
    65      */
    66     func testDecryptMessageWithoutAttachments() {
    67         let pepMessage: PEPMessage = [
    68             kPepAttachments: NSArray(),
    69             kPepTo: NSArray(array: [identity_me]),
    70             kPepFrom: identity_me,
    71             kPepShortMessage: "Subject" as NSString,
    72             kPepLongMessage: "Long long message" as NSString
    73         ]
    74         var pepDecryptedMessage: NSDictionary? = nil
    75         var keys: NSArray?
    76         let color = pEpSession.decryptMessageDict(
    77             pepMessage, dest: &pepDecryptedMessage, keys: &keys)
    78         XCTAssertEqual(color, PEP_rating_unencrypted)
    79     }
    80 }