Test and fix behavior with compression options

Changes in #20 were insufficient.
This commit is contained in:
Davide De Rosa 2018-11-04 11:50:26 +01:00
parent c1065751b6
commit f2b5c05d58
2 changed files with 18 additions and 3 deletions

View File

@ -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
}
}

View File

@ -55,6 +55,17 @@ class FileConfigurationTests: XCTestCase {
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")!
}