Skip to content

Commit

Permalink
Also check the token argument
Browse files Browse the repository at this point in the history
Signed-off-by: hi-rustin <rustin.liu@gmail.com>
  • Loading branch information
Rustin170506 committed Sep 26, 2022
1 parent d9927c8 commit e0702a5
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
10 changes: 5 additions & 5 deletions src/cargo/ops/registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) = &reg_cfg {
if old_token == &token {
config.shell().status("Login", "already logged in")?;
Expand Down
12 changes: 11 additions & 1 deletion tests/testsuite/login.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

0 comments on commit e0702a5

Please sign in to comment.