refactor: update deps (#655)

This commit is contained in:
sigoden
2026-01-08 12:02:41 +08:00
committed by GitHub
parent 23619033ae
commit 7cfb97dfdf
12 changed files with 648 additions and 469 deletions

1007
Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@@ -25,8 +25,7 @@ async_zip = { version = "0.0.18", default-features = false, features = ["deflate
headers = "0.4" headers = "0.4"
mime_guess = "2.0" mime_guess = "2.0"
if-addrs = "0.14" if-addrs = "0.14"
rustls-pemfile = { version = "2.0", optional = true } tokio-rustls = { version = "0.26", optional = true }
tokio-rustls = { version = "0.26", optional = true, default-features = false, features = ["ring", "tls12"]}
md5 = "0.8" md5 = "0.8"
lazy_static = "1.4" lazy_static = "1.4"
uuid = { version = "1.7", features = ["v4", "fast-rng"] } uuid = { version = "1.7", features = ["v4", "fast-rng"] }
@@ -58,11 +57,11 @@ hex = "0.4.3"
[features] [features]
default = ["tls"] default = ["tls"]
tls = ["rustls-pemfile", "tokio-rustls"] tls = ["tokio-rustls"]
[dev-dependencies] [dev-dependencies]
assert_cmd = "2" assert_cmd = "2"
reqwest = { version = "0.12", features = ["blocking", "multipart", "rustls-tls"], default-features = false } reqwest = { version = "0.13", features = ["blocking", "multipart", "rustls"], default-features = false }
assert_fs = "1" assert_fs = "1"
port_check = "0.3" port_check = "0.3"
rstest = "0.26.1" rstest = "0.26.1"

View File

@@ -492,21 +492,16 @@ impl BindAddr {
} }
} }
#[derive(Debug, Clone, Copy, PartialEq, Deserialize)] #[derive(Debug, Clone, Copy, PartialEq, Deserialize, Default)]
#[serde(rename_all = "lowercase")] #[serde(rename_all = "lowercase")]
pub enum Compress { pub enum Compress {
None, None,
#[default]
Low, Low,
Medium, Medium,
High, High,
} }
impl Default for Compress {
fn default() -> Self {
Self::Low
}
}
impl ValueEnum for Compress { impl ValueEnum for Compress {
fn value_variants<'a>() -> &'a [Self] { fn value_variants<'a>() -> &'a [Self] {
&[Self::None, Self::Low, Self::Medium, Self::High] &[Self::None, Self::Low, Self::Medium, Self::High]

View File

@@ -1,7 +1,7 @@
use anyhow::{anyhow, Context, Result}; use anyhow::{anyhow, Context, Result};
use chrono::{DateTime, Utc}; use chrono::{DateTime, Utc};
#[cfg(feature = "tls")] #[cfg(feature = "tls")]
use rustls_pki_types::{CertificateDer, PrivateKeyDer}; use rustls_pki_types::{pem::PemObject, CertificateDer, PrivateKeyDer};
use std::{ use std::{
borrow::Cow, borrow::Cow,
path::Path, path::Path,
@@ -62,42 +62,40 @@ pub fn glob(pattern: &str, target: &str) -> bool {
// Load public certificate from file. // Load public certificate from file.
#[cfg(feature = "tls")] #[cfg(feature = "tls")]
pub fn load_certs<T: AsRef<Path>>(filename: T) -> Result<Vec<CertificateDer<'static>>> { pub fn load_certs<T: AsRef<Path>>(file_name: T) -> Result<Vec<CertificateDer<'static>>> {
// Open certificate file.
let cert_file = std::fs::File::open(filename.as_ref())
.with_context(|| format!("Failed to access `{}`", filename.as_ref().display()))?;
let mut reader = std::io::BufReader::new(cert_file);
// Load and return certificate.
let mut certs = vec![]; let mut certs = vec![];
for cert in rustls_pemfile::certs(&mut reader) { for cert in CertificateDer::pem_file_iter(file_name.as_ref()).with_context(|| {
let cert = cert.with_context(|| "Failed to load certificate")?; format!(
"Failed to load cert file at `{}`",
file_name.as_ref().display()
)
})? {
let cert = cert.with_context(|| {
format!(
"Invalid certificate data in file `{}`",
file_name.as_ref().display()
)
})?;
certs.push(cert) certs.push(cert)
} }
if certs.is_empty() { if certs.is_empty() {
anyhow::bail!("No supported certificate in file"); anyhow::bail!(
"No supported certificate in file `{}`",
file_name.as_ref().display()
);
} }
Ok(certs) Ok(certs)
} }
// Load private key from file. // Load private key from file.
#[cfg(feature = "tls")] #[cfg(feature = "tls")]
pub fn load_private_key<T: AsRef<Path>>(filename: T) -> Result<PrivateKeyDer<'static>> { pub fn load_private_key<T: AsRef<Path>>(file_name: T) -> Result<PrivateKeyDer<'static>> {
let key_file = std::fs::File::open(filename.as_ref()) PrivateKeyDer::from_pem_file(file_name.as_ref()).with_context(|| {
.with_context(|| format!("Failed to access `{}`", filename.as_ref().display()))?; format!(
let mut reader = std::io::BufReader::new(key_file); "Failed to load key file at `{}`",
file_name.as_ref().display()
// Load and return a single private key. )
for key in rustls_pemfile::read_all(&mut reader) { })
let key = key.with_context(|| "There was a problem with reading private key")?;
match key {
rustls_pemfile::Item::Pkcs1Key(key) => return Ok(PrivateKeyDer::Pkcs1(key)),
rustls_pemfile::Item::Pkcs8Key(key) => return Ok(PrivateKeyDer::Pkcs8(key)),
rustls_pemfile::Item::Sec1Key(key) => return Ok(PrivateKeyDer::Sec1(key)),
_ => {}
}
}
anyhow::bail!("No supported private key in file");
} }
pub fn parse_range(range: &str, size: u64) -> Option<Vec<(u64, u64)>> { pub fn parse_range(range: &str, size: u64) -> Option<Vec<(u64, u64)>> {

View File

@@ -1,7 +1,6 @@
mod fixtures; mod fixtures;
mod utils; mod utils;
use assert_cmd::prelude::*;
use assert_fs::fixture::TempDir; use assert_fs::fixture::TempDir;
use fixtures::{port, server, tmpdir, wait_for_port, Error, TestServer, DIR_ASSETS}; use fixtures::{port, server, tmpdir, wait_for_port, Error, TestServer, DIR_ASSETS};
use rstest::rstest; use rstest::rstest;
@@ -101,7 +100,7 @@ fn asset_js_with_prefix(
#[rstest] #[rstest]
fn assets_override(tmpdir: TempDir, port: u16) -> Result<(), Error> { fn assets_override(tmpdir: TempDir, port: u16) -> Result<(), Error> {
let mut child = Command::cargo_bin("dufs")? let mut child = Command::new(assert_cmd::cargo::cargo_bin!())
.arg(tmpdir.path()) .arg(tmpdir.path())
.arg("-p") .arg("-p")
.arg(port.to_string()) .arg(port.to_string())

View File

@@ -12,7 +12,7 @@ use std::process::{Command, Stdio};
#[rstest] #[rstest]
#[case(&["-b", "20.205.243.166"])] #[case(&["-b", "20.205.243.166"])]
fn bind_fails(tmpdir: TempDir, port: u16, #[case] args: &[&str]) -> Result<(), Error> { fn bind_fails(tmpdir: TempDir, port: u16, #[case] args: &[&str]) -> Result<(), Error> {
Command::cargo_bin("dufs")? Command::new(assert_cmd::cargo::cargo_bin!())
.arg(tmpdir.path()) .arg(tmpdir.path())
.arg("-p") .arg("-p")
.arg(port.to_string()) .arg(port.to_string())
@@ -49,7 +49,7 @@ fn bind_ipv4_ipv6(
#[case(&[] as &[&str])] #[case(&[] as &[&str])]
#[case(&["--path-prefix", "/prefix"])] #[case(&["--path-prefix", "/prefix"])]
fn validate_printed_urls(tmpdir: TempDir, port: u16, #[case] args: &[&str]) -> Result<(), Error> { fn validate_printed_urls(tmpdir: TempDir, port: u16, #[case] args: &[&str]) -> Result<(), Error> {
let mut child = Command::cargo_bin("dufs")? let mut child = Command::new(assert_cmd::cargo::cargo_bin!())
.arg(tmpdir.path()) .arg(tmpdir.path())
.arg("-p") .arg("-p")
.arg(port.to_string()) .arg(port.to_string())

View File

@@ -11,7 +11,10 @@ use std::process::Command;
#[test] #[test]
/// Show help and exit. /// Show help and exit.
fn help_shows() -> Result<(), Error> { fn help_shows() -> Result<(), Error> {
Command::cargo_bin("dufs")?.arg("-h").assert().success(); Command::new(assert_cmd::cargo::cargo_bin!())
.arg("-h")
.assert()
.success();
Ok(()) Ok(())
} }
@@ -21,7 +24,7 @@ fn help_shows() -> Result<(), Error> {
fn print_completions() -> Result<(), Error> { fn print_completions() -> Result<(), Error> {
// let shell_enums = EnumValueParser::<Shell>::new(); // let shell_enums = EnumValueParser::<Shell>::new();
for shell in Shell::value_variants() { for shell in Shell::value_variants() {
Command::cargo_bin("dufs")? Command::new(assert_cmd::cargo::cargo_bin!())
.arg("--completions") .arg("--completions")
.arg(shell.to_string()) .arg(shell.to_string())
.assert() .assert()

View File

@@ -2,7 +2,6 @@ mod digest_auth_util;
mod fixtures; mod fixtures;
mod utils; mod utils;
use assert_cmd::prelude::*;
use assert_fs::TempDir; use assert_fs::TempDir;
use digest_auth_util::send_with_digest_auth; use digest_auth_util::send_with_digest_auth;
use fixtures::{port, tmpdir, wait_for_port, Error}; use fixtures::{port, tmpdir, wait_for_port, Error};
@@ -13,7 +12,7 @@ use std::process::{Command, Stdio};
#[rstest] #[rstest]
fn use_config_file(tmpdir: TempDir, port: u16) -> Result<(), Error> { fn use_config_file(tmpdir: TempDir, port: u16) -> Result<(), Error> {
let config_path = get_config_path().display().to_string(); let config_path = get_config_path().display().to_string();
let mut child = Command::cargo_bin("dufs")? let mut child = Command::new(assert_cmd::cargo::cargo_bin!())
.arg(tmpdir.path()) .arg(tmpdir.path())
.arg("-p") .arg("-p")
.arg(port.to_string()) .arg(port.to_string())

View File

@@ -1,4 +1,3 @@
use assert_cmd::prelude::*;
use assert_fs::fixture::TempDir; use assert_fs::fixture::TempDir;
use assert_fs::prelude::*; use assert_fs::prelude::*;
use port_check::free_local_port; use port_check::free_local_port;
@@ -129,8 +128,7 @@ where
{ {
let port = port(); let port = port();
let tmpdir = tmpdir(); let tmpdir = tmpdir();
let child = Command::cargo_bin("dufs") let child = Command::new(assert_cmd::cargo::cargo_bin!())
.expect("Couldn't find test binary")
.arg(tmpdir.path()) .arg(tmpdir.path())
.arg("-p") .arg("-p")
.arg(port.to_string()) .arg(port.to_string())

View File

@@ -5,7 +5,6 @@ mod utils;
use digest_auth_util::send_with_digest_auth; use digest_auth_util::send_with_digest_auth;
use fixtures::{port, tmpdir, wait_for_port, Error}; use fixtures::{port, tmpdir, wait_for_port, Error};
use assert_cmd::prelude::*;
use assert_fs::fixture::TempDir; use assert_fs::fixture::TempDir;
use rstest::rstest; use rstest::rstest;
use std::io::Read; use std::io::Read;
@@ -20,7 +19,7 @@ fn log_remote_user(
#[case] args: &[&str], #[case] args: &[&str],
#[case] is_basic: bool, #[case] is_basic: bool,
) -> Result<(), Error> { ) -> Result<(), Error> {
let mut child = Command::cargo_bin("dufs")? let mut child = Command::new(assert_cmd::cargo::cargo_bin!())
.arg(tmpdir.path()) .arg(tmpdir.path())
.arg("-p") .arg("-p")
.arg(port.to_string()) .arg(port.to_string())
@@ -55,7 +54,7 @@ fn log_remote_user(
#[rstest] #[rstest]
#[case(&["--log-format", ""])] #[case(&["--log-format", ""])]
fn no_log(tmpdir: TempDir, port: u16, #[case] args: &[&str]) -> Result<(), Error> { fn no_log(tmpdir: TempDir, port: u16, #[case] args: &[&str]) -> Result<(), Error> {
let mut child = Command::cargo_bin("dufs")? let mut child = Command::new(assert_cmd::cargo::cargo_bin!())
.arg(tmpdir.path()) .arg(tmpdir.path())
.arg("-p") .arg("-p")
.arg(port.to_string()) .arg(port.to_string())

View File

@@ -3,7 +3,6 @@
mod fixtures; mod fixtures;
mod utils; mod utils;
use assert_cmd::prelude::*;
use assert_fs::fixture::TempDir; use assert_fs::fixture::TempDir;
use fixtures::{port, tmpdir, wait_for_port, Error}; use fixtures::{port, tmpdir, wait_for_port, Error};
use rstest::rstest; use rstest::rstest;
@@ -12,7 +11,7 @@ use std::process::{Command, Stdio};
#[rstest] #[rstest]
#[case("index.html")] #[case("index.html")]
fn single_file(tmpdir: TempDir, port: u16, #[case] file: &str) -> Result<(), Error> { fn single_file(tmpdir: TempDir, port: u16, #[case] file: &str) -> Result<(), Error> {
let mut child = Command::cargo_bin("dufs")? let mut child = Command::new(assert_cmd::cargo::cargo_bin!())
.arg(tmpdir.path().join(file)) .arg(tmpdir.path().join(file))
.arg("-p") .arg("-p")
.arg(port.to_string()) .arg(port.to_string())
@@ -35,7 +34,7 @@ fn single_file(tmpdir: TempDir, port: u16, #[case] file: &str) -> Result<(), Err
#[rstest] #[rstest]
#[case("index.html")] #[case("index.html")]
fn path_prefix_single_file(tmpdir: TempDir, port: u16, #[case] file: &str) -> Result<(), Error> { fn path_prefix_single_file(tmpdir: TempDir, port: u16, #[case] file: &str) -> Result<(), Error> {
let mut child = Command::cargo_bin("dufs")? let mut child = Command::new(assert_cmd::cargo::cargo_bin!())
.arg(tmpdir.path().join(file)) .arg(tmpdir.path().join(file))
.arg("-p") .arg("-p")
.arg(port.to_string()) .arg(port.to_string())

View File

@@ -1,7 +1,6 @@
mod fixtures; mod fixtures;
mod utils; mod utils;
use assert_cmd::Command;
use fixtures::{server, Error, TestServer}; use fixtures::{server, Error, TestServer};
use predicates::str::contains; use predicates::str::contains;
use reqwest::blocking::ClientBuilder; use reqwest::blocking::ClientBuilder;
@@ -25,7 +24,7 @@ use crate::fixtures::port;
]))] ]))]
fn tls_works(#[case] server: TestServer) -> Result<(), Error> { fn tls_works(#[case] server: TestServer) -> Result<(), Error> {
let client = ClientBuilder::new() let client = ClientBuilder::new()
.danger_accept_invalid_certs(true) .tls_danger_accept_invalid_certs(true)
.build()?; .build()?;
let resp = client.get(server.url()).send()?.error_for_status()?; let resp = client.get(server.url()).send()?.error_for_status()?;
assert_resp_paths!(resp); assert_resp_paths!(resp);
@@ -36,7 +35,7 @@ fn tls_works(#[case] server: TestServer) -> Result<(), Error> {
#[rstest] #[rstest]
fn wrong_path_cert() -> Result<(), Error> { fn wrong_path_cert() -> Result<(), Error> {
let port = port().to_string(); let port = port().to_string();
Command::cargo_bin("dufs")? assert_cmd::cargo::cargo_bin_cmd!()
.args([ .args([
"--tls-cert", "--tls-cert",
"wrong", "wrong",
@@ -47,7 +46,7 @@ fn wrong_path_cert() -> Result<(), Error> {
]) ])
.assert() .assert()
.failure() .failure()
.stderr(contains("Failed to access `wrong`")); .stderr(contains("Failed to load cert file at `wrong`"));
Ok(()) Ok(())
} }
@@ -56,7 +55,7 @@ fn wrong_path_cert() -> Result<(), Error> {
#[rstest] #[rstest]
fn wrong_path_key() -> Result<(), Error> { fn wrong_path_key() -> Result<(), Error> {
let port = port().to_string(); let port = port().to_string();
Command::cargo_bin("dufs")? assert_cmd::cargo::cargo_bin_cmd!()
.args([ .args([
"--tls-cert", "--tls-cert",
"tests/data/cert.pem", "tests/data/cert.pem",
@@ -67,7 +66,7 @@ fn wrong_path_key() -> Result<(), Error> {
]) ])
.assert() .assert()
.failure() .failure()
.stderr(contains("Failed to access `wrong`")); .stderr(contains("Failed to load key file at `wrong`"));
Ok(()) Ok(())
} }