From 6c445a57dd512b0f5fd53bef3b7b4b7541f323e5 Mon Sep 17 00:00:00 2001 From: Ivan Ushakov Date: Sun, 20 Feb 2022 19:14:45 +0300 Subject: [PATCH] Create unit tests for composeEmail with signing key --- .../Core/FlowCryptCoreTests.swift | 82 +++++++++++++++++++ 1 file changed, 82 insertions(+) diff --git a/FlowCryptAppTests/Core/FlowCryptCoreTests.swift b/FlowCryptAppTests/Core/FlowCryptCoreTests.swift index b56da2385..199622f04 100644 --- a/FlowCryptAppTests/Core/FlowCryptCoreTests.swift +++ b/FlowCryptAppTests/Core/FlowCryptCoreTests.swift @@ -175,6 +175,88 @@ final class FlowCryptCoreTests: XCTestCase { XCTAssertNotNil(mime.range(of: "Subject: \(msg.subject)")) // has mime Subject header } + func testComposeEmailWithSigningKey() async throws { + // arrange + let signingKey = PrvKeyInfo( + private: TestData.k0.prv, + longid: TestData.k0.longid, + passphrase: TestData.k0.passphrase, + fingerprints: TestData.k0.fingerprints + ) + + let msg = SendableMsg( + text: "this is the message", + html: nil, + to: ["email@hello.com"], cc: [], bcc: [], + from: "sender@hello.com", + subject: "Signed email", + replyToMimeMsg: nil, + atts: [], + pubKeys: [TestData.k0.pub], + signingPrv: signingKey, + password: nil + ) + + // act + let r = try await core.composeEmail(msg: msg, fmt: .encryptInline) + + // assert + let decrypted = try await core.parseDecryptMsg( + encrypted: r.mimeEncoded, + keys: [signingKey], + msgPwd: nil, + isEmail: true, + verificationPubKeys: [TestData.k0.pub] + ) + guard let verifyResult = decrypted.blocks.first?.verifyRes else { + XCTFail("verify result expected") + return + } + XCTAssertTrue(verifyResult.match ?? false) + XCTAssertEqual(verifyResult.signer, "063635B3E33EB14C") + } + + func testComposeEmailWithSigningKeyWithoutVerificationKey() async throws { + // arrange + let signingKey = PrvKeyInfo( + private: TestData.k0.prv, + longid: TestData.k0.longid, + passphrase: TestData.k0.passphrase, + fingerprints: TestData.k0.fingerprints + ) + + let msg = SendableMsg( + text: "this is the message", + html: nil, + to: ["email@hello.com"], cc: [], bcc: [], + from: "sender@hello.com", + subject: "Signed email", + replyToMimeMsg: nil, + atts: [], + pubKeys: [TestData.k0.pub], + signingPrv: signingKey, + password: nil + ) + + // act + let r = try await core.composeEmail(msg: msg, fmt: .encryptInline) + + // assert + let decrypted = try await core.parseDecryptMsg( + encrypted: r.mimeEncoded, + keys: [signingKey], + msgPwd: nil, + isEmail: true, + verificationPubKeys: [] + ) + guard let verifyResult = decrypted.blocks.first?.verifyRes else { + XCTFail("verify result expected") + return + } + XCTAssertNil(verifyResult.match) + XCTAssertEqual(verifyResult.signer, "063635B3E33EB14C") + } + func testEndToEnd() async throws { let passphrase = "some pass phrase test" let email = "e2e@domain.com"