IOS-1518 DecryptionUtil is still needed. IOS-1518
authorDirk Zimmermann <dz@pep.security>
Tue, 14 May 2019 16:19:30 +0200
branchIOS-1518
changeset 860508ec251b0223
parent 8604 c1a6caacbdcf
child 8606 bad86bc2928d
IOS-1518 DecryptionUtil is still needed.
pEpForiOS.xcodeproj/project.pbxproj
pEpForiOSTests/TestUtils/DecryptionUtil.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 @@ -316,6 +316,7 @@
     1.4  		43B10C801EC2EE7F003E849F /* CppDummy.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 43B10C7F1EC2EE7F003E849F /* CppDummy.cpp */; };
     1.5  		43B2C31B1D2280ED00A08557 /* 5A90_3590_0E48_AB85_F3DB__045E_4623_C5D1_EAB6_643E.asc in Resources */ = {isa = PBXBuildFile; fileRef = 43B2C3161D2280ED00A08557 /* 5A90_3590_0E48_AB85_F3DB__045E_4623_C5D1_EAB6_643E.asc */; };
     1.6  		43B7154D1CECAADA0027861A /* ViewWidthsAligner.swift in Sources */ = {isa = PBXBuildFile; fileRef = 43B7154C1CECAADA0027861A /* ViewWidthsAligner.swift */; };
     1.7 +		43BB6657228AD3A400E93537 /* DecryptionUtil.swift in Sources */ = {isa = PBXBuildFile; fileRef = 43BB6656228AD3A300E93537 /* DecryptionUtil.swift */; };
     1.8  		43C273DD21C9024A002EB4C8 /* LoggerTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 43C273DC21C9024A002EB4C8 /* LoggerTest.swift */; };
     1.9  		43C322051EA89EED005073FB /* HandshakePartnerTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 43C322041EA89EED005073FB /* HandshakePartnerTableViewCell.swift */; };
    1.10  		43C322091EA90192005073FB /* PEP+UI.swift in Sources */ = {isa = PBXBuildFile; fileRef = 43C322081EA90192005073FB /* PEP+UI.swift */; };
    1.11 @@ -820,6 +821,7 @@
    1.12  		43B10C7F1EC2EE7F003E849F /* CppDummy.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CppDummy.cpp; sourceTree = "<group>"; };
    1.13  		43B2C3161D2280ED00A08557 /* 5A90_3590_0E48_AB85_F3DB__045E_4623_C5D1_EAB6_643E.asc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = 5A90_3590_0E48_AB85_F3DB__045E_4623_C5D1_EAB6_643E.asc; sourceTree = "<group>"; };
    1.14  		43B7154C1CECAADA0027861A /* ViewWidthsAligner.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ViewWidthsAligner.swift; sourceTree = "<group>"; };
    1.15 +		43BB6656228AD3A300E93537 /* DecryptionUtil.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DecryptionUtil.swift; sourceTree = "<group>"; };
    1.16  		43C046BE1CF48EA500BD0D9D /* AddressBook.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AddressBook.framework; path = System/Library/Frameworks/AddressBook.framework; sourceTree = SDKROOT; };
    1.17  		43C273DC21C9024A002EB4C8 /* LoggerTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LoggerTest.swift; sourceTree = "<group>"; };
    1.18  		43C322041EA89EED005073FB /* HandshakePartnerTableViewCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HandshakePartnerTableViewCell.swift; sourceTree = "<group>"; };
    1.19 @@ -1040,6 +1042,7 @@
    1.20  		151F71EB202A06750057C74D /* TestUtils */ = {
    1.21  			isa = PBXGroup;
    1.22  			children = (
    1.23 +				43BB6656228AD3A300E93537 /* DecryptionUtil.swift */,
    1.24  				151F71F6202A06750057C74D /* CdAccount+TestUtils.swift */,
    1.25  				151F71F3202A06750057C74D /* CdMessage+TestUtils.swift */,
    1.26  				151F71F1202A06750057C74D /* CoreDataDrivenTestBase.swift */,
    1.27 @@ -3004,6 +3007,7 @@
    1.28  				15D439A5216F7E0E00EB3933 /* AccountPickerViewModelTest.swift in Sources */,
    1.29  				1574D07D2114696B00FEDC93 /* URL+MailToTest.swift in Sources */,
    1.30  				43C273DD21C9024A002EB4C8 /* LoggerTest.swift in Sources */,
    1.31 +				43BB6657228AD3A400E93537 /* DecryptionUtil.swift in Sources */,
    1.32  				4365E85F2265DC3F00929D07 /* VerifiableAccountTest.swift in Sources */,
    1.33  				4356FFEC21356CB600804089 /* ReplyAllPossibleCheckerTest.swift in Sources */,
    1.34  				430C80E01D0EADC200CD4582 /* PepAdapterTests.swift in Sources */,
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/pEpForiOSTests/TestUtils/DecryptionUtil.swift	Tue May 14 16:19:30 2019 +0200
     2.3 @@ -0,0 +1,85 @@
     2.4 +//
     2.5 +//  DecryptionUtil.swift
     2.6 +//  pEpForiOSTests
     2.7 +//
     2.8 +//  Created by Dirk Zimmermann on 03.10.18.
     2.9 +//  Copyright © 2018 p≡p Security S.A. All rights reserved.
    2.10 +//
    2.11 +
    2.12 +import Foundation
    2.13 +import XCTest
    2.14 +
    2.15 +@testable import MessageModel
    2.16 +
    2.17 +class DecryptionUtil {
    2.18 +    public static func decryptTheMessage(
    2.19 +        testCase: XCTestCase,
    2.20 +        backgroundQueue: OperationQueue,
    2.21 +        cdOwnAccount: CdAccount,
    2.22 +        fileName: String,
    2.23 +        checkCdMessage: ((CdMessage) -> ())? = nil) -> CdMessage? {
    2.24 +        guard let cdMessage = TestUtil.cdMessage(
    2.25 +            fileName: fileName,
    2.26 +            cdOwnAccount: cdOwnAccount) else {
    2.27 +                XCTFail()
    2.28 +                return nil
    2.29 +        }
    2.30 +
    2.31 +        if let theChecker = checkCdMessage {
    2.32 +            theChecker(cdMessage)
    2.33 +        }
    2.34 +
    2.35 +        let expDecrypted = testCase.expectation(description: "expDecrypted")
    2.36 +        let errorContainer = ErrorContainer()
    2.37 +        let decryptOperation = DecryptMessagesOperation(
    2.38 +            parentName: #function, errorContainer: errorContainer)
    2.39 +        decryptOperation.completionBlock = {
    2.40 +            decryptOperation.completionBlock = nil
    2.41 +            expDecrypted.fulfill()
    2.42 +        }
    2.43 +        let decryptDelegate = DecryptionAttemptCounterDelegate()
    2.44 +        decryptOperation.delegate = decryptDelegate
    2.45 +        backgroundQueue.addOperation(decryptOperation)
    2.46 +
    2.47 +        testCase.waitForExpectations(timeout: TestUtil.waitTime) { error in
    2.48 +            XCTAssertNil(error)
    2.49 +        }
    2.50 +
    2.51 +        XCTAssertEqual(decryptDelegate.numberOfMessageDecryptAttempts, 1)
    2.52 +        Record.Context.main.refreshAllObjects()
    2.53 +
    2.54 +        guard
    2.55 +            let cdRecipients = cdMessage.to?.array as? [CdIdentity],
    2.56 +            cdRecipients.count == 1,
    2.57 +            let recipientIdentity = cdRecipients[0].identity()
    2.58 +            else {
    2.59 +                XCTFail()
    2.60 +                return cdMessage
    2.61 +        }
    2.62 +        XCTAssertTrue(recipientIdentity.isMySelf)
    2.63 +
    2.64 +        guard let theSenderIdentity = cdMessage.from?.identity() else {
    2.65 +            XCTFail()
    2.66 +            return cdMessage
    2.67 +        }
    2.68 +        XCTAssertFalse(theSenderIdentity.isMySelf)
    2.69 +
    2.70 +        return cdMessage
    2.71 +    }
    2.72 +
    2.73 +    public static func createLocalAccount(ownUserName: String, ownUserID: String,
    2.74 +                                          ownEmailAddress: String) -> CdAccount {
    2.75 +        let cdOwnAccount = SecretTestData().createWorkingCdAccount(number: 0)
    2.76 +        cdOwnAccount.identity?.userName = ownUserName
    2.77 +        cdOwnAccount.identity?.userID = ownUserID
    2.78 +        cdOwnAccount.identity?.address = ownEmailAddress
    2.79 +
    2.80 +        let cdInbox = CdFolder.create()
    2.81 +        cdInbox.name = ImapSync.defaultImapInboxName
    2.82 +        cdInbox.uuid = MessageID.generate()
    2.83 +        cdInbox.account = cdOwnAccount
    2.84 +        Record.saveAndWait()
    2.85 +
    2.86 +        return cdOwnAccount
    2.87 +    }
    2.88 +}