Skip to content

Commit

Permalink
LibGit2 rebase fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
nalimilan committed Dec 14, 2017
1 parent aa541cb commit 8cb9cc5
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 38 deletions.
10 changes: 6 additions & 4 deletions base/libgit2/types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1323,14 +1323,15 @@ The `shred` keyword controls whether sensitive information in the payload creden
should be destroyed. Should only be set to `false` during testing.
"""
function approve(p::CredentialPayload; shred::Bool=true)
p.credential === nothing && return # No credentials were used
cred = p.credential
cred === nothing && return # No credentials were used

if p.cache !== nothing
approve(p.cache, cred, p.url)
shred = false # Avoid wiping `cred` as this would also wipe the cached copy
end
if p.allow_git_helpers
approve(p.config, p.credential, p.url)
approve(p.config, cred, p.url)
end

shred && securezero!(cred)
Expand All @@ -1347,14 +1348,15 @@ The `shred` keyword controls whether sensitive information in the payload creden
should be destroyed. Should only be set to `false` during testing.
"""
function reject(p::CredentialPayload; shred::Bool=true)
p.credential === nothing && return # No credentials were used
cred = p.credential
cred === nothing && return # No credentials were used

if p.cache !== nothing
reject(p.cache, cred, p.url)
shred = false # Avoid wiping `cred` as this would also wipe the cached copy
end
if p.allow_git_helpers
reject(p.config, p.credential, p.url)
reject(p.config, cred, p.url)
end

shred && securezero!(cred)
Expand Down
2 changes: 1 addition & 1 deletion stdlib/Distributed/src/process_messages.jl
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ end

function handle_msg(msg::JoinCompleteMsg, header, r_stream, w_stream, version)
w = map_sock_wrkr[r_stream]
environ = get(w.config.environ, Dict())
environ = coalesce(w.config.environ, Dict())
environ[:cpu_cores] = msg.cpu_cores
w.config.environ = environ
w.config.ospid = msg.ospid
Expand Down
11 changes: 1 addition & 10 deletions test/libgit2-helpers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,4 @@ function credential_loop(
payload::CredentialPayload=DEFAULT_PAYLOAD;
shred::Bool=true)
credential_loop(valid_credential, url, user, 0x000046, payload, shred=shred)
end

function credential_loop(
valid_credential::AbstractCredential,
url::AbstractString,
user::AbstractString,
payload::CredentialPayload=DEFAULT_PAYLOAD;
shred::Bool=true)
credential_loop(valid_credential, url, user, payload, shred=shred)
end
end
46 changes: 23 additions & 23 deletions test/libgit2.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2182,8 +2182,8 @@ mktempdir() do dir
err, auth_attempts, p = challenge_prompt(ex, [])
@test err == git_ok
@test auth_attempts == 1
@test get(p.credential).prvkey == default_key
@test get(p.credential).pubkey == default_key * ".pub"
@test p.credential.prvkey == default_key
@test p.credential.pubkey == default_key * ".pub"

# Confirm the private key if any other prompting is required
ex = gen_ex(valid_p_cred)
Expand Down Expand Up @@ -2272,16 +2272,16 @@ mktempdir() do dir
err, auth_attempts, p = challenge_prompt(ex, [])
@test err == git_ok
@test auth_attempts == 1
@test get(p.explicit) == valid_cred
@test get(p.credential) != valid_cred
@test p.explicit == valid_cred
@test p.credential != valid_cred

# Explicitly provided credential is incorrect
ex = gen_ex(invalid_cred, allow_prompt=false, allow_ssh_agent=false)
err, auth_attempts, p = challenge_prompt(ex, [])
@test err == exhausted_error
@test auth_attempts == 3
@test get(p.explicit) == invalid_cred
@test get(p.credential) != invalid_cred
@test p.explicit == invalid_cred
@test p.credential != invalid_cred
end

@testset "HTTPS explicit credentials" begin
Expand All @@ -2304,16 +2304,16 @@ mktempdir() do dir
err, auth_attempts, p = challenge_prompt(ex, [])
@test err == git_ok
@test auth_attempts == 1
@test get(p.explicit) == valid_cred
@test get(p.credential) != valid_cred
@test p.explicit == valid_cred
@test p.credential != valid_cred

