Skip to content

Commit

Permalink
Auto merge of #12587 - arlosi:paseto-logout, r=epage
Browse files Browse the repository at this point in the history
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).
  • Loading branch information
bors committed Aug 29, 2023
2 parents 87a14ed + 0a5050c commit e597acd
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
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();
}

0 comments on commit e597acd

Please sign in to comment.