-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Credential prompt abort shouldn't modify the cache
Requires: - Approval/rejection (#23711) - Allow prompt keyword (#23690) Helpful: - Generate tests (#23668) I would apply this commit to the approval/rejection PR
- Loading branch information
Showing
1 changed file
with
23 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2053,12 +2053,12 @@ mktempdir() do dir | |
invalid_password = randstring(15) | ||
invalid_cred = LibGit2.UserPasswordCredentials(invalid_username, invalid_password) | ||
|
||
function gen_ex(; cached_cred=nothing) | ||
function gen_ex(; cached_cred=nothing, allow_prompt=true) | ||
quote | ||
include($LIBGIT2_HELPER_PATH) | ||
cache = CachedCredentials() | ||
$(cached_cred !== nothing && :(LibGit2.approve(cache, $cached_cred, $url))) | ||
payload = CredentialPayload(cache) | ||
payload = CredentialPayload(cache, allow_prompt=$allow_prompt) | ||
err, auth_attempts = credential_loop($valid_cred, $url, "", payload) | ||
(err, auth_attempts, cache) | ||
end | ||
|
@@ -2075,7 +2075,6 @@ mktempdir() do dir | |
"Username for 'https://github.com':" => "$valid_username\n", | ||
"Password for 'https://$valid_username@github.com':" => "$valid_password\n", | ||
] | ||
|
||
err, auth_attempts, cache = challenge_prompt(ex, challenges) | ||
@test err == git_ok | ||
@test auth_attempts == 1 | ||
|
@@ -2093,6 +2092,27 @@ mktempdir() do dir | |
@test auth_attempts == 2 | ||
@test typeof(cache) == LibGit2.CachedCredentials | ||
@test cache.cred == Dict(cred_id => valid_cred) | ||
|
||
# Canceling a credential request should leave the cache unmodified | ||
ex = gen_ex(cached_cred=invalid_cred) | ||
challenges = [ | ||
"Username for 'https://github.com' [alice]:" => "foo\n", | ||
"Password for 'https://[email protected]':" => "bar\n", | ||
"Username for 'https://github.com' [foo]:" => "\x04", | ||
] | ||
err, auth_attempts, cache = challenge_prompt(ex, challenges) | ||
@test err == abort_prompt | ||
@test auth_attempts == 3 | ||
@test typeof(cache) == LibGit2.CachedCredentials | ||
@test cache.cred == Dict(cred_id => invalid_cred) | ||
|
||
# An EAUTH error should remove credentials from the cache | ||
ex = gen_ex(cached_cred=invalid_cred, allow_prompt=false) | ||
err, auth_attempts, cache = challenge_prompt(ex, []) | ||
@test err == eauth_error | ||
@test auth_attempts == 2 | ||
@test typeof(cache) == LibGit2.CachedCredentials | ||
@test cache.cred == Dict() | ||
end | ||
|
||
@testset "Incompatible explicit credentials" begin | ||
|