summaryrefslogtreecommitdiffstats
path: root/src/tools/cargo/tests/testsuite/login.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/tools/cargo/tests/testsuite/login.rs')
-rw-r--r--src/tools/cargo/tests/testsuite/login.rs188
1 files changed, 65 insertions, 123 deletions
diff --git a/src/tools/cargo/tests/testsuite/login.rs b/src/tools/cargo/tests/testsuite/login.rs
index 85b299f28..16bd29dce 100644
--- a/src/tools/cargo/tests/testsuite/login.rs
+++ b/src/tools/cargo/tests/testsuite/login.rs
@@ -109,12 +109,14 @@ fn empty_login_token() {
cargo_process("login")
.replace_crates_io(registry.index_url())
- .with_stdout("please paste the token found on [..]/me below")
.with_stdin("\t\n")
.with_stderr(
"\
[UPDATING] crates.io index
-[ERROR] please provide a non-empty token
+[ERROR] credential provider `cargo:token` failed action `login`
+
+Caused by:
+ please provide a non-empty token
",
)
.with_status(101)
@@ -125,7 +127,10 @@ fn empty_login_token() {
.arg("")
.with_stderr(
"\
-[ERROR] please provide a non-empty token
+[ERROR] credential provider `cargo:token` failed action `login`
+
+Caused by:
+ please provide a non-empty token
",
)
.with_status(101)
@@ -143,7 +148,6 @@ fn invalid_login_token() {
let check = |stdin: &str, stderr: &str, status: i32| {
cargo_process("login")
.replace_crates_io(registry.index_url())
- .with_stdout("please paste the token found on [..]/me below")
.with_stdin(stdin)
.with_stderr(stderr)
.with_status(status)
@@ -153,12 +157,15 @@ fn invalid_login_token() {
let invalid = |stdin: &str| {
check(
stdin,
- "[ERROR] token contains invalid characters.
-Only printable ISO-8859-1 characters are allowed as it is sent in a HTTPS header.",
+ "[ERROR] credential provider `cargo:token` failed action `login`
+
+Caused by:
+ token contains invalid characters.
+ Only printable ISO-8859-1 characters are allowed as it is sent in a HTTPS header.",
101,
)
};
- let valid = |stdin: &str| check(stdin, "[LOGIN] token for `crates.io` saved", 0);
+ let valid = |stdin: &str| check(stdin, "[LOGIN] token for `crates-io` saved", 0);
// Update config.json so that the rest of the tests don't need to care
// whether or not `Updating` is printed.
@@ -166,7 +173,7 @@ Only printable ISO-8859-1 characters are allowed as it is sent in a HTTPS header
"test",
"\
[UPDATING] crates.io index
-[LOGIN] token for `crates.io` saved
+[LOGIN] token for `crates-io` saved
",
0,
);
@@ -184,54 +191,19 @@ Only printable ISO-8859-1 characters are allowed as it is sent in a HTTPS header
#[cargo_test]
fn bad_asymmetric_token_args() {
- // These cases are kept brief as the implementation is covered by clap, so this is only smoke testing that we have clap configured correctly.
- cargo_process("login --key-subject=foo tok")
- .with_stderr_contains(
- "error: the argument '--key-subject <SUBJECT>' cannot be used with '[token]'",
- )
- .with_status(1)
- .run();
-
- cargo_process("login --generate-keypair tok")
- .with_stderr_contains(
- "error: the argument '--generate-keypair' cannot be used with '[token]'",
- )
- .with_status(1)
- .run();
-
- cargo_process("login --secret-key tok")
- .with_stderr_contains("error: the argument '--secret-key' cannot be used with '[token]'")
- .with_status(1)
- .run();
+ let registry = RegistryBuilder::new()
+ .credential_provider(&["cargo:paseto"])
+ .no_configure_token()
+ .build();
- cargo_process("login --generate-keypair --secret-key")
+ // These cases are kept brief as the implementation is covered by clap, so this is only smoke testing that we have clap configured correctly.
+ cargo_process("login -Zcredential-process -- --key-subject")
+ .masquerade_as_nightly_cargo(&["credential-process"])
+ .replace_crates_io(registry.index_url())
.with_stderr_contains(
- "error: the argument '--generate-keypair' cannot be used with '--secret-key'",
+ " error: a value is required for '--key-subject <SUBJECT>' but none was supplied",
)
- .with_status(1)
- .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();
}
@@ -250,6 +222,28 @@ fn login_with_no_cargo_dir() {
}
#[cargo_test]
+fn login_with_asymmetric_token_and_subject_on_stdin() {
+ let registry = RegistryBuilder::new()
+ .credential_provider(&["cargo:paseto"])
+ .no_configure_token()
+ .build();
+ let credentials = credentials_toml();
+ cargo_process("login -v -Z credential-process -- --key-subject=foo")
+ .masquerade_as_nightly_cargo(&["credential-process"])
+ .replace_crates_io(registry.index_url())
+ .with_stderr_contains(
+ "\
+k3.public.AmDwjlyf8jAV3gm5Z7Kz9xAOcsKslt_Vwp5v-emjFzBHLCtcANzTaVEghTNEMj9PkQ",
+ )
+ .with_stdin("k3.secret.fNYVuMvBgOlljt9TDohnaYLblghqaHoQquVZwgR6X12cBFHZLFsaU3q7X3k1Zn36")
+ .run();
+ let credentials = fs::read_to_string(&credentials).unwrap();
+ assert!(credentials.starts_with("[registry]\n"));
+ assert!(credentials.contains("secret-key-subject = \"foo\"\n"));
+ assert!(credentials.contains("secret-key = \"k3.secret.fNYVuMvBgOlljt9TDohnaYLblghqaHoQquVZwgR6X12cBFHZLFsaU3q7X3k1Zn36\"\n"));
+}
+
+#[cargo_test]
fn login_with_differently_sized_token() {
// Verify that the configuration file gets properly truncated.
let registry = registry::init();
@@ -278,7 +272,6 @@ fn login_with_token_on_stdin() {
.run();
cargo_process("login")
.replace_crates_io(registry.index_url())
- .with_stdout("please paste the token found on [..]/me below")
.with_stdin("some token")
.run();
let credentials = fs::read_to_string(&credentials).unwrap();
@@ -286,89 +279,38 @@ fn login_with_token_on_stdin() {
}
#[cargo_test]
-fn login_with_asymmetric_token_and_subject_on_stdin() {
- let registry = registry::init();
- let credentials = credentials_toml();
- fs::remove_file(&credentials).unwrap();
- cargo_process("login --key-subject=foo --secret-key -v -Z registry-auth")
- .masquerade_as_nightly_cargo(&["registry-auth"])
- .replace_crates_io(registry.index_url())
- .with_stdout(
- "\
- please paste the API secret key below
-k3.public.AmDwjlyf8jAV3gm5Z7Kz9xAOcsKslt_Vwp5v-emjFzBHLCtcANzTaVEghTNEMj9PkQ",
- )
- .with_stdin("k3.secret.fNYVuMvBgOlljt9TDohnaYLblghqaHoQquVZwgR6X12cBFHZLFsaU3q7X3k1Zn36")
- .run();
- let credentials = fs::read_to_string(&credentials).unwrap();
- assert!(credentials.starts_with("[registry]\n"));
- assert!(credentials.contains("secret-key-subject = \"foo\"\n"));
- assert!(credentials.contains("secret-key = \"k3.secret.fNYVuMvBgOlljt9TDohnaYLblghqaHoQquVZwgR6X12cBFHZLFsaU3q7X3k1Zn36\"\n"));
-}
-
-#[cargo_test]
fn login_with_asymmetric_token_on_stdin() {
- let registry = registry::init();
+ let _registry = RegistryBuilder::new()
+ .credential_provider(&["cargo:paseto"])
+ .alternative()
+ .no_configure_token()
+ .build();
let credentials = credentials_toml();
- fs::remove_file(&credentials).unwrap();
- cargo_process("login --secret-key -v -Z registry-auth")
- .masquerade_as_nightly_cargo(&["registry-auth"])
- .replace_crates_io(registry.index_url())
- .with_stdout(
+ cargo_process("login -vZ credential-process --registry alternative")
+ .masquerade_as_nightly_cargo(&["credential-process"])
+ .with_stderr(
"\
- please paste the API secret key below
-k3.public.AmDwjlyf8jAV3gm5Z7Kz9xAOcsKslt_Vwp5v-emjFzBHLCtcANzTaVEghTNEMj9PkQ",
- )
- .with_stdin("k3.secret.fNYVuMvBgOlljt9TDohnaYLblghqaHoQquVZwgR6X12cBFHZLFsaU3q7X3k1Zn36")
- .run();
- let credentials = fs::read_to_string(&credentials).unwrap();
- assert_eq!(credentials, "[registry]\nsecret-key = \"k3.secret.fNYVuMvBgOlljt9TDohnaYLblghqaHoQquVZwgR6X12cBFHZLFsaU3q7X3k1Zn36\"\n");
-}
-
-#[cargo_test]
-fn login_with_asymmetric_key_subject_without_key() {
- let registry = registry::init();
- let credentials = credentials_toml();
- fs::remove_file(&credentials).unwrap();
- cargo_process("login --key-subject=foo -Z registry-auth")
- .masquerade_as_nightly_cargo(&["registry-auth"])
- .replace_crates_io(registry.index_url())
- .with_stderr_contains("error: need a secret_key to set a key_subject")
- .with_status(101)
- .run();
-
- // ok so add a secret_key to the credentials
- cargo_process("login --secret-key -v -Z registry-auth")
- .masquerade_as_nightly_cargo(&["registry-auth"])
- .replace_crates_io(registry.index_url())
- .with_stdout(
- "please paste the API secret key below
+[UPDATING] [..]
+[CREDENTIAL] cargo:paseto login alternative
k3.public.AmDwjlyf8jAV3gm5Z7Kz9xAOcsKslt_Vwp5v-emjFzBHLCtcANzTaVEghTNEMj9PkQ",
)
.with_stdin("k3.secret.fNYVuMvBgOlljt9TDohnaYLblghqaHoQquVZwgR6X12cBFHZLFsaU3q7X3k1Zn36")
.run();
-
- // and then it should work
- cargo_process("login --key-subject=foo -Z registry-auth")
- .masquerade_as_nightly_cargo(&["registry-auth"])
- .replace_crates_io(registry.index_url())
- .run();
-
let credentials = fs::read_to_string(&credentials).unwrap();
- assert!(credentials.starts_with("[registry]\n"));
- assert!(credentials.contains("secret-key-subject = \"foo\"\n"));
- assert!(credentials.contains("secret-key = \"k3.secret.fNYVuMvBgOlljt9TDohnaYLblghqaHoQquVZwgR6X12cBFHZLFsaU3q7X3k1Zn36\"\n"));
+ assert_eq!(credentials, "[registries.alternative]\nsecret-key = \"k3.secret.fNYVuMvBgOlljt9TDohnaYLblghqaHoQquVZwgR6X12cBFHZLFsaU3q7X3k1Zn36\"\n");
}
#[cargo_test]
fn login_with_generate_asymmetric_token() {
- let registry = registry::init();
+ let _registry = RegistryBuilder::new()
+ .credential_provider(&["cargo:paseto"])
+ .alternative()
+ .no_configure_token()
+ .build();
let credentials = credentials_toml();
- fs::remove_file(&credentials).unwrap();
- cargo_process("login --generate-keypair -Z registry-auth")
- .masquerade_as_nightly_cargo(&["registry-auth"])
- .replace_crates_io(registry.index_url())
- .with_stdout("k3.public.[..]")
+ cargo_process("login -Z credential-process --registry alternative")
+ .masquerade_as_nightly_cargo(&["credential-process"])
+ .with_stderr("[UPDATING] `alternative` index\nk3.public.[..]")
.run();
let credentials = fs::read_to_string(&credentials).unwrap();
assert!(credentials.contains("secret-key = \"k3.secret."));