Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a note to cargo logout that it does not revoke the token. #11919

Merged
merged 1 commit into from
Mar 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/cargo/ops/registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -954,6 +954,20 @@ pub fn registry_logout(config: &Config, reg: Option<&str>) -> CargoResult<()> {
reg_name
),
)?;
let location = if source_ids.original.is_crates_io() {
"<https://crates.io/me>".to_string()
} else {
// The URL for the source requires network access to load the config.
// That could be a fairly heavy operation to perform just to provide a
// help message, so for now this just provides some generic text.
// Perhaps in the future this could have an API to fetch the config if
// it is cached, but avoid network access otherwise?
format!("the `{reg_name}` website")
};
config.shell().note(format!(
"This does not revoke the token on the registry server.\n \
If you need to revoke the token, visit {location} and follow the instructions there."
))?;
Ok(())
}

Expand Down
3 changes: 3 additions & 0 deletions tests/testsuite/credential_process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,9 @@ fn logout() {
"\
token for `crates-io` has been erased!
[LOGOUT] token for `crates-io` has been removed from local storage
[NOTE] This does not revoke the token on the registry server.
If you need to revoke the token, visit <https://crates.io/me> \
and follow the instructions there.
",
)
.run();
Expand Down
25 changes: 13 additions & 12 deletions tests/testsuite/logout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ fn check_config_token(registry: Option<&str>, should_be_set: bool) {
}
}

fn simple_logout_test(registry: &TestRegistry, reg: Option<&str>, flag: &str) {
fn simple_logout_test(registry: &TestRegistry, reg: Option<&str>, flag: &str, note: &str) {
let msg = reg.unwrap_or("crates-io");
check_config_token(reg, true);
let mut cargo = cargo_process(&format!("logout -Z unstable-options {}", flag));
Expand All @@ -55,9 +55,10 @@ fn simple_logout_test(registry: &TestRegistry, reg: Option<&str>, flag: &str) {
.masquerade_as_nightly_cargo(&["cargo-logout"])
.with_stderr(&format!(
"\
[LOGOUT] token for `{}` has been removed from local storage
",
msg
[LOGOUT] token for `{msg}` has been removed from local storage
[NOTE] This does not revoke the token on the registry server.\n \
If you need to revoke the token, visit {note} and follow the instructions there.
"
))
.run();
check_config_token(reg, false);
Expand All @@ -68,24 +69,24 @@ fn simple_logout_test(registry: &TestRegistry, reg: Option<&str>, flag: &str) {
}
cargo
.masquerade_as_nightly_cargo(&["cargo-logout"])
.with_stderr(&format!(
"\
[LOGOUT] not currently logged in to `{}`
",
msg
))
.with_stderr(&format!("[LOGOUT] not currently logged in to `{msg}`"))
.run();
check_config_token(reg, false);
}

#[cargo_test]
fn default_registry() {
let registry = registry::init();
simple_logout_test(&registry, None, "");
simple_logout_test(&registry, None, "", "<https://crates.io/me>");
}

#[cargo_test]
fn other_registry() {
let registry = registry::alt_init();
simple_logout_test(&registry, Some("alternative"), "--registry alternative");
simple_logout_test(
&registry,
Some("alternative"),
"--registry alternative",
"the `alternative` website",
);
}