@@ -8,7 +8,9 @@ use cargo_test_support::{cargo_process, registry::registry_url};
8
8
use cargo_test_support:: { git, install:: cargo_home, t} ;
9
9
use cargo_util:: paths:: remove_dir_all;
10
10
use std:: fs:: { self , File } ;
11
+ use std:: io:: { BufRead , BufReader , Write } ;
11
12
use std:: path:: Path ;
13
+ use std:: process:: Stdio ;
12
14
13
15
#[ cargo_test]
14
16
fn simple ( ) {
@@ -883,6 +885,36 @@ fn login_with_differently_sized_token() {
883
885
assert_eq ! ( credentials, "[registry]\n token = \" lmaolmaolmao\" \n " ) ;
884
886
}
885
887
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]\n token = \" some token\" \n " ) ;
916
+ }
917
+
886
918
#[ cargo_test]
887
919
fn bad_license_file ( ) {
888
920
Package :: new ( "foo" , "1.0.0" ) . publish ( ) ;
0 commit comments