diff options
| author | Janito Vaqueiro Ferreira Filho <janito@mullvad.net> | 2018-04-20 16:16:13 -0300 |
|---|---|---|
| committer | Janito Vaqueiro Ferreira Filho <janito@mullvad.net> | 2018-06-26 10:32:00 -0300 |
| commit | f747c54c304e8e944972c3eb0ba6f6df110f36ab (patch) | |
| tree | 8be320700fc33fbbc6794f29b7a18ca460b41ee6 | |
| parent | 39368b6b5515c14f6f934e9541f3420ecc96c55b (diff) | |
| download | mullvadvpn-f747c54c304e8e944972c3eb0ba6f6df110f36ab.tar.xz mullvadvpn-f747c54c304e8e944972c3eb0ba6f6df110f36ab.zip | |
Create client RPC to mock OpenVPN plugin events
| -rw-r--r-- | Cargo.lock | 2 | ||||
| -rw-r--r-- | mullvad-tests/Cargo.toml | 2 | ||||
| -rw-r--r-- | mullvad-tests/src/lib.rs | 47 |
3 files changed, 47 insertions, 4 deletions
diff --git a/Cargo.lock b/Cargo.lock index 3c02c48546..737173d112 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -848,7 +848,9 @@ dependencies = [ "mullvad-paths 0.1.0", "mullvad-types 0.1.0", "notify 4.0.3 (registry+https://github.com/rust-lang/crates.io-index)", + "openvpn-plugin 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "os_pipe 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", + "talpid-ipc 0.1.0", "tempfile 3.0.2 (registry+https://github.com/rust-lang/crates.io-index)", ] diff --git a/mullvad-tests/Cargo.toml b/mullvad-tests/Cargo.toml index b114245c32..5760be7d49 100644 --- a/mullvad-tests/Cargo.toml +++ b/mullvad-tests/Cargo.toml @@ -14,7 +14,9 @@ mullvad-ipc-client = { path = "../mullvad-ipc-client" } mullvad-paths = { path = "../mullvad-paths" } mullvad-types = { path = "../mullvad-types" } notify = "4.0" +openvpn-plugin = { version = "0.3", features = ["serde"] } os_pipe = "0.6" +talpid-ipc = { path = "../talpid-ipc" } tempfile = "3.0" [target.'cfg(unix)'.dependencies] diff --git a/mullvad-tests/src/lib.rs b/mullvad-tests/src/lib.rs index 35d50e814c..d60d19f916 100644 --- a/mullvad-tests/src/lib.rs +++ b/mullvad-tests/src/lib.rs @@ -7,9 +7,12 @@ extern crate libc; extern crate mullvad_ipc_client; extern crate mullvad_paths; extern crate notify; +extern crate openvpn_plugin; extern crate os_pipe; +extern crate talpid_ipc; extern crate tempfile; +use std::collections::HashMap; use std::fs::{self, File}; use std::io::{BufRead, BufReader}; use std::path::{Path, PathBuf}; @@ -17,10 +20,12 @@ use std::sync::{mpsc, Arc, Mutex}; use std::thread; use std::time::{Duration, Instant}; -use self::mullvad_ipc_client::DaemonRpcClient; -use self::notify::{op, RawEvent, RecursiveMode, Watcher}; -use self::os_pipe::{pipe, PipeReader}; -use self::tempfile::TempDir; +use mullvad_ipc_client::DaemonRpcClient; +use notify::{op, RawEvent, RecursiveMode, Watcher}; +use openvpn_plugin::types::OpenVpnPluginEvent; +use os_pipe::{pipe, PipeReader}; +use talpid_ipc::WsIpcClient; +use tempfile::TempDir; use self::platform_specific::*; @@ -271,3 +276,37 @@ impl Drop for DaemonRunner { let _ = fs::remove_file(&self.rpc_address_file); } } + +pub struct MockOpenVpnPluginRpcClient { + rpc: WsIpcClient, +} + +impl MockOpenVpnPluginRpcClient { + pub fn with_address(address: String) -> Result<Self, String> { + let rpc = WsIpcClient::connect(&address).map_err(|error| { + format!("Failed to create Mock OpenVPN plugin RPC client: {}", error) + })?; + + Ok(MockOpenVpnPluginRpcClient { rpc }) + } + + pub fn up(&mut self) -> Result<(), String> { + let mut env: HashMap<String, String> = HashMap::new(); + + env.insert("dev".to_owned(), "dummy".to_owned()); + env.insert("ifconfig_local".to_owned(), "10.0.0.10".to_owned()); + env.insert("route_vpn_gateway".to_owned(), "10.0.0.1".to_owned()); + + self.send_event(OpenVpnPluginEvent::Up, env) + } + + fn send_event( + &mut self, + event: OpenVpnPluginEvent, + env: HashMap<String, String>, + ) -> Result<(), String> { + self.rpc + .call("openvpn_event", &(event, env)) + .map_err(|error| format!("Failed to send mock OpenVPN event {:?}: {}", event, error)) + } +} |
