|
600 | 600 | github_regex_test("ssh://git@github.com/$user/$repo", user, repo)
|
601 | 601 | @test !occursin(LibGit2.GITHUB_REGEX, "git@notgithub.com/$user/$repo.git")
|
602 | 602 | end
|
| 603 | + |
| 604 | + @testset "UserPasswordCredential/url constructor" begin |
| 605 | + user_pass_cred = LibGit2.UserPasswordCredential("user", "*******") |
| 606 | + url = "https://github.com" |
| 607 | + expected_cred = LibGit2.GitCredential("https", "github.com", nothing, "user", "*******") |
| 608 | + |
| 609 | + cred = LibGit2.GitCredential(user_pass_cred, url) |
| 610 | + @test cred == expected_cred |
| 611 | + |
| 612 | + # Shredding the UserPasswordCredential shouldn't result in information being lost |
| 613 | + # inside of a GitCredential. |
| 614 | + Base.shred!(user_pass_cred) |
| 615 | + @test cred == expected_cred |
| 616 | + |
| 617 | + Base.shred!(cred) |
| 618 | + Base.shred!(expected_cred) |
| 619 | + end |
603 | 620 | end
|
604 | 621 |
|
605 | 622 | mktempdir() do dir
|
@@ -2121,6 +2138,50 @@ mktempdir() do dir
|
2121 | 2138 | end
|
2122 | 2139 | end
|
2123 | 2140 | end
|
| 2141 | + |
| 2142 | + @testset "approve/reject with UserPasswordCredential" begin |
| 2143 | + # In order to use the "store" credential helper `git` needs to be installed and |
| 2144 | + # on the path. |
| 2145 | + if GIT_INSTALLED |
| 2146 | + config_path = joinpath(dir, config_file) |
| 2147 | + isfile(config_path) && rm(config_path) |
| 2148 | + |
| 2149 | + credential_path = joinpath(dir, ".git-credentials") |
| 2150 | + isfile(credential_path) && rm(credential_path) |
| 2151 | + |
| 2152 | + LibGit2.with(LibGit2.GitConfig(config_path, LibGit2.Consts.CONFIG_LEVEL_APP)) do cfg |
| 2153 | + query = LibGit2.GitCredential("https", "mygithost") |
| 2154 | + filled = LibGit2.GitCredential("https", "mygithost", nothing, "alice", "1234") |
| 2155 | + user_pass_cred = LibGit2.UserPasswordCredential("alice", "1234") |
| 2156 | + url = "https://mygithost" |
| 2157 | + |
| 2158 | + # Requires `git` to be installed and available on the path. |
| 2159 | + LibGit2.set!(cfg, "credential.helper", "store --file \"$credential_path\"") |
| 2160 | + helper = only(LibGit2.credential_helpers(cfg, query)) |
| 2161 | + |
| 2162 | + @test !isfile(credential_path) |
| 2163 | + |
| 2164 | + Base.shred!(LibGit2.fill!(helper, deepcopy(query))) do result |
| 2165 | + @test result == query |
| 2166 | + end |
| 2167 | + |
| 2168 | + LibGit2.approve(cfg, user_pass_cred, url) |
| 2169 | + @test isfile(credential_path) |
| 2170 | + Base.shred!(LibGit2.fill!(helper, deepcopy(query))) do result |
| 2171 | + @test result == filled |
| 2172 | + end |
| 2173 | + |
| 2174 | + LibGit2.reject(cfg, user_pass_cred, url) |
| 2175 | + Base.shred!(LibGit2.fill!(helper, deepcopy(query))) do result |
| 2176 | + @test result == query |
| 2177 | + end |
| 2178 | + |
| 2179 | + Base.shred!(query) |
| 2180 | + Base.shred!(filled) |
| 2181 | + Base.shred!(user_pass_cred) |
| 2182 | + end |
| 2183 | + end |
| 2184 | + end |
2124 | 2185 | end
|
2125 | 2186 |
|
2126 | 2187 | # The following tests require that we can fake a TTY so that we can provide passwords
|
|
0 commit comments