Skip to content
Snippets Groups Projects
Commit 7cb9417c authored by Oliver Wiese's avatar Oliver Wiese
Browse files

refactor for testcase

parent 6c7f1b33
No related branches found
No related tags found
1 merge request!68Resolve "Add autocrypt header"
...@@ -332,11 +332,8 @@ class OutgoingMail { ...@@ -332,11 +332,8 @@ class OutgoingMail {
headerString += "BCC: " + bccs + "\r\n" headerString += "BCC: " + bccs + "\r\n"
} }
headerString += "X-Mailer: Letterbox \r\n" headerString += "X-Mailer: Letterbox \r\n"
if autocrypt { if let header = Autocrypt.customAutocryptHeader {
Autocrypt.addAutocryptHeader(builder) headerString += header
if let autocrypt = builder.header.extraHeaderValue(forName: Autocrypt.AUTOCRYPTHEADER) {
headerString += Autocrypt.AUTOCRYPTHEADER + ": " + autocrypt + "\r\n"
}
} }
if let msgID = header?.messageID { if let msgID = header?.messageID {
headerString += "Message-ID: " + msgID + "\r\n" headerString += "Message-ID: " + msgID + "\r\n"
......
...@@ -32,7 +32,6 @@ class Autocrypt { ...@@ -32,7 +32,6 @@ class Autocrypt {
setPrefer_encryption(prefer_encryption) setPrefer_encryption(prefer_encryption)
} }
convenience init(header: MCOMessageHeader) { convenience init(header: MCOMessageHeader) {
var autocrypt = header.extraHeaderValue(forName: Autocrypt.AUTOCRYPTHEADER) var autocrypt = header.extraHeaderValue(forName: Autocrypt.AUTOCRYPTHEADER)
var field: [String] var field: [String]
...@@ -121,6 +120,15 @@ class Autocrypt { ...@@ -121,6 +120,15 @@ class Autocrypt {
} }
} }
/// Use this function to create an autocrypt header for manuel header creation.
/// - returns: Autcrypt: Addr = ...; key=...
static var customAutocryptHeader: String? {
guard let autocrypt = autocryptHeader else {
return nil
}
return Autocrypt.AUTOCRYPTHEADER + ": " + autocrypt + "\r\n"
}
static func addAutocryptHeader(_ builder: MCOMessageBuilder) { static func addAutocryptHeader(_ builder: MCOMessageBuilder) {
if let autocrypt = Autocrypt.autocryptHeader { if let autocrypt = Autocrypt.autocryptHeader {
builder.header.setExtraHeaderValue(autocrypt, forName: AUTOCRYPTHEADER) builder.header.setExtraHeaderValue(autocrypt, forName: AUTOCRYPTHEADER)
......
...@@ -103,6 +103,40 @@ class AutocryptTest: XCTestCase { ...@@ -103,6 +103,40 @@ class AutocryptTest: XCTestCase {
} }
} }
func testSelfCreatedHeader() {
print("My keyID: \(userKeyID)")
guard let customHeader = Autocrypt.customAutocryptHeader else {
XCTFail("No autocrypt...")
return
}
// Create custom header
var headerString = ""
headerString += "From: " + userAdr + "\r\n"
headerString += "To: " + "alice@example.com" + "\r\n"
headerString += customHeader
headerString += "Message-ID: " + "202029293239sisdj292323" + "\r\n"
headerString += "Subject: " + "subject" + "\r\n"
let mail = headerString + "Hello World"
guard let data = mail.data(using: .utf8) else {
XCTFail("No mail data...")
return
}
let inc = IncomingMail(rawData: data, uID: 0, folderPath: "Test", flags: .seen)
let prop = inc.export()
XCTAssertEqual(prop.autocryptHeaderKey.count, 1)
guard let key = prop.autocryptHeaderKey.first else {
XCTFail("No key...")
return
}
XCTAssertEqual(key.fingerprint, userKeyID)
XCTAssertEqual(key.cryptoProtocol, .PGP)
XCTAssertEqual(key.origin, .AutocryptHeader)
XCTAssertEqual(key.preferEncryption, .MUTUAL)
XCTAssertEqual(key.usedAddresses?.first?.email, userAdr)
}
func testAutocryptHeader(){ func testAutocryptHeader(){
let outmail = OutgoingMail(toEntrys: ["alice@example.com"], ccEntrys: [], bccEntrys: [], subject: "subject", textContent: "Body", htmlContent: nil) let outmail = OutgoingMail(toEntrys: ["alice@example.com"], ccEntrys: [], bccEntrys: [], subject: "subject", textContent: "Body", htmlContent: nil)
if let parser = MCOMessageParser(data: outmail.plainData), let _ = pgp.exportKey(id: userKeyID, isSecretkey: false, autocrypt: false) { if let parser = MCOMessageParser(data: outmail.plainData), let _ = pgp.exportKey(id: userKeyID, isSecretkey: false, autocrypt: false) {
......
// MARK: - Mocks generated from file: enzevalos_iphone/AuthenticationModel.swift at 2021-03-09 16:14:51 +0000 // MARK: - Mocks generated from file: enzevalos_iphone/AuthenticationModel.swift at 2021-03-09 16:51:40 +0000
// //
// AuthenticationModel.swift // AuthenticationModel.swift
...@@ -654,7 +654,7 @@ import Foundation ...@@ -654,7 +654,7 @@ import Foundation
} }
// MARK: - Mocks generated from file: enzevalos_iphone/AuthenticationViewModel.swift at 2021-03-09 16:14:51 +0000 // MARK: - Mocks generated from file: enzevalos_iphone/AuthenticationViewModel.swift at 2021-03-09 16:51:40 +0000
// //
// AuthenticationViewModel.swift // AuthenticationViewModel.swift
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment