Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
6 changes: 3 additions & 3 deletions clash-lib/src/app/logging.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,10 +200,10 @@ 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.) — requires RUSTFLAGS="--cfg tokio_unstable" at compile time.
#[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
10 changes: 7 additions & 3 deletions clash-lib/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,11 +181,15 @@ 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 crate fork with its own provider state.
_ = 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
27 changes: 10 additions & 17 deletions clash-lib/src/proxy/shadowsocks/outbound/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,8 @@ mod tests {
config_helper::test_config_base_dir,
consts::*,
docker_runner::{
DockerTestRunner, DockerTestRunnerBuilder, MultiDockerTestRunner,
DockerTestRunner, DockerTestRunnerBuilder,
MultiDockerTestRunner, alloc_docker_port,
},
run_test_suites_and_cleanup,
},
Expand Down Expand Up @@ -337,10 +338,9 @@ mod tests {
}

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

let opts = HandlerOptions {
Expand Down Expand Up @@ -388,19 +388,19 @@ mod tests {
"V3=1",
])
// .cmd(&["-s", "0.0.0.0:10002", "-m", CIPHER, "-k", PASSWORD, "-U"])
.port(stls_port)
.build()
.await
}

#[tokio::test]
#[serial_test::serial]
async fn test_shadowtls() -> anyhow::Result<()> {
initialize();
// the real port that used for communication
let shadow_tls_port = 10002;
let shadow_tls_port = alloc_docker_port();
// not important, you can assign any port that is not conflict with
// others
let ss_port = 10004;
let ss_port = alloc_docker_port();

let container1 = get_ss_runner(ss_port).await?;

Expand Down Expand Up @@ -462,13 +462,14 @@ mod tests {
&ss_server_env,
"-vv",
])
.port(obfs_port)
.build()
.await
}

async fn test_ss_obfs_inner(mode: SimpleOBFSMode) -> anyhow::Result<()> {
let obfs_port = 10002;
let ss_port = 10004;
let obfs_port = alloc_docker_port();
let ss_port = alloc_docker_port();

let container1 = get_ss_runner(ss_port).await?;
let container2 =
Expand Down Expand Up @@ -501,24 +502,21 @@ mod tests {
}

#[tokio::test]
#[serial_test::serial]
async fn test_ss_obfs_http() -> anyhow::Result<()> {
initialize();
test_ss_obfs_inner(SimpleOBFSMode::Http).await
}

#[tokio::test]
#[serial_test::serial]
async fn test_ss_obfs_tls() -> anyhow::Result<()> {
initialize();
test_ss_obfs_inner(SimpleOBFSMode::Tls).await
}

#[tokio::test]
#[serial_test::serial]
async fn test_ss_v2ray_plugin() -> anyhow::Result<()> {
initialize();
let ss_port = 10004;
let ss_port = alloc_docker_port();
let container = get_ss_runner_with_plugin(ss_port).await?;
let host = "example.org".to_owned();
let plugin = V2rayWsClient::try_new(
Expand Down Expand Up @@ -706,11 +704,6 @@ mod e2e {
socks-port: {socks_port}
bind-address: 127.0.0.1
mmdb: "{mmdb}"
# Clash-rs defaults geosite to "geosite.dat" in compatibility mode (which is
# on by default) and downloads it if missing. Point to /dev/null instead:
# an empty file is a valid protobuf GeoSiteList, so no download occurs and
# our geo-free rules still work.
geosite: /dev/null
mode: global
log-level: error
proxies:
Expand Down
Loading
Loading