Skip to content

Commit

Permalink
Fix username prompt condition
Browse files Browse the repository at this point in the history
Note: I need to look into this
  • Loading branch information
cnpryer committed Feb 25, 2024
1 parent a5c03c0 commit 9ad3bd0
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 8 deletions.
7 changes: 5 additions & 2 deletions rye/src/cli/publish.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,8 @@ fn resolve_repository_config(cmd: &Args) -> Result<RepositoryConfig, Error> {
}

// 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);
}
Expand All @@ -237,7 +238,9 @@ fn resolve_repository_config(cmd: &Args) -> Result<RepositoryConfig, Error> {
}

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() {
Expand Down
12 changes: 8 additions & 4 deletions rye/tests/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -124,6 +127,7 @@ pub fn get_bin() -> PathBuf {
get_cargo_bin("rye")
}

#[derive(Debug)]
pub struct Space {
#[allow(unused)]
tempdir: TempDir,
Expand Down
51 changes: 49 additions & 2 deletions rye/tests/test_publish.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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###"
Expand All @@ -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 -----
Expand All @@ -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
"###);
}

0 comments on commit 9ad3bd0

Please sign in to comment.