Add test cases for URL matching with the native keyring (#15641)

This commit is contained in:
Zanie Blue 2025-09-02 16:56:40 -05:00 committed by GitHub
parent 8fcd88d2d4
commit 63b93a1db0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 115 additions and 0 deletions

View File

@ -1287,3 +1287,118 @@ fn logout_text_store_multiple_usernames() {
"
);
}
#[test]
#[cfg(feature = "native-auth")]
fn native_auth_prefix_match() -> Result<()> {
let context = TestContext::new_with_versions(&[]).with_real_home();
// Clear state before the test
context
.auth_logout()
.arg("https://example.com/api")
.arg("--username")
.arg("testuser")
.env(EnvVars::UV_PREVIEW_FEATURES, "native-auth")
.status()?;
// Login with credentials for a path
uv_snapshot!(context.auth_login()
.arg("https://example.com/api")
.arg("--username")
.arg("testuser")
.arg("--password")
.arg("testpass")
.env(EnvVars::UV_PREVIEW_FEATURES, "native-auth"), @r"
success: true
exit_code: 0
----- stdout -----
----- stderr -----
Stored credentials for testuser@https://example.com/api
"
);
// A request for a child path does not match, the native store does not yet implement prefix
// matching
uv_snapshot!(context.auth_token()
.arg("https://example.com/api/v1")
.arg("--username")
.arg("testuser")
.env(EnvVars::UV_PREVIEW_FEATURES, "native-auth"), @r"
success: false
exit_code: 2
----- stdout -----
----- stderr -----
error: Failed to fetch credentials for testuser@https://example.com/api/v1
"
);
Ok(())
}
#[test]
#[cfg(feature = "native-auth")]
fn native_auth_host_fallback() -> Result<()> {
let context = TestContext::new_with_versions(&[]).with_real_home();
// Clear state before the test
context
.auth_logout()
.arg("example.com")
.arg("--username")
.arg("testuser")
.env(EnvVars::UV_PREVIEW_FEATURES, "native-auth")
.status()?;
// Login with credentials for the host
uv_snapshot!(context.auth_login()
.arg("example.com")
.arg("--username")
.arg("testuser")
.arg("--password")
.arg("hostpass")
.env(EnvVars::UV_PREVIEW_FEATURES, "native-auth"), @r"
success: true
exit_code: 0
----- stdout -----
----- stderr -----
Stored credentials for testuser@https://example.com/
"
);
// Should fallback to host-level matching
// TODO(zanieb): This is not working as intended
uv_snapshot!(context.auth_token()
.arg("https://example.com/any/path")
.arg("--username")
.arg("testuser")
.env(EnvVars::UV_PREVIEW_FEATURES, "native-auth"), @r"
success: false
exit_code: 2
----- stdout -----
----- stderr -----
error: Failed to fetch credentials for testuser@https://example.com/any/path
"
);
// A request to another host should not work
uv_snapshot!(context.auth_token()
.arg("https://another-example.com/any/path")
.arg("--username")
.arg("testuser")
.env(EnvVars::UV_PREVIEW_FEATURES, "native-auth"), @r"
success: false
exit_code: 2
----- stdout -----
----- stderr -----
error: Failed to fetch credentials for testuser@https://another-example.com/any/path
"
);
Ok(())
}