From ff575b290ff4dfa314aa0a2e151f63a783522254 Mon Sep 17 00:00:00 2001 From: hi-rustin Date: Mon, 26 Sep 2022 23:27:18 +0800 Subject: [PATCH] Also check the token argument Signed-off-by: hi-rustin --- src/cargo/ops/registry.rs | 10 +++++----- tests/testsuite/login.rs | 12 +++++++++++- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/src/cargo/ops/registry.rs b/src/cargo/ops/registry.rs index c819c6e5ba9..27180c6eca9 100644 --- a/src/cargo/ops/registry.rs +++ b/src/cargo/ops/registry.rs @@ -764,14 +764,14 @@ pub fn registry_login( .with_context(|| "failed to read stdin")?; // Automatically remove `cargo login` from an inputted token to // allow direct pastes from `registry.host()`/me. - line = line.replace("cargo login", "").trim().to_string(); - if line.is_empty() { - bail!("please provide a non-empty token"); - } - line + line.replace("cargo login", "").trim().to_string() } }; + if token.is_empty() { + bail!("please provide a non-empty token"); + } + if let RegistryConfig::Token(old_token) = ®_cfg { if old_token == &token { config.shell().status("Login", "already logged in")?; diff --git a/tests/testsuite/login.rs b/tests/testsuite/login.rs index f5a5d94c417..4e3f740d342 100644 --- a/tests/testsuite/login.rs +++ b/tests/testsuite/login.rs @@ -106,5 +106,15 @@ fn empty_login_token() { ", ) .with_status(101) - .run() + .run(); + + cargo_process("login") + .arg("") + .with_stderr( + "\ +[ERROR] please provide a non-empty token +", + ) + .with_status(101) + .run(); }