Skip to content

Commit

Permalink
Credential prompt abort shouldn't modify the cache
Browse files Browse the repository at this point in the history
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
omus committed Sep 18, 2017
1 parent d668a95 commit 2ea3e35
Showing 1 changed file with 23 additions and 3 deletions.
26 changes: 23 additions & 3 deletions test/libgit2.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 2ea3e35

Please sign in to comment.