mirror of
https://github.com/deneraraujo/OpenVPNAdapter.git
synced 2026-05-13 00:04:14 +08:00
Update tests in order to use VPNProfile
This commit is contained in:
@@ -30,12 +30,14 @@ class OpenVPNAdapterTests: XCTestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func testApplyConfiguration() {
|
func testApplyConfiguration() {
|
||||||
|
guard let vpnConfiguration = VPNProfile.configuration.data(using: .utf8) else { fatalError() }
|
||||||
|
|
||||||
let adapter = OpenVPNAdapter()
|
let adapter = OpenVPNAdapter()
|
||||||
|
|
||||||
let configuration = OpenVPNConfiguration()
|
let configuration = OpenVPNConfiguration()
|
||||||
configuration.fileContent = ProfileLoader.getVPNProfile(type: .localVPNServer)
|
configuration.fileContent = vpnConfiguration
|
||||||
configuration.settings = ["auth-user-pass": ""]
|
configuration.settings = ["auth-user-pass": ""]
|
||||||
|
|
||||||
let result: OpenVPNProperties
|
let result: OpenVPNProperties
|
||||||
do {
|
do {
|
||||||
result = try adapter.apply(configuration: configuration)
|
result = try adapter.apply(configuration: configuration)
|
||||||
@@ -43,10 +45,9 @@ class OpenVPNAdapterTests: XCTestCase {
|
|||||||
XCTFail("Failed to configure OpenVPN adapted due to error: \(error)")
|
XCTFail("Failed to configure OpenVPN adapted due to error: \(error)")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
XCTAssert(result.remoteHost == "192.168.1.200")
|
XCTAssert(result.remoteHost == VPNProfile.remoteHost)
|
||||||
XCTAssert(result.remotePort == 1194)
|
XCTAssert(result.remotePort == VPNProfile.remotePort)
|
||||||
XCTAssert(result.remoteProto == .UDP)
|
|
||||||
XCTAssert(result.autologin == false)
|
XCTAssert(result.autologin == false)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -65,67 +66,28 @@ class OpenVPNAdapterTests: XCTestCase {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Test connection with local VPN server
|
|
||||||
func testLocalConection() {
|
|
||||||
let adapter = OpenVPNAdapter()
|
|
||||||
|
|
||||||
let configuration = OpenVPNConfiguration()
|
|
||||||
configuration.fileContent = ProfileLoader.getVPNProfile(type: .localVPNServer)
|
|
||||||
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
|
|
||||||
}
|
|
||||||
|
|
||||||
guard !result.autologin else {
|
|
||||||
XCTFail()
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
let credentials = OpenVPNCredentials()
|
|
||||||
credentials.username = "testuser"
|
|
||||||
credentials.password = "nonsecure"
|
|
||||||
|
|
||||||
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()
|
|
||||||
|
|
||||||
waitForExpectations(timeout: 30.0) { (error) in
|
|
||||||
adapter.disconnect()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Test connection with remote VPN server
|
// Test connection to the VPN server
|
||||||
func testRemoteConnection() {
|
func testConnection() {
|
||||||
|
guard let vpnConfiguration = VPNProfile.configuration.data(using: .utf8) else { fatalError() }
|
||||||
|
|
||||||
let adapter = OpenVPNAdapter()
|
let adapter = OpenVPNAdapter()
|
||||||
|
|
||||||
let configuration = OpenVPNConfiguration()
|
let configuration = OpenVPNConfiguration()
|
||||||
configuration.fileContent = ProfileLoader.getVPNProfile(type: .remoteVPNServer)
|
configuration.fileContent = vpnConfiguration
|
||||||
|
|
||||||
do {
|
do {
|
||||||
_ = try adapter.apply(configuration: configuration)
|
_ = try adapter.apply(configuration: configuration)
|
||||||
} catch {
|
} catch {
|
||||||
XCTFail("Failed to configure OpenVPN adapted due to error: \(error)")
|
XCTFail("Failed to configure OpenVPN adapted due to error: \(error)")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
expectations[.connection] = expectation(description: "me.ss-abramchuk.openvpn-adapter.connection")
|
expectations[.connection] = expectation(description: "me.ss-abramchuk.openvpn-adapter.connection")
|
||||||
|
|
||||||
adapter.delegate = self
|
adapter.delegate = self
|
||||||
adapter.connect()
|
adapter.connect()
|
||||||
|
|
||||||
waitForExpectations(timeout: 30.0) { (error) in
|
waitForExpectations(timeout: 30.0) { (error) in
|
||||||
adapter.disconnect()
|
adapter.disconnect()
|
||||||
}
|
}
|
||||||
@@ -155,9 +117,11 @@ extension OpenVPNAdapterTests: OpenVPNAdapterDelegate {
|
|||||||
|
|
||||||
func openVPNAdapter(_ openVPNAdapter: OpenVPNAdapter, handleError error: Error) {
|
func openVPNAdapter(_ openVPNAdapter: OpenVPNAdapter, handleError error: Error) {
|
||||||
if let connectionExpectation = expectations[.connection] {
|
if let connectionExpectation = expectations[.connection] {
|
||||||
XCTFail("Failed to establish conection. \(error.localizedDescription)")
|
XCTFail("Failed to establish conection.")
|
||||||
connectionExpectation.fulfill()
|
connectionExpectation.fulfill()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
dump(error)
|
||||||
}
|
}
|
||||||
|
|
||||||
func openVPNAdapter(_ openVPNAdapter: OpenVPNAdapter, handleLogMessage logMessage: String) {
|
func openVPNAdapter(_ openVPNAdapter: OpenVPNAdapter, handleLogMessage logMessage: String) {
|
||||||
|
|||||||
Reference in New Issue
Block a user