mirror of
https://github.com/rust-lang/cargo
synced 2024-10-13 19:22:33 +00:00
add a test for the unstableness of registry-auth
This commit is contained in:
parent
29ff25f6d9
commit
6f8b15ce51
|
@ -988,29 +988,22 @@ impl CliUnstable {
|
|||
pub fn fail_if_stable_opt(&self, flag: &str, issue: u32) -> CargoResult<()> {
|
||||
if !self.unstable_options {
|
||||
let see = format!(
|
||||
"See https://github.com/rust-lang/cargo/issues/{} for more \
|
||||
information about the `{}` flag.",
|
||||
issue, flag
|
||||
"See https://github.com/rust-lang/cargo/issues/{issue} for more \
|
||||
information about the `{flag}` flag."
|
||||
);
|
||||
// NOTE: a `config` isn't available here, check the channel directly
|
||||
let channel = channel();
|
||||
if channel == "nightly" || channel == "dev" {
|
||||
bail!(
|
||||
"the `{}` flag is unstable, pass `-Z unstable-options` to enable it\n\
|
||||
{}",
|
||||
flag,
|
||||
see
|
||||
"the `{flag}` flag is unstable, pass `-Z unstable-options` to enable it\n\
|
||||
{see}"
|
||||
);
|
||||
} else {
|
||||
bail!(
|
||||
"the `{}` flag is unstable, and only available on the nightly channel \
|
||||
of Cargo, but this is the `{}` channel\n\
|
||||
{}\n\
|
||||
{}",
|
||||
flag,
|
||||
channel,
|
||||
SEE_CHANNELS,
|
||||
see
|
||||
"the `{flag}` flag is unstable, and only available on the nightly channel \
|
||||
of Cargo, but this is the `{channel}` channel\n\
|
||||
{SEE_CHANNELS}\n\
|
||||
{see}"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -807,10 +807,19 @@ pub fn registry_login(
|
|||
let new_token;
|
||||
if generate_keypair || secret_key_required || key_subject.is_some() {
|
||||
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!(
|
||||
"asymmetric token options are unstable and require the \
|
||||
`-Z registry-auth` option on the nightly channel"
|
||||
"the `{flag}` 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 `{flag}` flag."
|
||||
);
|
||||
}
|
||||
assert!(token.is_none());
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
//! Tests for the `cargo login` command.
|
||||
|
||||
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 std::fs::{self};
|
||||
use std::path::PathBuf;
|
||||
|
@ -154,19 +154,25 @@ fn bad_asymmetric_token_args() {
|
|||
.run();
|
||||
}
|
||||
|
||||
// todo why do theas hang when run as a test?
|
||||
// #[cargo_test]
|
||||
// fn asymmetric_requires_nightly() {
|
||||
// cargo_process("login --key-subject=foo")
|
||||
// .with_status(101)
|
||||
// .with_stderr_contains("asymmetric token options are unstable and require the `-Z registry-auth` option on the nightly channel")
|
||||
// .run();
|
||||
// cargo_process("login --generate-keypair")
|
||||
// .with_status(101)
|
||||
// .with_stderr_contains("asymmetric token options are unstable and require the `-Z registry-auth` option on the nightly channel")
|
||||
// .run();
|
||||
// cargo_process("login --secret-key")
|
||||
// .with_status(101)
|
||||
// .with_stderr_contains("asymmetric token options are unstable and require the `-Z registry-auth` option on the nightly channel")
|
||||
// .run();
|
||||
// }
|
||||
#[cargo_test]
|
||||
fn asymmetric_requires_nightly() {
|
||||
let registry = registry::init();
|
||||
cargo_process("login --key-subject=foo")
|
||||
.replace_crates_io(registry.index_url())
|
||||
.with_status(101)
|
||||
.with_stderr_contains("[ERROR] the `key-subject` 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 `key-subject` flag.")
|
||||
.run();
|
||||
cargo_process("login --generate-keypair")
|
||||
.replace_crates_io(registry.index_url())
|
||||
.with_status(101)
|
||||
.with_stderr_contains("[ERROR] the `generate-keypair` 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 `generate-keypair` flag.")
|
||||
.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();
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue