From 758d3d29848905ed61deadec3c78b26b22844331 Mon Sep 17 00:00:00 2001 From: Josef Schlehofer Date: Wed, 25 Nov 2026 14:07:03 +0100 Subject: [PATCH 1/4] fix: refuse options that contradict each other --ipv4 with --ipv6 and --secure with --insecure quietly took --ipv4 and --secure, and --simple with --json, --csv or --json-stream printed its lines into the machine-readable output. The Go client refuses them now, and the parity test checks that both do it in the same words. --- .github/workflows/ci.yml | 2 +- src/cli.rs | 2 -- src/speedtest.rs | 15 +++++++++++++++ tests/integration.rs | 26 ++++++++++++++++++++++++-- tests/parity/cases.rs | 7 ++++++- tests/parity/main.rs | 2 +- 6 files changed, 47 insertions(+), 7 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7c11b5e..cc3b990 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -121,7 +121,7 @@ jobs: env: # The commit the expectations were recorded against. The test is given # it too and refuses to run against another one. - LIBRESPEED_GO_COMMIT: 8aefd77bd4bde428cd86d3622102f0ac0443d96e + LIBRESPEED_GO_COMMIT: 7e6a359cdda8fc0a452ad060982bf77e61be4d31 steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: diff --git a/src/cli.rs b/src/cli.rs index 336fc3d..7295a5b 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -31,7 +31,6 @@ pub struct Cli { pub version: bool, /// Force IPv4 only - // Both may be given; --ipv4 wins, the precedence the Go client applies. #[arg(long = "ipv4", short = '4')] pub ipv4: bool, @@ -161,7 +160,6 @@ pub struct Cli { /// Force HTTPS for every test server, whichever scheme the server list /// gives. Does not affect how the server list itself is fetched - // Both may be given; --secure wins, as it does in the Go client. #[arg(long)] pub secure: bool, diff --git a/src/speedtest.rs b/src/speedtest.rs index ac502fd..3afc032 100644 --- a/src/speedtest.rs +++ b/src/speedtest.rs @@ -59,6 +59,21 @@ pub async fn run(cli: &Cli) -> anyhow::Result<()> { anyhow::bail!("incompatible options 'source' and 'interface'"); } + // These pairs contradict each other: only one address family and one + // scheme can be forced, and --simple would print its lines into the JSON, + // the CSV or the event stream. + for (first, second, both) in [ + ("ipv4", "ipv6", cli.ipv4 && cli.ipv6), + ("secure", "insecure", cli.secure && cli.insecure), + ("simple", "json", cli.simple && cli.json), + ("simple", "csv", cli.simple && cli.csv), + ("simple", "json-stream", cli.simple && cli.json_stream), + ] { + if both { + anyhow::bail!("incompatible options '{first}' and '{second}'"); + } + } + if cli.http2 && !cfg!(feature = "http2") { anyhow::bail!("this build has no HTTP/2 support, so --http2 cannot be used"); } diff --git a/tests/integration.rs b/tests/integration.rs index 67e2e53..9e5ebbf 100644 --- a/tests/integration.rs +++ b/tests/integration.rs @@ -654,8 +654,6 @@ fn command_lines_the_go_client_accepts_are_not_rejected() { for args in [ vec!["--concurrent=100"], vec!["--timeout=0"], - vec!["--ipv4", "--ipv6"], - vec!["--secure", "--insecure"], vec!["--upload-size=70000"], vec!["--duration=4000"], vec!["--chunks=200000"], @@ -667,6 +665,30 @@ fn command_lines_the_go_client_accepts_are_not_rejected() { } } +#[test] +fn contradicting_options_are_refused_with_the_go_clients_message() { + let backend = MockBackend::start(); + let list = backend.server_list("contradicting"); + for (args, first, second) in [ + (vec!["--ipv4", "--ipv6"], "ipv4", "ipv6"), + (vec!["-6", "-4"], "ipv4", "ipv6"), + (vec!["--secure", "--insecure"], "secure", "insecure"), + (vec!["--simple", "--json"], "simple", "json"), + (vec!["--csv", "--simple"], "simple", "csv"), + (vec!["--simple", "--json-stream"], "simple", "json-stream"), + ] { + let mut argv = args.clone(); + argv.extend(["--local-json", list.to_str().unwrap(), "--list"]); + let out = run(&argv); + assert_eq!(out.status.code(), Some(1), "{args:?} was accepted"); + assert_eq!( + String::from_utf8_lossy(&out.stderr), + format!("Terminated due to error: incompatible options '{first}' and '{second}'\n") + ); + assert!(stdout_of(&out).is_empty(), "{args:?}"); + } +} + #[test] fn mutually_exclusive_options_are_rejected() { for args in [ diff --git a/tests/parity/cases.rs b/tests/parity/cases.rs index 8c166da..5c97403 100644 --- a/tests/parity/cases.rs +++ b/tests/parity/cases.rs @@ -11,7 +11,7 @@ use crate::compare::View; /// The commit of librespeed/speedtest-cli the expectations were recorded /// against. CI builds exactly this one; keep `.github/workflows/ci.yml` in step. -pub const GO_COMMIT: &str = "8aefd77bd4bde428cd86d3622102f0ac0443d96e"; +pub const GO_COMMIT: &str = "7e6a359cdda8fc0a452ad060982bf77e61be4d31"; /// Why a difference is there: the words of README.md that explain it, so a /// difference nobody documented cannot be declared. @@ -517,6 +517,11 @@ fn usage() -> Vec { SERVERS, &["--source", "1.2.3.4", "--interface", "lo0", "--list"], ), + listed("ipv4_and_ipv6", SERVERS, &["--ipv4", "--ipv6", "--list"]), + listed("secure_and_insecure", SERVERS, &["--secure", "--insecure", "--list"]), + listed("simple_and_json", SERVERS, &["--simple", "--json", "--list"]), + listed("simple_and_csv", SERVERS, &["--simple", "--csv", "--list"]), + listed("simple_and_json_stream", SERVERS, &["--simple", "--json-stream", "--list"]), listed("telemetry_level_bad", SERVERS, &["--telemetry-level", "bogus", "--list"]), case("help_and_bogus", &["--help", "--bogus-flag"]).view(View::Help) .stdout( diff --git a/tests/parity/main.rs b/tests/parity/main.rs index 6e787b7..786c405 100644 --- a/tests/parity/main.rs +++ b/tests/parity/main.rs @@ -17,7 +17,7 @@ //! //! ```sh //! git clone https://github.com/librespeed/speedtest-cli go-client -//! git -C go-client checkout 8aefd77bd4bde428cd86d3622102f0ac0443d96e +//! git -C go-client checkout 7e6a359cdda8fc0a452ad060982bf77e61be4d31 //! (cd go-client && go build -o librespeed-go .) //! LIBRESPEED_GO_BIN=$PWD/go-client/librespeed-go cargo test --test parity //! ``` From 2163c956ce811823af1477167f48ff898033298d Mon Sep 17 00:00:00 2001 From: Josef Schlehofer Date: Wed, 25 Nov 2026 14:14:22 +0100 Subject: [PATCH 2/4] fix: refuse an upload size the Go client refuses --upload-size 0 sent empty requests in a loop, and a size of 2 GiB or more was allocated in one piece. Both are refused now in the Go client's words, where a payload is made from the size, and the parity test moves to the Go commit that added the check. --- .github/workflows/ci.yml | 2 +- README.md | 5 +-- src/defs/server.rs | 6 ++- src/speedtest.rs | 22 ++++++++++ tests/integration.rs | 89 ++++++++++++++++++++++++++++++++++++---- tests/parity/cases.rs | 11 ++++- tests/parity/main.rs | 2 +- 7 files changed, 121 insertions(+), 16 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index cc3b990..7c233fe 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -121,7 +121,7 @@ jobs: env: # The commit the expectations were recorded against. The test is given # it too and refuses to run against another one. - LIBRESPEED_GO_COMMIT: 7e6a359cdda8fc0a452ad060982bf77e61be4d31 + LIBRESPEED_GO_COMMIT: 7a9af2aa415c730aa36c630b792fdfdc20ffa603 steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: diff --git a/README.md b/README.md index 1c49e0d..45181eb 100644 --- a/README.md +++ b/README.md @@ -166,9 +166,8 @@ deliberately different. on Linux only. `--fwmark` stays Linux-only (`SO_MARK`). - **Numbers the Go client cannot act on are refused.** A negative value, a duration or timeout past the `time.Duration` range, and a count, size or - mark past 32 bits are out of range. Go panics on `--upload-size -1`. - A negative `--server` or `--exclude` is still taken, so `--server -1` tests - every server as it does in Go. + mark past 32 bits are out of range. A negative `--server` or `--exclude` + is still taken, so `--server -1` tests every server as it does in Go. - **CSV quoting follows the csv crate.** Only the delimiter, a quote or a line break causes quoting. Go also quotes a field that starts with a space or is exactly `\.`. diff --git a/src/defs/server.rs b/src/defs/server.rs index 4c668a0..ed99e16 100644 --- a/src/defs/server.rs +++ b/src/defs/server.rs @@ -464,12 +464,10 @@ impl Server { let mut counter = BytesCounter::new(); counter.set_mebi(opts.use_mebi); - counter.set_upload_size(opts.upload_size); // The body counts frames as hyper takes them, which runs ahead of what // the connections have written; this is what keeps the total from // reporting the difference as sent. counter.set_wire(client.wire()); - let counter = Arc::new(counter); // Pre-allocating one random blob and reusing it keeps the CPU out of the // measurement; --no-pre-allocate streams endless random data instead. @@ -480,8 +478,12 @@ impl Server { ); None } else { + // Only a payload uses the size. Without one it is not checked, and + // scaling it to bytes could overflow a 32-bit usize. + counter.set_upload_size(opts.upload_size); Some(Bytes::from(random_data(counter.upload_size()))) }; + let counter = Arc::new(counter); let url = url_join_path(&self.get_url()?, &self.upload_url); diff --git a/src/speedtest.rs b/src/speedtest.rs index 3afc032..dd84af6 100644 --- a/src/speedtest.rs +++ b/src/speedtest.rs @@ -32,6 +32,11 @@ const PING_WORKERS: usize = 10; /// exhaust memory on a router. const MAX_LOCAL_JSON: u64 = 8 * 1024 * 1024; +/// The largest `--upload-size`, in KiB: the Go client's limit, the most whose +/// byte count fits an `i32`, just under 2 GiB. The same limit holds on every +/// system, so a value that works on one works on another. +const MAX_UPLOAD_SIZE: u32 = i32::MAX as u32 / 1024; + /// Which URL scheme the server list entries are forced to. #[derive(Clone, Copy, PartialEq, Eq, Debug)] pub enum ForceScheme { @@ -93,6 +98,23 @@ pub async fn run(cli: &Cli) -> anyhow::Result<()> { anyhow::bail!("invalid concurrent requests setting"); } + // The upload payload is allocated in one piece of that many KiB. The size + // is not used where there is no upload or no payload to allocate, and + // neither where the run only lists the servers. + if !cli.no_upload && !cli.no_pre_allocate && !cli.list { + let size = cli.upload_size; + if size < 1 { + write_error!("Upload size cannot be lower than 1 KiB: {size} is given\n"); + anyhow::bail!("invalid upload size setting"); + } + if size > MAX_UPLOAD_SIZE { + write_error!( + "Upload size cannot be more than {MAX_UPLOAD_SIZE} KiB: {size} is given\n" + ); + anyhow::bail!("invalid upload size setting"); + } + } + // Read here rather than left to the TLS backend, so an unreadable bundle // is reported the way the Go client reports it: the error on its own. if let Some(path) = &cli.ca_cert { diff --git a/tests/integration.rs b/tests/integration.rs index 9e5ebbf..e303d7e 100644 --- a/tests/integration.rs +++ b/tests/integration.rs @@ -597,8 +597,8 @@ fn out_of_range_numeric_options_are_rejected() { } } -// Zero is not a number the Go client refuses, apart from --concurrent, which it -// refuses in words of its own. +// Zero is not a number the Go client refuses, apart from --concurrent and +// --upload-size, which it refuses in words of its own. #[test] fn concurrent_zero_is_refused_with_the_go_clients_message() { let out = run(&["--concurrent", "0", "--list"]); @@ -610,11 +610,86 @@ fn concurrent_zero_is_refused_with_the_go_clients_message() { assert!(stdout_of(&out).is_empty()); } -// --duration 0, --chunks 0 and --upload-size 0 run, as they do in the Go -// client: each phase runs only its ramp-up, and the report says what that -// moved. +// The bounds are checked before any server is asked, so the backend never +// sees a request. #[test] -fn zero_duration_chunks_and_upload_size_still_produce_a_report() { +fn an_upload_size_out_of_range_is_refused_with_the_go_clients_message() { + let backend = MockBackend::start(); + let list = backend.server_list("size"); + for (size, line) in [ + ("0", "Upload size cannot be lower than 1 KiB: 0 is given"), + ( + "2097152", + "Upload size cannot be more than 2097151 KiB: 2097152 is given", + ), + ] { + let out = run(&[ + "--upload-size", + size, + "--local-json", + list.to_str().unwrap(), + ]); + assert_eq!(out.status.code(), Some(1), "--upload-size {size}"); + assert_eq!( + String::from_utf8_lossy(&out.stderr), + format!("{line}\nTerminated due to error: invalid upload size setting\n") + ); + assert!(stdout_of(&out).is_empty()); + } +} + +// The size is checked only where a payload is allocated from it. +#[test] +fn an_upload_size_that_is_not_used_is_not_checked() { + let backend = MockBackend::start(); + let list = backend.server_list("unused"); + for unused in ["--no-upload", "--no-pre-allocate"] { + for size in ["0", "2097152"] { + let argv = [ + "--server", + "1", + "--no-icmp", + "--duration", + "0", + unused, + "--upload-size", + size, + "--local-json", + list.to_str().unwrap(), + ]; + let out = run(&argv); + assert_eq!( + out.status.code(), + Some(0), + "{argv:?}: {}", + String::from_utf8_lossy(&out.stderr) + ); + } + } + + // Listing the servers uploads nothing either. + for size in ["0", "2097152"] { + let argv = [ + "--upload-size", + size, + "--local-json", + list.to_str().unwrap(), + "--list", + ]; + let out = run(&argv); + assert_eq!( + out.status.code(), + Some(0), + "{argv:?}: {}", + String::from_utf8_lossy(&out.stderr) + ); + } +} + +// --duration 0 and --chunks 0 run, as they do in the Go client: each phase +// runs only its ramp-up, and the report says what that moved. +#[test] +fn zero_duration_and_chunks_still_produce_a_report() { let backend = MockBackend::start(); let list = backend.server_list("zero"); @@ -628,8 +703,6 @@ fn zero_duration_chunks_and_upload_size_still_produce_a_report() { "0", "--chunks", "0", - "--upload-size", - "0", "--json", ]); assert_eq!( diff --git a/tests/parity/cases.rs b/tests/parity/cases.rs index 5c97403..e3f0731 100644 --- a/tests/parity/cases.rs +++ b/tests/parity/cases.rs @@ -11,7 +11,7 @@ use crate::compare::View; /// The commit of librespeed/speedtest-cli the expectations were recorded /// against. CI builds exactly this one; keep `.github/workflows/ci.yml` in step. -pub const GO_COMMIT: &str = "7e6a359cdda8fc0a452ad060982bf77e61be4d31"; +pub const GO_COMMIT: &str = "7a9af2aa415c730aa36c630b792fdfdc20ffa603"; /// Why a difference is there: the words of README.md that explain it, so a /// difference nobody documented cannot be declared. @@ -610,6 +610,15 @@ fn numbers() -> Vec { "--json", "--debug", ], ), + listed("upload_size_max", SERVERS, &["--upload-size", "2097152"]), + listed( + "upload_size_0_unused", + SERVERS, + &[ + "--duration", "0", "--server", "1", "--upload-size", "0", "--no-upload", + "--json", "--debug", + ], + ), listed( "chunks_octal", SERVERS, diff --git a/tests/parity/main.rs b/tests/parity/main.rs index 786c405..a3e3f72 100644 --- a/tests/parity/main.rs +++ b/tests/parity/main.rs @@ -17,7 +17,7 @@ //! //! ```sh //! git clone https://github.com/librespeed/speedtest-cli go-client -//! git -C go-client checkout 7e6a359cdda8fc0a452ad060982bf77e61be4d31 +//! git -C go-client checkout 7a9af2aa415c730aa36c630b792fdfdc20ffa603 //! (cd go-client && go build -o librespeed-go .) //! LIBRESPEED_GO_BIN=$PWD/go-client/librespeed-go cargo test --test parity //! ``` From 64d8d594848539b777c47979ea9f5a88ab2f0e7f Mon Sep 17 00:00:00 2001 From: Josef Schlehofer Date: Wed, 25 Nov 2026 14:14:28 +0100 Subject: [PATCH 3/4] fix: do not refuse a CA bundle that --skip-cert-verify leaves unused Both TLS builds refused a --ca-cert bundle without a certificate even under --skip-cert-verify, where the Go client goes on because the bundle is not used. They now say that the bundle is unused and go on, and a bundle without a certificate is otherwise reported in Go's words. --- src/http/tls.rs | 38 +++++++++++++++++++++++++------------- tests/integration.rs | 43 +++++++++++++++++++++++++++++++++++++++++++ tests/parity/cases.rs | 2 ++ 3 files changed, 70 insertions(+), 13 deletions(-) diff --git a/src/http/tls.rs b/src/http/tls.rs index 49b39d1..c397d07 100644 --- a/src/http/tls.rs +++ b/src/http/tls.rs @@ -261,7 +261,7 @@ mod imp { let certs = rustls_pki_types::CertificateDer::pem_slice_iter(&pem) .collect::, _>>()?; if certs.is_empty() { - bail!("no certificates found in {}", path.display()); + bail!("no certificate found in {}", path.display()); } Ok(certs) } @@ -274,9 +274,9 @@ mod imp { if tls.skip_verify { // Say so rather than ignoring the bundle in silence: a run that // named a CA file and verified nothing looks like a run that - // verified against that file. + // verified against that file. The bundle is not parsed, so one + // without a certificate is no error here, as in the Go client. if let Some(path) = tls.ca_cert { - read_ca_bundle(path)?; crate::write_error!( "--skip-cert-verify overrides --ca-cert: {} is not used\n", path.display() @@ -362,18 +362,30 @@ mod imp { builder.danger_accept_invalid_hostnames(true); } - if let Some(path) = tls.ca_cert { - let pem = std::fs::read(path) - .with_context(|| format!("cannot read CA certificate bundle {}", path.display()))?; - let certs = split_pem(&pem); - if certs.is_empty() { - bail!("no certificates found in {}", path.display()); + match tls.ca_cert { + // As in the rustls build, the bundle is named and not parsed, so + // one without a certificate is no error here, as in the Go client. + Some(path) if tls.skip_verify => { + crate::write_error!( + "--skip-cert-verify overrides --ca-cert: {} is not used\n", + path.display() + ); } - for cert in certs { - builder.add_root_certificate(native_tls::Certificate::from_pem(&cert)?); + Some(path) => { + let pem = std::fs::read(path).with_context(|| { + format!("cannot read CA certificate bundle {}", path.display()) + })?; + let certs = split_pem(&pem); + if certs.is_empty() { + bail!("no certificate found in {}", path.display()); + } + for cert in certs { + builder.add_root_certificate(native_tls::Certificate::from_pem(&cert)?); + } + // `--ca-cert` replaces the system trust store, as it does in the Go version. + builder.disable_built_in_roots(true); } - // `--ca-cert` replaces the system trust store, as it does in the Go version. - builder.disable_built_in_roots(true); + None => {} } if cfg!(feature = "http2") && tls.http2 { diff --git a/tests/integration.rs b/tests/integration.rs index e303d7e..fe13176 100644 --- a/tests/integration.rs +++ b/tests/integration.rs @@ -980,6 +980,49 @@ fn unreadable_files_are_reported_the_way_the_go_client_reports_them() { ); } +// A bundle without a certificate would fail every HTTPS request, so it ends +// the run, unless verification is off and the bundle is not used. Both TLS +// backends behave alike, and the same as the Go client. +#[test] +fn a_ca_bundle_without_a_certificate_is_refused_unless_verification_is_off() { + let backend = MockBackend::start(); + let list = backend.server_list("no-certificate"); + let path = list.to_str().unwrap(); + + let out = run(&["--ca-cert", path, "--local-json", path, "--list"]); + assert_eq!(out.status.code(), Some(1)); + let stderr = String::from_utf8_lossy(&out.stderr); + assert!( + stderr.ends_with(&format!( + "Terminated due to error: no certificate found in {path}\n" + )), + "{stderr}" + ); + assert!(stdout_of(&out).is_empty()); + + let out = run(&[ + "--ca-cert", + path, + "--skip-cert-verify", + "--local-json", + path, + "--list", + ]); + assert_eq!( + out.status.code(), + Some(0), + "{}", + String::from_utf8_lossy(&out.stderr) + ); + assert!( + String::from_utf8_lossy(&out.stderr).contains(&format!( + "--skip-cert-verify overrides --ca-cert: {path} is not used\n" + )), + "{}", + String::from_utf8_lossy(&out.stderr) + ); +} + // clap's layout, the Go client's wording for every option. #[test] fn help_carries_the_go_clients_option_texts() { diff --git a/tests/parity/cases.rs b/tests/parity/cases.rs index e3f0731..d932450 100644 --- a/tests/parity/cases.rs +++ b/tests/parity/cases.rs @@ -659,6 +659,8 @@ fn files() -> Vec { ], ), listed("ca_cert_missing", SERVERS, &["--ca-cert", MISSING, "--list"]), + // A server list is a file without a certificate. + listed("ca_cert_no_certificate", SERVERS, &["--ca-cert", EMPTY, "--list"]), case("local_json_missing", &["--local-json", MISSING, "--no-icmp", "--list"]), case("local_json_dir", &["--local-json", "@FIX@", "--no-icmp", "--list"]), case("local_json_bad", &["--local-json", BAD, "--no-icmp", "--list"]) From da3d47a9567409ad9480fe577302fe05f4a9d1c3 Mon Sep 17 00:00:00 2001 From: Josef Schlehofer Date: Wed, 25 Nov 2026 14:28:37 +0100 Subject: [PATCH 4/4] fix: report an unreadable --ca-cert file like other errors Such a file ended the run without the prefix every other error gets. A bundle without a certificate now says that PEM is expected, as in the Go client, and the parity test moves to the Go commit with these changes. --- .github/workflows/ci.yml | 2 +- src/http/tls.rs | 4 ++-- src/speedtest.rs | 5 +++-- tests/integration.rs | 9 ++++++--- tests/parity/cases.rs | 3 ++- tests/parity/main.rs | 2 +- 6 files changed, 15 insertions(+), 10 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7c233fe..00e374c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -121,7 +121,7 @@ jobs: env: # The commit the expectations were recorded against. The test is given # it too and refuses to run against another one. - LIBRESPEED_GO_COMMIT: 7a9af2aa415c730aa36c630b792fdfdc20ffa603 + LIBRESPEED_GO_COMMIT: 0bf0ae364f11782e543a045b6604859a8d1b69db steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: diff --git a/src/http/tls.rs b/src/http/tls.rs index c397d07..d5547a9 100644 --- a/src/http/tls.rs +++ b/src/http/tls.rs @@ -261,7 +261,7 @@ mod imp { let certs = rustls_pki_types::CertificateDer::pem_slice_iter(&pem) .collect::, _>>()?; if certs.is_empty() { - bail!("no certificate found in {}", path.display()); + bail!("no usable PEM certificate found in {}", path.display()); } Ok(certs) } @@ -377,7 +377,7 @@ mod imp { })?; let certs = split_pem(&pem); if certs.is_empty() { - bail!("no certificate found in {}", path.display()); + bail!("no usable PEM certificate found in {}", path.display()); } for cert in certs { builder.add_root_certificate(native_tls::Certificate::from_pem(&cert)?); diff --git a/src/speedtest.rs b/src/speedtest.rs index dd84af6..673b684 100644 --- a/src/speedtest.rs +++ b/src/speedtest.rs @@ -116,10 +116,11 @@ pub async fn run(cli: &Cli) -> anyhow::Result<()> { } // Read here rather than left to the TLS backend, so an unreadable bundle - // is reported the way the Go client reports it: the error on its own. + // is reported the way the Go client reports it: the error from opening + // the file, after the prefix every other error gets. if let Some(path) = &cli.ca_cert { if let Err(e) = read_file(path, u64::MAX) { - output::fatal(e); + anyhow::bail!(e); } } diff --git a/tests/integration.rs b/tests/integration.rs index fe13176..deadae2 100644 --- a/tests/integration.rs +++ b/tests/integration.rs @@ -967,11 +967,14 @@ fn unreadable_files_are_reported_the_way_the_go_client_reports_them() { "{stderr}" ); - // An unreadable CA bundle ends the run with the error on its own. + // An unreadable CA bundle ends the run like any other error. let out = run(&["--ca-cert", missing, "--list"]); assert_eq!(out.status.code(), Some(1)); let stderr = String::from_utf8_lossy(&out.stderr); - assert!(stderr.starts_with(&format!("open {missing}: ")), "{stderr}"); + assert!( + stderr.starts_with(&format!("Terminated due to error: open {missing}: ")), + "{stderr}" + ); assert_eq!(stderr.lines().count(), 1, "{stderr}"); #[cfg(unix)] assert!( @@ -994,7 +997,7 @@ fn a_ca_bundle_without_a_certificate_is_refused_unless_verification_is_off() { let stderr = String::from_utf8_lossy(&out.stderr); assert!( stderr.ends_with(&format!( - "Terminated due to error: no certificate found in {path}\n" + "Terminated due to error: no usable PEM certificate found in {path}\n" )), "{stderr}" ); diff --git a/tests/parity/cases.rs b/tests/parity/cases.rs index d932450..6ed3571 100644 --- a/tests/parity/cases.rs +++ b/tests/parity/cases.rs @@ -11,7 +11,7 @@ use crate::compare::View; /// The commit of librespeed/speedtest-cli the expectations were recorded /// against. CI builds exactly this one; keep `.github/workflows/ci.yml` in step. -pub const GO_COMMIT: &str = "7a9af2aa415c730aa36c630b792fdfdc20ffa603"; +pub const GO_COMMIT: &str = "0bf0ae364f11782e543a045b6604859a8d1b69db"; /// Why a difference is there: the words of README.md that explain it, so a /// difference nobody documented cannot be declared. @@ -611,6 +611,7 @@ fn numbers() -> Vec { ], ), listed("upload_size_max", SERVERS, &["--upload-size", "2097152"]), + listed("upload_size_0_list", SERVERS, &["--upload-size", "0", "--list"]), listed( "upload_size_0_unused", SERVERS, diff --git a/tests/parity/main.rs b/tests/parity/main.rs index a3e3f72..3a54ffd 100644 --- a/tests/parity/main.rs +++ b/tests/parity/main.rs @@ -17,7 +17,7 @@ //! //! ```sh //! git clone https://github.com/librespeed/speedtest-cli go-client -//! git -C go-client checkout 7a9af2aa415c730aa36c630b792fdfdc20ffa603 +//! git -C go-client checkout 0bf0ae364f11782e543a045b6604859a8d1b69db //! (cd go-client && go build -o librespeed-go .) //! LIBRESPEED_GO_BIN=$PWD/go-client/librespeed-go cargo test --test parity //! ```