-
Notifications
You must be signed in to change notification settings - Fork 24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
PoC: Rust-based integration test PoC #879
Draft
mathiaspeters
wants to merge
1
commit into
main
Choose a base branch
from
LLT-5378_rust_integration_tests_poc
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
[package] | ||
name = "systests" | ||
version = "0.1.0" | ||
edition = "2018" | ||
license = "GPL-3.0-only" | ||
repository = "https://github.com/NordSecurity/libtelio" | ||
|
||
[[bin]] | ||
name = "systests" | ||
|
||
[dependencies] | ||
dersp = { git = "https://github.com/mathiaspeters/dersp.git", branch = "librarification"} | ||
env_logger = "0.10.1" | ||
dirs = "4.0.0" | ||
reqwest = { version = "0.11.16", default-features = false, features = [ | ||
"json", | ||
"blocking", | ||
"rustls-tls", | ||
] } | ||
rustyline = "11.0.0" | ||
shellwords = "1.1.0" | ||
# Used only for checking if the daemon is running. | ||
sysinfo = { version = "0.30.11", optional = true } | ||
# Used as a lightweight and safe (because a TCP server has the risk of remote code execution) | ||
# way for the API and daemon to communicate. | ||
# Tokio support is needed, because the daemon runs on the async runtime. | ||
interprocess = { version = "1.2.1", optional = true } | ||
|
||
anyhow.workspace = true | ||
base64.workspace = true | ||
clap.workspace = true | ||
crypto_box.workspace = true | ||
hex.workspace = true | ||
ipnet.workspace = true | ||
futures.workspace = true | ||
tracing.workspace = true | ||
tracing-subscriber.workspace = true | ||
tracing-appender.workspace = true | ||
parking_lot.workspace = true | ||
rand = { workspace = true, features = ["std", "std_rng"] } | ||
regex.workspace = true | ||
serde.workspace = true | ||
serde_json.workspace = true | ||
sha2.workspace = true | ||
thiserror.workspace = true | ||
time.workspace = true | ||
tokio = { workspace = true, features = ["full"] } | ||
|
||
telio = { path = ".." } | ||
telio-crypto.workspace = true | ||
telio-model.workspace = true | ||
telio-nat-detect.workspace = true | ||
telio-proto.workspace = true | ||
telio-relay.workspace = true | ||
telio-sockets.workspace = true | ||
telio-task.workspace = true | ||
telio-traversal.workspace = true | ||
telio-utils.workspace = true | ||
telio-wg.workspace = true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
use tests::{meshnet::test_meshnet_poc, vpn::test_vpn_poc}; | ||
|
||
mod tests; | ||
mod utils; | ||
|
||
fn main() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why don't we use the tests module approach here? #[cfg(test)]
mod test_vpn {
use super::*;
#[test]
fn test_vpn_poc_works() {
test_vpn_poc();
}
} then we could get nicer test result reports like thread 'test_vpn::test_vpn_poc_works' panicked at systests/src/tests/vpn.rs:51:5:
assertion failed: false
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Successfully executed 'ip link delete tun10'
Successfully executed 'ip rule del priority 32111'
failures:
test_vpn::test_vpn_poc_works
test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out; finished in 1.22s |
||
test_meshnet_poc(); | ||
test_vpn_poc(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
use std::panic::AssertUnwindSafe; | ||
use std::sync::Arc; | ||
|
||
use dersp::{ | ||
service::{DerpService, Service}, | ||
Config, | ||
}; | ||
use telio::defaults_builder::FeaturesDefaultsBuilder; | ||
|
||
use telio_crypto::SecretKey; | ||
use telio_model::features::PathType; | ||
use tokio::net::TcpListener; | ||
use tokio::sync::RwLock; | ||
use tracing::level_filters::LevelFilter; | ||
|
||
use crate::utils::interface_helper::InterfaceHelper; | ||
use crate::utils::test_client::TestClient; | ||
|
||
pub fn test_meshnet_poc() { | ||
let (non_blocking_writer, _tracing_worker_guard) = | ||
tracing_appender::non_blocking(std::fs::File::create("tcli.log").unwrap()); | ||
tracing_subscriber::fmt() | ||
.with_max_level(LevelFilter::DEBUG) | ||
.with_writer(non_blocking_writer) | ||
.with_ansi(false) | ||
.with_line_number(true) | ||
.with_level(true) | ||
.init(); | ||
|
||
let derp_rt = tokio::runtime::Builder::new_multi_thread() | ||
.enable_all() | ||
.build() | ||
.unwrap(); | ||
let _derp_handle = derp_rt.spawn(async move { | ||
let config = Config { | ||
listen_on: "0.0.0.0:8765".to_owned(), | ||
mesh_peers: Vec::new(), | ||
meshkey: Some(SecretKey::gen().public().to_string()), | ||
}; | ||
|
||
let listener = TcpListener::bind(&config.listen_on).await?; | ||
let service: Arc<RwLock<DerpService>> = DerpService::new(config).await?; | ||
|
||
service.run(listener).await | ||
}); | ||
|
||
let mut ifc_helper = InterfaceHelper::new(); | ||
let test_result = std::panic::catch_unwind(AssertUnwindSafe(|| { | ||
let features = Arc::new(FeaturesDefaultsBuilder::new()); | ||
let features = features.enable_direct().build(); | ||
let mut clients = | ||
TestClient::generate_clients(vec!["alpha", "beta"], &mut ifc_helper, features); | ||
|
||
let mut alpha = clients.remove("alpha").unwrap(); | ||
let mut beta = clients.remove("beta").unwrap(); | ||
|
||
alpha.start(); | ||
beta.start(); | ||
|
||
alpha.set_meshnet_config(&[&beta]); | ||
beta.set_meshnet_config(&[&alpha]); | ||
|
||
alpha | ||
.wait_for_connection_peer(beta.peer.public_key, &[PathType::Direct]) | ||
.unwrap(); | ||
beta.wait_for_connection_peer(alpha.peer.public_key, &[PathType::Direct]) | ||
.unwrap(); | ||
|
||
alpha.stop(); | ||
alpha.shutdown(); | ||
|
||
beta.stop(); | ||
beta.shutdown(); | ||
})); | ||
match test_result { | ||
Ok(()) => println!("test_meshnet_poc passed\n\n"), | ||
Err(e) => println!("test_meshnet_poc failed with error {e:?}\n\n"), | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
pub mod meshnet; | ||
pub mod vpn; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
use std::panic::AssertUnwindSafe; | ||
|
||
use telio_model::{features::PathType, mesh::ExitNode}; | ||
|
||
use crate::utils::{ | ||
interface_helper::InterfaceHelper, | ||
test_client::TestClient, | ||
vpn::{setup_vpn_servers, VpnConfig}, | ||
}; | ||
|
||
pub fn test_vpn_poc() { | ||
let mut ifc_helper = InterfaceHelper::new(); | ||
let test_result = std::panic::catch_unwind(AssertUnwindSafe(|| { | ||
let mut clients = | ||
TestClient::generate_clients(vec!["alpha"], &mut ifc_helper, Default::default()); | ||
let mut alpha = clients.remove("alpha").unwrap(); | ||
let vpn_config = VpnConfig::get_config(); | ||
setup_vpn_servers(&[&alpha.peer], &vpn_config); | ||
|
||
alpha.start(); | ||
|
||
if !alpha.ifc_configured { | ||
InterfaceHelper::configure_ifc(&alpha.ifc_name, alpha.ip); | ||
InterfaceHelper::create_vpn_route(&alpha.ifc_name); | ||
alpha.ifc_configured = true; | ||
} | ||
|
||
let node = ExitNode { | ||
identifier: "wgserver".to_owned(), | ||
public_key: vpn_config.key.public(), | ||
allowed_ips: None, | ||
endpoint: Some( | ||
format!("{}:{}", vpn_config.ip, vpn_config.port) | ||
.parse() | ||
.expect("Should be valid"), | ||
), | ||
}; | ||
alpha.connect_to_exit_node(&node); | ||
|
||
alpha | ||
.wait_for_connection_peer( | ||
vpn_config.key.public(), | ||
&[PathType::Relay, PathType::Direct], | ||
) | ||
.unwrap(); | ||
|
||
// stun should return VPN IP | ||
|
||
alpha.stop(); | ||
alpha.shutdown(); | ||
})); | ||
match test_result { | ||
Ok(()) => println!("test_vpn_poc passed\n\n"), | ||
Err(e) => println!("test_vpn_poc failed with error {e:?}\n\n"), | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
use std::str::FromStr; | ||
|
||
use telio_crypto::PublicKey; | ||
use telio_model::config::{RelayState, Server}; | ||
|
||
pub fn get_derp_servers() -> Vec<Server> { | ||
vec![Server { | ||
region_code: "nl".to_owned(), | ||
name: "Natlab #0001".to_owned(), | ||
hostname: "derp-01".to_owned(), | ||
ipv4: "0.0.0.0".parse().unwrap(), | ||
relay_port: 8765, | ||
stun_port: 3479, | ||
stun_plaintext_port: 3478, | ||
public_key: PublicKey::from_str("qK/ICYOGBu45EIGnopVu+aeHDugBrkLAZDroKGTuKU0=").unwrap(), | ||
weight: 1, | ||
use_plain_text: true, | ||
conn_state: RelayState::Disconnected, | ||
}] | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would be nice to have a
readme.md
with some minimal instructions