Add test for checking remote VPN connection

This commit is contained in:
Sergey Abramchuk 2017-10-28 12:59:56 +03:00
parent 513b9e20df
commit a4d2004128

View File

@ -16,6 +16,8 @@ class OpenVPNAdapterTests: XCTestCase {
case connection case connection
} }
let customFlow = CustomFlow()
var expectations = [ExpectationsType : XCTestExpectation]() var expectations = [ExpectationsType : XCTestExpectation]()
override func setUp() { override func setUp() {
@ -63,8 +65,8 @@ class OpenVPNAdapterTests: XCTestCase {
} }
} }
// Test connection without specifying username and password // Test connection with local VPN server
func testConection() { func testLocalConection() {
let adapter = OpenVPNAdapter() let adapter = OpenVPNAdapter()
let configuration = OpenVPNConfiguration() 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 { extension OpenVPNAdapterTests: OpenVPNAdapterDelegate {
func openVPNAdapter(_ openVPNAdapter: OpenVPNAdapter, configureTunnelWithNetworkSettings networkSettings: NEPacketTunnelNetworkSettings, completionHandler: @escaping (NEPacketTunnelFlow?) -> Void) { func openVPNAdapter(_ openVPNAdapter: OpenVPNAdapter, configureTunnelWithNetworkSettings networkSettings: NEPacketTunnelNetworkSettings, completionHandler: @escaping (NEPacketTunnelFlow?) -> Void) {
completionHandler(NEPacketTunnelFlow()) completionHandler(customFlow)
} }
func openVPNAdapter(_ openVPNAdapter: OpenVPNAdapter, handleEvent event: OpenVPNAdapterEvent, message: String?) { func openVPNAdapter(_ openVPNAdapter: OpenVPNAdapter, handleEvent event: OpenVPNAdapterEvent, message: String?) {