-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix issue where approved credentials were not sent to git credential …
…helpers (#40161) Due to the bug in the `GitCredential` constructor we were never writing credential data to the credential helper effectively making our use of git credential helpers read-only.
- Loading branch information
Showing
2 changed files
with
67 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -600,6 +600,23 @@ end | |
github_regex_test("ssh://[email protected]/$user/$repo", user, repo) | ||
@test !occursin(LibGit2.GITHUB_REGEX, "[email protected]/$user/$repo.git") | ||
end | ||
|
||
@testset "UserPasswordCredential/url constructor" begin | ||
user_pass_cred = LibGit2.UserPasswordCredential("user", "*******") | ||
url = "https://github.com" | ||
expected_cred = LibGit2.GitCredential("https", "github.com", nothing, "user", "*******") | ||
|
||
cred = LibGit2.GitCredential(user_pass_cred, url) | ||
@test cred == expected_cred | ||
|
||
# Shredding the UserPasswordCredential shouldn't result in information being lost | ||
# inside of a GitCredential. | ||
Base.shred!(user_pass_cred) | ||
@test cred == expected_cred | ||
|
||
Base.shred!(cred) | ||
Base.shred!(expected_cred) | ||
end | ||
end | ||
|
||
mktempdir() do dir | ||
|
@@ -2133,6 +2150,50 @@ mktempdir() do dir | |
end | ||
end | ||
end | ||
|
||
@testset "approve/reject with UserPasswordCredential" begin | ||
# In order to use the "store" credential helper `git` needs to be installed and | ||
# on the path. | ||
if GIT_INSTALLED | ||
config_path = joinpath(dir, config_file) | ||
isfile(config_path) && rm(config_path) | ||
|
||
credential_path = joinpath(dir, ".git-credentials") | ||
isfile(credential_path) && rm(credential_path) | ||
|
||
LibGit2.with(LibGit2.GitConfig(config_path, LibGit2.Consts.CONFIG_LEVEL_APP)) do cfg | ||
query = LibGit2.GitCredential("https", "mygithost") | ||
filled = LibGit2.GitCredential("https", "mygithost", nothing, "alice", "1234") | ||
user_pass_cred = LibGit2.UserPasswordCredential("alice", "1234") | ||
url = "https://mygithost" | ||
|
||
# Requires `git` to be installed and available on the path. | ||
LibGit2.set!(cfg, "credential.helper", "store --file \"$credential_path\"") | ||
helper = only(LibGit2.credential_helpers(cfg, query)) | ||
|
||
@test !isfile(credential_path) | ||
|
||
Base.shred!(LibGit2.fill!(helper, deepcopy(query))) do result | ||
@test result == query | ||
end | ||
|
||
LibGit2.approve(cfg, user_pass_cred, url) | ||
@test isfile(credential_path) | ||
Base.shred!(LibGit2.fill!(helper, deepcopy(query))) do result | ||
@test result == filled | ||
end | ||
|
||
LibGit2.reject(cfg, user_pass_cred, url) | ||
Base.shred!(LibGit2.fill!(helper, deepcopy(query))) do result | ||
@test result == query | ||
end | ||
|
||
Base.shred!(query) | ||
Base.shred!(filled) | ||
Base.shred!(user_pass_cred) | ||
end | ||
end | ||
end | ||
end | ||
|
||
# The following tests require that we can fake a TTY so that we can provide passwords | ||
|