From f2b5c05d580f5431a6360cac0a06cc3302c4c099 Mon Sep 17 00:00:00 2001 From: Davide De Rosa Date: Sun, 4 Nov 2018 11:50:26 +0100 Subject: [PATCH] Test and fix behavior with compression options Changes in #20 were insufficient. --- .../VPN/TunnelKitProvider+FileConfiguration.swift | 10 +++++++--- PassepartoutTests-iOS/FileConfigurationTests.swift | 11 +++++++++++ 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/Passepartout/Sources/VPN/TunnelKitProvider+FileConfiguration.swift b/Passepartout/Sources/VPN/TunnelKitProvider+FileConfiguration.swift index 14f8aa86..f991bca9 100644 --- a/Passepartout/Sources/VPN/TunnelKitProvider+FileConfiguration.swift +++ b/Passepartout/Sources/VPN/TunnelKitProvider+FileConfiguration.swift @@ -236,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 } } @@ -246,7 +250,7 @@ extension TunnelKitProvider.Configuration { compressionFraming = .compress guard $0.isEmpty else { - warning = warning ?? .unsupportedConfiguration(option: "compression") + unsupportedError = .unsupportedConfiguration(option: line) return } } diff --git a/PassepartoutTests-iOS/FileConfigurationTests.swift b/PassepartoutTests-iOS/FileConfigurationTests.swift index 9c6aa37d..ed66541c 100644 --- a/PassepartoutTests-iOS/FileConfigurationTests.swift +++ b/PassepartoutTests-iOS/FileConfigurationTests.swift @@ -55,6 +55,17 @@ class FileConfigurationTests: XCTestCase { print(stripped) } + func testCompression() throws { + let base: [String] = ["", "", "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")! }