Skip to content

Commit b3da66f

Browse files
committed
Add tests
Signed-off-by: hi-rustin <[email protected]>
1 parent 06bd857 commit b3da66f

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

src/cargo/ops/registry.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -764,7 +764,7 @@ 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.replace("cargo login", "").trim().to_string();
767+
line = line.replace("cargo login", "").trim().to_string();
768768
if line.is_empty() {
769769
bail!("please provide a non-empty token");
770770
}

tests/testsuite/login.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,3 +90,21 @@ 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+
}

0 commit comments

Comments
 (0)