From 54458439c326032330f4cef92d1a939497e1481b Mon Sep 17 00:00:00 2001 From: Sergey Abramchuk Date: Tue, 16 Jun 2020 12:39:50 +0300 Subject: [PATCH] Test connection with ca only and test connection with cert and key --- .../OpenVPNAdapter/OpenVPNAdapterTests.swift | 91 ++++++++++--------- 1 file changed, 48 insertions(+), 43 deletions(-) diff --git a/Tests/OpenVPNAdapter/OpenVPNAdapterTests.swift b/Tests/OpenVPNAdapter/OpenVPNAdapterTests.swift index 52d5e94..e52baea 100644 --- a/Tests/OpenVPNAdapter/OpenVPNAdapterTests.swift +++ b/Tests/OpenVPNAdapter/OpenVPNAdapterTests.swift @@ -29,52 +29,16 @@ class OpenVPNAdapterTests: XCTestCase { super.tearDown() } - func testApplyConfiguration() { - guard let vpnConfiguration = VPNProfile.configuration.data(using: .utf8) else { fatalError() } - - let adapter = OpenVPNAdapter() - - let configuration = OpenVPNConfiguration() - configuration.fileContent = vpnConfiguration - configuration.settings = ["auth-user-pass": ""] - - let result: OpenVPNProperties - do { - result = try adapter.apply(configuration: configuration) - } catch { - XCTFail("Failed to configure OpenVPN adapted due to error: \(error)") - return - } - - XCTAssert(result.remoteHost == VPNProfile.remoteHost) - XCTAssert(result.remotePort == VPNProfile.remotePort) - XCTAssert(result.autologin == false) - } - - func testProvideCredentials() { - let adapter = OpenVPNAdapter() - - let credentials = OpenVPNCredentials() - credentials.username = "username" - credentials.password = "password" - - do { - try adapter.provide(credentials: credentials) - } catch { - XCTFail("Failed to provide credentials. \(error)") - return - } - } - - - // Test connection to the VPN server - func testConnection() { - guard let vpnConfiguration = VPNProfile.configuration.data(using: .utf8) else { fatalError() } + // Test connection to the VPN server without cert and key + func testConnectionCAOnly() { + guard let vpnConfiguration = VPNProfile.caOnly.configuration.data(using: .utf8) else { fatalError() } let adapter = OpenVPNAdapter() let configuration = OpenVPNConfiguration() configuration.fileContent = vpnConfiguration + configuration.settings = VPNProfile.caOnly.settings + configuration.disableClientCert = true let result: OpenVPNProperties do { @@ -86,8 +50,49 @@ class OpenVPNAdapterTests: XCTestCase { if !result.autologin { let credentials = OpenVPNCredentials() - credentials.username = VPNProfile.username - credentials.password = VPNProfile.password + credentials.username = VPNProfile.caOnly.username + credentials.password = VPNProfile.caOnly.password + + do { + try adapter.provide(credentials: credentials) + } catch { + XCTFail("Failed to provide credentials. \(error)") + return + } + } + + expectations[.connection] = expectation(description: "me.ss-abramchuk.openvpn-adapter.connection") + + adapter.delegate = self + adapter.connect(using: customFlow) + + waitForExpectations(timeout: 30.0) { (error) in + adapter.disconnect() + } + } + + // Test connection to the VPN server with cert and key + func testConnectionCAWithCertAndKey() { + guard let vpnConfiguration = VPNProfile.caWithCertAndKey.configuration.data(using: .utf8) else { fatalError() } + + let adapter = OpenVPNAdapter() + + let configuration = OpenVPNConfiguration() + configuration.fileContent = vpnConfiguration + configuration.settings = VPNProfile.caWithCertAndKey.settings + + let result: OpenVPNProperties + do { + result = try adapter.apply(configuration: configuration) + } catch { + XCTFail("Failed to configure OpenVPN adapted due to error: \(error)") + return + } + + if !result.autologin { + let credentials = OpenVPNCredentials() + credentials.username = VPNProfile.caWithCertAndKey.username + credentials.password = VPNProfile.caWithCertAndKey.password do { try adapter.provide(credentials: credentials)