diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-08-03 00:09:24 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-08-03 00:09:24 +0300 |
commit | ec00688fc83b21455813fa3ee338d65ee66e6d0b (patch) | |
tree | 1b207b861e32742da874ee2882009299716a494b /workhorse/internal/upstream | |
parent | 93fdeb5a619e45cb64ff346c127ff4d68c619ffe (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'workhorse/internal/upstream')
-rw-r--r-- | workhorse/internal/upstream/routes.go | 1 | ||||
-rw-r--r-- | workhorse/internal/upstream/routes_test.go | 11 | ||||
-rw-r--r-- | workhorse/internal/upstream/upstream_test.go | 38 |
3 files changed, 50 insertions, 0 deletions
diff --git a/workhorse/internal/upstream/routes.go b/workhorse/internal/upstream/routes.go index e634f0ca66c..f1b4199b87f 100644 --- a/workhorse/internal/upstream/routes.go +++ b/workhorse/internal/upstream/routes.go @@ -394,6 +394,7 @@ func configureRoutes(u *upstream) { u.route("GET", geoGitProjectPattern+`info/refs\z`, git.GetInfoRefsHandler(api)), u.route("POST", geoGitProjectPattern+`git-upload-pack\z`, contentEncodingHandler(git.UploadPack(api)), withMatcher(isContentType("application/x-git-upload-pack-request"))), u.route("GET", geoGitProjectPattern+`gitlab-lfs/objects/([0-9a-f]{64})\z`, defaultUpstream), + u.route("POST", geoGitProjectPattern+`info/lfs/objects/batch\z`, defaultUpstream), // Serve health checks from this Geo secondary u.route("", "^/-/(readiness|liveness)$", static.DeployPage(probeUpstream)), diff --git a/workhorse/internal/upstream/routes_test.go b/workhorse/internal/upstream/routes_test.go index 13c000bf791..09551b7f605 100644 --- a/workhorse/internal/upstream/routes_test.go +++ b/workhorse/internal/upstream/routes_test.go @@ -1,6 +1,7 @@ package upstream import ( + "bytes" "testing" "gitlab.com/gitlab-org/gitlab/workhorse/internal/testhelper" @@ -86,3 +87,13 @@ func TestAssetsServedLocallyWithGeoProxy(t *testing.T) { runTestCasesWithGeoProxyEnabled(t, testCases) } + +func TestLfsBatchSecondaryGitSSHPullWithGeoProxy(t *testing.T) { + body := bytes.NewBuffer([]byte(`{"operation":"download","objects": [{"oid":"fakeoid", "size":10}], "transfers":["basic", "ssh","lfs-standalone-file"],"ref":{"name":"refs/heads/fakeref"},"hash_algo":"sha256"}`)) + contentType := "application/vnd.git-lfs+json; charset=utf-8" + testCases := []testCasePost{ + {testCase{"GitLab Shell call to /group/project.git/info/lfs/objects/batch", "/group/project.git/info/lfs/objects/batch", "Local Rails server received request to path /group/project.git/info/lfs/objects/batch"}, contentType, body}, + } + + runTestCasesWithGeoProxyEnabledPost(t, testCases) +} diff --git a/workhorse/internal/upstream/upstream_test.go b/workhorse/internal/upstream/upstream_test.go index 705e40c74d5..02da6baa8bf 100644 --- a/workhorse/internal/upstream/upstream_test.go +++ b/workhorse/internal/upstream/upstream_test.go @@ -30,6 +30,12 @@ type testCase struct { expectedResponse string } +type testCasePost struct { + test testCase + contentType string + body io.Reader +} + func TestMain(m *testing.M) { // Secret should be configured before any Geo API poll happens to prevent // race conditions where the first API call happens without a secret path @@ -345,6 +351,24 @@ func runTestCases(t *testing.T, ws *httptest.Server, testCases []testCase) { } } +func runTestCasesPost(t *testing.T, ws *httptest.Server, testCases []testCasePost) { + t.Helper() + for _, tc := range testCases { + t.Run(tc.test.desc, func(t *testing.T) { + + resp, err := http.Post(ws.URL+tc.test.path, tc.contentType, tc.body) + require.NoError(t, err) + defer resp.Body.Close() + + body, err := io.ReadAll(resp.Body) + require.NoError(t, err) + + require.Equal(t, 200, resp.StatusCode, "response code") + require.Equal(t, tc.test.expectedResponse, string(body)) + }) + } +} + func runTestCasesWithGeoProxyEnabled(t *testing.T, testCases []testCase) { remoteServer, rsDeferredClose := startRemoteServer("Geo primary") defer rsDeferredClose() @@ -359,6 +383,20 @@ func runTestCasesWithGeoProxyEnabled(t *testing.T, testCases []testCase) { runTestCases(t, ws, testCases) } +func runTestCasesWithGeoProxyEnabledPost(t *testing.T, testCases []testCasePost) { + remoteServer, rsDeferredClose := startRemoteServer("Geo primary") + defer rsDeferredClose() + + geoProxyEndpointResponseBody := fmt.Sprintf(`{"geo_enabled":true,"geo_proxy_url":"%v"}`, remoteServer.URL) + railsServer, deferredClose := startRailsServer("Local Rails server", &geoProxyEndpointResponseBody) + defer deferredClose() + + ws, wsDeferredClose, _ := startWorkhorseServer(railsServer.URL, true) + defer wsDeferredClose() + + runTestCasesPost(t, ws, testCases) +} + func newUpstreamConfig(authBackend string) *config.Config { return &config.Config{ Version: "123", |