Skip to content

Commit e597acd

Browse files
committed
Auto merge of #12587 - arlosi:paseto-logout, r=epage
Improve logout message for asymmetric tokens When doing `cargo logout` with an asymmetric token, it currently always succeeds with no message printed. This changes the `cargo:paseto` provider to match the other providers and respond with `NotFound` if the user is not logged in. It also adds a message to indicate that the token was successfully removed (if it existed).
2 parents 87a14ed + 0a5050c commit e597acd

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

src/cargo/util/credential/paseto.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,8 +200,17 @@ impl<'a> Credential for PasetoCredential<'a> {
200200
Ok(CredentialResponse::Login)
201201
}
202202
Action::Logout => {
203-
config::save_credentials(self.config, None, &sid)?;
204-
Ok(CredentialResponse::Logout)
203+
if reg_cfg.and_then(|c| c.secret_key).is_some() {
204+
config::save_credentials(self.config, None, &sid)?;
205+
let reg_name = sid.display_registry_name();
206+
let _ = self.config.shell().status(
207+
"Logout",
208+
format!("secret-key for `{reg_name}` has been removed from local storage"),
209+
);
210+
Ok(CredentialResponse::Logout)
211+
} else {
212+
Err(Error::NotFound)
213+
}
205214
}
206215
_ => Err(Error::OperationNotSupported),
207216
}

tests/testsuite/logout.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,3 +102,20 @@ fn default_registry_configured() {
102102
.with_stderr("[LOGOUT] not currently logged in to `dummy-registry`")
103103
.run();
104104
}
105+
106+
#[cargo_test]
107+
fn logout_asymmetric() {
108+
let _registry = registry::RegistryBuilder::new()
109+
.token(cargo_test_support::registry::Token::rfc_key())
110+
.build();
111+
112+
cargo_process("logout --registry crates-io -Zasymmetric-token")
113+
.masquerade_as_nightly_cargo(&["asymmetric-token"])
114+
.with_stderr("[LOGOUT] secret-key for `crates-io` has been removed from local storage")
115+
.run();
116+
117+
cargo_process("logout --registry crates-io -Zasymmetric-token")
118+
.masquerade_as_nightly_cargo(&["asymmetric-token"])
119+
.with_stderr("[LOGOUT] not currently logged in to `crates-io`")
120+
.run();
121+
}

0 commit comments

Comments
 (0)