From 2e81564f9071858bcdd557c5085bce14baa8e1a7 Mon Sep 17 00:00:00 2001 From: wildart Date: Tue, 17 May 2016 22:12:35 -0400 Subject: [PATCH] fixed typos, documentation & test --- base/libgit2/callbacks.jl | 28 +++++++++++++++++----------- test/libgit2-online.jl | 36 +++++++++++++++++++----------------- 2 files changed, 36 insertions(+), 28 deletions(-) diff --git a/base/libgit2/callbacks.jl b/base/libgit2/callbacks.jl index a2fabb67757b0b..740d3fde44bf4a 100644 --- a/base/libgit2/callbacks.jl +++ b/base/libgit2/callbacks.jl @@ -27,21 +27,27 @@ end """Credentials callback function Function provides different credential acquisition functionality w.r.t. a connection protocol. -If payload is provided then `payload_ptr` should contain `LibGit2.AbstractPayload` object. +If payload is provided then `payload_ptr` should contain `LibGit2.AbstractCredentials` object. For `LibGit2.Consts.CREDTYPE_USERPASS_PLAINTEXT` type, if payload contains fields: -`user` & `pass` they are used to create authentication credentials. -In addition, if payload has field `used` it can be set to `true` to indicate that payload was used -and abort callback with error. This behavior is required to avoid repeated authentication calls with incorrect credentials. +`user` & `pass`, they are used to create authentication credentials. +Empty `user` name and `pass`word trigger authentication error. + +For `LibGit2.Consts.CREDTYPE_SSH_KEY` type, if payload contains fields: +`user`, `prvkey`, `pubkey` & `pass`, they are used to create authentication credentials. +Empty `user` name triggers authentication error. Order of credential checks (if supported): -- ssh key pair (ssh-agent if specified in `payload`) +- ssh key pair (ssh-agent if specified in payload's `usesshagent` field) - plain text **Note**: Due to the specifics of `libgit2` authentication procedure, when authentication fails, -this functions is called again without any indication whether authentication was successful or not. +this function is called again without any indication whether authentication was successful or not. To avoid an infinite loop from repeatedly using the same faulty credentials, -use a call counting strategy to counteract this behaviour. +`checkused!` function can be called to test if credentials were used if call returns `true` value. +Used credentials trigger user prompt for (re)entering required information. +`UserPasswordCredentials` and `CachedCredentials` are implemented using a call counting strategy +that prevents repeated usage of faulty credentials. """ function credentials_callback(cred::Ptr{Ptr{Void}}, url_ptr::Cstring, username_ptr::Cstring, @@ -55,7 +61,7 @@ function credentials_callback(cred::Ptr{Ptr{Void}}, url_ptr::Cstring, host = urlparts.captures[5] schema = schema === nothing ? "" : schema*"://" - # get credentials object form payload ref + # get credentials object from payload pointer creds = EmptyCredentials() if payload_ptr != C_NULL tmpobj = unsafe_pointer_to_objref(payload_ptr) @@ -69,8 +75,8 @@ function credentials_callback(cred::Ptr{Ptr{Void}}, url_ptr::Cstring, if isset(allowed_types, Cuint(Consts.CREDTYPE_SSH_KEY)) credid = "ssh://$host" - # set ssh-agent triger for first use - if creds[:usesshagent, credid] == nothing + # set ssh-agent trigger for first use + if creds[:usesshagent, credid] === nothing creds[:usesshagent, credid] = "Y" end @@ -147,7 +153,7 @@ function credentials_callback(cred::Ptr{Ptr{Void}}, url_ptr::Cstring, end creds[:pass, credid] = passphrase # save credentials - isempty(username) && return Cint(Error.EAUTH) + isempty(username) && return Cint(Error.EAUTH) err = ccall((:git_cred_ssh_key_new, :libgit2), Cint, (Ptr{Ptr{Void}}, Cstring, Cstring, Cstring, Cstring), diff --git a/test/libgit2-online.jl b/test/libgit2-online.jl index 98fe4c4167d7e8..436003eb37160a 100644 --- a/test/libgit2-online.jl +++ b/test/libgit2-online.jl @@ -21,28 +21,30 @@ mktempdir() do dir finalize(repo) end #end - try + #@testset "with incorrect url" begin - repo_path = joinpath(dir, "Example2") - # credential are required because github try authenticate on unknown repo - cred = LibGit2.UserPasswordCredentials("","") # empty credentials cause authentication error - LibGit2.clone(https_prefix*repo_url*randstring(10), repo_path, payload=Nullable(cred)) - error("unexpected") + try + repo_path = joinpath(dir, "Example2") + # credentials are required because github tries to authenticate on unknown repo + cred = LibGit2.UserPasswordCredentials("","") # empty credentials cause authentication error + LibGit2.clone(https_prefix*repo_url*randstring(10), repo_path, payload=Nullable(cred)) + error("unexpected") + catch ex + @test isa(ex, LibGit2.Error.GitError) + @test ex.code == LibGit2.Error.EAUTH + end #end - catch ex - @test isa(ex, LibGit2.Error.GitError) - @test ex.code == LibGit2.Error.EAUTH - end - try - #@testset "with 'ssh' protocol (by default is not supported)" begin + #TODO: remove or condition on libgit2 features this test when ssh protocol will be supported + #@testset "with 'ssh' protocol (by default is not supported)" begin + try repo_path = joinpath(dir, "Example3") @test_throws LibGit2.Error.GitError LibGit2.clone(ssh_prefix*repo_url, repo_path) - #end - catch ex - # but we cloned succesfully, so check that repo was created - ex.fail == 1 && @test isdir(joinpath(path, ".git")) - end + catch ex + # but we cloned succesfully, so check that repo was created + ex.fail == 1 && @test isdir(joinpath(path, ".git")) + end + #end #end end