Skip to content

Commit 88f3bb9

Browse files
committed
add a test for login on stdin
1 parent 7ca522a commit 88f3bb9

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

tests/testsuite/registry.rs

+32
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ use cargo_test_support::{cargo_process, registry::registry_url};
88
use cargo_test_support::{git, install::cargo_home, t};
99
use cargo_util::paths::remove_dir_all;
1010
use std::fs::{self, File};
11+
use std::io::{BufRead, BufReader, Write};
1112
use std::path::Path;
13+
use std::process::Stdio;
1214

1315
#[cargo_test]
1416
fn simple() {
@@ -883,6 +885,36 @@ fn login_with_differently_sized_token() {
883885
assert_eq!(credentials, "[registry]\ntoken = \"lmaolmaolmao\"\n");
884886
}
885887

888+
#[cargo_test]
889+
fn login_with_token_on_stdin() {
890+
registry::init();
891+
let credentials = paths::home().join(".cargo/credentials");
892+
fs::remove_file(&credentials).unwrap();
893+
cargo_process("login lmao -v").run();
894+
let mut cargo = cargo_process("login").build_command();
895+
cargo
896+
.stdin(Stdio::piped())
897+
.stdout(Stdio::piped())
898+
.stderr(Stdio::piped());
899+
let mut child = cargo.spawn().unwrap();
900+
let out = BufReader::new(child.stdout.as_mut().unwrap())
901+
.lines()
902+
.next()
903+
.unwrap()
904+
.unwrap();
905+
assert!(out.starts_with("please paste the API Token found on "));
906+
assert!(out.ends_with("/me below"));
907+
child
908+
.stdin
909+
.as_ref()
910+
.unwrap()
911+
.write_all(b"some token\n")
912+
.unwrap();
913+
child.wait().unwrap();
914+
let credentials = fs::read_to_string(&credentials).unwrap();
915+
assert_eq!(credentials, "[registry]\ntoken = \"some token\"\n");
916+
}
917+
886918
#[cargo_test]
887919
fn bad_license_file() {
888920
Package::new("foo", "1.0.0").publish();

0 commit comments

Comments
 (0)