π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Move paste tests into CLI integration target
Manav Rathi0fcef4677589
diff --git a/rust/apps/cli/Cargo.toml b/rust/apps/cli/Cargo.tomlindex 802cae942a..ab60f93681 100644--- a/rust/apps/cli/Cargo.toml+++ b/rust/apps/cli/Cargo.toml@@ -7,6 +7,14 @@ homepage = "https://ente.com"repository = "https://github.com/ente-io/ente"license = "AGPL-3.0-only"+[features]+museum = []+pglite = []++[[test]]+name = "paste"+required-features = ["museum", "pglite"]+[dependencies]# CLIclap = { version = "4.5", features = ["derive", "env"] }diff --git a/rust/apps/cli/README.md b/rust/apps/cli/README.mdindex 4b53293ec6..2854dff77b 100644--- a/rust/apps/cli/README.md+++ b/rust/apps/cli/README.md@@ -5,3 +5,19 @@ WIP Ente Rust CLI.```shcargo run --bin ente-rs -- --help```++## Integration tests++The integration tests spin up a local Museum server backed by an in-memory Postgres using [pglite](https://pglite.dev). These are gated behind Cargo features, so a plain `cargo test -p ente-rs` skips them.++One-time setup:++```sh+npm ci --prefix rust/apps/cli/tests/pglite+```++Run the tests from the `rust/` directory:++```sh+cargo test -p ente-rs --features museum,pglite+```diff --git a/rust/apps/cli/tests/paste.rs b/rust/apps/cli/tests/paste.rsnew file mode 100644index 0000000000..1f611ca439--- /dev/null+++ b/rust/apps/cli/tests/paste.rs@@ -0,0 +1,175 @@+mod support;++use std::process::Output;++use reqwest::Url;+use support::{Cli, Fixture, TestResult};+use uuid::Uuid;++#[test]+fn paste() -> TestResult {+ let fixture = Fixture::start()?;++ full_link_roundtrip(&fixture)?;+ token_and_key_roundtrip(&fixture)?;+ stdin_roundtrip(&fixture)?;++ Ok(())+}++fn full_link_roundtrip(fixture: &Fixture) -> TestResult {+ let cli = fixture.cli("full-link")?;+ let text = unique_text("full-link");+ let link = create_paste(&cli, fixture, &text)?;++ let consumed = cli_success(cli.run(&[+ "paste",+ "consume",+ "--endpoint",+ fixture.endpoint(),+ &link.raw,+ ])?);+ assert_eq!(consumed, text);++ let second_consume = cli.run(&[+ "paste",+ "consume",+ "--endpoint",+ fixture.endpoint(),+ &link.raw,+ ])?;+ assert!(+ !second_consume.status.success(),+ "second consume unexpectedly succeeded with stdout: {}",+ String::from_utf8_lossy(&second_consume.stdout),+ );+ assert!(+ String::from_utf8_lossy(&second_consume.stderr).contains("API error (410)"),+ "second consume should fail with 410, got stderr: {}",+ String::from_utf8_lossy(&second_consume.stderr),+ );++ Ok(())+}++fn token_and_key_roundtrip(fixture: &Fixture) -> TestResult {+ let cli = fixture.cli("token-key")?;+ let text = unique_text("token-key");+ let link = create_paste(&cli, fixture, &text)?;++ let consumed = cli_success(cli.run(&[+ "paste",+ "consume",+ "--endpoint",+ fixture.endpoint(),+ "--key",+ &link.key,+ &link.token,+ ])?);+ assert_eq!(consumed, text);++ Ok(())+}++fn stdin_roundtrip(fixture: &Fixture) -> TestResult {+ let cli = fixture.cli("stdin")?;+ let text = format!(+ "paste stdin scenario {}\n\nsecond line stays intact\n",+ Uuid::new_v4()+ );+ let link = cli_success(cli.run_with_stdin(+ &[+ "paste",+ "create",+ "--endpoint",+ fixture.endpoint(),+ "--paste-origin",+ fixture.paste_origin(),+ ],+ &text,+ )?);+ let link = PasteLink::parse(link.trim(), fixture.paste_origin());++ let consumed = cli_success(cli.run(&[+ "paste",+ "consume",+ "--endpoint",+ fixture.endpoint(),+ &link.raw,+ ])?);+ assert_eq!(consumed, text);++ Ok(())+}++fn create_paste(cli: &Cli, fixture: &Fixture, text: &str) -> TestResult<PasteLink> {+ let link = cli_success(cli.run(&[+ "paste",+ "create",+ "--endpoint",+ fixture.endpoint(),+ "--paste-origin",+ fixture.paste_origin(),+ text,+ ])?);+ Ok(PasteLink::parse(link.trim(), fixture.paste_origin()))+}++fn unique_text(scope: &str) -> String {+ format!("paste cli {scope} scenario {}", Uuid::new_v4())+}++struct PasteLink {+ raw: String,+ token: String,+ key: String,+}++impl PasteLink {+ fn parse(raw: &str, expected_origin: &str) -> Self {+ let url = Url::parse(raw).unwrap_or_else(|error| {+ panic!("invalid paste link {raw}: {error}");+ });+ let actual_origin = url.origin().ascii_serialization();+ let expected_origin = Url::parse(expected_origin)+ .expect("expected paste origin should be a URL")+ .origin()+ .ascii_serialization();+ let token = url+ .path_segments()+ .and_then(|mut segments| segments.rfind(|segment| !segment.is_empty()))+ .expect("paste link should include an access token")+ .to_string();+ let key = url+ .fragment()+ .expect("paste link should include a decryption key fragment")+ .to_string();++ assert_eq!(+ actual_origin, expected_origin,+ "paste link used unexpected origin: {raw}",+ );+ assert!(+ key.len() == 12 && key.bytes().all(|byte| byte.is_ascii_alphanumeric()),+ "paste link key has unexpected format: {key}",+ );+ assert!(!token.is_empty(), "paste link token is empty: {raw}");++ Self {+ raw: raw.to_string(),+ token,+ key,+ }+ }+}++fn cli_success(output: Output) -> String {+ assert!(+ output.status.success(),+ "ente-rs failed\nstatus: {}\nstdout:\n{}\nstderr:\n{}",+ output.status,+ String::from_utf8_lossy(&output.stdout),+ String::from_utf8_lossy(&output.stderr),+ );+ String::from_utf8(output.stdout).expect("ente-rs stdout should be UTF-8")+}diff --git a/rust/apps/cli/tests/pglite/package-lock.json b/rust/apps/cli/tests/pglite/package-lock.jsonnew file mode 100644index 0000000000..1c85511c78--- /dev/null+++ b/rust/apps/cli/tests/pglite/package-lock.json@@ -0,0 +1,34 @@+{+ "name": "ente-cli-pglite-fixture",+ "lockfileVersion": 3,+ "requires": true,+ "packages": {+ "": {+ "name": "ente-cli-pglite-fixture",+ "devDependencies": {+ "@electric-sql/pglite-socket": "0.1.3"+ }+ },+ "node_modules/@electric-sql/pglite": {+ "version": "0.4.3",+ "resolved": "https://registry.npmjs.org/@electric-sql/pglite/-/pglite-0.4.3.tgz",+ "integrity": "sha512-ichuWTgtd4mOM1G4SpyGJa5trT03lWbMypDV0fUXUCXg5hiHqVAz/bZyV68NqmkLB7WcYmj1RMJVSp8HV/v/ZQ==",+ "dev": true,+ "license": "Apache-2.0",+ "peer": true+ },+ "node_modules/@electric-sql/pglite-socket": {+ "version": "0.1.3",+ "resolved": "https://registry.npmjs.org/@electric-sql/pglite-socket/-/pglite-socket-0.1.3.tgz",+ "integrity": "sha512-LAciWM0M1dCL8hlsxu2venbVZcdxema0BtDfpWYVqr+Y468UADw0pFWidhKw1M8sfJ8rdLT71tjMmnirf/IZRQ==",+ "dev": true,+ "license": "Apache-2.0",+ "bin": {+ "pglite-server": "dist/scripts/server.js"+ },+ "peerDependencies": {+ "@electric-sql/pglite": "0.4.3"+ }+ }+ }+}diff --git a/rust/apps/cli/tests/pglite/package.json b/rust/apps/cli/tests/pglite/package.jsonnew file mode 100644index 0000000000..be37570a7a--- /dev/null+++ b/rust/apps/cli/tests/pglite/package.json@@ -0,0 +1,7 @@+{+ "name": "ente-cli-pglite-fixture",+ "private": true,+ "devDependencies": {+ "@electric-sql/pglite-socket": "0.1.3"+ }+}diff --git a/rust/apps/cli/tests/support/cli.rs b/rust/apps/cli/tests/support/cli.rsnew file mode 100644index 0000000000..3c35865854--- /dev/null+++ b/rust/apps/cli/tests/support/cli.rs@@ -0,0 +1,51 @@+use std::{+ io::Write,+ path::{Path, PathBuf},+ process::{Command, Output, Stdio},+};++use super::TestResult;++pub struct Cli {+ bin: PathBuf,+ config_dir: PathBuf,+}++impl Cli {+ pub fn new(config_dir: PathBuf) -> Self {+ Self {+ bin: PathBuf::from(env!("CARGO_BIN_EXE_ente-rs")),+ config_dir,+ }+ }++ pub fn run(&self, args: &[&str]) -> TestResult<Output> {+ Ok(command(&self.bin, &self.config_dir, args).output()?)+ }++ pub fn run_with_stdin(&self, args: &[&str], stdin: &str) -> TestResult<Output> {+ let mut child = command(&self.bin, &self.config_dir, args)+ .stdin(Stdio::piped())+ .stdout(Stdio::piped())+ .stderr(Stdio::piped())+ .spawn()?;++ child+ .stdin+ .take()+ .expect("ente-rs stdin should be piped")+ .write_all(stdin.as_bytes())?;++ Ok(child.wait_with_output()?)+ }+}++fn command(bin: &Path, config_dir: &Path, args: &[&str]) -> Command {+ let mut command = Command::new(bin);+ command+ .args(args)+ .env("ENTE_CLI_CONFIG_DIR", config_dir)+ .env("NO_PROXY", "127.0.0.1,localhost")+ .env("no_proxy", "127.0.0.1,localhost");+ command+}diff --git a/rust/apps/cli/tests/support/fixture.rs b/rust/apps/cli/tests/support/fixture.rsnew file mode 100644index 0000000000..a4e9119ea6--- /dev/null+++ b/rust/apps/cli/tests/support/fixture.rs@@ -0,0 +1,113 @@+use std::{+ fs,+ net::TcpListener,+ path::{Path, PathBuf},+};++use uuid::Uuid;++use super::{Cli, LOCAL_HOST, TestResult, museum, pglite, process::ChildProcess};++pub struct Fixture {+ temp_dir: TempDir,+ endpoint: String,+ paste_origin: String,+ _pglite: ChildProcess,+ _museum: ChildProcess,+}++impl Fixture {+ pub fn start() -> TestResult<Self> {+ let paths = Paths::discover()?;+ let temp_dir = TempDir::new("ente-cli-paste")?;+ let log_dir = temp_dir.path().join("logs");+ let pglite_port = free_port()?;+ let museum_port = free_port()?;+ let paste_port = free_port()?;+ let paste_origin = format!("http://{LOCAL_HOST}:{paste_port}");+ let endpoint = format!("http://{LOCAL_HOST}:{museum_port}");+ let credentials_file = temp_dir.path().join("credentials.yaml");++ museum::write_credentials(&credentials_file, pglite_port)?;+ let pglite = pglite::start(&paths.pglite_dir, &log_dir, pglite_port)?;+ let museum = museum::start(+ &paths.server_dir,+ &log_dir,+ &credentials_file,+ museum_port,+ pglite_port,+ &paste_origin,+ )?;++ Ok(Self {+ temp_dir,+ endpoint,+ paste_origin,+ _pglite: pglite,+ _museum: museum,+ })+ }++ pub fn endpoint(&self) -> &str {+ &self.endpoint+ }++ pub fn paste_origin(&self) -> &str {+ &self.paste_origin+ }++ pub fn cli(&self, name: &str) -> TestResult<Cli> {+ let config_dir = self.temp_dir.path().join("cli").join(name);+ fs::create_dir_all(&config_dir)?;+ Ok(Cli::new(config_dir))+ }+}++struct Paths {+ server_dir: PathBuf,+ pglite_dir: PathBuf,+}++impl Paths {+ fn discover() -> TestResult<Self> {+ let cli_dir = PathBuf::from(env!("CARGO_MANIFEST_DIR"));+ let rust_dir = cli_dir+ .parent()+ .and_then(Path::parent)+ .ok_or("failed to resolve rust directory")?;+ let repo_dir = rust_dir+ .parent()+ .ok_or("failed to resolve repository directory")?;++ Ok(Self {+ server_dir: repo_dir.join("server"),+ pglite_dir: cli_dir.join("tests").join("pglite"),+ })+ }+}++struct TempDir {+ path: PathBuf,+}++impl TempDir {+ fn new(prefix: &str) -> TestResult<Self> {+ let path = std::env::temp_dir().join(format!("{prefix}-{}", Uuid::new_v4()));+ fs::create_dir_all(&path)?;+ Ok(Self { path })+ }++ fn path(&self) -> &Path {+ &self.path+ }+}++impl Drop for TempDir {+ fn drop(&mut self) {+ let _ = fs::remove_dir_all(&self.path);+ }+}++fn free_port() -> TestResult<u16> {+ Ok(TcpListener::bind((LOCAL_HOST, 0))?.local_addr()?.port())+}diff --git a/rust/apps/cli/tests/support/mod.rs b/rust/apps/cli/tests/support/mod.rsnew file mode 100644index 0000000000..d052f693f2--- /dev/null+++ b/rust/apps/cli/tests/support/mod.rs@@ -0,0 +1,12 @@+mod cli;+mod fixture;+mod museum;+mod pglite;+mod process;++pub use cli::Cli;+pub use fixture::Fixture;++pub type TestResult<T = ()> = Result<T, Box<dyn std::error::Error>>;++const LOCAL_HOST: &str = "127.0.0.1";diff --git a/rust/apps/cli/tests/support/museum.rs b/rust/apps/cli/tests/support/museum.rsnew file mode 100644index 0000000000..5f6a6e0e54--- /dev/null+++ b/rust/apps/cli/tests/support/museum.rs@@ -0,0 +1,122 @@+use std::{+ fs,+ io::{Read, Write},+ net::TcpStream,+ path::Path,+ process::Command,+ time::{Duration, Instant},+};++use super::{LOCAL_HOST, TestResult, process::ChildProcess};++pub fn start(+ server_dir: &Path,+ log_dir: &Path,+ credentials_file: &Path,+ museum_port: u16,+ pglite_port: u16,+ paste_origin: &str,+) -> TestResult<ChildProcess> {+ require_go()?;++ let mut command = Command::new("go");+ command+ .arg("run")+ .arg("./cmd/museum")+ .current_dir(server_dir)+ .env("ENTE_CREDENTIALS_FILE", credentials_file)+ .env("ENTE_HTTP_PORT", museum_port.to_string())+ .env("ENTE_APPS_PUBLIC_PASTE", paste_origin)+ .env("ENTE_DB_HOST", LOCAL_HOST)+ .env("ENTE_DB_PORT", pglite_port.to_string())+ .env("ENTE_DB_NAME", "postgres")+ .env("ENTE_DB_USER", "postgres")+ .env("ENTE_DB_PASSWORD", "")+ .env("ENTE_DB_SSLMODE", "disable")+ .env(+ "ENTE_INTERNAL_HARDCODED_OTT_LOCAL_DOMAIN_SUFFIX",+ "@ente-rust-test.org",+ )+ .env("ENTE_INTERNAL_HARDCODED_OTT_LOCAL_DOMAIN_VALUE", "123456");++ let mut museum = ChildProcess::spawn("museum", &mut command, log_dir)?;+ wait_for_museum(&mut museum, museum_port)?;+ Ok(museum)+}++pub fn write_credentials(path: &Path, pglite_port: u16) -> TestResult {+ fs::write(+ path,+ format!(+ r#"db:+ host: {LOCAL_HOST}+ port: {pglite_port}+ name: postgres+ user: postgres+ password: ""+ sslmode: disable++s3:+ are_local_buckets: true+ b2-eu-cen:+ key: changeme+ secret: changeme1234+ endpoint: localhost:3200+ region: eu-central-2+ bucket: b2-eu-cen+ wasabi-eu-central-2-v3:+ key: changeme+ secret: changeme1234+ endpoint: localhost:3200+ region: eu-central-2+ bucket: wasabi-eu-central-2-v3+ compliance: false+ scw-eu-fr-v3:+ key: changeme+ secret: changeme1234+ endpoint: localhost:3200+ region: eu-central-2+ bucket: scw-eu-fr-v3+"#+ ),+ )?;+ Ok(())+}++fn require_go() -> TestResult {+ match Command::new("go").arg("version").output() {+ Ok(output) if output.status.success() => Ok(()),+ _ => Err("Museum live tests require `go` on PATH".into()),+ }+}++fn wait_for_museum(process: &mut ChildProcess, port: u16) -> TestResult {+ let deadline = Instant::now() + Duration::from_secs(90);+ loop {+ process.ensure_running()?;+ if ping(port)? {+ return Ok(());+ }+ if Instant::now() >= deadline {+ return Err(format!(+ "Museum did not become ready at http://{LOCAL_HOST}:{port}/ping\n{}",+ process.log_summary()+ )+ .into());+ }+ std::thread::sleep(Duration::from_millis(500));+ }+}++fn ping(port: u16) -> TestResult<bool> {+ let mut stream = match TcpStream::connect((LOCAL_HOST, port)) {+ Ok(stream) => stream,+ Err(_) => return Ok(false),+ };+ stream.set_read_timeout(Some(Duration::from_secs(2)))?;+ stream.write_all(b"GET /ping HTTP/1.1\r\nHost: localhost\r\nConnection: close\r\n\r\n")?;++ let mut response = String::new();+ stream.read_to_string(&mut response)?;+ Ok(response.starts_with("HTTP/1.1 200") || response.starts_with("HTTP/1.0 200"))+}diff --git a/rust/apps/cli/tests/support/pglite.rs b/rust/apps/cli/tests/support/pglite.rsnew file mode 100644index 0000000000..8e062ea34a--- /dev/null+++ b/rust/apps/cli/tests/support/pglite.rs@@ -0,0 +1,80 @@+use std::{+ fs,+ net::TcpStream,+ path::{Path, PathBuf},+ process::Command,+ time::{Duration, Instant},+};++use serde_json::Value;++use super::{LOCAL_HOST, TestResult, process::ChildProcess};++pub fn start(package_dir: &Path, log_dir: &Path, port: u16) -> TestResult<ChildProcess> {+ let bin = pglite_server_bin(package_dir)?;+ let mut command = Command::new(bin);+ command+ .arg("--db=memory://")+ .arg(format!("--host={LOCAL_HOST}"))+ .arg(format!("--port={port}"))+ .arg("--max-connections=20")+ .current_dir(package_dir);+ let mut pglite = ChildProcess::spawn("pglite", &mut command, log_dir)?;+ wait_for_pglite(&mut pglite, port)?;+ Ok(pglite)+}++fn pglite_server_bin(package_dir: &Path) -> TestResult<PathBuf> {+ let expected_version = package_version(package_dir.join("package.json"))?;+ let installed_package = package_dir+ .join("node_modules")+ .join("@electric-sql")+ .join("pglite-socket")+ .join("package.json");+ let installed_version = package_version(installed_package).map_err(|_| install_error())?;+ if installed_version != expected_version {+ return Err(install_error());+ }++ let bin = package_dir+ .join("node_modules")+ .join(".bin")+ .join("pglite-server");+ if bin.is_file() {+ Ok(bin)+ } else {+ Err(install_error())+ }+}++fn package_version(path: impl AsRef<Path>) -> TestResult<String> {+ let package_json: Value = serde_json::from_str(&fs::read_to_string(path)?)?;+ package_json+ .get("version")+ .or_else(|| {+ package_json+ .get("devDependencies")+ .and_then(|deps| deps.get("@electric-sql/pglite-socket"))+ })+ .and_then(Value::as_str)+ .map(|version| version.trim_start_matches('=').to_string())+ .ok_or_else(|| "missing @electric-sql/pglite-socket version".into())+}++fn install_error() -> Box<dyn std::error::Error> {+ "PGlite is not installed. Run `npm ci --prefix rust/apps/cli/tests/pglite` from the repository root.".into()+}++fn wait_for_pglite(process: &mut ChildProcess, port: u16) -> TestResult {+ let deadline = Instant::now() + Duration::from_secs(30);+ loop {+ process.ensure_running()?;+ if TcpStream::connect((LOCAL_HOST, port)).is_ok() {+ return Ok(());+ }+ if Instant::now() >= deadline {+ return Err(format!("PGlite did not start on {LOCAL_HOST}:{port}").into());+ }+ std::thread::sleep(Duration::from_millis(200));+ }+}diff --git a/rust/apps/cli/tests/support/process.rs b/rust/apps/cli/tests/support/process.rsnew file mode 100644index 0000000000..26189a839f--- /dev/null+++ b/rust/apps/cli/tests/support/process.rs@@ -0,0 +1,67 @@+use std::{+ fs::{self, File, OpenOptions},+ path::{Path, PathBuf},+ process::{Child, Command, Stdio},+};++use super::TestResult;++pub struct ChildProcess {+ name: &'static str,+ child: Child,+ log_path: PathBuf,+}++impl ChildProcess {+ pub fn spawn(name: &'static str, command: &mut Command, log_dir: &Path) -> TestResult<Self> {+ fs::create_dir_all(log_dir)?;+ let log_path = log_dir.join(format!("{name}.log"));+ let log = OpenOptions::new()+ .create(true)+ .append(true)+ .open(&log_path)?;+ let child = command+ .stdout(Stdio::from(clone_file(&log)?))+ .stderr(Stdio::from(log))+ .spawn()?;+ Ok(Self {+ name,+ child,+ log_path,+ })+ }++ pub fn ensure_running(&mut self) -> TestResult {+ if let Some(status) = self.child.try_wait()? {+ return Err(format!(+ "{} exited early with {status}\n{}",+ self.name,+ self.log_summary()+ )+ .into());+ }+ Ok(())+ }++ pub fn log_summary(&self) -> String {+ match fs::read_to_string(&self.log_path) {+ Ok(log) => format!("{} log at {}\n{log}", self.name, self.log_path.display()),+ Err(error) => format!(+ "{} log at {} could not be read: {error}",+ self.name,+ self.log_path.display()+ ),+ }+ }+}++impl Drop for ChildProcess {+ fn drop(&mut self) {+ let _ = self.child.kill();+ let _ = self.child.wait();+ }+}++fn clone_file(file: &File) -> TestResult<File> {+ Ok(file.try_clone()?)+}diff --git a/rust/e2e/COVERAGE.md b/rust/e2e/COVERAGE.mdindex bd659195b6..55e972729f 100644--- a/rust/e2e/COVERAGE.md+++ b/rust/e2e/COVERAGE.md@@ -5,7 +5,6 @@ Current suite entrypoint:- [`auth_contacts_e2e`](tests/full_e2e.rs)- [`legacy_contact_recovery_e2e`](tests/full_e2e.rs)- [`legacy_kit_recovery_e2e`](tests/full_e2e.rs)-- [`paste_cli_e2e`](tests/paste_cli_e2e.rs)Shared setup and helpers:@@ -13,7 +12,6 @@ Shared setup and helpers:- auth helpers: [`tests/support/auth.rs`](tests/support/auth.rs)- contacts and legacy-info helpers: [`tests/support/contacts.rs`](tests/support/contacts.rs)- local/CI runner: [`scripts/run.sh`](scripts/run.sh)-- no-Docker paste runner: [`scripts/run-pglite.sh`](scripts/run-pglite.sh)- CI workflow: [`../../.github/workflows/rust-e2e-test.yml`](../../.github/workflows/rust-e2e-test.yml)## Covered Scenarios@@ -34,9 +32,6 @@ Shared setup and helpers:| Legacy | trusted contact stops recovery and both recovery-session views clear | [`run_legacy_stop_stage`](tests/full_e2e.rs) || Legacy | revoke and re-invite trusted contact back to accepted state | [`run_legacy_reinvite_stage`](tests/full_e2e.rs) || Legacy | full recovery flow to `READY` after owner approval | [`run_legacy_reset_stage`](tests/full_e2e.rs) |-| Paste | CLI creates a one-time encrypted paste through Museum | [`paste_cli_e2e`](tests/paste_cli_e2e.rs) |-| Paste | CLI consumes and decrypts the paste body | [`paste_cli_e2e`](tests/paste_cli_e2e.rs) |-| Paste | second consume fails with `410 Paste is unavailable` | [`paste_cli_e2e`](tests/paste_cli_e2e.rs) || Recovery | recovered contact changes password through legacy recovery | [`run_legacy_reset_stage`](tests/full_e2e.rs) || Recovery | old password login fails after recovery | [`run_legacy_reset_stage`](tests/full_e2e.rs) || Recovery | new password login succeeds after recovery | [`run_legacy_reset_stage`](tests/full_e2e.rs) |diff --git a/rust/e2e/README.md b/rust/e2e/README.mdindex e13e17685b..ad5dc67aba 100644--- a/rust/e2e/README.md+++ b/rust/e2e/README.md@@ -5,7 +5,6 @@ Rust end-to-end tests that require a live Museum instance belong here.Current server-backed coverage in this crate:- ignored stage tests that reuse shared fixtures inside one test binary: `auth_contacts_e2e`, `legacy_contact_recovery_e2e`, and `legacy_kit_recovery_e2e`-- ignored paste CLI coverage: `paste_cli_e2e`Detailed scenario coverage lives in [`COVERAGE.md`](COVERAGE.md).@@ -23,22 +22,8 @@ That runner:- enables deterministic OTT for `@ente-rust-test.org`- defaults to `http://localhost:18080` to avoid colliding with an already running local Museum on `8080`- waits for `GET /ping`-- builds the `ente-rs` CLI binary- runs this crate's ignored tests-Paste CLI E2E can also run without Docker by using PGlite:--```sh-rust/e2e/scripts/run-pglite.sh-```--That runner:--- starts PGlite in memory through `@electric-sql/pglite-socket`-- starts Museum locally with DB settings pointed at PGlite-- builds the `ente-rs` CLI binary-- defaults `ENTE_E2E_ONLY` to `paste_cli_e2e`-For a compile-only sanity check that does not hit a live server:```sh@@ -57,15 +42,6 @@ To run only one ignored stage:ENTE_E2E_ENDPOINT=http://localhost:8080 cargo test --manifest-path rust/Cargo.toml -p ente-e2e legacy_kit_recovery_e2e -- --ignored --nocapture```-For a paste CLI run against an already-running server, build the CLI and pass its path:--```sh-cargo build --manifest-path rust/Cargo.toml -p ente-rs --bin ente-rs-ENTE_E2E_ENDPOINT=http://localhost:8080 \-ENTE_E2E_CLI_BIN=rust/target/debug/ente-rs \-cargo test --manifest-path rust/Cargo.toml -p ente-e2e paste_cli_e2e -- --ignored --nocapture-```-To skip or select stages during a full ignored run:```shdiff --git a/rust/e2e/scripts/run-pglite.sh b/rust/e2e/scripts/run-pglite.shdeleted file mode 100755index 10a588fb14..0000000000--- a/rust/e2e/scripts/run-pglite.sh+++ /dev/null@@ -1,170 +0,0 @@-#!/bin/sh--set -eu--script_dir=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)-e2e_dir=$(CDPATH= cd -- "$script_dir/.." && pwd)-repo_dir=$(CDPATH= cd -- "$e2e_dir/../.." && pwd)-server_dir="$repo_dir/server"-endpoint="${ENTE_E2E_ENDPOINT:-http://localhost:18080}"-paste_origin="${ENTE_E2E_PASTE_ORIGIN:-http://localhost:3008}"-pglite_port="${ENTE_E2E_PGLITE_PORT:-15432}"-endpoint_port=$(printf '%s' "$endpoint" | sed -E 's#^https?://[^:]+:([0-9]+).*$#\1#')-tmp_dir=$(mktemp -d "${TMPDIR:-/tmp}/ente-rust-e2e-pglite.XXXXXX")-credentials_yaml="$tmp_dir/credentials.yaml"-pglite_log="$tmp_dir/pglite.log"-museum_log="$tmp_dir/museum.log"-target_dir="${ENTE_E2E_TARGET_DIR:-$repo_dir/rust/target}"-cli_bin="$target_dir/debug/ente-rs"--dump_logs() {- echo "pglite log: $pglite_log" >&2- sed -n '1,240p' "$pglite_log" >&2 || true- echo "museum log: $museum_log" >&2- sed -n '1,240p' "$museum_log" >&2 || true- echo "museum log tail: $museum_log" >&2- tail -n 240 "$museum_log" >&2 || true-}--wait_for_pglite() {- attempt=0- until node -e '-const net = require("node:net");-const socket = net.connect(Number(process.argv[2]), process.argv[1]);-socket.once("connect", () => {- socket.end();- process.exit(0);-});-socket.once("error", () => process.exit(1));-setTimeout(() => process.exit(1), 500);-' 127.0.0.1 "$pglite_port"; do- attempt=$((attempt + 1))- if [ "$attempt" -ge 30 ]; then- echo "PGlite did not start on 127.0.0.1:$pglite_port" >&2- dump_logs- exit 1- fi- if ! kill -0 "$pglite_pid" >/dev/null 2>&1; then- echo "PGlite exited before accepting connections" >&2- dump_logs- exit 1- fi- sleep 1- done-}--cleanup() {- status=$?- if [ -n "${museum_pid:-}" ]; then- kill "$museum_pid" >/dev/null 2>&1 || true- wait "$museum_pid" >/dev/null 2>&1 || true- fi- if [ -n "${pglite_pid:-}" ]; then- kill "$pglite_pid" >/dev/null 2>&1 || true- wait "$pglite_pid" >/dev/null 2>&1 || true- fi- rm -rf "$tmp_dir"- exit "$status"-}--trap cleanup EXIT INT TERM--if [ -z "$endpoint_port" ] || [ "$endpoint_port" = "$endpoint" ]; then- echo "ENTE_E2E_ENDPOINT must include an explicit host port, got: $endpoint" >&2- exit 1-fi--cat >"$credentials_yaml" <<EOF-db:- host: 127.0.0.1- port: $pglite_port- name: postgres- user: postgres- password: ""- sslmode: disable--s3:- are_local_buckets: true- b2-eu-cen:- key: changeme- secret: changeme1234- endpoint: localhost:3200- region: eu-central-2- bucket: b2-eu-cen- wasabi-eu-central-2-v3:- key: changeme- secret: changeme1234- endpoint: localhost:3200- region: eu-central-2- bucket: wasabi-eu-central-2-v3- compliance: false- scw-eu-fr-v3:- key: changeme- secret: changeme1234- endpoint: localhost:3200- region: eu-central-2- bucket: scw-eu-fr-v3-EOF--(- cd "$repo_dir/rust"- cargo build -p ente-rs --target-dir "$target_dir" --bin ente-rs-)--npm exec --yes --package @electric-sql/pglite-socket pglite-server -- \- --db=memory:// \- --host=127.0.0.1 \- --port="$pglite_port" \- --max-connections=20 \- >"$pglite_log" 2>&1 &-pglite_pid=$!-wait_for_pglite--(- cd "$server_dir"- ENTE_CREDENTIALS_FILE="$credentials_yaml" \- ENTE_HTTP_PORT="$endpoint_port" \- ENTE_APPS_PUBLIC_PASTE="$paste_origin" \- ENTE_DB_HOST=127.0.0.1 \- ENTE_DB_PORT="$pglite_port" \- ENTE_DB_NAME=postgres \- ENTE_DB_USER=postgres \- ENTE_DB_PASSWORD="" \- ENTE_DB_SSLMODE=disable \- ENTE_INTERNAL_HARDCODED_OTT_LOCAL_DOMAIN_SUFFIX="@ente-rust-test.org" \- ENTE_INTERNAL_HARDCODED_OTT_LOCAL_DOMAIN_VALUE=123456 \- go run ./cmd/museum-) >"$museum_log" 2>&1 &-museum_pid=$!--attempt=0-until curl -fsS "$endpoint/ping" >/dev/null 2>&1; do- attempt=$((attempt + 1))- if [ "$attempt" -ge 90 ]; then- echo "Museum did not become ready at $endpoint/ping" >&2- dump_logs- exit 1- fi- if ! kill -0 "$pglite_pid" >/dev/null 2>&1; then- echo "PGlite exited before Museum became ready" >&2- dump_logs- exit 1- fi- if ! kill -0 "$museum_pid" >/dev/null 2>&1; then- echo "Museum exited before becoming ready" >&2- dump_logs- exit 1- fi- sleep 2-done--cd "$repo_dir/rust"-export ENTE_E2E_ENDPOINT="$endpoint"-export ENTE_E2E_PASTE_ORIGIN="$paste_origin"-export ENTE_E2E_CLI_BIN="$cli_bin"-export ENTE_E2E_ONLY="${ENTE_E2E_ONLY:-paste_cli_e2e}"--if ! cargo test -p ente-e2e --target-dir "$target_dir" "$@" -- --ignored --nocapture; then- dump_logs- exit 1-fidiff --git a/rust/e2e/scripts/run.sh b/rust/e2e/scripts/run.shindex dd2e2281ad..80dabb6e7a 100755--- a/rust/e2e/scripts/run.sh+++ b/rust/e2e/scripts/run.sh@@ -11,8 +11,6 @@ museum_yaml="$fixture_dir/museum.yaml"endpoint="${ENTE_E2E_ENDPOINT:-http://localhost:18080}"project_name="${ENTE_E2E_DOCKER_PROJECT:-ente-rust-e2e}"endpoint_port=$(printf '%s' "$endpoint" | sed -E 's#^https?://[^:]+:([0-9]+).*$#\1#')-target_dir="${ENTE_E2E_TARGET_DIR:-$repo_dir/rust/target}"-cli_bin="$target_dir/debug/ente-rs"compose() {docker compose -p "$project_name" -f "$compose_file" "$@"@@ -60,11 +58,8 @@ donecd "$repo_dir/rust"export ENTE_E2E_ENDPOINT="$endpoint"-export ENTE_E2E_CLI_BIN="$cli_bin"-cargo build -p ente-rs --target-dir "$target_dir" --bin ente-rs--if ! cargo test -p ente-e2e --target-dir "$target_dir" "$@" -- --ignored --nocapture; then+if ! cargo test -p ente-e2e "$@" -- --ignored --nocapture; thendump_logsexit 1fidiff --git a/rust/e2e/tests/paste_cli_e2e.rs b/rust/e2e/tests/paste_cli_e2e.rsdeleted file mode 100644index 0b2d42ade9..0000000000--- a/rust/e2e/tests/paste_cli_e2e.rs+++ /dev/null@@ -1,290 +0,0 @@-#[allow(dead_code)]-mod support;--use std::{- io::Write,- path::{Path, PathBuf},- process::{Command, Output, Stdio},-};--use uuid::Uuid;--const STAGE_PASTE_CLI: &str = "paste_cli_e2e";--#[tokio::test]-#[ignore = "requires local Museum at ENTE_E2E_ENDPOINT and ENTE_E2E_CLI_BIN"]-async fn paste_cli_e2e() {- let endpoint = support::endpoint();- if !support::assert_stage_enabled_or_skip(STAGE_PASTE_CLI) {- return;- }- let Some(cli_bin) = cli_bin_or_skip(STAGE_PASTE_CLI) else {- return;- };- if !support::assert_server_or_skip(&endpoint, STAGE_PASTE_CLI).await {- return;- }-- let paste_origin = paste_origin();- let config_dir = TempConfigDir::new();-- full_link_roundtrip(&cli_bin, config_dir.path(), &endpoint, &paste_origin);- token_and_key_roundtrip(&cli_bin, config_dir.path(), &endpoint, &paste_origin);- stdin_roundtrip(&cli_bin, config_dir.path(), &endpoint, &paste_origin);-}--fn full_link_roundtrip(cli_bin: &Path, config_dir: &Path, endpoint: &str, paste_origin: &str) {- let text = unique_text("full-link");- let link = create_paste(cli_bin, config_dir, endpoint, paste_origin, &text);-- let consumed = run_cli_success(- cli_bin,- config_dir,- &["paste", "consume", "--endpoint", endpoint, &link.raw],- );- assert_eq!(consumed, text);-- let second_consume = run_cli(- cli_bin,- config_dir,- &["paste", "consume", "--endpoint", endpoint, &link.raw],- );- assert!(- !second_consume.status.success(),- "second consume unexpectedly succeeded with stdout: {}",- String::from_utf8_lossy(&second_consume.stdout),- );- assert!(- String::from_utf8_lossy(&second_consume.stderr).contains("API error (410)"),- "second consume should fail with 410, got stderr: {}",- String::from_utf8_lossy(&second_consume.stderr),- );-}--fn token_and_key_roundtrip(cli_bin: &Path, config_dir: &Path, endpoint: &str, paste_origin: &str) {- let text = unique_text("token-key");- let link = create_paste(cli_bin, config_dir, endpoint, paste_origin, &text);-- let consumed = run_cli_success(- cli_bin,- config_dir,- &[- "paste",- "consume",- "--endpoint",- endpoint,- "--key",- &link.key,- &link.token,- ],- );- assert_eq!(consumed, text);-}--fn stdin_roundtrip(cli_bin: &Path, config_dir: &Path, endpoint: &str, paste_origin: &str) {- let text = format!(- "paste stdin scenario {}\n\nsecond line stays intact\n",- Uuid::new_v4()- );- let link = run_cli_with_stdin_success(- cli_bin,- config_dir,- &[- "paste",- "create",- "--endpoint",- endpoint,- "--paste-origin",- paste_origin,- ],- &text,- );- let link = PasteLink::parse(link.trim(), paste_origin);-- let consumed = run_cli_success(- cli_bin,- config_dir,- &["paste", "consume", "--endpoint", endpoint, &link.raw],- );- assert_eq!(consumed, text);-}--fn create_paste(- cli_bin: &Path,- config_dir: &Path,- endpoint: &str,- paste_origin: &str,- text: &str,-) -> PasteLink {- let link = run_cli_success(- cli_bin,- config_dir,- &[- "paste",- "create",- "--endpoint",- endpoint,- "--paste-origin",- paste_origin,- text,- ],- );- PasteLink::parse(link.trim(), paste_origin)-}--fn unique_text(scope: &str) -> String {- format!("paste cli {scope} scenario {}", Uuid::new_v4())-}--struct PasteLink {- raw: String,- token: String,- key: String,-}--impl PasteLink {- fn parse(raw: &str, expected_origin: &str) -> Self {- let url = reqwest::Url::parse(raw).unwrap_or_else(|error| {- panic!("invalid paste link {raw}: {error}");- });- let actual_origin = url.origin().ascii_serialization();- let expected_origin = reqwest::Url::parse(expected_origin)- .expect("expected paste origin should be a URL")- .origin()- .ascii_serialization();- let token = url- .path_segments()- .and_then(|mut segments| segments.rfind(|segment| !segment.is_empty()))- .expect("paste link should include an access token")- .to_string();- let key = url- .fragment()- .expect("paste link should include a decryption key fragment")- .to_string();-- assert_eq!(- actual_origin, expected_origin,- "paste link used unexpected origin: {raw}",- );- assert!(- key.len() == 12 && key.bytes().all(|byte| byte.is_ascii_alphanumeric()),- "paste link key has unexpected format: {key}",- );- assert!(!token.is_empty(), "paste link token is empty: {raw}");-- Self {- raw: raw.to_string(),- token,- key,- }- }-}--fn cli_bin_or_skip(test_name: &str) -> Option<PathBuf> {- let path = match std::env::var_os("ENTE_E2E_CLI_BIN") {- Some(path) => PathBuf::from(path),- None => {- eprintln!("skipping {test_name}: ENTE_E2E_CLI_BIN is not set");- return None;- }- };- if path.is_file() {- Some(path)- } else {- eprintln!(- "skipping {test_name}: ENTE_E2E_CLI_BIN does not point to a file: {}",- path.display()- );- None- }-}--fn paste_origin() -> String {- std::env::var("ENTE_E2E_PASTE_ORIGIN").unwrap_or_else(|_| "http://localhost:3008".to_string())-}--fn run_cli_success(cli_bin: &Path, config_dir: &Path, args: &[&str]) -> String {- let output = run_cli(cli_bin, config_dir, args);- assert!(- output.status.success(),- "ente-rs {} failed\nstatus: {}\nstdout:\n{}\nstderr:\n{}",- args.join(" "),- output.status,- String::from_utf8_lossy(&output.stdout),- String::from_utf8_lossy(&output.stderr),- );- String::from_utf8(output.stdout).expect("ente-rs stdout should be UTF-8")-}--fn run_cli_with_stdin_success(- cli_bin: &Path,- config_dir: &Path,- args: &[&str],- stdin: &str,-) -> String {- let output = run_cli_with_stdin(cli_bin, config_dir, args, stdin);- assert!(- output.status.success(),- "ente-rs {} failed\nstatus: {}\nstdout:\n{}\nstderr:\n{}",- args.join(" "),- output.status,- String::from_utf8_lossy(&output.stdout),- String::from_utf8_lossy(&output.stderr),- );- String::from_utf8(output.stdout).expect("ente-rs stdout should be UTF-8")-}--fn run_cli(cli_bin: &Path, config_dir: &Path, args: &[&str]) -> Output {- Command::new(cli_bin)- .args(args)- .env("ENTE_CLI_CONFIG_DIR", config_dir)- .env("NO_PROXY", "127.0.0.1,localhost")- .env("no_proxy", "127.0.0.1,localhost")- .output()- .expect("failed to spawn ente-rs")-}--fn run_cli_with_stdin(cli_bin: &Path, config_dir: &Path, args: &[&str], stdin: &str) -> Output {- let mut child = Command::new(cli_bin)- .args(args)- .env("ENTE_CLI_CONFIG_DIR", config_dir)- .env("NO_PROXY", "127.0.0.1,localhost")- .env("no_proxy", "127.0.0.1,localhost")- .stdin(Stdio::piped())- .stdout(Stdio::piped())- .stderr(Stdio::piped())- .spawn()- .expect("failed to spawn ente-rs");-- child- .stdin- .take()- .expect("ente-rs stdin should be piped")- .write_all(stdin.as_bytes())- .expect("failed to write ente-rs stdin");- child- .wait_with_output()- .expect("failed to wait for ente-rs")-}--struct TempConfigDir {- path: PathBuf,-}--impl TempConfigDir {- fn new() -> Self {- let path = std::env::temp_dir().join(format!("ente-rs-paste-cli-e2e-{}", Uuid::new_v4()));- std::fs::create_dir_all(&path).expect("failed to create temporary CLI config directory");- Self { path }- }-- fn path(&self) -> &Path {- &self.path- }-}--impl Drop for TempConfigDir {- fn drop(&mut self) {- let _ = std::fs::remove_dir_all(&self.path);- }-}