Skip to content

Commit e589a5f

Browse files
committed
Auto merge of #11919 - ehuss:logout-note, r=epage
Add a note to `cargo logout` that it does not revoke the token. This adds a note to help emphasize that `cargo logout` does not "log out of the server", and suggests what to do if that is what you want. Unfortunately getting the URL for a registry is not a simple operation, so for now it just gives a generic message for the non-crates.io case.
2 parents 4a60ff7 + f393f96 commit e589a5f

File tree

3 files changed

+30
-12
lines changed

3 files changed

+30
-12
lines changed

src/cargo/ops/registry.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -954,6 +954,20 @@ pub fn registry_logout(config: &Config, reg: Option<&str>) -> CargoResult<()> {
954954
reg_name
955955
),
956956
)?;
957+
let location = if source_ids.original.is_crates_io() {
958+
"<https://crates.io/me>".to_string()
959+
} else {
960+
// The URL for the source requires network access to load the config.
961+
// That could be a fairly heavy operation to perform just to provide a
962+
// help message, so for now this just provides some generic text.
963+
// Perhaps in the future this could have an API to fetch the config if
964+
// it is cached, but avoid network access otherwise?
965+
format!("the `{reg_name}` website")
966+
};
967+
config.shell().note(format!(
968+
"This does not revoke the token on the registry server.\n \
969+
If you need to revoke the token, visit {location} and follow the instructions there."
970+
))?;
957971
Ok(())
958972
}
959973

tests/testsuite/credential_process.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,9 @@ fn logout() {
383383
"\
384384
token for `crates-io` has been erased!
385385
[LOGOUT] token for `crates-io` has been removed from local storage
386+
[NOTE] This does not revoke the token on the registry server.
387+
If you need to revoke the token, visit <https://crates.io/me> \
388+
and follow the instructions there.
386389
",
387390
)
388391
.run();

tests/testsuite/logout.rs

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ fn check_config_token(registry: Option<&str>, should_be_set: bool) {
4444
}
4545
}
4646

47-
fn simple_logout_test(registry: &TestRegistry, reg: Option<&str>, flag: &str) {
47+
fn simple_logout_test(registry: &TestRegistry, reg: Option<&str>, flag: &str, note: &str) {
4848
let msg = reg.unwrap_or("crates-io");
4949
check_config_token(reg, true);
5050
let mut cargo = cargo_process(&format!("logout -Z unstable-options {}", flag));
@@ -55,9 +55,10 @@ fn simple_logout_test(registry: &TestRegistry, reg: Option<&str>, flag: &str) {
5555
.masquerade_as_nightly_cargo(&["cargo-logout"])
5656
.with_stderr(&format!(
5757
"\
58-
[LOGOUT] token for `{}` has been removed from local storage
59-
",
60-
msg
58+
[LOGOUT] token for `{msg}` has been removed from local storage
59+
[NOTE] This does not revoke the token on the registry server.\n \
60+
If you need to revoke the token, visit {note} and follow the instructions there.
61+
"
6162
))
6263
.run();
6364
check_config_token(reg, false);
@@ -68,24 +69,24 @@ fn simple_logout_test(registry: &TestRegistry, reg: Option<&str>, flag: &str) {
6869
}
6970
cargo
7071
.masquerade_as_nightly_cargo(&["cargo-logout"])
71-
.with_stderr(&format!(
72-
"\
73-
[LOGOUT] not currently logged in to `{}`
74-
",
75-
msg
76-
))
72+
.with_stderr(&format!("[LOGOUT] not currently logged in to `{msg}`"))
7773
.run();
7874
check_config_token(reg, false);
7975
}
8076

8177
#[cargo_test]
8278
fn default_registry() {
8379
let registry = registry::init();
84-
simple_logout_test(&registry, None, "");
80+
simple_logout_test(&registry, None, "", "<https://crates.io/me>");
8581
}
8682

8783
#[cargo_test]
8884
fn other_registry() {
8985
let registry = registry::alt_init();
90-
simple_logout_test(&registry, Some("alternative"), "--registry alternative");
86+
simple_logout_test(
87+
&registry,
88+
Some("alternative"),
89+
"--registry alternative",
90+
"the `alternative` website",
91+
);
9192
}

0 commit comments

Comments
 (0)