Skip to content

Commit 2ea3e35

Browse files
committed
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
1 parent d668a95 commit 2ea3e35

File tree

1 file changed

+23
-3
lines changed

1 file changed

+23
-3
lines changed

test/libgit2.jl

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2053,12 +2053,12 @@ mktempdir() do dir
20532053
invalid_password = randstring(15)
20542054
invalid_cred = LibGit2.UserPasswordCredentials(invalid_username, invalid_password)
20552055

2056-
function gen_ex(; cached_cred=nothing)
2056+
function gen_ex(; cached_cred=nothing, allow_prompt=true)
20572057
quote
20582058
include($LIBGIT2_HELPER_PATH)
20592059
cache = CachedCredentials()
20602060
$(cached_cred !== nothing && :(LibGit2.approve(cache, $cached_cred, $url)))
2061-
payload = CredentialPayload(cache)
2061+
payload = CredentialPayload(cache, allow_prompt=$allow_prompt)
20622062
err, auth_attempts = credential_loop($valid_cred, $url, "", payload)
20632063
(err, auth_attempts, cache)
20642064
end
@@ -2075,7 +2075,6 @@ mktempdir() do dir
20752075
"Username for 'https://github.com':" => "$valid_username\n",
20762076
"Password for 'https://$valid_username@github.com':" => "$valid_password\n",
20772077
]
2078-
20792078
err, auth_attempts, cache = challenge_prompt(ex, challenges)
20802079
@test err == git_ok
20812080
@test auth_attempts == 1
@@ -2093,6 +2092,27 @@ mktempdir() do dir
20932092
@test auth_attempts == 2
20942093
@test typeof(cache) == LibGit2.CachedCredentials
20952094
@test cache.cred == Dict(cred_id => valid_cred)
2095+
2096+
# Canceling a credential request should leave the cache unmodified
2097+
ex = gen_ex(cached_cred=invalid_cred)
2098+
challenges = [
2099+
"Username for 'https://github.com' [alice]:" => "foo\n",
2100+
"Password for 'https://[email protected]':" => "bar\n",
2101+
"Username for 'https://github.com' [foo]:" => "\x04",
2102+
]
2103+
err, auth_attempts, cache = challenge_prompt(ex, challenges)
2104+
@test err == abort_prompt
2105+
@test auth_attempts == 3
2106+
@test typeof(cache) == LibGit2.CachedCredentials
2107+
@test cache.cred == Dict(cred_id => invalid_cred)
2108+
2109+
# An EAUTH error should remove credentials from the cache
2110+
ex = gen_ex(cached_cred=invalid_cred, allow_prompt=false)
2111+
err, auth_attempts, cache = challenge_prompt(ex, [])
2112+
@test err == eauth_error
2113+
@test auth_attempts == 2
2114+
@test typeof(cache) == LibGit2.CachedCredentials
2115+
@test cache.cred == Dict()
20962116
end
20972117

20982118
@testset "Incompatible explicit credentials" begin

0 commit comments

Comments
 (0)