Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ panic = "abort"

[workspace.lints.rust]
warnings = "deny"
unexpected_cfgs = { level = "warn", check-cfg = ['cfg(docker_test)', 'cfg(throughput_test)'] }
unexpected_cfgs = { level = "warn", check-cfg = ['cfg(docker_test)', 'cfg(throughput_test)', 'cfg(tokio_unstable)'] }

[workspace.lints.clippy]
redundant_clone = "deny"
Expand Down
10 changes: 7 additions & 3 deletions clash-lib/src/app/logging.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,10 +200,14 @@ fn setup_logging_inner(
let subscriber = tracing_subscriber::registry();

// Collect and expose data about the Tokio runtime (tasks, threads, resources,
// etc.)
#[cfg(feature = "telemetry")]
// etc.) — gated on tokio_unstable because console_subscriber panics at
// runtime if Tokio was compiled without --cfg tokio_unstable. When tests
// are run with RUSTFLAGS="--cfg docker_test", that env-var overrides
// .cargo/config.toml, so tokio_unstable is absent and the gate correctly
// excludes this code.
#[cfg(all(feature = "telemetry", tokio_unstable))]
let subscriber = subscriber.with(console_subscriber::spawn());
#[cfg(feature = "telemetry")]
#[cfg(all(feature = "telemetry", tokio_unstable))]
let filter = filter
.add_directive("tokio=trace".parse().unwrap())
.add_directive("runtime=trace".parse().unwrap());
Expand Down
5 changes: 3 additions & 2 deletions clash-lib/src/common/mmdb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,9 @@ impl Mmdb {
e.to_string()
);

// try to download again
fs::remove_file(&mmdb_file)?;
// try to download again; ignore ENOENT — another concurrent
// caller may have already removed the file
let _ = fs::remove_file(&mmdb_file);

info!(
"mmdb {:?} corrupt, re-downloading mmdb from {download_url}",
Expand Down
15 changes: 12 additions & 3 deletions clash-lib/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,11 +181,20 @@ pub fn setup_default_crypto_provider() {
CRYPTO_PROVIDER_LOCK.get_or_init(|| {
#[cfg(feature = "aws-lc-rs")]
{
_ = rustls::crypto::aws_lc_rs::default_provider().install_default()
_ = rustls::crypto::aws_lc_rs::default_provider().install_default();
// watfaq-rustls is a separate fork with its own global provider
// state. When both `ring` and `aws-lc-rs` features are active
// (e.g. `--all-features`), its
// `get_default_or_install_from_crate_features` treats the
// combination as ambiguous and returns None, causing a
// panic. Explicit installation is therefore required.
_ = watfaq_rustls::crypto::aws_lc_rs::default_provider()
.install_default();
}
#[cfg(feature = "ring")]
#[cfg(all(feature = "ring", not(feature = "aws-lc-rs")))]
{
_ = rustls::crypto::ring::default_provider().install_default()
_ = rustls::crypto::ring::default_provider().install_default();
_ = watfaq_rustls::crypto::ring::default_provider().install_default();
}
});
}
Expand Down
11 changes: 7 additions & 4 deletions clash-lib/src/proxy/anytls/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,9 @@ mod tests {
Suite,
config_helper::test_config_base_dir,
consts::{IMAGE_SINGBOX, LOCAL_ADDR},
docker_runner::{DockerTestRunner, DockerTestRunnerBuilder},
docker_runner::{
DockerTestRunner, DockerTestRunnerBuilder, alloc_docker_port,
},
run_test_suites_and_cleanup,
},
},
Expand Down Expand Up @@ -798,7 +800,7 @@ mod tests {
// ---- docker integration tests ----

#[cfg(docker_test)]
async fn get_runner() -> anyhow::Result<DockerTestRunner> {
async fn get_runner(host_port: u16) -> anyhow::Result<DockerTestRunner> {
let test_config_dir = test_config_base_dir();
let conf = test_config_dir.join("anytls.json");
let cert = test_config_dir.join("example.org.pem");
Expand All @@ -812,15 +814,16 @@ mod tests {
(cert.to_str().unwrap(), "/etc/ssl/v2ray/fullchain.pem"),
(key.to_str().unwrap(), "/etc/ssl/v2ray/privkey.pem"),
])
.host_port(host_port, 10002)
.build()
.await
}

#[cfg(docker_test)]
#[tokio::test]
#[serial_test::serial]
async fn test_anytls() -> anyhow::Result<()> {
initialize();
let host_port = alloc_docker_port();

let tls = transport::TlsClient::new(
true,
Expand All @@ -829,7 +832,7 @@ mod tests {
None,
);

let runner = get_runner().await?;
let runner = get_runner(host_port).await?;

let opts = HandlerOptions {
name: "test-anytls".to_owned(),
Expand Down
11 changes: 6 additions & 5 deletions clash-lib/src/proxy/group/relay/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,9 @@ mod tests {
utils::test_utils::{
Suite,
consts::*,
docker_runner::{DockerTestRunner, DockerTestRunnerBuilder},
docker_runner::{
DockerTestRunner, DockerTestRunnerBuilder, alloc_docker_port,
},
run_test_suites_and_cleanup,
},
},
Expand All @@ -229,17 +231,17 @@ mod tests {
let host = format!("0.0.0.0:{}", port);
DockerTestRunnerBuilder::new()
.image(IMAGE_SS_RUST)
.port(port)
.entrypoint(&["ssserver"])
.cmd(&["-s", &host, "-m", CIPHER, "-k", PASSWORD, "-U"])
.build()
.await
}

#[tokio::test]
#[serial_test::serial]
async fn test_relay_1() -> anyhow::Result<()> {
initialize();
let port = 10002;
let port = alloc_docker_port();
let container = get_ss_runner(port).await?;

let container_ip = container.container_ip();
Expand Down Expand Up @@ -275,10 +277,9 @@ mod tests {
}

#[tokio::test]
#[serial_test::serial]
async fn test_relay_2() -> anyhow::Result<()> {
initialize();
let port = 10002;
let port = alloc_docker_port();
let container = get_ss_runner(port).await?;

let container_ip = container.container_ip();
Expand Down
8 changes: 5 additions & 3 deletions clash-lib/src/proxy/group/smart/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -757,7 +757,9 @@ mod tests {
utils::test_utils::{
Suite,
consts::*,
docker_runner::{DockerTestRunner, DockerTestRunnerBuilder},
docker_runner::{
DockerTestRunner, DockerTestRunnerBuilder, alloc_docker_port,
},
run_test_suites_and_cleanup,
},
},
Expand All @@ -775,17 +777,17 @@ mod tests {
let host = format!("0.0.0.0:{}", port);
DockerTestRunnerBuilder::new()
.image(IMAGE_SS_RUST)
.port(port)
.entrypoint(&["ssserver"])
.cmd(&["-s", &host, "-m", CIPHER, "-k", PASSWORD, "-U"])
.build()
.await
}

#[tokio::test]
#[serial_test::serial]
async fn test_smart_group_smoke() -> anyhow::Result<()> {
initialize();
let ss_port = 10002;
let ss_port = alloc_docker_port();

let docker_runner = get_ss_runner(ss_port).await?;

Expand Down
15 changes: 10 additions & 5 deletions clash-lib/src/proxy/hysteria2/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -702,16 +702,20 @@ mod tests {
proxy::utils::{
GLOBAL_DIRECT_CONNECTOR,
test_utils::{
Suite, config_helper::test_config_base_dir,
docker_runner::DockerTestRunnerBuilder, run_test_suites_and_cleanup,
Suite,
config_helper::test_config_base_dir,
docker_runner::{DockerTestRunnerBuilder, alloc_docker_port},
run_test_suites_and_cleanup,
},
},
tests::initialize,
};

use super::*;

async fn get_hysteria_runner() -> anyhow::Result<DockerTestRunner> {
async fn get_hysteria_runner(
host_port: u16,
) -> anyhow::Result<DockerTestRunner> {
let test_config_dir = test_config_base_dir();
let conf = test_config_dir.join("hysteria.json");
let cert = test_config_dir.join("example.org.pem");
Expand All @@ -725,16 +729,17 @@ mod tests {
(key.to_str().unwrap(), "/home/ubuntu/my.key"),
])
.cmd(&["server"])
.host_port(host_port, 10002)
.build()
.await
}

#[tokio::test]
#[serial_test::serial]
async fn test_hysteria() -> anyhow::Result<()> {
initialize();
let host_port = alloc_docker_port();

let container = get_hysteria_runner().await?;
let container = get_hysteria_runner(host_port).await?;

let container_ip =
container.container_ip().unwrap_or("127.0.0.1".to_owned());
Expand Down
29 changes: 17 additions & 12 deletions clash-lib/src/proxy/shadowquic/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -273,36 +273,41 @@ mod tests {
proxy::utils::{
GLOBAL_DIRECT_CONNECTOR,
test_utils::{
Suite, config_helper::test_config_base_dir,
docker_runner::DockerTestRunnerBuilder, run_test_suites_and_cleanup,
Suite,
config_helper::test_config_base_dir,
docker_runner::{DockerTestRunnerBuilder, alloc_docker_port},
run_test_suites_and_cleanup,
},
},
tests::initialize,
};
use std::sync::Arc;

use super::*;
async fn get_shadowquic_runner() -> anyhow::Result<DockerTestRunner> {
async fn get_shadowquic_runner(
host_port: u16,
) -> anyhow::Result<DockerTestRunner> {
let test_config_dir = test_config_base_dir();
let conf = test_config_dir.join("shadowquic.yaml");

DockerTestRunnerBuilder::new()
.image(IMAGE_SHADOWQUIC)
.mounts(&[(conf.to_str().unwrap(), "/etc/shadowquic/config.yaml")])
.host_port(host_port, 10002)
.build()
.await
}

const PORT: u16 = 10002;

fn gen_options(
opt_ip: Option<String>,
host_port: u16,
over_stream: bool,
) -> anyhow::Result<HandlerOptions> {
let port = if opt_ip.is_some() { 10002 } else { host_port };
Ok(HandlerOptions {
addr: SocketAddr::new(
opt_ip.unwrap_or(LOCAL_ADDR.to_owned()).parse().unwrap(),
PORT,
port,
)
.to_string(),
password: "12345678".into(),
Expand All @@ -317,15 +322,15 @@ mod tests {
}

#[tokio::test]
#[serial_test::serial]
async fn test_shadowquic_over_datagram() -> anyhow::Result<()> {
initialize();
let host_port = alloc_docker_port();

let container = get_shadowquic_runner().await?;
let container = get_shadowquic_runner(host_port).await?;

let container_ip = container.container_ip();

let opts = gen_options(container_ip, false)?;
let opts = gen_options(container_ip, host_port, false)?;

let handler = Arc::new(Handler::new("test-shadowquic".into(), opts));
handler
Expand All @@ -334,14 +339,14 @@ mod tests {
run_test_suites_and_cleanup(handler, container, Suite::all()).await
}
#[tokio::test]
#[serial_test::serial]
async fn test_shadowquic_over_stream() -> anyhow::Result<()> {
initialize();
let container = get_shadowquic_runner().await?;
let host_port = alloc_docker_port();
let container = get_shadowquic_runner(host_port).await?;

let container_ip = container.container_ip();

let mut opts = gen_options(container_ip, true)?;
let mut opts = gen_options(container_ip, host_port, true)?;
opts.over_stream = true;

let handler = Arc::new(Handler::new("test-shadowquic".into(), opts));
Expand Down
Loading
Loading