Skip to content

Commit

Permalink
Add tests
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 29, 2022
1 parent 06bd857 commit b3da66f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/cargo/ops/registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -764,7 +764,7 @@ 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.replace("cargo login", "").trim().to_string();
line = line.replace("cargo login", "").trim().to_string();
if line.is_empty() {
bail!("please provide a non-empty token");
}
Expand Down
18 changes: 18 additions & 0 deletions tests/testsuite/login.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,3 +90,21 @@ fn registry_credentials() {
assert!(check_token(TOKEN, Some(reg)));
assert!(check_token(TOKEN2, Some(reg2)));
}

#[cargo_test]
fn empty_login_token() {
let _registry = RegistryBuilder::new().build();
setup_new_credentials();

cargo_process("login")
.with_stdout("please paste the API Token found on [..]/me below")
.with_stdin("\t\n")
.with_stderr(
"\
[UPDATING] `dummy-registry` index
[ERROR] please provide a non-empty token
",
)
.with_status(101)
.run()
}

0 comments on commit b3da66f

Please sign in to comment.