1 commit e9219b88de5ed37af337ee2d2e71e7ec7c0aad1b
2 Author: Robbert van Ginkel <rvanginkel@buf.build>
3 Date: Thu Oct 20 16:43:28 2022 -0400
5 Fix git unit test by using fake git server rather than file:// (#1518)
7 More recent versions of git fix a CVE by disabling some usage of the
8 `file://` transport, see
9 https://github.blog/2022-10-18-git-security-vulnerabilities-announced/#cve-2022-39253.
10 We were using this transport in tests.
12 Instead, use https://git-scm.com/docs/git-http-backend to serve up this
13 repository locally so we don't have to use the file protocol. This
14 should be a more accurate tests, since we mostly expect submodules to
17 diff --git a/private/pkg/git/git_test.go b/private/pkg/git/git_test.go
18 index 7b77b6cd..7132054e 100644
19 --- a/private/pkg/git/git_test.go
20 +++ b/private/pkg/git/git_test.go
21 @@ -17,6 +17,8 @@ package git
30 @@ -213,6 +215,21 @@ func createGitDirs(
31 runCommand(ctx, t, container, runner, "git", "-C", submodulePath, "add", "test.proto")
32 runCommand(ctx, t, container, runner, "git", "-C", submodulePath, "commit", "-m", "commit 0")
34 + gitExecPath, err := command.RunStdout(ctx, container, runner, "git", "--exec-path")
35 + require.NoError(t, err)
36 + t.Log(filepath.Join(string(gitExecPath), "git-http-backend"))
37 + // https://git-scm.com/docs/git-http-backend#_description
38 + f, err := os.Create(filepath.Join(submodulePath, ".git", "git-daemon-export-ok"))
39 + require.NoError(t, err)
40 + require.NoError(t, f.Close())
41 + server := httptest.NewServer(&cgi.Handler{
42 + Path: filepath.Join(strings.TrimSpace(string(gitExecPath)), "git-http-backend"),
44 + Env: []string{"GIT_PROJECT_ROOT=" + submodulePath},
46 + t.Cleanup(server.Close)
47 + submodulePath = server.URL
49 originPath := filepath.Join(tmpDir, "origin")
50 require.NoError(t, os.MkdirAll(originPath, 0777))
51 runCommand(ctx, t, container, runner, "git", "-C", originPath, "init")