Skip to content

Commit

Permalink
Skip SSH agent when using cached credentials
Browse files Browse the repository at this point in the history
  • Loading branch information
omus committed Sep 22, 2017
1 parent 3f97c24 commit 773d226
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
2 changes: 1 addition & 1 deletion base/libgit2/callbacks.jl
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ function authenticate_ssh(libgit2credptr::Ptr{Ptr{Void}}, p::CredentialPayload,
end

# first try ssh-agent if credentials support its usage
if p.use_ssh_agent && username_ptr != Cstring(C_NULL)
if p.use_ssh_agent && username_ptr != Cstring(C_NULL) && (!revised || !isfilled(cred))
err = ccall((:git_cred_ssh_key_from_agent, :libgit2), Cint,
(Ptr{Ptr{Void}}, Cstring), libgit2credptr, username_ptr)

Expand Down
12 changes: 7 additions & 5 deletions test/libgit2.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2110,22 +2110,24 @@ mktempdir() do dir
invalid_key = joinpath(KEY_DIR, "invalid")
invalid_cred = LibGit2.SSHCredentials(username, "", invalid_key, invalid_key * ".pub")

function gen_ex(cred; allow_prompt=true)
function gen_ex(cred; allow_prompt=true, allow_ssh_agent=false)
quote
include($LIBGIT2_HELPER_PATH)
payload = CredentialPayload($cred, allow_ssh_agent=false, allow_prompt=$allow_prompt)
payload = CredentialPayload($cred, allow_ssh_agent=$allow_ssh_agent,
allow_prompt=$allow_prompt)
credential_loop($valid_cred, $url, $username, payload)
end
end

# Explicitly provided credential is correct
ex = gen_ex(valid_cred, allow_prompt=true)
# Explicitly provided credential is correct. Note: allowing prompting and
# SSH agent to ensure they are skipped.
ex = gen_ex(valid_cred, allow_prompt=true, allow_ssh_agent=true)
err, auth_attempts = challenge_prompt(ex, [])
@test err == git_ok
@test auth_attempts == 1

# Explicitly provided credential is incorrect
ex = gen_ex(invalid_cred, allow_prompt=false)
ex = gen_ex(invalid_cred, allow_prompt=false, allow_ssh_agent=false)
err, auth_attempts = challenge_prompt(ex, [])
@test err == exhausted_error
@test auth_attempts == 3
Expand Down

0 comments on commit 773d226

Please sign in to comment.