From 5495e8d236a58d0621498a18efe9c353e3e3c65b Mon Sep 17 00:00:00 2001 From: SyscallBrain <61458775+SyscallBrain@users.noreply.github.com> Date: Mon, 16 Nov 2026 00:53:37 +0000 Subject: [PATCH] fix: validate rclone compatibility before releases Test minimum and current rclone versions, handle legacy job lists and offer token login when browser cancellation is unsupported. Isolate test daemons and correct OAuth documentation. --- .github/workflows/ci.yml | 26 +++++++++++++----- .github/workflows/release.yml | 7 +++++ CHANGELOG.md | 7 +++++ CONTRIBUTING.md | 25 ++++++++++++++++++ README.md | 7 ++++- book/src/accounts.md | 5 +++- book/src/how-it-works.md | 5 ++-- book/src/installation.md | 2 ++ docs/RELEASE.md | 3 +++ scripts/install-test-rclone.sh | 40 ++++++++++++++++++++++++++++ src/app/account/mod.rs | 8 ++++++ src/backend/mod.rs | 2 ++ src/backend/rc.rs | 10 ++++++- src/reaper.rs | 38 +++++++++++++++++++++++++-- tests/app_accounts.rs | 22 ++++++++++++++++ tests/common/mod.rs | 48 ++++++++++++++++++++++++++++++++-- tests/daemon.rs | 1 + tests/rc_backend.rs | 35 +++++++++++++++++++------ tests/rc_client.rs | 31 +++++++++++++++++++++- 19 files changed, 298 insertions(+), 24 deletions(-) create mode 100644 scripts/install-test-rclone.sh diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f0125ab..ea830d6 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -4,6 +4,7 @@ on: push: branches: [main] pull_request: + workflow_call: permissions: contents: read @@ -24,13 +25,26 @@ jobs: rustup toolchain install stable --profile minimal --component rustfmt --component clippy rustup default stable - uses: Swatinem/rust-cache@d1527c8f67ef9af357290475d4af4b0fab8f12e0 # v2.9.3 - # The tests that talk to a real `rclone rcd` skip themselves without it: - # install the current release so they run (the distribution's is too old). - - name: Install rclone - run: curl -fsSL https://rclone.org/install.sh | sudo bash - run: cargo fmt --check - - run: cargo clippy --all-targets -- -D warnings - - run: cargo test + - run: cargo clippy --locked --all-targets -- -D warnings + - name: Install minimum supported rclone + run: bash scripts/install-test-rclone.sh 1.68.0 "$RUNNER_TEMP/rclone-minimum" + - name: Test with rclone 1.68.0 + run: | + export PATH="$RUNNER_TEMP/rclone-minimum:$PATH" + RATCLONE_TEST_RCLONE_VERSION=1.68.0 cargo test --locked + - name: Install current rclone release + run: bash scripts/install-test-rclone.sh latest "$RUNNER_TEMP/rclone-current" + - name: Test with current rclone + run: | + export PATH="$RUNNER_TEMP/rclone-current:$PATH" + RATCLONE_TEST_RCLONE_VERSION=$(cat "$RUNNER_TEMP/rclone-current/version") cargo test --locked + - name: Install minimum rclone for cancellable browser login + run: bash scripts/install-test-rclone.sh 1.75.0 "$RUNNER_TEMP/rclone-oauth-minimum" + - name: Test browser login cancellation with rclone 1.75.0 + run: | + export PATH="$RUNNER_TEMP/rclone-oauth-minimum:$PATH" + RATCLONE_TEST_RCLONE_VERSION=1.75.0 cargo test --locked --test rc_backend local_login_requires_cancellable_rclone_or_frees_port # Licences, advisories, banned crates and sources (deny.toml). supply-chain: diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 2eff394..d35cb3c 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -18,9 +18,16 @@ env: CARGO_GENERATE_RPM_VERSION: 0.21.1 jobs: + # A local reusable workflow checks out this tag/dispatch commit. Publication + # cannot proceed until fmt, clippy and the full suite pass against both + # the minimum supported and current rclone, along with the other CI gates. + validate: + uses: ./.github/workflows/ci.yml + # A static (musl) binary per architecture, each built natively, so it runs # on any Linux distribution whatever its glibc. build: + needs: validate strategy: matrix: include: diff --git a/CHANGELOG.md b/CHANGELOG.md index 677c7e4..c0ce48f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,13 @@ All notable changes to this project are documented here. The format follows ## [Unreleased] +### Fixed + +- Keep background transfers running with rclone 1.68.0, whose `job/list` + response does not include the newer `runningIds` field. +- Offer authorization-token login on rclone versions older than 1.75.0, + which cannot cancel an in-app browser login cleanly. + ## [0.1.1] - 2026-11-15 ### Added diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index dbc3e97..d0004c1 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -20,6 +20,31 @@ You need Rust 1.88 or newer. rclone v1.68.0 or newer is only needed to try the real backend and for the tests that talk to `rclone rcd`; without it those tests skip themselves. +CI and releases require the real integration suite against both rclone 1.68.0 +and the current official release, plus a focused browser-login cancellation +test on rclone 1.75.0 (the minimum for that feature). The existing +`fmt, clippy, test` check name is unchanged. To reproduce a run without +replacing your installed rclone: + +```sh +test_dir=$(mktemp -d) +bash scripts/install-test-rclone.sh 1.68.0 "$test_dir" # or latest +PATH="$test_dir:$PATH" RATCLONE_TEST_RCLONE_VERSION=$(cat "$test_dir/version") cargo test --locked +rm -rf "$test_dir" +``` + +The installer verifies the archive against the official `SHA256SUMS` and checks +the binary's version. Setting `RATCLONE_TEST_RCLONE_VERSION` makes a missing or +different rclone fail the run; the OAuth test also fails if its localhost port +is unavailable. Tests use temporary rclone configurations and local files, +without your cloud credentials or accounts. These checks cover the rc API and +local backend; provider-specific behavior still depends on rclone and the provider. +Test daemons run with a disposable HOME and a cleared environment, so +environment-defined remotes and provider credentials cannot override fixtures. +The minimum-version suite verifies that older rclone rejects browser login +before starting a listener and offers token authorization instead. The +1.75.0 and current-version checks exercise real listener startup and cancellation. + ## Before you open a pull request Run the same checks as CI: diff --git a/README.md b/README.md index f1303c9..17821e2 100644 --- a/README.md +++ b/README.md @@ -74,6 +74,10 @@ and Ubuntu ship rclone 1.60, which is too old: install the current one from [rclone.org](https://rclone.org/install/) with `sudo -v ; curl https://rclone.org/install.sh | sudo bash`. +Browser login inside the app requires **rclone v1.75.0 or newer** so it can +be cancelled cleanly. Older supported versions automatically offer the +authorization-token flow instead; existing accounts work as usual. + Download the file for your system from the [latest release](https://github.com/SyscallBrain/ratclone/releases/latest). x86_64 packages are named `amd64` or `x86_64`, and aarch64 packages `arm64` @@ -127,7 +131,8 @@ ratclone --rclone ~/bin/rclone ## How it works ratclone starts its own `rclone rcd` on a private unix socket and talks to it -through the rc API; it never listens on a network port. Copies and moves are +through the rc API, which is only available through that socket. Browser logins +may temporarily open a localhost port for OAuth. Copies and moves are rclone jobs, so they outlive the app: a small helper records how each one ends and stops the rcd once they are done. See [How it works](https://syscallbrain.github.io/ratclone/how-it-works.html). diff --git a/book/src/accounts.md b/book/src/accounts.md index 51cc8d5..3ab01fd 100644 --- a/book/src/accounts.md +++ b/book/src/accounts.md @@ -37,7 +37,10 @@ only sent if you type a new one. Only the fields you change are sent. Google Drive, Dropbox, OneDrive and other accounts log in through a browser. -- **On your own computer**, the browser opens and the app waits for you. +- **On your own computer with rclone 1.75 or newer**, the browser opens and + the app waits for you. Older versions cannot cancel this login reliably, + so the app automatically offers the authorization-token flow below. You + can run the displayed command in another terminal on the same computer. - **Over SSH** there is no browser, so the app shows the command to run on a machine that has one, such as `rclone authorize "dropbox"`. `y` copies it (through OSC 52, so it works over SSH too), and you paste the result back. diff --git a/book/src/how-it-works.md b/book/src/how-it-works.md index 091745c..7712c9a 100644 --- a/book/src/how-it-works.md +++ b/book/src/how-it-works.md @@ -5,8 +5,9 @@ ratclone starts its own `rclone rcd`, rclone's remote-control server, on a private unix socket (`$XDG_RUNTIME_DIR/ratclone/rc.sock`, in a directory only you can open) and talks to it through the -[rc API](https://rclone.org/rc/). It never listens on a network port, and -never builds shell commands. +[rc API](https://rclone.org/rc/), which is only available through that socket. +Browser logins may temporarily open a localhost port for OAuth. ratclone never +builds shell commands. Listing, renaming, deleting and account changes are rc calls. Copies and moves are rclone *jobs*, so they keep going while you browse. diff --git a/book/src/installation.md b/book/src/installation.md index 2e99f7f..c32f3a6 100644 --- a/book/src/installation.md +++ b/book/src/installation.md @@ -4,6 +4,8 @@ ratclone runs on Linux, on x86_64 and aarch64. It needs: - **rclone v1.68.0 or newer.** ratclone checks the version when it starts and says so if it is older. + Browser login inside the app needs **v1.75.0 or newer**; older supported + versions use the [authorization-token flow](accounts.md#browser-logins). - A terminal with truecolor and a [Nerd Font](https://www.nerdfonts.com) for the icons. Without one, set `icons = "ascii"` in the [configuration](configuration.md) or in the settings (`,`). diff --git a/docs/RELEASE.md b/docs/RELEASE.md index 9258035..0210d1c 100644 --- a/docs/RELEASE.md +++ b/docs/RELEASE.md @@ -1,6 +1,9 @@ # Release checklist 1. The gates are green: `cargo fmt --check && cargo clippy --all-targets -- -D warnings && cargo test`. + The Release workflow also runs CI for the exact tag/manual-run commit and + blocks release builds on it, including the real integration suite with + rclone 1.68.0 and the current official release (see `CONTRIBUTING.md`). 2. `CHANGELOG.md` has the release section `## [X.Y.Z] - YYYY-MM-DD`; the Release workflow uses it as the release notes and fails without it. 3. The new version is in `Cargo.toml` (and `Cargo.lock`), in diff --git a/scripts/install-test-rclone.sh b/scripts/install-test-rclone.sh new file mode 100644 index 0000000..a2f9af4 --- /dev/null +++ b/scripts/install-test-rclone.sh @@ -0,0 +1,40 @@ +#!/usr/bin/env bash +# Install an official, checksum-verified rclone in a disposable test directory. +# Usage: scripts/install-test-rclone.sh 1.68.0|latest DESTINATION +set -euo pipefail +version=${1:?usage: install-test-rclone.sh VERSION DESTINATION} +destination=${2:?usage: install-test-rclone.sh VERSION DESTINATION} +if [ "$version" = latest ]; then + version=$(curl --fail --silent --show-error https://downloads.rclone.org/version.txt) + version=${version#rclone v} +fi +[[ "$version" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]] || { echo "invalid rclone version: $version" >&2; exit 1; } +case $(uname -m) in + x86_64) arch=amd64 ;; + aarch64) arch=arm64 ;; + *) echo 'unsupported test host architecture' >&2; exit 1 ;; +esac +work=$(mktemp -d) +trap 'rm -rf "$work"' EXIT +archive="rclone-v$version-linux-$arch.zip" +url="https://downloads.rclone.org/v$version" +curl --fail --silent --show-error -o "$work/$archive" "$url/$archive" +curl --fail --silent --show-error -o "$work/SHA256SUMS" "$url/SHA256SUMS" +# SHA256SUMS is a clear-signed document: select exactly this archive's entry. +awk -v file="$archive" '$2 == file { print; count++ } END { if (count != 1) exit 1 }' \ + "$work/SHA256SUMS" > "$work/checksum" +(cd "$work" && sha256sum --check --strict checksum) +mkdir -p "$destination" +python3 - "$work/$archive" "rclone-v$version-linux-$arch/rclone" "$destination/rclone" <<'PY' +import pathlib +import sys +import zipfile + +with zipfile.ZipFile(sys.argv[1]) as archive: + pathlib.Path(sys.argv[3]).write_bytes(archive.read(sys.argv[2])) +PY +chmod 755 "$destination/rclone" +actual=$("$destination/rclone" version) +[[ "${actual%%$'\n'*}" = "rclone v$version" ]] || { echo "unexpected rclone version: $actual" >&2; exit 1; } +printf '%s\n' "$version" > "$destination/version" +printf '%s\n' "$actual" diff --git a/src/app/account/mod.rs b/src/app/account/mod.rs index 342f8ab..e2d4ead 100644 --- a/src/app/account/mod.rs +++ b/src/app/account/mod.rs @@ -791,6 +791,14 @@ impl App { let Some(w) = self.wizard() else { return }; match (&mut w.step, result) { (Step::WaitingBrowser { jobid, .. }, Ok(id)) => *jobid = Some(id), + (Step::WaitingBrowser { .. }, Err(BackendError::LocalOAuthUnsupported)) => { + let Some(state) = w.local_state.clone() else { + return self.wizard_failed(BackendError::LocalOAuthUnsupported); + }; + w.local_flipped = !w.over_ssh; + w.auto_note = Some("Browser login needs rclone 1.75+: paste an authorization token".into()); + self.answer_local(state, false); + } (_, Ok(id)) => self.stop_job_quietly(id), (_, Err(e)) => self.wizard_failed(e), } diff --git a/src/backend/mod.rs b/src/backend/mod.rs index 0172414..55afdc6 100644 --- a/src/backend/mod.rs +++ b/src/backend/mod.rs @@ -119,6 +119,8 @@ pub enum BackendError { Rclone(String), #[error("lost connection to rclone")] Disconnected, + #[error("browser login requires rclone 1.75 or newer; paste an authorization token instead")] + LocalOAuthUnsupported, #[error("{0}")] Other(String), } diff --git a/src/backend/rc.rs b/src/backend/rc.rs index 05f09a8..317ab17 100644 --- a/src/backend/rc.rs +++ b/src/backend/rc.rs @@ -14,7 +14,7 @@ use super::{ }; use crate::location::{Location, Remote}; use crate::rc::types::{ - RcAbout, RcConfigOut, RcJobId, RcJobStatus, RcList, RcListItem, RcOption, RcProviders, RcStats, + RcAbout, RcConfigOut, RcJobId, RcJobStatus, RcList, RcListItem, RcOption, RcProviders, RcStats, RcVersion, }; use crate::rc::{RcError, UnixRc}; use crate::transfer::spec::{FileProgress, TransferKind, TransferProgress, TransferSpec, aggregate}; @@ -591,6 +591,14 @@ impl Backend for RcBackend { answer: &str, obscure: bool, ) -> Result { + // Before 1.75 the OAuth callback wait ignores job cancellation, leaving + // the job and localhost listener alive. Use the token-paste flow instead. + if answer == "true" { + let version: RcVersion = self.rc.call_typed("core/version", json!({})).await?; + if version.decomposed < [1, 75, 0] { + return Err(BackendError::LocalOAuthUnsupported); + } + } let mut body = continue_body(name, state, answer, obscure); body["_async"] = json!(true); let id: RcJobId = self.rc.call_typed("config/update", body).await?; diff --git a/src/reaper.rs b/src/reaper.rs index 2f012de..d83a16a 100644 --- a/src/reaper.rs +++ b/src/reaper.rs @@ -97,7 +97,16 @@ pub async fn record_outcomes(backend: &dyn Backend, path: &Path) { #[derive(serde::Deserialize)] struct JobList { #[serde(rename = "runningIds", default)] - running: Vec, + running: Option>, + jobids: Vec, +} + +impl JobList { + fn candidates(self) -> Vec { + // Older supported rclones return only jobids. Check their status below + // instead of treating a missing runningIds field as an idle daemon. + self.running.unwrap_or(self.jobids) + } } #[derive(serde::Deserialize)] @@ -109,7 +118,7 @@ struct Mounts { /// Any app transfer still running, or any mount active? async fn busy(rc: &UnixRc) -> Result { let jobs: JobList = rc.call_typed("job/list", json!({})).await?; - for id in jobs.running { + for id in jobs.candidates() { if let Ok(s) = rc .call_typed::("job/status", json!({ "jobid": id })) .await @@ -122,3 +131,28 @@ async fn busy(rc: &UnixRc) -> Result { let mounts: Mounts = rc.call_typed("mount/listmounts", json!({})).await?; Ok(!mounts.mount_points.is_empty()) } + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn legacy_job_list_keeps_candidates_for_status_checks() { + // rclone 1.68 returns jobids but has no runningIds/finishedIds fields. + let jobs: JobList = serde_json::from_value(json!({ + "executeId": "legacy", "jobids": [1, 2, 3] + })) + .unwrap(); + assert_eq!(jobs.candidates(), vec![1, 2, 3]); + } + + #[test] + fn current_job_list_limits_status_checks_to_running_jobs() { + let jobs: JobList = serde_json::from_value(json!({ + "executeId": "current", "jobids": [1, 2, 3], + "finishedIds": [1, 3], "runningIds": [2] + })) + .unwrap(); + assert_eq!(jobs.candidates(), vec![2]); + } +} diff --git a/tests/app_accounts.rs b/tests/app_accounts.rs index 3118629..226f444 100644 --- a/tests/app_accounts.rs +++ b/tests/app_accounts.rs @@ -402,6 +402,28 @@ async fn dropbox_local_waits_then_done() { assert_eq!(message(&app).0, "Account d3 added"); } +#[tokio::test] +async fn older_rclone_falls_back_to_token_without_losing_account() { + let (_d, f, mut app) = sidebar_app().await; + start_add(&mut app, "dropbox", "oldcli").await; + f.fail_next("config_continue_job", BackendError::LocalOAuthUnsupported); + press(&mut app, ""); + app.settle().await; + assert_eq!(step_name(&app), "token"); + assert!(wizard(&app).auto_note.as_deref().unwrap().contains("1.75")); + assert!(f.config_of("oldcli").is_some(), "unfinished account is kept"); + + // Trying the browser again must still offer the usable token flow. + f.fail_next("config_continue_job", BackendError::LocalOAuthUnsupported); + press(&mut app, "L"); + app.settle().await; + assert_eq!(step_name(&app), "token"); + press(&mut app, "{\"x\":1}"); + app.settle().await; + assert!(app.overlay.is_none()); + assert!(f.config_of("oldcli").unwrap().contains_key("token")); +} + #[tokio::test] async fn esc_during_browser_wait_stops_and_deletes() { let (_d, f, mut app) = sidebar_app().await; diff --git a/tests/common/mod.rs b/tests/common/mod.rs index d9c54e3..f2407ea 100644 --- a/tests/common/mod.rs +++ b/tests/common/mod.rs @@ -9,11 +9,54 @@ use ratclone::rc::UnixRc; use tempfile::TempDir; pub fn rclone_bin() -> Option { - std::env::var_os("PATH").and_then(|paths| { + let binary = std::env::var_os("PATH").and_then(|paths| { std::env::split_paths(&paths) .map(|p| p.join("rclone")) .find(|p| p.is_file()) - }) + }); + if let Ok(expected) = std::env::var("RATCLONE_TEST_RCLONE_VERSION") { + let binary = binary + .as_ref() + .expect("required integration-test rclone is missing from PATH"); + let output = Command::new(binary) + .arg("version") + .output() + .expect("run required rclone"); + assert!(output.status.success(), "required rclone version command failed"); + let output = String::from_utf8(output.stdout).expect("rclone version is UTF-8"); + assert_eq!( + output.lines().next(), + Some(format!("rclone v{expected}").as_str()), + "wrong integration-test rclone" + ); + } else { + assert!( + std::env::var_os("GITHUB_ACTIONS").is_none(), + "CI must set RATCLONE_TEST_RCLONE_VERSION to require real integration tests" + ); + } + binary +} + +/// Keep test daemons independent of environment-defined remotes and credentials. +/// The wrapper execs rclone, preserving its PID and the caller's fake-browser PATH. +pub fn isolated_rclone(binary: &Path, directory: &Path) -> PathBuf { + use std::os::unix::fs::PermissionsExt; + let quote = |path: &Path| format!("'{}'", path.to_str().unwrap().replace('\'', "'\\''")); + let wrapper = directory.join("rclone-test-wrapper"); + std::fs::write( + &wrapper, + format!( + "#!/bin/sh\nexec /usr/bin/env -i PATH=\"$PATH\" HOME={} XDG_CONFIG_HOME={} XDG_CACHE_HOME={} {} \"$@\"\n", + quote(directory), + quote(&directory.join("config")), + quote(&directory.join("cache")), + quote(&binary.canonicalize().unwrap()), + ), + ) + .unwrap(); + std::fs::set_permissions(&wrapper, std::fs::Permissions::from_mode(0o700)).unwrap(); + wrapper } pub struct RcdFixture { @@ -42,6 +85,7 @@ impl RcdFixture { return None; }; let dir = tempfile::tempdir().unwrap(); + let rclone = isolated_rclone(&rclone, dir.path()); let root = dir.path().join("root"); std::fs::create_dir(&root).unwrap(); let conf = dir.path().join("rclone.conf"); diff --git a/tests/daemon.rs b/tests/daemon.rs index cc11025..41a26c7 100644 --- a/tests/daemon.rs +++ b/tests/daemon.rs @@ -17,6 +17,7 @@ struct Env { fn env() -> Option { let rclone = common::rclone_bin()?; let dir = tempfile::tempdir().unwrap(); + let rclone = common::isolated_rclone(&rclone, dir.path()); { use std::os::unix::fs::PermissionsExt; std::fs::set_permissions(dir.path(), std::fs::Permissions::from_mode(0o700)).unwrap(); diff --git a/tests/rc_backend.rs b/tests/rc_backend.rs index bcd603c..6ae3131 100644 --- a/tests/rc_backend.rs +++ b/tests/rc_backend.rs @@ -636,7 +636,8 @@ async fn providers_include_drive_mega_dropbox() { .unwrap() .is_password ); - assert!(mega.options.iter().any(|o| o.name == "2fa")); + // Additional provider fields (such as Mega's 2fa) depend on rclone's + // version. The form renders the options returned by that rclone. } #[tokio::test] @@ -752,16 +753,20 @@ async fn continue_job_runs_and_stops() { let _ = backend.stop_job(job).await; } -/// Answering "use this machine's browser" starts rclone's login server; stopping the -/// job ends it (the port is free again) and leaves no token behind. +/// Older rclone must use the token flow; supported browser logins stop cleanly +/// without leaving a listener or token behind. #[tokio::test] -async fn local_login_job_stops_and_frees_port() { +async fn local_login_requires_cancellable_rclone_or_frees_port() { let Some(f) = RcdFixture::start_with_fake_browser() else { return; }; let backend = RcBackend::new(f.rc.clone()); let port_open = || std::net::TcpStream::connect(("127.0.0.1", 53682)).is_ok(); if port_open() { + assert!( + std::env::var_os("RATCLONE_TEST_RCLONE_VERSION").is_none(), + "required OAuth integration test cannot run: port 53682 already in use" + ); eprintln!("skipping: port 53682 already in use"); return; } @@ -772,10 +777,24 @@ async fn local_login_job_stops_and_frees_port() { let ConfigStep::Question { state, .. } = step else { panic!() }; - let job = backend - .config_continue_job("d", &state, "true", false) - .await - .unwrap(); + let version: ratclone::rc::types::RcVersion = + f.rc.call_typed("core/version", serde_json::json!({})) + .await + .unwrap(); + let started = backend.config_continue_job("d", &state, "true", false).await; + if version.decomposed < [1, 75, 0] { + assert_eq!(started, Err(BackendError::LocalOAuthUnsupported)); + assert!(!port_open(), "unsupported login must not open a listener"); + assert!(!f.dir.path().join("opened.txt").exists(), "browser must not open"); + let token_step = backend + .config_continue("d", &state, "false", false) + .await + .unwrap(); + assert_eq!(question_name(&token_step), "config_token"); + assert!(!backend.remote_config("d").await.unwrap().contains_key("token")); + return; + } + let job = started.unwrap(); let start = std::time::Instant::now(); while !port_open() { assert!( diff --git a/tests/rc_client.rs b/tests/rc_client.rs index 106c0de..79c45b8 100644 --- a/tests/rc_client.rs +++ b/tests/rc_client.rs @@ -5,6 +5,33 @@ use ratclone::rc::types::{RcList, RcVersion}; use ratclone::rc::{RcError, UnixRc}; use serde_json::json; +#[test] +fn daemon_wrapper_excludes_inherited_credentials_and_remotes() { + // Spaces and quotes must remain literal paths when invoking the wrapper. + let dir = tempfile::Builder::new() + .prefix("ratclone test's ") + .tempdir() + .unwrap(); + let wrapper = common::isolated_rclone(std::path::Path::new("/usr/bin/env"), dir.path()); + let output = std::process::Command::new(wrapper) + .env_clear() + .env("RCLONE_CONFIG_TST_REMOTE", "/personal/files") + .env("RCLONE_CONFIG_PASS", "private-password") + .env("AWS_SECRET_ACCESS_KEY", "private-key") + .env("HOME", "/personal/home") + .env("PATH", "/fake/browser/path") + .output() + .unwrap(); + assert!(output.status.success()); + let env = String::from_utf8(output.stdout).unwrap(); + assert!(!env.contains("private-") && !env.contains("/personal/"), "{env}"); + assert!( + env.lines() + .any(|line| line == format!("HOME={}", dir.path().display())) + ); + assert!(env.lines().any(|line| line == "PATH=/fake/browser/path")); +} + #[tokio::test] async fn version_roundtrip() { let Some(f) = RcdFixture::start() else { return }; @@ -35,7 +62,9 @@ async fn api_error_is_mapped() { .await .unwrap_err(); assert!( - matches!(e, RcError::Api { status: 500, ref message, .. } if message.contains("nosuch")), + // Older rclone omits the remote name from this error message. + matches!(e, RcError::Api { status: 500, ref message, ref path } + if message.contains("didn't find section in config file") && path == "operations/list"), "{e:?}" ); }