add a test for the unstableness of registry-auth

This commit is contained in:
Jacob Finkelman 2022-12-14 20:10:55 +00:00
parent 29ff25f6d9
commit 6f8b15ce51
3 changed files with 43 additions and 35 deletions

View file

@ -988,29 +988,22 @@ impl CliUnstable {
pub fn fail_if_stable_opt(&self, flag: &str, issue: u32) -> CargoResult<()> { pub fn fail_if_stable_opt(&self, flag: &str, issue: u32) -> CargoResult<()> {
if !self.unstable_options { if !self.unstable_options {
let see = format!( let see = format!(
"See https://github.com/rust-lang/cargo/issues/{} for more \ "See https://github.com/rust-lang/cargo/issues/{issue} for more \
information about the `{}` flag.", information about the `{flag}` flag."
issue, flag
); );
// NOTE: a `config` isn't available here, check the channel directly // NOTE: a `config` isn't available here, check the channel directly
let channel = channel(); let channel = channel();
if channel == "nightly" || channel == "dev" { if channel == "nightly" || channel == "dev" {
bail!( bail!(
"the `{}` flag is unstable, pass `-Z unstable-options` to enable it\n\ "the `{flag}` flag is unstable, pass `-Z unstable-options` to enable it\n\
{}", {see}"
flag,
see
); );
} else { } else {
bail!( bail!(
"the `{}` flag is unstable, and only available on the nightly channel \ "the `{flag}` flag is unstable, and only available on the nightly channel \
of Cargo, but this is the `{}` channel\n\ of Cargo, but this is the `{channel}` channel\n\
{}\n\ {SEE_CHANNELS}\n\
{}", {see}"
flag,
channel,
SEE_CHANNELS,
see
); );
} }
} }

View file

@ -807,10 +807,19 @@ pub fn registry_login(
let new_token; let new_token;
if generate_keypair || secret_key_required || key_subject.is_some() { if generate_keypair || secret_key_required || key_subject.is_some() {
if !config.cli_unstable().registry_auth { if !config.cli_unstable().registry_auth {
// todo use fail_if_stable_opt let flag = if generate_keypair {
"generate-keypair"
} else if secret_key_required {
"secret-key"
} else if key_subject.is_some() {
"key-subject"
} else {
unreachable!("how did whe get here");
};
bail!( bail!(
"asymmetric token options are unstable and require the \ "the `{flag}` flag is unstable, pass `-Z registry-auth` to enable it\n\
`-Z registry-auth` option on the nightly channel" See https://github.com/rust-lang/cargo/issues/10519 for more \
information about the `{flag}` flag."
); );
} }
assert!(token.is_none()); assert!(token.is_none());

View file

@ -1,7 +1,7 @@
//! Tests for the `cargo login` command. //! Tests for the `cargo login` command.
use cargo_test_support::install::cargo_home; use cargo_test_support::install::cargo_home;
use cargo_test_support::registry::RegistryBuilder; use cargo_test_support::registry::{self, RegistryBuilder};
use cargo_test_support::{cargo_process, t}; use cargo_test_support::{cargo_process, t};
use std::fs::{self}; use std::fs::{self};
use std::path::PathBuf; use std::path::PathBuf;
@ -154,19 +154,25 @@ fn bad_asymmetric_token_args() {
.run(); .run();
} }
// todo why do theas hang when run as a test? #[cargo_test]
// #[cargo_test] fn asymmetric_requires_nightly() {
// fn asymmetric_requires_nightly() { let registry = registry::init();
// cargo_process("login --key-subject=foo") cargo_process("login --key-subject=foo")
// .with_status(101) .replace_crates_io(registry.index_url())
// .with_stderr_contains("asymmetric token options are unstable and require the `-Z registry-auth` option on the nightly channel") .with_status(101)
// .run(); .with_stderr_contains("[ERROR] the `key-subject` flag is unstable, pass `-Z registry-auth` to enable it\n\
// cargo_process("login --generate-keypair") See https://github.com/rust-lang/cargo/issues/10519 for more information about the `key-subject` flag.")
// .with_status(101) .run();
// .with_stderr_contains("asymmetric token options are unstable and require the `-Z registry-auth` option on the nightly channel") cargo_process("login --generate-keypair")
// .run(); .replace_crates_io(registry.index_url())
// cargo_process("login --secret-key") .with_status(101)
// .with_status(101) .with_stderr_contains("[ERROR] the `generate-keypair` flag is unstable, pass `-Z registry-auth` to enable it\n\
// .with_stderr_contains("asymmetric token options are unstable and require the `-Z registry-auth` option on the nightly channel") See https://github.com/rust-lang/cargo/issues/10519 for more information about the `generate-keypair` flag.")
// .run(); .run();
// } cargo_process("login --secret-key")
.replace_crates_io(registry.index_url())
.with_status(101)
.with_stderr_contains("[ERROR] the `secret-key` flag is unstable, pass `-Z registry-auth` to enable it\n\
See https://github.com/rust-lang/cargo/issues/10519 for more information about the `secret-key` flag.")
.run();
}