Skip to content

armgit / ente

Public Imported from GitHub
0

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

Retry incorrect passwords during interactive login

Manav Rathi93236d123f31
diff --git a/rust/apps/cli-next/src/login.rs b/rust/apps/cli-next/src/login.rs
index 6cda4a1324..fdf5628223 100644
--- a/rust/apps/cli-next/src/login.rs
+++ b/rust/apps/cli-next/src/login.rs
@@ -9,7 +9,7 @@ use ente_accounts::{
use ente_core::http::{Api, ApiConfig, Http};
use serde::Deserialize;
use uuid::Uuid;
-use zeroize::{ZeroizeOnDrop, Zeroizing};
+use zeroize::{Zeroize, ZeroizeOnDrop, Zeroizing};
use crate::{
api,
@@ -262,7 +262,19 @@ async fn authenticate(
Err(error) => return Err(error.into()),
}
},
- LoginStep::Password => flow.submit_password(client, &credentials.password).await?,
+ LoginStep::Password => loop {
+ match flow.submit_password(client, &credentials.password).await {
+ Ok(next) => break next,
+ Err(ente_accounts::Error::IncorrectPassword) if interactive => {
+ eprintln!("Incorrect password. Try again.");
+ credentials.password.zeroize();
+ credentials.password = Password::new()
+ .with_prompt("Password")
+ .interact_on(&Term::stderr())?;
+ }
+ Err(error) => return Err(error.into()),
+ }
+ },
LoginStep::SecondFactor { totp, passkey } => {
let use_passkey = match (totp, passkey) {
(true, true) if interactive => {
diff --git a/rust/apps/cli-next/tests/support/account.rs b/rust/apps/cli-next/tests/support/account.rs
index e153024edb..30a3cd8a65 100644
--- a/rust/apps/cli-next/tests/support/account.rs
+++ b/rust/apps/cli-next/tests/support/account.rs
@@ -390,7 +390,7 @@ fn creation_enrollment_and_login_across_processes() -> ente_test_support::TestRe
#[cfg(all(unix, feature = "museum"))]
#[test]
-fn interactive_creation_and_enrollment() -> ente_test_support::TestResult {
+fn interactive_creation_password_retry_and_enrollment() -> ente_test_support::TestResult {
ente_test_support::Museum::run_async(|origin| async move {
let home = TestHome::new();
let email = format!("cli-interactive-{}@example.org", uuid::Uuid::new_v4());
diff --git a/rust/apps/cli-next/tests/support/account_prompt.py b/rust/apps/cli-next/tests/support/account_prompt.py
index d799753327..32237b0b47 100644
--- a/rust/apps/cli-next/tests/support/account_prompt.py
+++ b/rust/apps/cli-next/tests/support/account_prompt.py
@@ -1,11 +1,13 @@
import base64
import hashlib
import hmac
+import json
import os
import pty
import re
import select
import signal
+import subprocess
import sys
import termios
import time
@@ -80,5 +82,24 @@ def enable(expect, send):
send(f"{code:06d}".encode(), True)
+def login(expect, send, email_mfa):
+ expect(b"Password:")
+ send(b"wrong-password", True)
+ if email_mfa:
+ expect(b"Email verification code:")
+ send(b"123456", True)
+ expect(b"Incorrect password. Try again.")
+ expect(b"Password:")
+ send(b"disposable-password", True)
+ expect(b"Logged in")
+
+
run([binary, "account", "create", "--host", origin], create)
+for email_mfa in [True, False]:
+ subprocess.run(
+ [binary, "photos", "api", "/users/email-mfa", "--method", "PUT", "--body", "-"],
+ input=json.dumps({"isEnabled": email_mfa}).encode(), check=True, capture_output=True,
+ )
+ run([binary, "account", "login", "--app", "photos", "--email", email],
+ lambda expect, send: login(expect, send, email_mfa))
run([binary, "account", "totp", "enable"], enable)