From a4d200412860571049cb25bb8242adc9114c0ef8 Mon Sep 17 00:00:00 2001 From: Sergey Abramchuk Date: Sat, 28 Oct 2017 12:59:56 +0300 Subject: [PATCH] Add test for checking remote VPN connection --- .../OpenVPNAdapterTests.swift | 32 +++++++++++++++++-- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/OpenVPN Adapter Tests/OpenVPNAdapterTests.swift b/OpenVPN Adapter Tests/OpenVPNAdapterTests.swift index 8bcebb3..0642e45 100644 --- a/OpenVPN Adapter Tests/OpenVPNAdapterTests.swift +++ b/OpenVPN Adapter Tests/OpenVPNAdapterTests.swift @@ -16,6 +16,8 @@ class OpenVPNAdapterTests: XCTestCase { case connection } + let customFlow = CustomFlow() + var expectations = [ExpectationsType : XCTestExpectation]() override func setUp() { @@ -63,8 +65,8 @@ class OpenVPNAdapterTests: XCTestCase { } } - // Test connection without specifying username and password - func testConection() { + // Test connection with local VPN server + func testLocalConection() { let adapter = OpenVPNAdapter() let configuration = OpenVPNConfiguration() @@ -105,12 +107,36 @@ class OpenVPNAdapterTests: XCTestCase { } } + // Test connection with remote VPN server + func testRemoteConnection() { + let adapter = OpenVPNAdapter() + + let configuration = OpenVPNConfiguration() + configuration.fileContent = ProfileLoader.getVPNProfile(type: .remoteVPNServer) + + do { + _ = try adapter.apply(configuration: configuration) + } catch { + XCTFail("Failed to configure OpenVPN adapted due to error: \(error)") + return + } + + expectations[.connection] = expectation(description: "me.ss-abramchuk.openvpn-adapter.connection") + + adapter.delegate = self + adapter.connect() + + waitForExpectations(timeout: 30.0) { (error) in + adapter.disconnect() + } + } + } extension OpenVPNAdapterTests: OpenVPNAdapterDelegate { func openVPNAdapter(_ openVPNAdapter: OpenVPNAdapter, configureTunnelWithNetworkSettings networkSettings: NEPacketTunnelNetworkSettings, completionHandler: @escaping (NEPacketTunnelFlow?) -> Void) { - completionHandler(NEPacketTunnelFlow()) + completionHandler(customFlow) } func openVPNAdapter(_ openVPNAdapter: OpenVPNAdapter, handleEvent event: OpenVPNAdapterEvent, message: String?) {