From 88f3bb9a677d4516fd43529561b318ea94433e76 Mon Sep 17 00:00:00 2001 From: Jacob Finkelman Date: Fri, 4 Mar 2022 23:05:48 +0000 Subject: [PATCH] add a test for login on stdin --- tests/testsuite/registry.rs | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/tests/testsuite/registry.rs b/tests/testsuite/registry.rs index c62037012..7d2fda653 100644 --- a/tests/testsuite/registry.rs +++ b/tests/testsuite/registry.rs @@ -8,7 +8,9 @@ use cargo_test_support::{cargo_process, registry::registry_url}; use cargo_test_support::{git, install::cargo_home, t}; use cargo_util::paths::remove_dir_all; use std::fs::{self, File}; +use std::io::{BufRead, BufReader, Write}; use std::path::Path; +use std::process::Stdio; #[cargo_test] fn simple() { @@ -883,6 +885,36 @@ fn login_with_differently_sized_token() { assert_eq!(credentials, "[registry]\ntoken = \"lmaolmaolmao\"\n"); } +#[cargo_test] +fn login_with_token_on_stdin() { + registry::init(); + let credentials = paths::home().join(".cargo/credentials"); + fs::remove_file(&credentials).unwrap(); + cargo_process("login lmao -v").run(); + let mut cargo = cargo_process("login").build_command(); + cargo + .stdin(Stdio::piped()) + .stdout(Stdio::piped()) + .stderr(Stdio::piped()); + let mut child = cargo.spawn().unwrap(); + let out = BufReader::new(child.stdout.as_mut().unwrap()) + .lines() + .next() + .unwrap() + .unwrap(); + assert!(out.starts_with("please paste the API Token found on ")); + assert!(out.ends_with("/me below")); + child + .stdin + .as_ref() + .unwrap() + .write_all(b"some token\n") + .unwrap(); + child.wait().unwrap(); + let credentials = fs::read_to_string(&credentials).unwrap(); + assert_eq!(credentials, "[registry]\ntoken = \"some token\"\n"); +} + #[cargo_test] fn bad_license_file() { Package::new("foo", "1.0.0").publish();