Skip to content

Commit 7cfb97d

Browse files
authored
refactor: update deps (#655)
1 parent 2361903 commit 7cfb97d

File tree

12 files changed

+644
-465
lines changed

12 files changed

+644
-465
lines changed

Cargo.lock

Lines changed: 595 additions & 404 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@ async_zip = { version = "0.0.18", default-features = false, features = ["deflate
2525
headers = "0.4"
2626
mime_guess = "2.0"
2727
if-addrs = "0.14"
28-
rustls-pemfile = { version = "2.0", optional = true }
29-
tokio-rustls = { version = "0.26", optional = true, default-features = false, features = ["ring", "tls12"]}
28+
tokio-rustls = { version = "0.26", optional = true }
3029
md5 = "0.8"
3130
lazy_static = "1.4"
3231
uuid = { version = "1.7", features = ["v4", "fast-rng"] }
@@ -58,11 +57,11 @@ hex = "0.4.3"
5857

5958
[features]
6059
default = ["tls"]
61-
tls = ["rustls-pemfile", "tokio-rustls"]
60+
tls = ["tokio-rustls"]
6261

6362
[dev-dependencies]
6463
assert_cmd = "2"
65-
reqwest = { version = "0.12", features = ["blocking", "multipart", "rustls-tls"], default-features = false }
64+
reqwest = { version = "0.13", features = ["blocking", "multipart", "rustls"], default-features = false }
6665
assert_fs = "1"
6766
port_check = "0.3"
6867
rstest = "0.26.1"

src/args.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -492,21 +492,16 @@ impl BindAddr {
492492
}
493493
}
494494

495-
#[derive(Debug, Clone, Copy, PartialEq, Deserialize)]
495+
#[derive(Debug, Clone, Copy, PartialEq, Deserialize, Default)]
496496
#[serde(rename_all = "lowercase")]
497497
pub enum Compress {
498498
None,
499+
#[default]
499500
Low,
500501
Medium,
501502
High,
502503
}
503504

504-
impl Default for Compress {
505-
fn default() -> Self {
506-
Self::Low
507-
}
508-
}
509-
510505
impl ValueEnum for Compress {
511506
fn value_variants<'a>() -> &'a [Self] {
512507
&[Self::None, Self::Low, Self::Medium, Self::High]

src/utils.rs

Lines changed: 25 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use anyhow::{anyhow, Context, Result};
22
use chrono::{DateTime, Utc};
33
#[cfg(feature = "tls")]
4-
use rustls_pki_types::{CertificateDer, PrivateKeyDer};
4+
use rustls_pki_types::{pem::PemObject, CertificateDer, PrivateKeyDer};
55
use std::{
66
borrow::Cow,
77
path::Path,
@@ -62,42 +62,40 @@ pub fn glob(pattern: &str, target: &str) -> bool {
6262

6363
// Load public certificate from file.
6464
#[cfg(feature = "tls")]
65-
pub fn load_certs<T: AsRef<Path>>(filename: T) -> Result<Vec<CertificateDer<'static>>> {
66-
// Open certificate file.
67-
let cert_file = std::fs::File::open(filename.as_ref())
68-
.with_context(|| format!("Failed to access `{}`", filename.as_ref().display()))?;
69-
let mut reader = std::io::BufReader::new(cert_file);
70-
71-
// Load and return certificate.
65+
pub fn load_certs<T: AsRef<Path>>(file_name: T) -> Result<Vec<CertificateDer<'static>>> {
7266
let mut certs = vec![];
73-
for cert in rustls_pemfile::certs(&mut reader) {
74-
let cert = cert.with_context(|| "Failed to load certificate")?;
67+
for cert in CertificateDer::pem_file_iter(file_name.as_ref()).with_context(|| {
68+
format!(
69+
"Failed to load cert file at `{}`",
70+
file_name.as_ref().display()
71+
)
72+
})? {
73+
let cert = cert.with_context(|| {
74+
format!(
75+
"Invalid certificate data in file `{}`",
76+
file_name.as_ref().display()
77+
)
78+
})?;
7579
certs.push(cert)
7680
}
7781
if certs.is_empty() {
78-
anyhow::bail!("No supported certificate in file");
82+
anyhow::bail!(
83+
"No supported certificate in file `{}`",
84+
file_name.as_ref().display()
85+
);
7986
}
8087
Ok(certs)
8188
}
8289

8390
// Load private key from file.
8491
#[cfg(feature = "tls")]
85-
pub fn load_private_key<T: AsRef<Path>>(filename: T) -> Result<PrivateKeyDer<'static>> {
86-
let key_file = std::fs::File::open(filename.as_ref())
87-
.with_context(|| format!("Failed to access `{}`", filename.as_ref().display()))?;
88-
let mut reader = std::io::BufReader::new(key_file);
89-
90-
// Load and return a single private key.
91-
for key in rustls_pemfile::read_all(&mut reader) {
92-
let key = key.with_context(|| "There was a problem with reading private key")?;
93-
match key {
94-
rustls_pemfile::Item::Pkcs1Key(key) => return Ok(PrivateKeyDer::Pkcs1(key)),
95-
rustls_pemfile::Item::Pkcs8Key(key) => return Ok(PrivateKeyDer::Pkcs8(key)),
96-
rustls_pemfile::Item::Sec1Key(key) => return Ok(PrivateKeyDer::Sec1(key)),
97-
_ => {}
98-
}
99-
}
100-
anyhow::bail!("No supported private key in file");
92+
pub fn load_private_key<T: AsRef<Path>>(file_name: T) -> Result<PrivateKeyDer<'static>> {
93+
PrivateKeyDer::from_pem_file(file_name.as_ref()).with_context(|| {
94+
format!(
95+
"Failed to load key file at `{}`",
96+
file_name.as_ref().display()
97+
)
98+
})
10199
}
102100

103101
pub fn parse_range(range: &str, size: u64) -> Option<Vec<(u64, u64)>> {

tests/assets.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
mod fixtures;
22
mod utils;
33

4-
use assert_cmd::prelude::*;
54
use assert_fs::fixture::TempDir;
65
use fixtures::{port, server, tmpdir, wait_for_port, Error, TestServer, DIR_ASSETS};
76
use rstest::rstest;
@@ -101,7 +100,7 @@ fn asset_js_with_prefix(
101100

102101
#[rstest]
103102
fn assets_override(tmpdir: TempDir, port: u16) -> Result<(), Error> {
104-
let mut child = Command::cargo_bin("dufs")?
103+
let mut child = Command::new(assert_cmd::cargo::cargo_bin!())
105104
.arg(tmpdir.path())
106105
.arg("-p")
107106
.arg(port.to_string())

tests/bind.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use std::process::{Command, Stdio};
1212
#[rstest]
1313
#[case(&["-b", "20.205.243.166"])]
1414
fn bind_fails(tmpdir: TempDir, port: u16, #[case] args: &[&str]) -> Result<(), Error> {
15-
Command::cargo_bin("dufs")?
15+
Command::new(assert_cmd::cargo::cargo_bin!())
1616
.arg(tmpdir.path())
1717
.arg("-p")
1818
.arg(port.to_string())
@@ -49,7 +49,7 @@ fn bind_ipv4_ipv6(
4949
#[case(&[] as &[&str])]
5050
#[case(&["--path-prefix", "/prefix"])]
5151
fn validate_printed_urls(tmpdir: TempDir, port: u16, #[case] args: &[&str]) -> Result<(), Error> {
52-
let mut child = Command::cargo_bin("dufs")?
52+
let mut child = Command::new(assert_cmd::cargo::cargo_bin!())
5353
.arg(tmpdir.path())
5454
.arg("-p")
5555
.arg(port.to_string())

tests/cli.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@ use std::process::Command;
1111
#[test]
1212
/// Show help and exit.
1313
fn help_shows() -> Result<(), Error> {
14-
Command::cargo_bin("dufs")?.arg("-h").assert().success();
14+
Command::new(assert_cmd::cargo::cargo_bin!())
15+
.arg("-h")
16+
.assert()
17+
.success();
1518

1619
Ok(())
1720
}
@@ -21,7 +24,7 @@ fn help_shows() -> Result<(), Error> {
2124
fn print_completions() -> Result<(), Error> {
2225
// let shell_enums = EnumValueParser::<Shell>::new();
2326
for shell in Shell::value_variants() {
24-
Command::cargo_bin("dufs")?
27+
Command::new(assert_cmd::cargo::cargo_bin!())
2528
.arg("--completions")
2629
.arg(shell.to_string())
2730
.assert()

tests/config.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ mod digest_auth_util;
22
mod fixtures;
33
mod utils;
44

5-
use assert_cmd::prelude::*;
65
use assert_fs::TempDir;
76
use digest_auth_util::send_with_digest_auth;
87
use fixtures::{port, tmpdir, wait_for_port, Error};
@@ -13,7 +12,7 @@ use std::process::{Command, Stdio};
1312
#[rstest]
1413
fn use_config_file(tmpdir: TempDir, port: u16) -> Result<(), Error> {
1514
let config_path = get_config_path().display().to_string();
16-
let mut child = Command::cargo_bin("dufs")?
15+
let mut child = Command::new(assert_cmd::cargo::cargo_bin!())
1716
.arg(tmpdir.path())
1817
.arg("-p")
1918
.arg(port.to_string())

tests/fixtures.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
use assert_cmd::prelude::*;
21
use assert_fs::fixture::TempDir;
32
use assert_fs::prelude::*;
43
use port_check::free_local_port;
@@ -129,8 +128,7 @@ where
129128
{
130129
let port = port();
131130
let tmpdir = tmpdir();
132-
let child = Command::cargo_bin("dufs")
133-
.expect("Couldn't find test binary")
131+
let child = Command::new(assert_cmd::cargo::cargo_bin!())
134132
.arg(tmpdir.path())
135133
.arg("-p")
136134
.arg(port.to_string())

tests/http_logger.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ mod utils;
55
use digest_auth_util::send_with_digest_auth;
66
use fixtures::{port, tmpdir, wait_for_port, Error};
77

8-
use assert_cmd::prelude::*;
98
use assert_fs::fixture::TempDir;
109
use rstest::rstest;
1110
use std::io::Read;
@@ -20,7 +19,7 @@ fn log_remote_user(
2019
#[case] args: &[&str],
2120
#[case] is_basic: bool,
2221
) -> Result<(), Error> {
23-
let mut child = Command::cargo_bin("dufs")?
22+
let mut child = Command::new(assert_cmd::cargo::cargo_bin!())
2423
.arg(tmpdir.path())
2524
.arg("-p")
2625
.arg(port.to_string())
@@ -55,7 +54,7 @@ fn log_remote_user(
5554
#[rstest]
5655
#[case(&["--log-format", ""])]
5756
fn no_log(tmpdir: TempDir, port: u16, #[case] args: &[&str]) -> Result<(), Error> {
58-
let mut child = Command::cargo_bin("dufs")?
57+
let mut child = Command::new(assert_cmd::cargo::cargo_bin!())
5958
.arg(tmpdir.path())
6059
.arg("-p")
6160
.arg(port.to_string())

0 commit comments

Comments
 (0)