diff --git a/test/libgit2.jl b/test/libgit2.jl index 52ea4fa8f3b873..dd1821f672e811 100644 --- a/test/libgit2.jl +++ b/test/libgit2.jl @@ -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://foo@github.com':" => "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