Skip to content

armgit / ente

Public Imported from GitHub
0

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

Use the shared HTTP client in Contacts and Space tests

Manav Rathi4f81bba2b931
diff --git a/rust/Cargo.lock b/rust/Cargo.lock
index 20606f6df2..37fc44209e 100644
--- a/rust/Cargo.lock
+++ b/rust/Cargo.lock
@@ -2447,7 +2447,6 @@ dependencies = [
"hmac 0.13.0",
"md-5 0.11.0",
"mockito",
- "reqwest 0.12.28",
"serde",
"serde_json",
"sha1 0.11.0",
@@ -2830,7 +2829,6 @@ dependencies = [
"log",
"md-5 0.11.0",
"mockito",
- "reqwest 0.12.28",
"serde",
"serde_json",
"thiserror 2.0.18",
diff --git a/rust/checks/dependency-boundaries/check.mjs b/rust/checks/dependency-boundaries/check.mjs
index 98a4c5d0a6..679cc01414 100644
--- a/rust/checks/dependency-boundaries/check.mjs
+++ b/rust/checks/dependency-boundaries/check.mjs
@@ -35,9 +35,9 @@ for (const pkg of metadata.packages) {
const manifest = pathFromRoot(pkg.manifest_path);
if (httpOwners.has(manifest)) continue;
for (const dependency of pkg.dependencies) {
- if (dependency.name !== "reqwest" || dependency.kind === "dev") continue;
+ if (dependency.name !== "reqwest") continue;
console.error(
- `${manifest}: use ente-core::http instead of a production reqwest dependency`,
+ `${manifest}: use ente-core::http instead of a direct reqwest dependency`,
);
process.exitCode = 1;
}
diff --git a/rust/checks/dependency-boundaries/test.mjs b/rust/checks/dependency-boundaries/test.mjs
index 8f1f2f3973..6a7c399e03 100644
--- a/rust/checks/dependency-boundaries/test.mjs
+++ b/rust/checks/dependency-boundaries/test.mjs
@@ -51,17 +51,16 @@ assert.equal(result.stderr, "");
for (const dependencyKind of [
"dependencies",
+ "dev-dependencies",
"build-dependencies",
`target.'cfg(target_arch = "wasm32")'.dependencies`,
+ `target.'cfg(target_arch = "wasm32")'.dev-dependencies`,
]) {
result = run({ framework: "reqwest", dependencyKind });
assert.equal(result.status, 1, result.stderr);
- assert.match(result.stderr, /use ente-core::http instead of a production reqwest dependency/);
+ assert.match(result.stderr, /use ente-core::http instead of a direct reqwest dependency/);
}
-result = run({ framework: "reqwest" });
-assert.equal(result.status, 0, result.stderr);
-
result = run({ framework: "reqwest", bindingDependencyKind: "dependencies" });
assert.equal(result.status, 1, result.stderr);
assert.match(result.stderr, /rust\/bindings\/wasm\/lib\/Cargo\.toml: use ente-core::http/);
diff --git a/rust/crates/contacts/Cargo.toml b/rust/crates/contacts/Cargo.toml
index 470ccb696e..e69bd6d83b 100644
--- a/rust/crates/contacts/Cargo.toml
+++ b/rust/crates/contacts/Cargo.toml
@@ -17,7 +17,6 @@ ente-legacy.workspace = true
ente-test-support.workspace = true
hmac.workspace = true
mockito.workspace = true
-reqwest = { workspace = true, features = ["json"] }
serde_json.workspace = true
sha1.workspace = true
tokio = { workspace = true, features = ["macros", "rt-multi-thread", "time"] }
diff --git a/rust/crates/contacts/tests/contacts.rs b/rust/crates/contacts/tests/contacts.rs
index f19798f915..a23c69a7d3 100644
--- a/rust/crates/contacts/tests/contacts.rs
+++ b/rust/crates/contacts/tests/contacts.rs
@@ -345,10 +345,10 @@ async fn run_legacy_reset_stage(endpoint: &str, pair: &mut legacy::LegacyPair) {
async fn run_legacy_kit_stage(endpoint: &str, owner: &mut legacy_kit::LegacyKitOwner) {
let recovery_client = LegacyKitRecoveryClient::new(endpoint).expect("legacy kit client");
- let public_client = reqwest::Client::new();
+ let public_client = http::Http::new().expect("HTTP client");
let missing_notice_period = public_client
- .post(format!("{endpoint}/legacy-kits"))
- .header("X-Auth-Token", owner.owner.auth_token.clone())
+ .post(&format!("{endpoint}/legacy-kits"))
+ .header("X-Auth-Token", &owner.owner.auth_token)
.header("X-Client-Package", CLIENT_PACKAGE)
.json(&json!({
"id": Uuid::new_v4().to_string(),
@@ -360,14 +360,11 @@ async fn run_legacy_kit_stage(endpoint: &str, owner: &mut legacy_kit::LegacyKitO
.send()
.await
.expect("legacy kit missing notice period request failed");
- assert_eq!(
- missing_notice_period.status(),
- reqwest::StatusCode::BAD_REQUEST
- );
+ assert_eq!(missing_notice_period.status(), 400);
let invalid_create = public_client
- .post(format!("{endpoint}/legacy-kits"))
- .header("X-Auth-Token", owner.owner.auth_token.clone())
+ .post(&format!("{endpoint}/legacy-kits"))
+ .header("X-Auth-Token", &owner.owner.auth_token)
.header("X-Client-Package", CLIENT_PACKAGE)
.json(&CreateLegacyKitRequest {
id: Uuid::new_v4().to_string(),
@@ -380,7 +377,7 @@ async fn run_legacy_kit_stage(endpoint: &str, owner: &mut legacy_kit::LegacyKitO
.send()
.await
.expect("legacy kit invalid create request failed");
- assert_eq!(invalid_create.status(), reqwest::StatusCode::BAD_REQUEST);
+ assert_eq!(invalid_create.status(), 400);
let waiting_kit = ente_legacy::create_kit(
&owner.owner_session,
@@ -415,25 +412,21 @@ async fn run_legacy_kit_stage(endpoint: &str, owner: &mut legacy_kit::LegacyKitO
waiting_kit.shares[1].checksum
);
- let invalid_challenge = public_client
- .post(format!("{endpoint}/legacy-kits/recovery/challenge"))
+ let invalid_challenge: LegacyKitChallengeResponse = public_client
+ .post(&format!("{endpoint}/legacy-kits/recovery/challenge"))
.json(&LegacyKitChallengeRequest {
kit_id: waiting_kit.kit.id.clone(),
})
.send()
.await
- .expect("legacy kit challenge request failed");
- assert!(
- invalid_challenge.status().is_success(),
- "challenge request should succeed, got {}",
- invalid_challenge.status()
- );
- let invalid_challenge: LegacyKitChallengeResponse = invalid_challenge
+ .expect("legacy kit challenge request failed")
+ .error_for_status()
+ .expect("legacy kit challenge should succeed")
.json()
.await
.expect("legacy kit challenge response decode failed");
let invalid_open = public_client
- .post(format!("{endpoint}/legacy-kits/recovery/open"))
+ .post(&format!("{endpoint}/legacy-kits/recovery/open"))
.json(&LegacyKitOpenRecoveryRequest {
kit_id: waiting_kit.kit.id.clone(),
challenge: invalid_challenge.encrypted_challenge,
@@ -443,7 +436,7 @@ async fn run_legacy_kit_stage(endpoint: &str, owner: &mut legacy_kit::LegacyKitO
.send()
.await
.expect("legacy kit invalid recovery open request failed");
- assert_eq!(invalid_open.status(), reqwest::StatusCode::BAD_REQUEST);
+ assert_eq!(invalid_open.status(), 400);
let listed_after_invalid_open = ente_legacy::kits(&owner.owner_session)
.await
@@ -459,38 +452,30 @@ async fn run_legacy_kit_stage(endpoint: &str, owner: &mut legacy_kit::LegacyKitO
"invalid challenge must not create a recovery session"
);
- let first_waiting_challenge = public_client
- .post(format!("{endpoint}/legacy-kits/recovery/challenge"))
+ let first_waiting_challenge: LegacyKitChallengeResponse = public_client
+ .post(&format!("{endpoint}/legacy-kits/recovery/challenge"))
.json(&LegacyKitChallengeRequest {
kit_id: waiting_kit.kit.id.clone(),
})
.send()
.await
- .expect("first waiting legacy kit challenge request failed");
- assert!(
- first_waiting_challenge.status().is_success(),
- "first waiting challenge request should succeed, got {}",
- first_waiting_challenge.status()
- );
- let first_waiting_challenge: LegacyKitChallengeResponse = first_waiting_challenge
+ .expect("first waiting legacy kit challenge request failed")
+ .error_for_status()
+ .expect("first waiting challenge should succeed")
.json()
.await
.expect("first waiting challenge response decode failed");
- let second_waiting_challenge = public_client
- .post(format!("{endpoint}/legacy-kits/recovery/challenge"))
+ let second_waiting_challenge: LegacyKitChallengeResponse = public_client
+ .post(&format!("{endpoint}/legacy-kits/recovery/challenge"))
.json(&LegacyKitChallengeRequest {
kit_id: waiting_kit.kit.id.clone(),
})
.send()
.await
- .expect("second waiting legacy kit challenge request failed");
- assert!(
- second_waiting_challenge.status().is_success(),
- "second waiting challenge request should succeed, got {}",
- second_waiting_challenge.status()
- );
- let second_waiting_challenge: LegacyKitChallengeResponse = second_waiting_challenge
+ .expect("second waiting legacy kit challenge request failed")
+ .error_for_status()
+ .expect("second waiting challenge should succeed")
.json()
.await
.expect("second waiting challenge response decode failed");
diff --git a/rust/crates/space/Cargo.toml b/rust/crates/space/Cargo.toml
index b900aa6178..16389ea5aa 100644
--- a/rust/crates/space/Cargo.toml
+++ b/rust/crates/space/Cargo.toml
@@ -21,7 +21,6 @@ zeroize.workspace = true
ente-accounts.workspace = true
ente-test-support.workspace = true
mockito.workspace = true
-reqwest = { workspace = true, features = ["json"] }
tokio = { workspace = true, features = ["macros", "rt-multi-thread"] }
uuid = { workspace = true, features = ["v4"] }
diff --git a/rust/crates/space/tests/support/space.rs b/rust/crates/space/tests/support/space.rs
index 9ff5fed369..c7d3e48a0a 100644
--- a/rust/crates/space/tests/support/space.rs
+++ b/rust/crates/space/tests/support/space.rs
@@ -21,20 +21,17 @@ struct SpaceEntityKeyResponse {
pub async fn open_ctx(endpoint: &str, account: &TestAccount) -> AccountSpaceCtx {
let space_root_key = ensure_space_root_key(endpoint, account).await;
- let session = reqwest::Client::new()
- .post(format!("{endpoint}/account/space/sessions"))
+ let session = http::Http::new()
+ .expect("HTTP client")
+ .post(&format!("{endpoint}/account/space/sessions"))
.header("X-Auth-Token", &account.auth_token)
.header("X-Client-Package", CLIENT_PACKAGE)
.json(&serde_json::json!({ "sessionWrapKey": b64::encode(Key::generate().as_bytes()) }))
.send()
.await
- .expect("space session create request failed");
- assert!(
- session.status().is_success(),
- "space session create failed with HTTP {}",
- session.status()
- );
- let session = session
+ .expect("space session create request failed")
+ .error_for_status()
+ .expect("space session create should succeed")
.json::<SpaceBrowserSessionResponse>()
.await
.expect("space session create response parse failed");
@@ -57,8 +54,9 @@ async fn ensure_space_root_key(endpoint: &str, account: &TestAccount) -> Vec<u8>
let encrypted = secretbox::encrypt_combined(&candidate, &master_key);
let (header, encrypted_key) = encrypted.split_at(Nonce::BYTES);
- let response = reqwest::Client::new()
- .post(format!("{endpoint}/user-entity/key/ensure"))
+ let ensured = http::Http::new()
+ .expect("HTTP client")
+ .post(&format!("{endpoint}/user-entity/key/ensure"))
.header("X-Auth-Token", &account.auth_token)
.header("X-Client-Package", CLIENT_PACKAGE)
.json(&serde_json::json!({
@@ -68,13 +66,9 @@ async fn ensure_space_root_key(endpoint: &str, account: &TestAccount) -> Vec<u8>
}))
.send()
.await
- .expect("space entity key ensure request failed");
- assert!(
- response.status().is_success(),
- "space entity key ensure failed with HTTP {}",
- response.status()
- );
- let ensured = response
+ .expect("space entity key ensure request failed")
+ .error_for_status()
+ .expect("space entity key ensure should succeed")
.json::<SpaceEntityKeyResponse>()
.await
.expect("space entity key ensure response parse failed");