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

Improve logout message for asymmetric tokens #12587

Merged
merged 1 commit into from
Aug 29, 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
13 changes: 11 additions & 2 deletions src/cargo/util/credential/paseto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,17 @@ impl<'a> Credential for PasetoCredential<'a> {
Ok(CredentialResponse::Login)
}
Action::Logout => {
config::save_credentials(self.config, None, &sid)?;
Ok(CredentialResponse::Logout)
if reg_cfg.and_then(|c| c.secret_key).is_some() {
config::save_credentials(self.config, None, &sid)?;
let reg_name = sid.display_registry_name();
let _ = self.config.shell().status(
"Logout",
format!("secret-key for `{reg_name}` has been removed from local storage"),
);
Ok(CredentialResponse::Logout)
} else {
Err(Error::NotFound)
}
}
_ => Err(Error::OperationNotSupported),
}
Expand Down
17 changes: 17 additions & 0 deletions tests/testsuite/logout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,20 @@ fn default_registry_configured() {
.with_stderr("[LOGOUT] not currently logged in to `dummy-registry`")
.run();
}

#[cargo_test]
fn logout_asymmetric() {
let _registry = registry::RegistryBuilder::new()
.token(cargo_test_support::registry::Token::rfc_key())
.build();

cargo_process("logout --registry crates-io -Zasymmetric-token")
.masquerade_as_nightly_cargo(&["asymmetric-token"])
.with_stderr("[LOGOUT] secret-key for `crates-io` has been removed from local storage")
.run();

cargo_process("logout --registry crates-io -Zasymmetric-token")
.masquerade_as_nightly_cargo(&["asymmetric-token"])
.with_stderr("[LOGOUT] not currently logged in to `crates-io`")
.run();
}