fix(credential): trim newlines in token from stdin for credential providers

This commit is contained in:
Arlo Siemsen 2024-04-17 12:16:35 -05:00
parent a498391686
commit 6207f93087
3 changed files with 3 additions and 2 deletions

View File

@ -39,7 +39,7 @@ pub fn registry_login(
let mut token_from_stdin = None;
let token = token_from_cmdline.or_else(|| {
if !std::io::stdin().is_terminal() {
let token = std::io::read_to_string(std::io::stdin()).unwrap_or_default();
let token = cargo_credential::read_line().unwrap_or_default();
if !token.is_empty() {
token_from_stdin = Some(token);
}

View File

@ -709,7 +709,7 @@ fn login_token_from_stdin() {
.with_stdin("abcdefg\n")
.with_stderr(
r#"[UPDATING] [..]
{"v":1,"registry":{"index-url":"https://github.com/rust-lang/crates.io-index","name":"crates-io"},"kind":"login","token":"abcdefg\n","login-url":"[..]"}
{"v":1,"registry":{"index-url":"https://github.com/rust-lang/crates.io-index","name":"crates-io"},"kind":"login","token":"abcdefg","login-url":"[..]"}
"#,
)
.run();

View File

@ -113,6 +113,7 @@ fn empty_login_token() {
.with_stderr(
"\
[UPDATING] crates.io index
please paste the token found on [..] below
[ERROR] credential provider `cargo:token` failed action `login`
Caused by: