diff --git a/rye/src/cli/publish.rs b/rye/src/cli/publish.rs index 3ebfb84a42..c0fea301db 100644 --- a/rye/src/cli/publish.rs +++ b/rye/src/cli/publish.rs @@ -211,7 +211,8 @@ fn resolve_repository_config(cmd: &Args) -> Result { } // If no token/password is resolved we can fallback to keyring with username and url. - if config.password.is_none() && config.username.is_none() { + // TODO(cnpryer): Username is empty string + if config.password.is_none() && config.username.as_ref().map_or(true, |it| !it.is_empty()) { if config.repository_url.is_none() { bail!("no configuration was found for '{}'", cmd.repository); } @@ -237,7 +238,9 @@ fn resolve_repository_config(cmd: &Args) -> Result { } if let Some(usr) = config.username.as_ref() { - repo_credentials["username"] = Item::Value(usr.clone().into()); + if !usr.is_empty() { + repo_credentials["username"] = Item::Value(usr.clone().into()); + } } if let Some(url) = config.repository_url.as_ref() { diff --git a/rye/tests/common/mod.rs b/rye/tests/common/mod.rs index 6ff19b0fce..6162682514 100644 --- a/rye/tests/common/mod.rs +++ b/rye/tests/common/mod.rs @@ -70,14 +70,17 @@ repository-url = "bad url" username = "bad name" token = "bad token" -[good-repo-bad-auth] -repository-url = "https://pypi.test.org/legacy/" +[good-repo-bad-token] +repository-url = "https://test.pypi.org/legacy/" token = "bad token" -[good-repo-kerying] -repository-url = "https://pypi.test.org/legacy/" +[good-repo-keyring] +repository-url = "https://test.pypi.org/legacy/" username = "test-keyring" + +[no-repo-username-keyring] +repository-url = "https://test.pypi.org/legacy/" "#, ) .unwrap(); @@ -124,6 +127,7 @@ pub fn get_bin() -> PathBuf { get_cargo_bin("rye") } +#[derive(Debug)] pub struct Space { #[allow(unused)] tempdir: TempDir, diff --git a/rye/tests/test_publish.rs b/rye/tests/test_publish.rs index 45d5c91798..53a607c272 100644 --- a/rye/tests/test_publish.rs +++ b/rye/tests/test_publish.rs @@ -9,6 +9,7 @@ fn test_publish() { space.init("my-project"); // Build 'my-project' for distribution + // TODO(cnpryer) space.rye_cmd().arg("build").status().unwrap(); rye_cmd_snapshot!(space.rye_cmd().arg("publish"), @r###" @@ -24,7 +25,11 @@ fn test_publish() { not a terminal "###); - rye_cmd_snapshot!(space.rye_cmd().arg("publish").arg("--repository").arg("no-repo"), @r###" + // TODO(cnpryer) + // rye_cmd_snapshot!(space.rye_cmd().arg("publish").arg("--skip-save-credentials"), @r###" + // "###); + + rye_cmd_snapshot!(space.rye_cmd().arg("publish").arg("--skip-save-credentials").arg("--repository").arg("no-repo"), @r###" success: false exit_code: 1 ----- stdout ----- @@ -33,6 +38,48 @@ fn test_publish() { error: no configuration was found for 'no-repo' "###); - rye_cmd_snapshot!(space.rye_cmd().arg("publish").arg("--repository").arg("bad-repo"), @r###" + rye_cmd_snapshot!(space.rye_cmd().arg("publish").arg("--skip-save-credentials").arg("--repository").arg("bad-repo"), @r###" + success: false + exit_code: 1 + ----- stdout ----- + + ----- stderr ----- + error: relative URL without a base + "###); + + // TODO(cnpryer) + // rye_cmd_snapshot!(space.rye_cmd().arg("publish").arg("--skip-save-credentials").arg("--repository").arg("good-repo-bad-token").arg("-y"), @r###" + // success: false + // exit_code: 1 + // ----- stdout ----- + + // ----- stderr ----- + // error: relative URL without a base + // "###); + + // TODO(cnpryer) + // fail until keyring setup + rye_cmd_snapshot!(space.rye_cmd().arg("publish").arg("-r").arg("good-repo-keyring").arg("--skip-save-credentials").arg("-y"), @r###" + success: false + exit_code: 1 + ----- stdout ----- + Uploading distributions to https://test.pypi.org/legacy/ + ERROR NonInteractive: Credential not found for password. + + ----- stderr ----- + error: failed to publish files + "###); + + // TODO(cnpryer) + // prompt username + rye_cmd_snapshot!(space.rye_cmd().arg("publish").arg("-r").arg("no-repo-username-keyring"), @r###" + success: false + exit_code: 1 + ----- stdout ----- + Uploading distributions to https://test.pypi.org/legacy/ + ERROR NonInteractive: Credential not found for password. + + ----- stderr ----- + Username: error: failed to publish files "###); }