π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Add paste CLI e2e test
Manav Rathie6524405c7d3
diff --git a/rust/e2e/COVERAGE.md b/rust/e2e/COVERAGE.mdindex 55e972729f..bd659195b6 100644--- a/rust/e2e/COVERAGE.md+++ b/rust/e2e/COVERAGE.md@@ -5,6 +5,7 @@ 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:@@ -12,6 +13,7 @@ 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@@ -32,6 +34,9 @@ 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 ad5dc67aba..e13e17685b 100644--- a/rust/e2e/README.md+++ b/rust/e2e/README.md@@ -5,6 +5,7 @@ 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).@@ -22,8 +23,22 @@ 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@@ -42,6 +57,15 @@ 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.shnew file mode 100755index 0000000000..10a588fb14--- /dev/null+++ b/rust/e2e/scripts/run-pglite.sh@@ -0,0 +1,170 @@+#!/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 80dabb6e7a..dd2e2281ad 100755--- a/rust/e2e/scripts/run.sh+++ b/rust/e2e/scripts/run.sh@@ -11,6 +11,8 @@ 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" "$@"@@ -58,8 +60,11 @@ donecd "$repo_dir/rust"export ENTE_E2E_ENDPOINT="$endpoint"+export ENTE_E2E_CLI_BIN="$cli_bin"-if ! cargo test -p ente-e2e "$@" -- --ignored --nocapture; then+cargo build -p ente-rs --target-dir "$target_dir" --bin ente-rs++if ! cargo test -p ente-e2e --target-dir "$target_dir" "$@" -- --ignored --nocapture; thendump_logsexit 1fidiff --git a/rust/e2e/tests/paste_cli_e2e.rs b/rust/e2e/tests/paste_cli_e2e.rsnew file mode 100644index 0000000000..e28528e57b--- /dev/null+++ b/rust/e2e/tests/paste_cli_e2e.rs@@ -0,0 +1,145 @@+#[allow(dead_code)]+mod support;++use std::{+ path::{Path, PathBuf},+ process::{Command, Output},+};++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();+ let text = format!("hello from paste cli e2e {}", Uuid::new_v4());++ let link = run_cli_success(+ &cli_bin,+ config_dir.path(),+ &[+ "paste",+ "create",+ "--endpoint",+ &endpoint,+ "--paste-origin",+ &paste_origin,+ &text,+ ],+ );+ let link = link.trim();++ assert!(+ link.starts_with(&format!("{}/", paste_origin.trim_end_matches('/'))),+ "paste link used unexpected origin: {link}",+ );+ assert!(+ link.contains('#'),+ "paste link should carry its decryption key in the URL fragment: {link}",+ );++ let consumed = run_cli_success(+ &cli_bin,+ config_dir.path(),+ &["paste", "consume", "--endpoint", &endpoint, link],+ );+ assert_eq!(consumed, text);++ let second_consume = run_cli(+ &cli_bin,+ config_dir.path(),+ &["paste", "consume", "--endpoint", &endpoint, link],+ );+ 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 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(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")+}++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);+ }+}