IOS-1518 Don't move ContentDispositionTest. Backed out changeset bc035a9e83dd. IOS-1518
authorDirk Zimmermann <dz@pep.security>
Tue, 14 May 2019 16:19:30 +0200
branchIOS-1518
changeset 8602736f8c97aedd
parent 8601 8def561084dd
child 8603 b2a9c31628ad
IOS-1518 Don't move ContentDispositionTest. Backed out changeset bc035a9e83dd.
pEpForiOS.xcodeproj/project.pbxproj
pEpForiOSTests/ContentDispositionTest.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 @@ -117,6 +117,7 @@
     1.4  		1541D7F31FC8292D00D52A5D /* URL+MIME.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1541D7F21FC8292D00D52A5D /* URL+MIME.swift */; };
     1.5  		1541D7F51FC82A4900D52A5D /* URL+MIME.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1541D7F41FC82A4900D52A5D /* URL+MIME.swift */; };
     1.6  		1544BD0221524C9F0075C5A0 /* AttachmentFilterTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1544BD0121524C9F0075C5A0 /* AttachmentFilterTest.swift */; };
     1.7 +		154F0A8220874B3E00C77D72 /* ContentDispositionTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 154F0A8120874B3E00C77D72 /* ContentDispositionTest.swift */; };
     1.8  		155050F01FE82356009CEAD2 /* UserNotificationTool.swift in Sources */ = {isa = PBXBuildFile; fileRef = 155050EF1FE82356009CEAD2 /* UserNotificationTool.swift */; };
     1.9  		155050F21FE95D8A009CEAD2 /* UserNotificationTool+pEp.swift in Sources */ = {isa = PBXBuildFile; fileRef = 155050F11FE95D8A009CEAD2 /* UserNotificationTool+pEp.swift */; };
    1.10  		1554755F2137F6F8005A52D0 /* SwipeActionDescriptor.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1554755E2137F6F8005A52D0 /* SwipeActionDescriptor.swift */; };
    1.11 @@ -586,6 +587,7 @@
    1.12  		1541D7F21FC8292D00D52A5D /* URL+MIME.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "URL+MIME.swift"; sourceTree = "<group>"; };
    1.13  		1541D7F41FC82A4900D52A5D /* URL+MIME.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "URL+MIME.swift"; sourceTree = "<group>"; };
    1.14  		1544BD0121524C9F0075C5A0 /* AttachmentFilterTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = AttachmentFilterTest.swift; path = pEpForiOSTests/Models/Filter/AttachmentFilterTest.swift; sourceTree = SOURCE_ROOT; };
    1.15 +		154F0A8120874B3E00C77D72 /* ContentDispositionTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentDispositionTest.swift; sourceTree = "<group>"; };
    1.16  		155050EF1FE82356009CEAD2 /* UserNotificationTool.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UserNotificationTool.swift; sourceTree = "<group>"; };
    1.17  		155050F11FE95D8A009CEAD2 /* UserNotificationTool+pEp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UserNotificationTool+pEp.swift"; sourceTree = "<group>"; };
    1.18  		1554755E2137F6F8005A52D0 /* SwipeActionDescriptor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwipeActionDescriptor.swift; sourceTree = "<group>"; };
    1.19 @@ -1784,6 +1786,7 @@
    1.20  				1541D7EF1FC81ED900D52A5D /* URL+ExtensionsTest.swift */,
    1.21  				1541D7F41FC82A4900D52A5D /* URL+MIME.swift */,
    1.22  				430BA228203438A3003B041C /* CdMessagePEPMessageTests.swift */,
    1.23 +				154F0A8120874B3E00C77D72 /* ContentDispositionTest.swift */,
    1.24  				4395CDED20AAC909003FC5F1 /* UIImageExtensionsTests.swift */,
    1.25  				434DDC2A20D10F9A00755F44 /* EncryptionTests.swift */,
    1.26  				438BA0F4214F89CC001A4A82 /* MailParsingTests.swift */,
    1.27 @@ -2979,6 +2982,7 @@
    1.28  				436F8E141D36706A007E9829 /* StringExtensionsTest.swift in Sources */,
    1.29  				15D7D997219C374600A1A2B9 /* ComposeViewModelStateTest.swift in Sources */,
    1.30  				F73E4F7A2180744700CCFFED /* FolderCellViewModelTests.swift in Sources */,
    1.31 +				154F0A8220874B3E00C77D72 /* ContentDispositionTest.swift in Sources */,
    1.32  				B7F4A793212DDFC500507B76 /* EmailListViewModelTest.swift in Sources */,
    1.33  				151F71FC202A06760057C74D /* CoreDataDrivenTestBase.swift in Sources */,
    1.34  				151F71FF202A06760057C74D /* Message+TestUtils.swift in Sources */,
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/pEpForiOSTests/ContentDispositionTest.swift	Tue May 14 16:19:30 2019 +0200
     2.3 @@ -0,0 +1,108 @@
     2.4 +//
     2.5 +//  ContentDispositionTest.swift
     2.6 +//  pEpForiOSTests
     2.7 +//
     2.8 +//  Created by Andreas Buff on 18.04.18.
     2.9 +//  Copyright © 2018 p≡p Security S.A. All rights reserved.
    2.10 +//
    2.11 +
    2.12 +import XCTest
    2.13 +import CoreData
    2.14 +
    2.15 +@testable import MessageModel
    2.16 +@testable import pEpForiOS
    2.17 +
    2.18 +class ContentDispositionTest: CoreDataDrivenTestBase {
    2.19 +    // Commented as randomly failing and crashing. See IOS-1465.
    2.20 +//    func testInlinedAttachmentRoundTrip() {
    2.21 +//        attchmentRoundTrip(attachmentsInlined: true)
    2.22 +//    }
    2.23 +
    2.24 +    // Commented as randomly failing. See IOS-1382.
    2.25 +//    func testNonInlinedAttachmentRoundTrip() {
    2.26 +//        attchmentRoundTrip(attachmentsInlined: false)
    2.27 +//    }
    2.28 +
    2.29 +    // MARK: - HELPER
    2.30 +
    2.31 +    /// Tests if sent attachments are received with correct content disposition
    2.32 +    func attchmentRoundTrip(attachmentsInlined: Bool) {
    2.33 +        // Setup 2 accounts
    2.34 +        cdAccount.createRequiredFoldersAndWait(testCase: self)
    2.35 +        Record.saveAndWait()
    2.36 +
    2.37 +        let cdAccount2 = SecretTestData().createWorkingCdAccount(number: 1)
    2.38 +        Record.saveAndWait()
    2.39 +        cdAccount2.createRequiredFoldersAndWait(testCase: self)
    2.40 +        Record.saveAndWait()
    2.41 +
    2.42 +        guard let id1 = cdAccount.identity,
    2.43 +            let id2 = cdAccount2.identity else {
    2.44 +                XCTFail("We all loose identity ...")
    2.45 +                return
    2.46 +        }
    2.47 +
    2.48 +        // Sync both acocunts and remember what we got before starting the actual test
    2.49 +        TestUtil.syncAndWait(numAccountsToSync: 2, testCase: self)
    2.50 +        let msgsBeforeId2 = cdAccount2.allMessages(inFolderOfType: .inbox, sendFrom: id1)
    2.51 +
    2.52 +        // Create mails from ID1 to ID2 with attachments (inlined or not)
    2.53 +        let dateBeforeSend = Date().addingTimeInterval(-1.0)
    2.54 +        let numMailsToSend = 1
    2.55 +        let mailsToSend = try!
    2.56 +            TestUtil.createOutgoingMails(cdAccount: cdAccount,
    2.57 +                                         fromIdentity: id1,
    2.58 +                                         toIdentity: id2,
    2.59 +                                         setSentTimeOffsetForManualOrdering: false,
    2.60 +                                         testCase: self,
    2.61 +                                         numberOfMails: numMailsToSend,
    2.62 +                                         withAttachments: true,
    2.63 +                                         attachmentsInlined: attachmentsInlined,
    2.64 +                                         encrypt: false,
    2.65 +                                         forceUnencrypted: true)
    2.66 +        XCTAssertEqual(mailsToSend.count, numMailsToSend)
    2.67 +
    2.68 +        // ... and send them.
    2.69 +        TestUtil.syncAndWait(numAccountsToSync: 2, testCase: self)
    2.70 +
    2.71 +        // Sync once again. Just to make sure we mirror the servers state (i.e. receive the
    2.72 +        // sent mails)
    2.73 +        TestUtil.syncAndWait(numAccountsToSync: 2, testCase: self)
    2.74 +
    2.75 +        // Now let's see what we got.
    2.76 +        let msgsAfterId2 = cdAccount2.allMessages(inFolderOfType: .inbox, sendFrom: id1)
    2.77 +        XCTAssertEqual(msgsAfterId2.count, msgsBeforeId2.count + numMailsToSend)
    2.78 +
    2.79 +        // Ignore messages that have not been created by this test
    2.80 +        let testees = msgsAfterId2.filter {
    2.81 +            guard let sent = $0.sent else {
    2.82 +                XCTFail("No sent")
    2.83 +                return false
    2.84 +            }
    2.85 +            return sent > dateBeforeSend
    2.86 +        }
    2.87 +        XCTAssertEqual(testees.count, numMailsToSend)
    2.88 +
    2.89 +        // Assure the contentDisposition is correct (as sent)
    2.90 +        for cdMessage in testees {
    2.91 +            guard let cdAttachments = cdMessage.attachments?.array as? [CdAttachment] else {
    2.92 +                XCTFail("No attachments")
    2.93 +                continue
    2.94 +            }
    2.95 +            XCTAssertGreaterThan(cdAttachments.count, 0)
    2.96 +            for cdAttachment in cdAttachments {
    2.97 +                guard let contentDisposition = Attachment.ContentDispositionType(rawValue:
    2.98 +                        cdAttachment.contentDispositionTypeRawValue)
    2.99 +                    else {
   2.100 +                        XCTFail("Missing data")
   2.101 +                        continue
   2.102 +                }
   2.103 +                if attachmentsInlined {
   2.104 +                    XCTAssertTrue(contentDisposition == .inline)
   2.105 +                } else {
   2.106 +                    XCTAssertTrue(contentDisposition == .attachment)
   2.107 +                }
   2.108 +            }
   2.109 +        }
   2.110 +    }
   2.111 +}