Skip to content

Commit ff575b2

Browse files
committed
Also check the token argument
Signed-off-by: hi-rustin <[email protected]>
1 parent b3da66f commit ff575b2

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

src/cargo/ops/registry.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -764,14 +764,14 @@ pub fn registry_login(
764764
.with_context(|| "failed to read stdin")?;
765765
// Automatically remove `cargo login` from an inputted token to
766766
// allow direct pastes from `registry.host()`/me.
767-
line = line.replace("cargo login", "").trim().to_string();
768-
if line.is_empty() {
769-
bail!("please provide a non-empty token");
770-
}
771-
line
767+
line.replace("cargo login", "").trim().to_string()
772768
}
773769
};
774770

771+
if token.is_empty() {
772+
bail!("please provide a non-empty token");
773+
}
774+
775775
if let RegistryConfig::Token(old_token) = &reg_cfg {
776776
if old_token == &token {
777777
config.shell().status("Login", "already logged in")?;

tests/testsuite/login.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,5 +106,15 @@ fn empty_login_token() {
106106
",
107107
)
108108
.with_status(101)
109-
.run()
109+
.run();
110+
111+
cargo_process("login")
112+
.arg("")
113+
.with_stderr(
114+
"\
115+
[ERROR] please provide a non-empty token
116+
",
117+
)
118+
.with_status(101)
119+
.run();
110120
}

0 commit comments

Comments
 (0)