Merge branch 'fix-again-compression-warnings'

This commit is contained in:
Davide De Rosa 2018-11-04 12:01:27 +01:00
commit 2afe881aa9
8 changed files with 33 additions and 30 deletions

View File

@ -91,7 +91,7 @@ class IssueReporter: NSObject {
}
if let url = configurationURL {
do {
let parsedFile = try TunnelKitProvider.Configuration.parsed(from: url, returnsStripped: true)
let parsedFile = try TunnelKitProvider.Configuration.parsed(fromURL: url, returnsStripped: true)
if let attachment = parsedFile.strippedLines?.joined(separator: "\n").data(using: .utf8) {
vc.addAttachmentData(attachment, mimeType: AppConstants.IssueReporter.MIME.configuration, fileName: AppConstants.IssueReporter.Filenames.configuration)
}

View File

@ -35,7 +35,7 @@ extension ParsedFile {
let file: ParsedFile
log.debug("Parsing configuration URL: \(url)")
do {
file = try TunnelKitProvider.Configuration.parsed(from: url)
file = try TunnelKitProvider.Configuration.parsed(fromURL: url)
} catch let e {
let message = localizedMessage(forError: e)
alertImportError(url: url, in: viewController, withMessage: message)

View File

@ -123,7 +123,7 @@ class ConfigurationViewController: UIViewController, TableModelHost {
}
let parsedFile: ParsedFile
do {
parsedFile = try TunnelKitProvider.Configuration.parsed(from: originalURL)
parsedFile = try TunnelKitProvider.Configuration.parsed(fromURL: originalURL)
} catch let e {
log.error("Could not parse original configuration: \(e)")
return

View File

@ -88,7 +88,7 @@ class WizardHostViewController: UITableViewController, TableModelHost {
// MARK: Actions
private func useSuggestedTitle() {
cellTitle?.field.text = parsedFile?.url.normalizedFilename
cellTitle?.field.text = parsedFile?.url?.normalizedFilename
}
@IBAction private func next() {

View File

@ -107,8 +107,8 @@ class AppConstants {
return "debug-\(iso).txt"
}
// static let configuration = "profile.ovpn"
static let configuration = "profile.ovpn.txt"
static let configuration = "profile.ovpn"
// static let configuration = "profile.ovpn.txt"
}
class MIME {

View File

@ -30,7 +30,7 @@ import SwiftyBeaver
private let log = SwiftyBeaver.self
struct ParsedFile {
let url: URL
let url: URL?
let hostname: String
@ -77,8 +77,12 @@ extension TunnelKitProvider.Configuration {
static let externalFiles = Utils.regex("^(ca|cert|key|tls-auth|tls-crypt) ")
}
static func parsed(from url: URL, returnsStripped: Bool = false) throws -> ParsedFile {
static func parsed(fromURL url: URL, returnsStripped: Bool = false) throws -> ParsedFile {
let lines = try String(contentsOf: url).trimmedLines()
return try parsed(fromLines: lines, originalURL: url, returnsStripped: returnsStripped)
}
static func parsed(fromLines lines: [String], originalURL: URL? = nil, returnsStripped: Bool = false) throws -> ParsedFile {
var strippedLines: [String]? = returnsStripped ? [] : nil
var warning: ApplicationError? = nil
@ -232,8 +236,12 @@ extension TunnelKitProvider.Configuration {
isHandled = true
compressionFraming = .compLZO
guard let arg = $0.first, arg == "no" else {
warning = warning ?? .unsupportedConfiguration(option: "compression")
guard let arg = $0.first else {
warning = warning ?? .unsupportedConfiguration(option: line)
return
}
guard arg == "no" else {
unsupportedError = .unsupportedConfiguration(option: line)
return
}
}
@ -242,7 +250,7 @@ extension TunnelKitProvider.Configuration {
compressionFraming = .compress
guard $0.isEmpty else {
warning = warning ?? .unsupportedConfiguration(option: "compression")
unsupportedError = .unsupportedConfiguration(option: line)
return
}
}
@ -343,7 +351,7 @@ extension TunnelKitProvider.Configuration {
builder.endpointProtocols = endpointProtocols
return ParsedFile(
url: url,
url: originalURL,
hostname: hostname,
configuration: builder.build(),
strippedLines: strippedLines,

View File

@ -43,22 +43,6 @@ class ConnectionServiceTests: XCTestCase {
XCTAssertNoThrow(try JSONSerialization.jsonObject(with: jsonData, options: []))
}
func testMigrate() {
let migrated = try! ConnectionService.migrateJSON(at: url)
let json = String(data: migrated, encoding: .utf8)!
print(json)
let service = try! JSONDecoder().decode(ConnectionService.self, from: migrated)
guard let activeProfile = service.activeProfile as? HostConnectionProfile else {
XCTFail()
return
}
XCTAssert(activeProfile.id == "host.edu")
XCTAssert(activeProfile.hostname == "1.2.4.5")
XCTAssert(activeProfile.parameters.sessionConfiguration.cipher == .aes256cbc)
XCTAssert(activeProfile.parameters.sessionConfiguration.ca.pem == "bogus+ca")
}
func testPathExtension() {
XCTAssertTrue(privateTestPathExtension("file:///foo/bar/johndoe.json"))
XCTAssertFalse(privateTestPathExtension("file:///foo/bar/break.json.johndoe.json"))

View File

@ -39,7 +39,7 @@ class FileConfigurationTests: XCTestCase {
}
func testPIA() throws {
let file = try TunnelKitProvider.Configuration.parsed(from: url(withName: "pia-hungary"))
let file = try TunnelKitProvider.Configuration.parsed(fromURL: url(withName: "pia-hungary"))
XCTAssertEqual(file.hostname, "hungary.privateinternetaccess.com")
XCTAssertEqual(file.configuration.sessionConfiguration.cipher, .aes128cbc)
XCTAssertEqual(file.configuration.sessionConfiguration.digest, .sha1)
@ -50,11 +50,22 @@ class FileConfigurationTests: XCTestCase {
}
func testStripped() throws {
let lines = try TunnelKitProvider.Configuration.parsed(from: url(withName: "pia-hungary"), returnsStripped: true).strippedLines!
let lines = try TunnelKitProvider.Configuration.parsed(fromURL: url(withName: "pia-hungary"), returnsStripped: true).strippedLines!
let stripped = lines.joined(separator: "\n")
print(stripped)
}
func testCompression() throws {
let base: [String] = ["<ca>", "</ca>", "remote 1.2.3.4"]
XCTAssertNotNil(try TunnelKitProvider.Configuration.parsed(fromLines: base + ["comp-lzo"]).warning)
XCTAssertNoThrow(try TunnelKitProvider.Configuration.parsed(fromLines: base + ["comp-lzo no"]))
XCTAssertThrowsError(try TunnelKitProvider.Configuration.parsed(fromLines: base + ["comp-lzo yes"]))
XCTAssertNoThrow(try TunnelKitProvider.Configuration.parsed(fromLines: base + ["compress"]))
XCTAssertThrowsError(try TunnelKitProvider.Configuration.parsed(fromLines: base + ["compress lzo"]))
}
private func url(withName name: String) -> URL {
return Bundle(for: FileConfigurationTests.self).url(forResource: name, withExtension: "ovpn")!
}