IOS-1518 Move MessageReevalutionTests. IOS-1518
authorDirk Zimmermann <dz@pep.security>
Tue, 14 May 2019 16:19:30 +0200
branchIOS-1518
changeset 8608ea608184fc03
parent 8607 e40d70c54b48
child 8609 cefa5ff5dfa1
IOS-1518 Move MessageReevalutionTests.
pEpForiOS.xcodeproj/project.pbxproj
pEpForiOSTests/MessageReevalutionTests.swift
     1.1 --- a/pEpForiOS.xcodeproj/project.pbxproj	Tue May 14 16:19:30 2019 +0200
     1.2 +++ b/pEpForiOS.xcodeproj/project.pbxproj	Tue May 14 16:19:30 2019 +0200
     1.3 @@ -265,7 +265,6 @@
     1.4  		4365E85F2265DC3F00929D07 /* VerifiableAccountTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4365E85E2265DC3F00929D07 /* VerifiableAccountTest.swift */; };
     1.5  		4365E86A226615F200929D07 /* VerifiableAccountIMAP.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4365E869226615F200929D07 /* VerifiableAccountIMAP.swift */; };
     1.6  		4365E87222661B9700929D07 /* VerifiableAccount.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4365E87122661B9700929D07 /* VerifiableAccount.swift */; };
     1.7 -		436795F81EE98B9A00B03E23 /* MessageReevalutionTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 436795F71EE98B9A00B03E23 /* MessageReevalutionTests.swift */; };
     1.8  		436795FB1EE98E9900B03E23 /* CommunicationTypeTests_test002@peptest.ch_sec.asc in Resources */ = {isa = PBXBuildFile; fileRef = 436795F91EE98E9900B03E23 /* CommunicationTypeTests_test002@peptest.ch_sec.asc */; };
     1.9  		436795FC1EE98E9900B03E23 /* CommunicationTypeTests_test002@peptest.ch.asc in Resources */ = {isa = PBXBuildFile; fileRef = 436795FA1EE98E9900B03E23 /* CommunicationTypeTests_test002@peptest.ch.asc */; };
    1.10  		436795FF1EE98F6E00B03E23 /* CommunicationTypeTests_test001@peptest.ch_sec.asc in Resources */ = {isa = PBXBuildFile; fileRef = 436795FD1EE98F6E00B03E23 /* CommunicationTypeTests_test001@peptest.ch_sec.asc */; };
    1.11 @@ -752,7 +751,6 @@
    1.12  		4365E85E2265DC3F00929D07 /* VerifiableAccountTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VerifiableAccountTest.swift; sourceTree = "<group>"; };
    1.13  		4365E869226615F200929D07 /* VerifiableAccountIMAP.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VerifiableAccountIMAP.swift; sourceTree = "<group>"; };
    1.14  		4365E87122661B9700929D07 /* VerifiableAccount.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = VerifiableAccount.swift; sourceTree = "<group>"; };
    1.15 -		436795F71EE98B9A00B03E23 /* MessageReevalutionTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MessageReevalutionTests.swift; sourceTree = "<group>"; };
    1.16  		436795F91EE98E9900B03E23 /* CommunicationTypeTests_test002@peptest.ch_sec.asc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = "CommunicationTypeTests_test002@peptest.ch_sec.asc"; sourceTree = "<group>"; };
    1.17  		436795FA1EE98E9900B03E23 /* CommunicationTypeTests_test002@peptest.ch.asc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = "CommunicationTypeTests_test002@peptest.ch.asc"; sourceTree = "<group>"; };
    1.18  		436795FD1EE98F6E00B03E23 /* CommunicationTypeTests_test001@peptest.ch_sec.asc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = "CommunicationTypeTests_test001@peptest.ch_sec.asc"; sourceTree = "<group>"; };
    1.19 @@ -1772,7 +1770,6 @@
    1.20  				438281821E891B7E00087343 /* DateTests.swift */,
    1.21  				43FAA0D31EC9CBC0005BFC4B /* DecryptionTestsInternal.swift */,
    1.22  				431E58FB1ED5926B00EFA77F /* AccountVerificationServiceTests.swift */,
    1.23 -				436795F71EE98B9A00B03E23 /* MessageReevalutionTests.swift */,
    1.24  				43F7F0791F6AD44600BDF151 /* HandshakeTests.swift */,
    1.25  				431F987E1F6FD3E300A1E4D2 /* HandshakePartnerTableViewCellViewModelTests.swift */,
    1.26  				1541D7EF1FC81ED900D52A5D /* URL+ExtensionsTest.swift */,
    1.27 @@ -2957,7 +2954,6 @@
    1.28  				151F71FA202A06760057C74D /* DecryptionAttemptCounterDelegate.swift in Sources */,
    1.29  				431C2B171F387C4100D87FFD /* LoginViewModelTests.swift in Sources */,
    1.30  				151AD7AD219D74C700FC36FF /* ComposeViewModelTest.swift in Sources */,
    1.31 -				436795F81EE98B9A00B03E23 /* MessageReevalutionTests.swift in Sources */,
    1.32  				43EE994E1E4392530060EACE /* FlagImageTests.swift in Sources */,
    1.33  				00227E6A21635DED000D9BDB /* FilterViewModelTest.swift in Sources */,
    1.34  				437795C82154D6FD00CC62C2 /* PEPMessage+TestExtension.swift in Sources */,
     2.1 --- a/pEpForiOSTests/MessageReevalutionTests.swift	Tue May 14 16:19:30 2019 +0200
     2.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.3 @@ -1,218 +0,0 @@
     2.4 -//
     2.5 -//  CommunicationTypeTests.swift
     2.6 -//  pEpForiOS
     2.7 -//
     2.8 -//  Created by Dirk Zimmermann on 08.06.17.
     2.9 -//  Copyright © 2017 p≡p Security S.A. All rights reserved.
    2.10 -//
    2.11 -
    2.12 -import XCTest
    2.13 -
    2.14 -@testable import pEpForiOS
    2.15 -@testable import MessageModel //FIXME:
    2.16 -import PEPObjCAdapterFramework
    2.17 -
    2.18 -class MessageReevalutionTests: XCTestCase {
    2.19 -    var cdOwnAccount: CdAccount!
    2.20 -    var pEpOwnIdentity: PEPIdentity!
    2.21 -    var cdSenderIdentity: CdIdentity!
    2.22 -    var pEpSenderIdentity: PEPIdentity!
    2.23 -    var cdInbox: CdFolder!
    2.24 -    var senderIdentity: Identity!
    2.25 -    var cdDecryptedMessage: CdMessage!
    2.26 -
    2.27 -    var persistentSetup: PersistentSetup!
    2.28 -    var session: PEPSession {
    2.29 -        return PEPSession()
    2.30 -    }
    2.31 -    var backgroundQueue: OperationQueue!
    2.32 -
    2.33 -    override func setUp() {
    2.34 -        super.setUp()
    2.35 -
    2.36 -        XCTAssertTrue(PEPUtil.pEpClean())
    2.37 -
    2.38 -        persistentSetup = PersistentSetup()
    2.39 -
    2.40 -        let ownIdentity = PEPIdentity(address: "iostest002@peptest.ch",
    2.41 -                                      userID: "iostest002@peptest.ch_ID",
    2.42 -                                      userName: "iOS Test 002",
    2.43 -                                      isOwn: true)
    2.44 -
    2.45 -        // Account
    2.46 -        let cdMyAccount = SecretTestData().createWorkingCdAccount(number: 0)
    2.47 -        cdMyAccount.identity?.userName = ownIdentity.userName
    2.48 -        cdMyAccount.identity?.userID = ownIdentity.userID
    2.49 -        cdMyAccount.identity?.address = ownIdentity.address
    2.50 -
    2.51 -        // Inbox
    2.52 -        cdInbox = CdFolder.create()
    2.53 -        cdInbox.name = ImapSync.defaultImapInboxName
    2.54 -        cdInbox.uuid = MessageID.generate()
    2.55 -        cdInbox.account = cdMyAccount
    2.56 -        self.cdOwnAccount = cdMyAccount
    2.57 -
    2.58 -        // Sender
    2.59 -        let senderUserName = "iOS Test 001"
    2.60 -        let senderUserID = "iostest001@peptest.ch_ID"
    2.61 -        let senderAddress = "iostest001@peptest.ch"
    2.62 -        let senderIdentityBuilder = Identity.create(address: senderAddress,
    2.63 -                                                    userID: senderUserID,
    2.64 -                                                    userName: senderUserName,
    2.65 -                                                    isMySelf: false)
    2.66 -        senderIdentityBuilder.save()
    2.67 -        guard let sender = CdIdentity.search(address: senderAddress) else {
    2.68 -            XCTFail("Can't find")
    2.69 -            return
    2.70 -        }
    2.71 -        Record.saveAndWait()
    2.72 -        self.cdSenderIdentity =  sender
    2.73 -
    2.74 -        // sender pubkey
    2.75 -        try! TestUtil.importKeyByFileName(
    2.76 -            session, fileName: "CommunicationTypeTests_test001@peptest.ch_sec.asc")
    2.77 -
    2.78 -        // own identity, fingerprint 2CAC9CE95910FBEDB539BDE49AB835A954F5BBF6
    2.79 -        try! TestUtil.importKeyByFileName(
    2.80 -            session, fileName: "CommunicationTypeTests_test002@peptest.ch_sec.asc")
    2.81 -        try! TestUtil.importKeyByFileName(
    2.82 -            session, fileName: "CommunicationTypeTests_test002@peptest.ch.asc")
    2.83 -
    2.84 -        try! session.setOwnKey(ownIdentity,
    2.85 -                               fingerprint: "2CAC9CE95910FBEDB539BDE49AB835A954F5BBF6")
    2.86 -
    2.87 -        self.backgroundQueue = OperationQueue()
    2.88 -        decryptTheMessage()
    2.89 -    }
    2.90 -
    2.91 -    override func tearDown() {
    2.92 -        persistentSetup = nil
    2.93 -        backgroundQueue.cancelAllOperations()
    2.94 -        backgroundQueue = nil
    2.95 -        PEPSession.cleanup()
    2.96 -        super.tearDown()
    2.97 -    }
    2.98 -
    2.99 -    func decryptTheMessage() {
   2.100 -        guard let cdMessage = TestUtil.cdMessage(
   2.101 -            fileName: "CommunicationTypeTests_Message_test001_to_test002.txt",
   2.102 -            cdOwnAccount: cdOwnAccount) else {
   2.103 -                XCTFail()
   2.104 -                return
   2.105 -        }
   2.106 -
   2.107 -        let expDecrypted = expectation(description: "expDecrypted")
   2.108 -        let errorContainer = ErrorContainer()
   2.109 -        let decryptOperation = DecryptMessagesOperation(
   2.110 -            parentName: #function, errorContainer: errorContainer)
   2.111 -        decryptOperation.completionBlock = {
   2.112 -            decryptOperation.completionBlock = nil
   2.113 -            expDecrypted.fulfill()
   2.114 -        }
   2.115 -        let decryptDelegate = DecryptionAttemptCounterDelegate()
   2.116 -        decryptOperation.delegate = decryptDelegate
   2.117 -        backgroundQueue.addOperation(decryptOperation)
   2.118 -
   2.119 -        waitForExpectations(timeout: TestUtil.waitTime) { error in
   2.120 -            XCTAssertNil(error)
   2.121 -        }
   2.122 -
   2.123 -        XCTAssertEqual(decryptDelegate.numberOfMessageDecryptAttempts, 1)
   2.124 -        Record.Context.main.refreshAllObjects()
   2.125 -        cdDecryptedMessage = cdMessage
   2.126 -        XCTAssertEqual(cdMessage.pEpRating, Int16(PEPRating.reliable.rawValue))
   2.127 -        XCTAssertEqual(cdMessage.shortMessage, "oh yeah, subject")
   2.128 -        XCTAssertTrue(cdMessage.longMessage?.startsWith("Some text body!") ?? false)
   2.129 -
   2.130 -        guard
   2.131 -            let cdRecipients = cdMessage.to?.array as? [CdIdentity],
   2.132 -            cdRecipients.count == 1,
   2.133 -            let recipientIdentity = cdRecipients[0].identity()
   2.134 -            else {
   2.135 -                XCTFail()
   2.136 -                return
   2.137 -        }
   2.138 -        XCTAssertTrue(recipientIdentity.isMySelf)
   2.139 -
   2.140 -        guard let theSenderIdentity = cdMessage.from?.identity() else {
   2.141 -            XCTFail()
   2.142 -            return
   2.143 -        }
   2.144 -        XCTAssertEqual(theSenderIdentity.address, cdSenderIdentity.address)
   2.145 -        XCTAssertFalse(theSenderIdentity.isMySelf)
   2.146 -
   2.147 -        senderIdentity = theSenderIdentity
   2.148 -    }
   2.149 -
   2.150 -    func testCommunicationTypes() {
   2.151 -        let senderIdent = senderIdentity.updatedIdentity(session: session)
   2.152 -        XCTAssertFalse(try! senderIdent.isPEPUser(session).boolValue)
   2.153 -        XCTAssertEqual(senderIdentity.pEpRating(session: session), .reliable)
   2.154 -
   2.155 -        try! session.keyMistrusted(senderIdent)
   2.156 -
   2.157 -        let senderDict2 = senderIdentity.updatedIdentity(session: session)
   2.158 -        XCTAssertFalse(try! senderDict2.isPEPUser(session).boolValue)
   2.159 -        // ENGINE-343: At one point the rating was .Undefined.
   2.160 -        XCTAssertEqual(senderIdentity.pEpRating(), .haveNoKey)
   2.161 -    }
   2.162 -
   2.163 -    func reevaluateMessage(expectedRating: PEPRating, inBackground: Bool = true,
   2.164 -                           infoMessage: String) {
   2.165 -        guard let message = cdDecryptedMessage.message() else {
   2.166 -            XCTFail()
   2.167 -            return
   2.168 -        }
   2.169 -        if inBackground {
   2.170 -            let expReevaluated = expectation(description: "expReevaluated")
   2.171 -            let reevalOp = ReevaluateMessageRatingOperation(parentName: #function, message: message)
   2.172 -            reevalOp.completionBlock = {
   2.173 -                reevalOp.completionBlock = nil
   2.174 -                expReevaluated.fulfill()
   2.175 -            }
   2.176 -            backgroundQueue.addOperation(reevalOp)
   2.177 -            waitForExpectations(timeout: TestUtil.waitTime, handler: { error in
   2.178 -                XCTAssertNil(error)
   2.179 -            })
   2.180 -
   2.181 -            Record.Context.default.refreshAllObjects()
   2.182 -            XCTAssertEqual(cdDecryptedMessage.pEpRating, Int16(expectedRating.rawValue),
   2.183 -                           infoMessage)
   2.184 -        } else {
   2.185 -            let reevalOp = ReevaluateMessageRatingOperation(
   2.186 -                parentName: #function, message: message)
   2.187 -            reevalOp.reEvaluate(context: Record.Context.default)
   2.188 -        }
   2.189 -    }
   2.190 -
   2.191 -    func testTrustMistrust() {
   2.192 -        let runReevaluationInBackground = false
   2.193 -        let senderIdent = senderIdentity.updatedIdentity(session: session)
   2.194 -
   2.195 -        try! session.keyResetTrust(senderIdent)
   2.196 -        XCTAssertFalse(senderIdent.isConfirmed)
   2.197 -        reevaluateMessage(
   2.198 -            expectedRating: .reliable,
   2.199 -            inBackground: runReevaluationInBackground,
   2.200 -            infoMessage: "in the beginning")
   2.201 -
   2.202 -        for _ in 0..<1 {
   2.203 -            try! session.trustPersonalKey(senderIdent)
   2.204 -            XCTAssertTrue(senderIdent.isConfirmed)
   2.205 -            XCTAssertEqual(senderIdentity.pEpRating(session: session), .trusted)
   2.206 -            reevaluateMessage(
   2.207 -                expectedRating: .trusted,
   2.208 -                inBackground: runReevaluationInBackground,
   2.209 -                infoMessage: "after trust")
   2.210 -
   2.211 -            try! session.keyMistrusted(senderIdent)
   2.212 -            XCTAssertEqual(senderIdentity.pEpRating(session: session), .haveNoKey)
   2.213 -            reevaluateMessage(
   2.214 -                expectedRating: .mistrust,
   2.215 -                inBackground: runReevaluationInBackground,
   2.216 -                infoMessage: "after mistrust")
   2.217 -            try! session.update(senderIdent)
   2.218 -            XCTAssertFalse(senderIdent.isConfirmed)
   2.219 -        }
   2.220 -    }
   2.221 -}