Skip to content

Commit 882c5dd

Browse files
committed
Auto merge of #11145 - hi-rustin:rustin-patch-login, r=weihanglo
Check empty input for login ### What does this PR try to resolve? close #11144 Check empty input for login. ### How should we test and review this PR? - unit test - cargo login and enter
2 parents d1a2592 + ff575b2 commit 882c5dd

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

src/cargo/ops/registry.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -768,6 +768,10 @@ pub fn registry_login(
768768
}
769769
};
770770

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

tests/testsuite/login.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,3 +90,31 @@ fn registry_credentials() {
9090
assert!(check_token(TOKEN, Some(reg)));
9191
assert!(check_token(TOKEN2, Some(reg2)));
9292
}
93+
94+
#[cargo_test]
95+
fn empty_login_token() {
96+
let _registry = RegistryBuilder::new().build();
97+
setup_new_credentials();
98+
99+
cargo_process("login")
100+
.with_stdout("please paste the API Token found on [..]/me below")
101+
.with_stdin("\t\n")
102+
.with_stderr(
103+
"\
104+
[UPDATING] `dummy-registry` index
105+
[ERROR] please provide a non-empty token
106+
",
107+
)
108+
.with_status(101)
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();
120+
}

0 commit comments

Comments
 (0)