Skip to content

Commit 6f8b15c

Browse files
committed
add a test for the unstableness of registry-auth
1 parent 29ff25f commit 6f8b15c

File tree

3 files changed

+43
-35
lines changed

3 files changed

+43
-35
lines changed

src/cargo/core/features.rs

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -988,29 +988,22 @@ impl CliUnstable {
988988
pub fn fail_if_stable_opt(&self, flag: &str, issue: u32) -> CargoResult<()> {
989989
if !self.unstable_options {
990990
let see = format!(
991-
"See https://github.com/rust-lang/cargo/issues/{} for more \
992-
information about the `{}` flag.",
993-
issue, flag
991+
"See https://github.com/rust-lang/cargo/issues/{issue} for more \
992+
information about the `{flag}` flag."
994993
);
995994
// NOTE: a `config` isn't available here, check the channel directly
996995
let channel = channel();
997996
if channel == "nightly" || channel == "dev" {
998997
bail!(
999-
"the `{}` flag is unstable, pass `-Z unstable-options` to enable it\n\
1000-
{}",
1001-
flag,
1002-
see
998+
"the `{flag}` flag is unstable, pass `-Z unstable-options` to enable it\n\
999+
{see}"
10031000
);
10041001
} else {
10051002
bail!(
1006-
"the `{}` flag is unstable, and only available on the nightly channel \
1007-
of Cargo, but this is the `{}` channel\n\
1008-
{}\n\
1009-
{}",
1010-
flag,
1011-
channel,
1012-
SEE_CHANNELS,
1013-
see
1003+
"the `{flag}` flag is unstable, and only available on the nightly channel \
1004+
of Cargo, but this is the `{channel}` channel\n\
1005+
{SEE_CHANNELS}\n\
1006+
{see}"
10141007
);
10151008
}
10161009
}

src/cargo/ops/registry.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -807,10 +807,19 @@ pub fn registry_login(
807807
let new_token;
808808
if generate_keypair || secret_key_required || key_subject.is_some() {
809809
if !config.cli_unstable().registry_auth {
810-
// todo use fail_if_stable_opt
810+
let flag = if generate_keypair {
811+
"generate-keypair"
812+
} else if secret_key_required {
813+
"secret-key"
814+
} else if key_subject.is_some() {
815+
"key-subject"
816+
} else {
817+
unreachable!("how did whe get here");
818+
};
811819
bail!(
812-
"asymmetric token options are unstable and require the \
813-
`-Z registry-auth` option on the nightly channel"
820+
"the `{flag}` flag is unstable, pass `-Z registry-auth` to enable it\n\
821+
See https://github.com/rust-lang/cargo/issues/10519 for more \
822+
information about the `{flag}` flag."
814823
);
815824
}
816825
assert!(token.is_none());

tests/testsuite/login.rs

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//! Tests for the `cargo login` command.
22
33
use cargo_test_support::install::cargo_home;
4-
use cargo_test_support::registry::RegistryBuilder;
4+
use cargo_test_support::registry::{self, RegistryBuilder};
55
use cargo_test_support::{cargo_process, t};
66
use std::fs::{self};
77
use std::path::PathBuf;
@@ -154,19 +154,25 @@ fn bad_asymmetric_token_args() {
154154
.run();
155155
}
156156

157-
// todo why do theas hang when run as a test?
158-
// #[cargo_test]
159-
// fn asymmetric_requires_nightly() {
160-
// cargo_process("login --key-subject=foo")
161-
// .with_status(101)
162-
// .with_stderr_contains("asymmetric token options are unstable and require the `-Z registry-auth` option on the nightly channel")
163-
// .run();
164-
// cargo_process("login --generate-keypair")
165-
// .with_status(101)
166-
// .with_stderr_contains("asymmetric token options are unstable and require the `-Z registry-auth` option on the nightly channel")
167-
// .run();
168-
// cargo_process("login --secret-key")
169-
// .with_status(101)
170-
// .with_stderr_contains("asymmetric token options are unstable and require the `-Z registry-auth` option on the nightly channel")
171-
// .run();
172-
// }
157+
#[cargo_test]
158+
fn asymmetric_requires_nightly() {
159+
let registry = registry::init();
160+
cargo_process("login --key-subject=foo")
161+
.replace_crates_io(registry.index_url())
162+
.with_status(101)
163+
.with_stderr_contains("[ERROR] the `key-subject` flag is unstable, pass `-Z registry-auth` to enable it\n\
164+
See https://github.com/rust-lang/cargo/issues/10519 for more information about the `key-subject` flag.")
165+
.run();
166+
cargo_process("login --generate-keypair")
167+
.replace_crates_io(registry.index_url())
168+
.with_status(101)
169+
.with_stderr_contains("[ERROR] the `generate-keypair` flag is unstable, pass `-Z registry-auth` to enable it\n\
170+
See https://github.com/rust-lang/cargo/issues/10519 for more information about the `generate-keypair` flag.")
171+
.run();
172+
cargo_process("login --secret-key")
173+
.replace_crates_io(registry.index_url())
174+
.with_status(101)
175+
.with_stderr_contains("[ERROR] the `secret-key` flag is unstable, pass `-Z registry-auth` to enable it\n\
176+
See https://github.com/rust-lang/cargo/issues/10519 for more information about the `secret-key` flag.")
177+
.run();
178+
}

0 commit comments

Comments
 (0)