π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Tighten replacement CLI requests and state updates
Manav Rathi2f0479e04105
diff --git a/rust/apps/cli-next/src/api.rs b/rust/apps/cli-next/src/api.rsindex 1d12add272..b87a4d32b9 100644--- a/rust/apps/cli-next/src/api.rs+++ b/rust/apps/cli-next/src/api.rs@@ -10,6 +10,7 @@ use ente_core::{use reqwest::{Client, Method,header::{HeaderMap, HeaderName, HeaderValue},+ redirect::Policy,};use url::Url;use zeroize::Zeroizing;@@ -27,6 +28,7 @@ pub fn http() -> Result<Client> {.user_agent(USER_AGENT).connect_timeout(Duration::from_secs(15)).read_timeout(Duration::from_secs(30))+ .redirect(Policy::none()).build()?)}@@ -109,9 +111,8 @@ pub async fn raw(account: &Account, product: Product, args: ApiArgs) -> Result<(HeaderValue::from_static(product.client_package()),);}- let mut request = http()?- .request(Method::from_bytes(args.method.as_bytes())?, url)- .headers(headers);+ let method = Method::from_bytes(args.method.to_ascii_uppercase().as_bytes())?;+ let mut request = http()?.request(method, url).headers(headers);if let Some(path) = args.body {request = request.body(read_input(&path)?.to_vec());}diff --git a/rust/apps/cli-next/src/login.rs b/rust/apps/cli-next/src/login.rsindex cd733bece0..a9e57dc3f5 100644--- a/rust/apps/cli-next/src/login.rs+++ b/rust/apps/cli-next/src/login.rs@@ -41,6 +41,9 @@ pub async fn login(};let credentials = args.input.as_deref().map(Credentials::read).transpose()?;let vault = Vault::open()?;+ if let Some(name) = args.name.as_deref() {+ vault.state.check_name(name)?;+ }let (expected, origin) = match target {Target::Existing(name) => {let account = &vault.state.accounts[vault.state.named(name)?];diff --git a/rust/apps/cli-next/src/main.rs b/rust/apps/cli-next/src/main.rsindex 8be29a3513..4a7096879b 100644--- a/rust/apps/cli-next/src/main.rs+++ b/rust/apps/cli-next/src/main.rs@@ -156,8 +156,11 @@ async fn account_command(command: AccountCommand, json_output: bool) -> Result<(let mut vault = Vault::open()?;let state = &mut vault.state;let index = state.named(&name)?;- state.selected = Some(state.accounts[index].storage_id);- vault.save()?;+ let selected = Some(state.accounts[index].storage_id);+ if state.selected != selected {+ state.selected = selected;+ vault.save()?;+ }output_account(vault.into_state(), index, json_output)}AccountCommand::Rename { name, new_name } => {diff --git a/rust/apps/cli-next/tests/cli.rs b/rust/apps/cli-next/tests/cli.rsindex bc4e5d5c11..437a40228a 100644--- a/rust/apps/cli-next/tests/cli.rs+++ b/rust/apps/cli-next/tests/cli.rs@@ -237,7 +237,7 @@ fn vault_schema_version_is_checked_after_decryption() {}#[tokio::test]-async fn raw_api_preserves_requests_and_responses_without_leaking_credentials() {+async fn raw_api_preserves_requests_and_responses() {let mut origin = mockito::Server::new_async().await;let home = TestHome::new();home.seed(&origin.url());@@ -268,13 +268,12 @@ async fn raw_api_preserves_requests_and_responses_without_leaking_credentials().match_header("x-auth-token", secret).match_header("x-client-package", "io.ente.photos").with_body(body)- .expect(2)+ .expect(1).create_async().await;- assert_eq!(- success(home.run(&["photos", "api", "/local", "--json"])).stdout,- body- );+ let output = home.run(&["photos", "api", "/local"]);+ assert!(failure(&output).contains("HTTP 307 Temporary Redirect"));+ assert!(output.stdout.is_empty());assert_eq!(success(home.run(&["photos", "api", &format!("{}/bytes", origin.url())])).stdout,body@@ -300,7 +299,7 @@ async fn raw_api_preserves_requests_and_responses_without_leaking_credentials()"api","/request","--method",- "PATCH",+ "patch","--query","label=a & b","--headers",@@ -555,6 +554,8 @@ fn account_updates_preserve_identity_and_selection() {after[..Header::BYTES],"vault rewrite reused its nonce");+ success(home.run(&["account", "switch", "other"]));+ assert_eq!(home.read_encrypted_vault(), after);}struct TestHome {diff --git a/rust/crates/accounts/src/client.rs b/rust/crates/accounts/src/client.rsindex d209618bac..2b31f37571 100644--- a/rust/crates/accounts/src/client.rs+++ b/rust/crates/accounts/src/client.rs@@ -80,6 +80,7 @@ impl AccountsClient {let details: Details = self.api.get("/users/details/v2")+ .query(&[("memoryCount", false)]).send().await?.error_for_code()