Skip to content

armgit / ente

Public Imported from GitHub
0

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

rust/e2e: switch auth helpers to ente-accounts

Neeraj Gupta8b72b10a28c6
diff --git a/rust/e2e/Cargo.lock b/rust/e2e/Cargo.lock
index 0d973f4176..020e4cbfce 100644
--- a/rust/e2e/Cargo.lock
+++ b/rust/e2e/Cargo.lock
@@ -616,6 +616,22 @@ dependencies = [
"cfg-if",
]
+[[package]]
+name = "ente-accounts"
+version = "0.0.1"
+dependencies = [
+ "base64",
+ "ente-core",
+ "log",
+ "serde",
+ "serde_json",
+ "thiserror 2.0.18",
+ "tokio",
+ "urlencoding",
+ "uuid",
+ "zeroize",
+]
+
[[package]]
name = "ente-contacts"
version = "0.0.1"
@@ -660,6 +676,7 @@ name = "ente-e2e"
version = "0.0.1"
dependencies = [
"base64",
+ "ente-accounts",
"ente-contacts",
"ente-core",
"ente-rs",
@@ -681,6 +698,7 @@ dependencies = [
"clap",
"dialoguer",
"dirs",
+ "ente-accounts",
"ente-core",
"env_logger",
"futures",
diff --git a/rust/e2e/Cargo.toml b/rust/e2e/Cargo.toml
index 14126e13f3..5065836106 100644
--- a/rust/e2e/Cargo.toml
+++ b/rust/e2e/Cargo.toml
@@ -6,6 +6,7 @@ publish = false
[dependencies]
ente-rs = { path = "../cli" }
+ente-accounts = { path = "../accounts" }
ente-contacts = { path = "../contacts" }
ente-core = { path = "../core", features = ["srp"] }
tokio = { version = "1", features = ["macros", "rt-multi-thread", "sync", "time"] }
diff --git a/rust/e2e/tests/full_e2e.rs b/rust/e2e/tests/full_e2e.rs
index 9271da4930..62dca0a3f6 100644
--- a/rust/e2e/tests/full_e2e.rs
+++ b/rust/e2e/tests/full_e2e.rs
@@ -2,8 +2,8 @@ mod support;
use ente_contacts::legacy_models::{LegacyContactState, LegacyRecoveryStatus};
use ente_contacts::models::ContactData;
+use ente_accounts::Error as CliError;
use ente_core::http::Error as CoreHttpError;
-use ente_rs::models::error::Error as CliError;
use support::{auth, contacts, legacy};
@@ -242,7 +242,7 @@ async fn run_legacy_reset_stage(endpoint: &str, pair: &legacy::LegacyPair) {
Err(CliError::AuthenticationFailed(message)) => {
assert_eq!(message, "Incorrect password");
}
- Err(CliError::ApiError { status: 401, .. }) => {}
+ Err(error) if error.is_http_status(&[401]) => {}
other => panic!("expected old password login to fail, got {other:?}"),
}
diff --git a/rust/e2e/tests/support/auth.rs b/rust/e2e/tests/support/auth.rs
index d8019d8406..1bd7460772 100644
--- a/rust/e2e/tests/support/auth.rs
+++ b/rust/e2e/tests/support/auth.rs
@@ -1,20 +1,14 @@
use std::time::{Duration, SystemTime, UNIX_EPOCH};
use base64::{Engine, engine::general_purpose::URL_SAFE};
-use ente_core::crypto::SecretVec;
-use ente_rs::{
- api::ApiClient,
- auth_flow::{
- AuthFlow, AuthFlowUi, AuthenticatedAccount, CreateAccountParams, LoginParams, OtpPurpose,
- SecondFactorMethod, SetupTwoFactorParams, TotpPurpose,
- },
- models::{
- account::App,
- error::{Error as CliError, Result as CliResult},
- },
+use ente_accounts::{
+ AccountsClient, AccountsClientConfig, AuthFlow, AuthFlowUi, AuthenticatedAccount,
+ CreateAccountParams, Error as CliError, KeyAttributes, LoginParams, OtpPurpose,
+ Result as CliResult, SecondFactorMethod, SetupTwoFactorParams, TotpPurpose,
};
+use ente_core::crypto::SecretVec;
+use ente_rs::models::account::App;
use hmac::{Hmac, Mac};
-use serde::Deserialize;
use sha1::Sha1;
use zeroize::Zeroizing;
@@ -27,7 +21,7 @@ pub struct TestAccount {
pub user_id: i64,
pub auth_token: String,
pub master_key: Vec<u8>,
- pub key_attributes: ente_rs::api::models::KeyAttributes,
+ pub key_attributes: KeyAttributes,
}
struct TestUi {
@@ -106,21 +100,12 @@ impl AuthFlowUi for TestUi {
}
}
-#[derive(Deserialize)]
-struct TwoFactorStatusResponse {
- status: bool,
-}
-
pub async fn create_account(endpoint: &str, email: String, password: String) -> TestAccount {
- let api = ApiClient::new_with_client_package(
- Some(endpoint.to_string()),
- App::Photos.client_package(),
- )
- .unwrap();
+ let client = accounts_client(endpoint).unwrap();
let mut ui = TestUi::otp_only();
let authenticated = tokio::time::timeout(Duration::from_secs(180), async {
- let mut flow = AuthFlow::new(&api, App::Photos, &mut ui);
+ let mut flow = AuthFlow::new(&client, &mut ui);
flow.create_account(CreateAccountParams {
email: email.clone(),
password: Zeroizing::new(password.clone()),
@@ -160,14 +145,10 @@ async fn login_with_ui<U: AuthFlowUi>(
password: &str,
ui: &mut U,
) -> CliResult<AuthenticatedAccount> {
- let api = ApiClient::new_with_client_package(
- Some(endpoint.to_string()),
- App::Photos.client_package(),
- )
- .unwrap();
+ let client = accounts_client(endpoint)?;
tokio::time::timeout(Duration::from_secs(90), async {
- let mut flow = AuthFlow::new(&api, App::Photos, ui);
+ let mut flow = AuthFlow::new(&client, ui);
flow.login(LoginParams {
email: email.to_string(),
password: Zeroizing::new(password.to_string()),
@@ -179,18 +160,13 @@ async fn login_with_ui<U: AuthFlowUi>(
}
pub async fn enable_totp(endpoint: &str, account: &TestAccount) -> String {
- let api = ApiClient::new_with_client_package(
- Some(endpoint.to_string()),
- App::Photos.client_package(),
- )
- .unwrap();
- api.add_token(&account.email, &account.auth_token);
+ let client = accounts_client(endpoint).unwrap();
+ client.set_auth_token(Some(account.auth_token.clone()));
let mut ui = TestUi::with_totp(None);
let result = tokio::time::timeout(Duration::from_secs(60), async {
- let mut flow = AuthFlow::new(&api, App::Photos, &mut ui);
+ let mut flow = AuthFlow::new(&client, &mut ui);
flow.setup_two_factor(SetupTwoFactorParams {
- account_id: account.email.clone(),
master_key: SecretVec::new(account.master_key.clone()),
key_attributes: Some(account.key_attributes.clone()),
})
@@ -204,23 +180,16 @@ pub async fn enable_totp(endpoint: &str, account: &TestAccount) -> String {
}
pub async fn fetch_two_factor_status(endpoint: &str, account: &TestAccount) -> CliResult<bool> {
- fetch_two_factor_status_with_token(endpoint, &account.email, &account.auth_token).await
+ fetch_two_factor_status_with_token(endpoint, &account.auth_token).await
}
async fn fetch_two_factor_status_with_token(
endpoint: &str,
- account_id: &str,
auth_token: &str,
) -> CliResult<bool> {
- let api = ApiClient::new_with_client_package(
- Some(endpoint.to_string()),
- App::Photos.client_package(),
- )?;
- api.add_token(account_id, auth_token);
- let response: TwoFactorStatusResponse = api
- .get("/users/two-factor/status", Some(account_id))
- .await?;
- Ok(response.status)
+ let client = accounts_client(endpoint)?;
+ client.set_auth_token(Some(auth_token.to_string()));
+ client.get_two_factor_status().await
}
fn auth_token_from_authenticated(account: &AuthenticatedAccount) -> String {
@@ -295,3 +264,11 @@ fn decode_base32(secret: &str) -> Vec<u8> {
output
}
+
+fn accounts_client(endpoint: &str) -> CliResult<AccountsClient> {
+ AccountsClient::new(
+ AccountsClientConfig::new(App::Photos.client_package())
+ .with_base_url(endpoint.to_string())
+ .with_user_agent("ente-e2e"),
+ )
+}
diff --git a/rust/e2e/tests/support/contacts.rs b/rust/e2e/tests/support/contacts.rs
index a393455958..0f42453a4e 100644
--- a/rust/e2e/tests/support/contacts.rs
+++ b/rust/e2e/tests/support/contacts.rs
@@ -2,8 +2,9 @@ use ente_contacts::{
client::{ContactsCtx, OpenContactsCtxInput},
legacy_models::{LegacyContactRecord, LegacyInfo, LegacyRecoverySession},
};
+use ente_accounts::KeyAttributes as ApiKeyAttributes;
use ente_core::auth::KeyAttributes as CoreKeyAttributes;
-use ente_rs::{api::models::KeyAttributes as ApiKeyAttributes, models::account::App};
+use ente_rs::models::account::App;
use crate::support::auth::TestAccount;