diff options
| author | Janito Vaqueiro Ferreira Filho <janito@mullvad.net> | 2018-04-28 09:01:06 -0300 |
|---|---|---|
| committer | Janito Vaqueiro Ferreira Filho <janito@mullvad.net> | 2018-07-03 10:53:20 -0300 |
| commit | 2aa01f3300533568a277a992fc935d7c2f5b1a7a (patch) | |
| tree | 344ab089d0f9a29c68ca53857e38c75c3c6310b9 | |
| parent | 6c5e078fe446e7adee9a47d6d9b2acd3d7bdca99 (diff) | |
| download | mullvadvpn-2aa01f3300533568a277a992fc935d7c2f5b1a7a.tar.xz mullvadvpn-2aa01f3300533568a277a992fc935d7c2f5b1a7a.zip | |
Test if account token is used correctly
| -rw-r--r-- | mullvad-tests/tests/account.rs | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/mullvad-tests/tests/account.rs b/mullvad-tests/tests/account.rs new file mode 100644 index 0000000000..88eda432fc --- /dev/null +++ b/mullvad-tests/tests/account.rs @@ -0,0 +1,55 @@ +#![cfg(all(target_os = "linux", feature = "integration-tests"))] + +extern crate mullvad_tests; + +use std::fs::File; +use std::io::{BufRead, BufReader}; +use std::path::Path; + +use mullvad_tests::mock_openvpn::search_openvpn_args; +use mullvad_tests::{DaemonRunner, PathWatcher}; + +#[test] +fn uses_account_token() { + let mut daemon = DaemonRunner::spawn(); + let mut rpc_client = daemon.rpc_client().unwrap(); + let openvpn_args_file = daemon.mock_openvpn_args_file(); + let mut openvpn_args_file_events = PathWatcher::watch(&openvpn_args_file).unwrap(); + + let specified_account = "123456"; + rpc_client + .set_account(Some(specified_account.to_owned())) + .unwrap(); + rpc_client.connect().unwrap(); + + openvpn_args_file_events.assert_create_write_close_sequence(); + + let account_token_sent_to_plugin = read_account_token(openvpn_args_file).unwrap(); + + assert_eq!(account_token_sent_to_plugin, specified_account); +} + +fn read_account_token<P: AsRef<Path>>(openvpn_args_file_path: P) -> Result<String, String> { + let account_token_file_path = search_openvpn_args(openvpn_args_file_path, "--auth-user-pass") + .skip(1) + .next() + .ok_or_else(|| "Missing account token file parameter to Talpid OpenVPN plugin".to_owned())? + .map_err(|error| { + format!( + "Failed to read from mock OpenVPN command line file: {}", + error + ) + })?; + + let account_token_file = File::open(account_token_file_path) + .map_err(|error| format!("Failed to open account token file: {}", error))?; + + let mut reader = BufReader::new(account_token_file); + let mut account = String::new(); + + reader + .read_line(&mut account) + .map_err(|error| format!("Failed to read from account token file: {}", error))?; + + Ok(account.trim().to_owned()) +} |
