From b48575a13a96c2ef4cbbac1c73374e704a3d546f Mon Sep 17 00:00:00 2001 From: Davide De Rosa Date: Wed, 3 Apr 2019 12:56:02 +0200 Subject: [PATCH] Split tests related to options parsing --- TunnelKit.xcodeproj/project.pbxproj | 6 ++ TunnelKitTests/ConfigurationParserTests.swift | 26 -------- TunnelKitTests/OptionsBundleTests.swift | 65 +++++++++++++++++++ 3 files changed, 71 insertions(+), 26 deletions(-) create mode 100644 TunnelKitTests/OptionsBundleTests.swift diff --git a/TunnelKit.xcodeproj/project.pbxproj b/TunnelKit.xcodeproj/project.pbxproj index c76fa64..7468d55 100644 --- a/TunnelKit.xcodeproj/project.pbxproj +++ b/TunnelKit.xcodeproj/project.pbxproj @@ -141,6 +141,8 @@ 0ECC60D6225497400020BEAC /* OptionsBundle.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0ECC60D4225497400020BEAC /* OptionsBundle.swift */; }; 0ECC60D82254981A0020BEAC /* OptionsError.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0ECC60D72254981A0020BEAC /* OptionsError.swift */; }; 0ECC60D92254981A0020BEAC /* OptionsError.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0ECC60D72254981A0020BEAC /* OptionsError.swift */; }; + 0ECC60DB2254C8190020BEAC /* OptionsBundleTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0ECC60DA2254C8190020BEAC /* OptionsBundleTests.swift */; }; + 0ECC60DC2254C8190020BEAC /* OptionsBundleTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0ECC60DA2254C8190020BEAC /* OptionsBundleTests.swift */; }; 0ECE3528212EB7770040F253 /* CryptoContainer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0ECE3527212EB7770040F253 /* CryptoContainer.swift */; }; 0ECE352A212EB88E0040F253 /* CryptoContainer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0ECE3527212EB7770040F253 /* CryptoContainer.swift */; }; 0ECEB1152252C8E900E9E551 /* tunnelbear.enc.8.ovpn in Resources */ = {isa = PBXBuildFile; fileRef = 0ECEB1132252C8E900E9E551 /* tunnelbear.enc.8.ovpn */; }; @@ -348,6 +350,7 @@ 0EC1BBA720D7D803007C4C7B /* ConnectionStrategy.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ConnectionStrategy.swift; sourceTree = ""; }; 0ECC60D4225497400020BEAC /* OptionsBundle.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OptionsBundle.swift; sourceTree = ""; }; 0ECC60D72254981A0020BEAC /* OptionsError.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OptionsError.swift; sourceTree = ""; }; + 0ECC60DA2254C8190020BEAC /* OptionsBundleTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OptionsBundleTests.swift; sourceTree = ""; }; 0ECE3527212EB7770040F253 /* CryptoContainer.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CryptoContainer.swift; sourceTree = ""; }; 0ECEB1132252C8E900E9E551 /* tunnelbear.enc.8.ovpn */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = tunnelbear.enc.8.ovpn; sourceTree = ""; }; 0ECEB1142252C8E900E9E551 /* tunnelbear.enc.8.key */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = tunnelbear.enc.8.key; sourceTree = ""; }; @@ -470,6 +473,7 @@ 0EB2B45E20F0C098004233D7 /* EncryptionPerformanceTests.swift */, 0EB2B45220F0BB44004233D7 /* EncryptionTests.swift */, 0EB2B45820F0BD9A004233D7 /* LinkTests.swift */, + 0ECC60DA2254C8190020BEAC /* OptionsBundleTests.swift */, 0E12B2A22145341B00B4BAE9 /* PacketTests.swift */, 0E245D682135972800B012A2 /* PushTests.swift */, 0EB2B45620F0BD16004233D7 /* RandomTests.swift */, @@ -1151,6 +1155,7 @@ files = ( 0EB2B45720F0BD16004233D7 /* RandomTests.swift in Sources */, 0E011F812196E23700BA59EE /* ConfigurationParserTests.swift in Sources */, + 0ECC60DB2254C8190020BEAC /* OptionsBundleTests.swift in Sources */, 0EB2B45920F0BD9A004233D7 /* LinkTests.swift in Sources */, 0EB2B45520F0BB53004233D7 /* DataManipulationTests.swift in Sources */, 0E50D57521634E0A00FC87A8 /* ControlChannelTests.swift in Sources */, @@ -1322,6 +1327,7 @@ files = ( 0EA82A3A2190B2B9007960EB /* RandomTests.swift in Sources */, 0E011F822196E23800BA59EE /* ConfigurationParserTests.swift in Sources */, + 0ECC60DC2254C8190020BEAC /* OptionsBundleTests.swift in Sources */, 0EA82A332190B2B9007960EB /* DataPathPerformanceTests.swift in Sources */, 0EA82A372190B2B9007960EB /* LinkTests.swift in Sources */, 0EA82A352190B2B9007960EB /* EncryptionPerformanceTests.swift in Sources */, diff --git a/TunnelKitTests/ConfigurationParserTests.swift b/TunnelKitTests/ConfigurationParserTests.swift index 405e770..d2c6fc1 100644 --- a/TunnelKitTests/ConfigurationParserTests.swift +++ b/TunnelKitTests/ConfigurationParserTests.swift @@ -27,8 +27,6 @@ import XCTest import TunnelKit class ConfigurationParserTests: XCTestCase { - let base: [String] = ["", "", "remote 1.2.3.4"] - override func setUp() { super.setUp() // Put setup code here. This method is called before the invocation of each test method in the class. @@ -56,30 +54,6 @@ class ConfigurationParserTests: XCTestCase { print(stripped) } - func testCompression() throws { -// XCTAssertNotNil(try ConfigurationParser.parsed(fromLines: base + ["comp-lzo"]).warning) - XCTAssertNil(try ConfigurationParser.parsed(fromLines: base + ["comp-lzo"]).warning) - XCTAssertNoThrow(try ConfigurationParser.parsed(fromLines: base + ["comp-lzo no"])) - XCTAssertNoThrow(try ConfigurationParser.parsed(fromLines: base + ["comp-lzo yes"])) -// XCTAssertThrowsError(try ConfigurationParser.parsed(fromLines: base + ["comp-lzo yes"])) - - XCTAssertNoThrow(try ConfigurationParser.parsed(fromLines: base + ["compress"])) - XCTAssertNoThrow(try ConfigurationParser.parsed(fromLines: base + ["compress lzo"])) - } - - func testDHCPOption() throws { - let lines = base + ["dhcp-option DNS 8.8.8.8", "dhcp-option DNS6 ffff::1"] - XCTAssertNoThrow(try ConfigurationParser.parsed(fromLines: lines)) - - let parsed = try! ConfigurationParser.parsed(fromLines: lines) - XCTAssertEqual(parsed.configuration.dnsServers, ["8.8.8.8", "ffff::1"]) - } - - func testConnectionBlock() throws { - let lines = base + ["", ""] - XCTAssertThrowsError(try ConfigurationParser.parsed(fromLines: lines)) - } - func testEncryptedCertificateKey() throws { try privateTestEncryptedCertificateKey(pkcs: "1") try privateTestEncryptedCertificateKey(pkcs: "8") diff --git a/TunnelKitTests/OptionsBundleTests.swift b/TunnelKitTests/OptionsBundleTests.swift new file mode 100644 index 0000000..c9852af --- /dev/null +++ b/TunnelKitTests/OptionsBundleTests.swift @@ -0,0 +1,65 @@ +// +// OptionsBundleTests.swift +// TunnelKitTests +// +// Created by Davide De Rosa on 4/3/19. +// Copyright (c) 2019 Davide De Rosa. All rights reserved. +// +// https://github.com/keeshux +// +// This file is part of TunnelKit. +// +// TunnelKit is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// TunnelKit is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with TunnelKit. If not, see . +// + +import XCTest +import TunnelKit + +class OptionsBundleTests: XCTestCase { + let base: [String] = ["", "", "remote 1.2.3.4"] + + override func setUp() { + super.setUp() + // Put setup code here. This method is called before the invocation of each test method in the class. + } + + override func tearDown() { + // Put teardown code here. This method is called after the invocation of each test method in the class. + super.tearDown() + } + + func testCompression() throws { +// XCTAssertNotNil(try OptionsBundle.parsed(fromLines: base + ["comp-lzo"]).warning) + XCTAssertNil(try OptionsBundle(from: base + ["comp-lzo"]).warning) + XCTAssertNoThrow(try OptionsBundle(from: base + ["comp-lzo no"])) + XCTAssertNoThrow(try OptionsBundle(from: base + ["comp-lzo yes"])) +// XCTAssertThrowsError(try OptionsBundle(from: base + ["comp-lzo yes"])) + + XCTAssertNoThrow(try OptionsBundle(from: base + ["compress"])) + XCTAssertNoThrow(try OptionsBundle(from: base + ["compress lzo"])) + } + + func testDHCPOption() throws { + let lines = base + ["dhcp-option DNS 8.8.8.8", "dhcp-option DNS6 ffff::1"] + XCTAssertNoThrow(try OptionsBundle(from: lines)) + + let parsed = try! OptionsBundle(from: lines) + XCTAssertEqual(parsed.dnsServers, ["8.8.8.8", "ffff::1"]) + } + + func testConnectionBlock() throws { + let lines = base + ["", ""] + XCTAssertThrowsError(try OptionsBundle(from: lines)) + } +}