1
1
//! Tests for the `cargo logout` command.
2
2
3
3
use super :: login:: check_token;
4
+ use cargo_test_support:: paths:: { self , CargoPathExt } ;
4
5
use cargo_test_support:: registry:: TestRegistry ;
5
6
use cargo_test_support:: { cargo_process, registry} ;
6
7
@@ -51,7 +52,7 @@ If you need to revoke the token, visit {note} and follow the instructions there.
51
52
}
52
53
53
54
#[ cargo_test]
54
- fn default_registry ( ) {
55
+ fn default_registry_unconfigured ( ) {
55
56
let registry = registry:: init ( ) ;
56
57
simple_logout_test ( & registry, None , "" , "<https://crates.io/me>" ) ;
57
58
}
@@ -68,3 +69,54 @@ fn other_registry() {
68
69
// It should not touch crates.io.
69
70
check_token ( Some ( "sekrit" ) , None ) ;
70
71
}
72
+
73
+ #[ cargo_test]
74
+ fn default_registry_configured ( ) {
75
+ // When registry.default is set, logout should use that one when
76
+ // --registry is not used.
77
+ let cargo_home = paths:: home ( ) . join ( ".cargo" ) ;
78
+ cargo_home. mkdir_p ( ) ;
79
+ cargo_util:: paths:: write (
80
+ & cargo_home. join ( "config.toml" ) ,
81
+ r#"
82
+ [registry]
83
+ default = "dummy-registry"
84
+
85
+ [registries.dummy-registry]
86
+ index = "https://127.0.0.1/index"
87
+ "# ,
88
+ )
89
+ . unwrap ( ) ;
90
+ cargo_util:: paths:: write (
91
+ & cargo_home. join ( "credentials.toml" ) ,
92
+ r#"
93
+ [registry]
94
+ token = "crates-io-token"
95
+
96
+ [registries.dummy-registry]
97
+ token = "dummy-token"
98
+ "# ,
99
+ )
100
+ . unwrap ( ) ;
101
+ check_token ( Some ( "dummy-token" ) , Some ( "dummy-registry" ) ) ;
102
+ check_token ( Some ( "crates-io-token" ) , None ) ;
103
+
104
+ cargo_process ( "logout -Zunstable-options" )
105
+ . masquerade_as_nightly_cargo ( & [ "cargo-logout" ] )
106
+ . with_stderr (
107
+ "\
108
+ [LOGOUT] token for `crates-io` has been removed from local storage
109
+ [NOTE] This does not revoke the token on the registry server.
110
+ If you need to revoke the token, visit <https://crates.io/me> \
111
+ and follow the instructions there.
112
+ " ,
113
+ )
114
+ . run ( ) ;
115
+ check_token ( Some ( "dummy-token" ) , Some ( "dummy-registry" ) ) ;
116
+ check_token ( None , None ) ;
117
+
118
+ cargo_process ( "logout -Zunstable-options" )
119
+ . masquerade_as_nightly_cargo ( & [ "cargo-logout" ] )
120
+ . with_stderr ( "[LOGOUT] not currently logged in to `crates-io`" )
121
+ . run ( ) ;
122
+ }
0 commit comments