# Explicitly provided credential is incorrect
ex = gen_ex(invalid_cred, allow_prompt=false)
err, auth_attempts, p = challenge_prompt(ex, [])
@test err == exhausted_error
@test auth_attempts == 2
@test get(p.explicit) == invalid_cred
@test get(p.credential) != invalid_cred
@test p.explicit == invalid_cred
@test p.credential != invalid_cred
end

@testset "Cached credentials" begin
Expand Down Expand Up @@ -2353,12 +2353,12 @@ mktempdir() do dir
"Password for 'https://$valid_username@github.com':" => "$valid_password\n",
]
err, auth_attempts, p = challenge_prompt(ex, challenges)
cache = get(p.cache)
cache = p.cache
@test err == git_ok
@test auth_attempts == 1
@test typeof(cache) == LibGit2.CachedCredentials
@test cache.cred == Dict(cred_id => valid_cred)
@test get(p.credential) == valid_cred
@test p.credential == valid_cred

# Replace a credential in the cache
ex = gen_ex(cached_cred=invalid_cred)
Expand All @@ -2367,12 +2367,12 @@ mktempdir() do dir
"Password for 'https://$valid_username@github.com':" => "$valid_password\n",
]
err, auth_attempts, p = challenge_prompt(ex, challenges)
cache = get(p.cache)
cache = p.cache
@test err == git_ok
@test auth_attempts == 2
@test typeof(cache) == LibGit2.CachedCredentials
@test cache.cred == Dict(cred_id => valid_cred)
@test get(p.credential) == valid_cred
@test p.credential == valid_cred

# Canceling a credential request should leave the cache unmodified
ex = gen_ex(cached_cred=invalid_cred)
Expand All @@ -2382,22 +2382,22 @@ mktempdir() do dir
"Username for 'https://github.com' [foo]:" => "\x04",
]
err, auth_attempts, p = challenge_prompt(ex, challenges)
cache = get(p.cache)
cache = p.cache
@test err == abort_prompt
@test auth_attempts == 3
@test typeof(cache) == LibGit2.CachedCredentials
@test cache.cred == Dict(cred_id => invalid_cred)
@test get(p.credential) != invalid_cred
@test p.credential != invalid_cred

# An EAUTH error should remove credentials from the cache
ex = gen_ex(cached_cred=invalid_cred, allow_prompt=false)
err, auth_attempts, p = challenge_prompt(ex, [])
cache = get(p.cache)
cache = p.cache
@test err == exhausted_error
@test auth_attempts == 2
@test typeof(cache) == LibGit2.CachedCredentials
@test cache.cred == Dict()
@test get(p.credential) != invalid_cred
@test p.credential != invalid_cred
end

@testset "HTTPS git helper username" begin
Expand Down Expand Up @@ -2433,7 +2433,7 @@ mktempdir() do dir
@test auth_attempts == 1

# Verify credential wasn't accidentally zeroed (#24731)
@test get(p.credential) == valid_cred
@test p.credential == valid_cred
end

@testset "Incompatible explicit credentials" begin
Expand All @@ -2450,8 +2450,8 @@ mktempdir() do dir
err, auth_attempts, p = challenge_prompt(expect_ssh_ex, [])
@test err == incompatible_error
@test auth_attempts == 1
@test get(p.explicit) == valid_cred
@test get(p.credential) != valid_cred
@test p.explicit == valid_cred
@test p.credential != valid_cred


# User provides a SSH credential where a user/password credential is required.
Expand All @@ -2467,8 +2467,8 @@ mktempdir() do dir
err, auth_attempts, p = challenge_prompt(expect_https_ex, [])
@test err == incompatible_error
@test auth_attempts == 1
@test get(p.explicit) == valid_cred
@test get(p.credential) != valid_cred
@test p.explicit == valid_cred
@test p.credential != valid_cred
end

# A hypothetical scenario where the the allowed authentication can either be
Expand Down

0 comments on commit 8cb9cc5

Please sign in to comment.