|
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
|
@@ -2133,6 +2150,50 @@ mktempdir() do dir
|
2133 | 2150 | end
|
2134 | 2151 | end
|
2135 | 2152 | end
|
| 2153 | + |
| 2154 | + @testset "approve/reject with UserPasswordCredential" begin |
| 2155 | + # In order to use the "store" credential helper `git` needs to be installed and |
| 2156 | + # on the path. |
| 2157 | + if GIT_INSTALLED |
| 2158 | + config_path = joinpath(dir, config_file) |
| 2159 | + isfile(config_path) && rm(config_path) |
| 2160 | + |
| 2161 | + credential_path = joinpath(dir, ".git-credentials") |
| 2162 | + isfile(credential_path) && rm(credential_path) |
| 2163 | + |
| 2164 | + LibGit2.with(LibGit2.GitConfig(config_path, LibGit2.Consts.CONFIG_LEVEL_APP)) do cfg |
| 2165 | + query = LibGit2.GitCredential("https", "mygithost") |
| 2166 | + filled = LibGit2.GitCredential("https", "mygithost", nothing, "alice", "1234") |
| 2167 | + user_pass_cred = LibGit2.UserPasswordCredential("alice", "1234") |
| 2168 | + url = "https://mygithost" |
| 2169 | + |
| 2170 | + # Requires `git` to be installed and available on the path. |
| 2171 | + LibGit2.set!(cfg, "credential.helper", "store --file \"$credential_path\"") |
| 2172 | + helper = only(LibGit2.credential_helpers(cfg, query)) |
| 2173 | + |
| 2174 | + @test !isfile(credential_path) |
| 2175 | + |
| 2176 | + Base.shred!(LibGit2.fill!(helper, deepcopy(query))) do result |
| 2177 | + @test result == query |
| 2178 | + end |
| 2179 | + |
| 2180 | + LibGit2.approve(cfg, user_pass_cred, url) |
| 2181 | + @test isfile(credential_path) |
| 2182 | + Base.shred!(LibGit2.fill!(helper, deepcopy(query))) do result |
| 2183 | + @test result == filled |
| 2184 | + end |
| 2185 | + |
| 2186 | + LibGit2.reject(cfg, user_pass_cred, url) |
| 2187 | + Base.shred!(LibGit2.fill!(helper, deepcopy(query))) do result |
| 2188 | + @test result == query |
| 2189 | + end |
| 2190 | + |
| 2191 | + Base.shred!(query) |
| 2192 | + Base.shred!(filled) |
| 2193 | + Base.shred!(user_pass_cred) |
| 2194 | + end |
| 2195 | + end |
| 2196 | + end |
2136 | 2197 | end
|
2137 | 2198 |
|
2138 | 2199 | # The following tests require that we can fake a TTY so that we can provide passwords
|
|
0 commit comments