Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

Tidy the ente-test-support API and switch test emails to example.org

Manav Rathi971787e61e11
diff --git a/rust/crates/test-support/src/lib.rs b/rust/crates/test-support/src/lib.rs
index 16e3a1bc49..bf156631c1 100644
--- a/rust/crates/test-support/src/lib.rs
+++ b/rust/crates/test-support/src/lib.rs
@@ -2,6 +2,8 @@
//!
//! [`Museum`] spins up a local Museum server backed by a temporary local
//! Postgres ([postgresql_embedded]). See the crate README for requirements.
+//!
+//! [postgresql_embedded]: https://crates.io/crates/postgresql_embedded
mod museum;
mod postgres;
@@ -14,7 +16,16 @@ pub type TestResult<T = ()> = Result<T, Box<dyn std::error::Error>>;
const LOCAL_HOST: &str = "127.0.0.1";
-/// Museum is configured to accept this OTT for `HARDCODED_OTT_EMAIL_SUFFIX`
-/// addresses, letting tests verify emails without an email inbox.
+/// Museum accepts [`HARDCODED_OTT`] as the email verification code for any
+/// address ending in [`HARDCODED_OTT_EMAIL_SUFFIX`], so tests can sign up and
+/// log in without an email inbox.
pub const HARDCODED_OTT: &str = "123456";
-pub const HARDCODED_OTT_EMAIL_SUFFIX: &str = "@ente-rust-test.org";
+
+/// See [`HARDCODED_OTT`].
+pub const HARDCODED_OTT_EMAIL_SUFFIX: &str = "@example.org";
+
+fn free_port() -> TestResult<u16> {
+ Ok(std::net::TcpListener::bind((LOCAL_HOST, 0))?
+ .local_addr()?
+ .port())
+}
diff --git a/rust/crates/test-support/src/museum.rs b/rust/crates/test-support/src/museum.rs
index 36f9da3427..5f57b1897f 100644
--- a/rust/crates/test-support/src/museum.rs
+++ b/rust/crates/test-support/src/museum.rs
@@ -1,15 +1,19 @@
use std::{
fs,
- net::TcpListener,
path::{Path, PathBuf},
};
use uuid::Uuid;
-use crate::{LOCAL_HOST, TestResult, postgres, process::ChildProcess, server};
+use crate::{LOCAL_HOST, TestResult, free_port, postgres, process::ChildProcess, server};
+/// A running Museum for integration tests, backed by a temporary Postgres.
+///
+/// Created with [`Museum::run`], which boots both, runs the test, and tears
+/// everything down on drop. The temporary directory is removed unless the test
+/// fails, in which case it is retained for inspection.
pub struct Museum {
- _museum: ChildProcess,
+ _server: ChildProcess,
_postgres: postgres::Postgres,
temp_dir: TempDir,
endpoint: String,
@@ -17,17 +21,21 @@ pub struct Museum {
}
impl Museum {
+ /// Boot a Museum, run `test` against it, then tear everything down.
+ ///
+ /// On failure the temporary directory is retained (its path is printed to
+ /// stderr) so the museum and Postgres logs can be inspected.
pub fn run(test: impl FnOnce(&Self) -> TestResult) -> TestResult {
let mut museum = Self::start()?;
let result = test(&museum);
if result.is_err() {
- museum.retain_temp_dir();
+ museum.temp_dir.retain();
}
result
}
- pub fn start() -> TestResult<Self> {
- let paths = Paths::discover()?;
+ fn start() -> TestResult<Self> {
+ let server_dir = server_dir()?;
let mut temp_dir = TempDir::new("ente-test")?;
let log_dir = temp_dir.path().join("logs");
let museum_port = free_port()?;
@@ -38,17 +46,17 @@ impl Museum {
let result = (|| {
server::write_config(&museum_config_file, museum_port, &paste_origin)?;
let postgres = postgres::start()?;
- let museum = server::start(
- &paths.server_dir,
+ let server = server::start(
+ &server_dir,
&log_dir,
&museum_config_file,
museum_port,
&postgres,
)?;
- Ok((postgres, museum))
+ Ok((postgres, server))
})();
- let (postgres, museum) = match result {
+ let (postgres, server) = match result {
Ok(processes) => processes,
Err(error) => {
temp_dir.retain();
@@ -57,7 +65,7 @@ impl Museum {
};
Ok(Self {
- _museum: museum,
+ _server: server,
_postgres: postgres,
temp_dir,
endpoint,
@@ -65,40 +73,31 @@ impl Museum {
})
}
+ /// The base URL of the running Museum, e.g. `http://127.0.0.1:1234`.
pub fn endpoint(&self) -> &str {
&self.endpoint
}
+ /// The origin Museum uses when generating public paste links.
pub fn paste_origin(&self) -> &str {
&self.paste_origin
}
+ /// A scratch directory tied to this Museum's lifetime, for test-local files.
pub fn temp_dir(&self) -> &Path {
self.temp_dir.path()
}
-
- pub fn retain_temp_dir(&mut self) {
- self.temp_dir.retain();
- }
}
-struct Paths {
- server_dir: PathBuf,
-}
-
-impl Paths {
- fn discover() -> TestResult<Self> {
- let crate_dir = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
- let repo_dir = crate_dir
- .parent()
- .and_then(Path::parent)
- .and_then(Path::parent)
- .ok_or("failed to resolve repository directory")?;
-
- Ok(Self {
- server_dir: repo_dir.join("server"),
- })
- }
+/// The repository's `server/` directory, which Museum is run from.
+fn server_dir() -> TestResult<PathBuf> {
+ let crate_dir = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
+ let repo_dir = crate_dir
+ .parent()
+ .and_then(Path::parent)
+ .and_then(Path::parent)
+ .ok_or("failed to resolve repository directory")?;
+ Ok(repo_dir.join("server"))
}
struct TempDir {
@@ -136,7 +135,3 @@ impl Drop for TempDir {
}
}
}
-
-fn free_port() -> TestResult<u16> {
- Ok(TcpListener::bind((LOCAL_HOST, 0))?.local_addr()?.port())
-}
diff --git a/rust/crates/test-support/src/postgres.rs b/rust/crates/test-support/src/postgres.rs
index 95113a0821..644701f8cd 100644
--- a/rust/crates/test-support/src/postgres.rs
+++ b/rust/crates/test-support/src/postgres.rs
@@ -1,9 +1,7 @@
-use std::net::TcpListener;
-
use postgresql_embedded::Settings;
use postgresql_embedded::blocking::PostgreSQL;
-use crate::{LOCAL_HOST, TestResult};
+use crate::{LOCAL_HOST, TestResult, free_port};
const DATABASE: &str = "ente";
@@ -47,7 +45,3 @@ pub fn start() -> TestResult<Postgres> {
inner.create_database(DATABASE)?;
Ok(Postgres { inner })
}
-
-fn free_port() -> TestResult<u16> {
- Ok(TcpListener::bind((LOCAL_HOST, 0))?.local_addr()?.port())
-}
diff --git a/rust/crates/test-support/src/server.rs b/rust/crates/test-support/src/server.rs
index 048914eb6c..23c08b57a4 100644
--- a/rust/crates/test-support/src/server.rs
+++ b/rust/crates/test-support/src/server.rs
@@ -53,6 +53,7 @@ apps:
public-paste: "{paste_origin}"
s3:
+ # Museum requires S3 credentials at boot; no current test exercises object storage.
are_local_buckets: true
b2-eu-cen:
key: changeme
diff --git a/rust/e2e/tests/full_e2e.rs b/rust/e2e/tests/full_e2e.rs
index 0ccb5865b7..8530820421 100644
--- a/rust/e2e/tests/full_e2e.rs
+++ b/rust/e2e/tests/full_e2e.rs
@@ -469,7 +469,7 @@ async fn run_legacy_kit_stage(endpoint: &str, owner: &mut legacy_kit::LegacyKitO
kit_id: waiting_kit.kit.id.clone(),
challenge: invalid_challenge.encrypted_challenge,
used_part_indexes: None,
- email: Some("[email protected]".into()),
+ email: Some("[email protected]".into()),
})
.send()
.await
@@ -532,7 +532,7 @@ async fn run_legacy_kit_stage(endpoint: &str, owner: &mut legacy_kit::LegacyKitO
.open_from_encrypted_challenge(
&downloaded_shares[0..2],
&first_waiting_challenge.encrypted_challenge,
)
.await
.expect("legacy kit waiting recovery open failed");
@@ -662,10 +662,7 @@ async fn run_legacy_kit_stage(endpoint: &str, owner: &mut legacy_kit::LegacyKitO
.await
.expect("immediate legacy kit create failed");
let ready_handle = recovery_client
- .open_from_shares(
- &immediate_kit.shares[0..2],
- )
+ .open_from_shares(&immediate_kit.shares[0..2], Some("[email protected]"))
.await
.expect("immediate legacy kit recovery open failed");
assert_eq!(