diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-01-20 18:10:29 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-01-20 18:10:29 +0300 |
commit | ef8c47e97e1c178291e4857314a3f53875d75062 (patch) | |
tree | 89ef0c1cd34e864aad1346a0ee07bccb81a9ac65 /workhorse/internal | |
parent | f2ebc27236ecef67e67da1da864bbf58e9b9c267 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'workhorse/internal')
-rw-r--r-- | workhorse/internal/filestore/save_file_opts.go | 2 | ||||
-rw-r--r-- | workhorse/internal/filestore/save_file_opts_test.go | 10 | ||||
-rw-r--r-- | workhorse/internal/git/info-refs.go | 5 | ||||
-rw-r--r-- | workhorse/internal/git/info-refs_test.go | 33 | ||||
-rw-r--r-- | workhorse/internal/upstream/routes.go | 22 |
5 files changed, 60 insertions, 12 deletions
diff --git a/workhorse/internal/filestore/save_file_opts.go b/workhorse/internal/filestore/save_file_opts.go index 1eb708c3f55..d0b2c6ec809 100644 --- a/workhorse/internal/filestore/save_file_opts.go +++ b/workhorse/internal/filestore/save_file_opts.go @@ -146,7 +146,7 @@ func (c *ObjectStorageConfig) IsGoCloud() bool { func (c *ObjectStorageConfig) IsValid() bool { if c.IsAWS() { - return c.S3Config.Bucket != "" && c.S3Config.Region != "" && c.s3CredentialsValid() + return c.S3Config.Bucket != "" && c.s3CredentialsValid() } else if c.IsGoCloud() { // We could parse and validate the URL, but GoCloud providers // such as AzureRM don't have a fallback to normal HTTP, so we diff --git a/workhorse/internal/filestore/save_file_opts_test.go b/workhorse/internal/filestore/save_file_opts_test.go index 2d6cd683b51..facfb1cdc85 100644 --- a/workhorse/internal/filestore/save_file_opts_test.go +++ b/workhorse/internal/filestore/save_file_opts_test.go @@ -187,6 +187,9 @@ func TestUseWorkhorseClientEnabled(t *testing.T) { iamConfig := missingCfg iamConfig.S3Config.UseIamProfile = true + missingRegion := cfg + missingRegion.S3Config.Region = "" + tests := []struct { name string UseWorkhorseClient bool @@ -245,6 +248,13 @@ func TestUseWorkhorseClientEnabled(t *testing.T) { }, expected: false, }, + { + name: "missing S3 region", + UseWorkhorseClient: true, + remoteTempObjectID: "test-object", + objectStorageConfig: missingRegion, + expected: true, + }, } for _, test := range tests { diff --git a/workhorse/internal/git/info-refs.go b/workhorse/internal/git/info-refs.go index e5491a7b733..6d0826a22f9 100644 --- a/workhorse/internal/git/info-refs.go +++ b/workhorse/internal/git/info-refs.go @@ -20,6 +20,11 @@ func GetInfoRefsHandler(a *api.API) http.Handler { return repoPreAuthorizeHandler(a, handleGetInfoRefs) } +func IsSmartInfoRefs(r *http.Request) bool { + service := r.URL.Query().Get("service") + return r.Method == "GET" && (service == "git-upload-pack" || service == "git-receive-pack") +} + func handleGetInfoRefs(rw http.ResponseWriter, r *http.Request, a *api.Response) { responseWriter := NewHttpResponseWriter(rw) // Log 0 bytes in because we ignore the request body (and there usually is none anyway). diff --git a/workhorse/internal/git/info-refs_test.go b/workhorse/internal/git/info-refs_test.go new file mode 100644 index 00000000000..ed66518b8d3 --- /dev/null +++ b/workhorse/internal/git/info-refs_test.go @@ -0,0 +1,33 @@ +package git + +import ( + "net/http" + "net/url" + "testing" + + "github.com/stretchr/testify/require" +) + +func TestIsSmartInfoRefs(t *testing.T) { + testCases := []struct { + method string + url string + match bool + }{ + {"GET", "?service=git-upload-pack", true}, + {"GET", "?service=git-receive-pack", true}, + {"GET", "", false}, + {"GET", "?service=", false}, + {"GET", "?service=foo", false}, + {"POST", "?service=git-upload-pack", false}, + {"POST", "?service=git-receive-pack", false}, + } + + for _, tc := range testCases { + url, err := url.Parse(tc.url) + require.NoError(t, err) + + r := http.Request{Method: tc.method, URL: url} + require.Equal(t, tc.match, IsSmartInfoRefs(&r)) + } +} diff --git a/workhorse/internal/upstream/routes.go b/workhorse/internal/upstream/routes.go index 5bbd245719b..b8a97a1b5f6 100644 --- a/workhorse/internal/upstream/routes.go +++ b/workhorse/internal/upstream/routes.go @@ -53,13 +53,13 @@ type uploadPreparers struct { } const ( - apiPattern = `^/api/` - ciAPIPattern = `^/ci/api/` - gitProjectPattern = `^/([^/]+/){1,}[^/]+\.git/` - projectPattern = `^/([^/]+/){1,}[^/]+/` - snippetUploadPattern = `^/uploads/personal_snippet` - userUploadPattern = `^/uploads/user` - importPattern = `^/import/` + apiPattern = `\A/api/` + ciAPIPattern = `\A/ci/api/` + gitRepositoryPattern = `\A/.+\.git/` + projectPattern = `\A/([^/]+/){1,}[^/]+/` + snippetUploadPattern = `\A/uploads/personal_snippet` + userUploadPattern = `\A/uploads/user` + importPattern = `\A/import/` ) func compileRegexp(regexpStr string) *regexp.Regexp { @@ -222,10 +222,10 @@ func (u *upstream) configureRoutes() { u.Routes = []routeEntry{ // Git Clone - u.route("GET", gitProjectPattern+`info/refs\z`, git.GetInfoRefsHandler(api)), - u.route("POST", gitProjectPattern+`git-upload-pack\z`, contentEncodingHandler(git.UploadPack(api)), withMatcher(isContentType("application/x-git-upload-pack-request"))), - u.route("POST", gitProjectPattern+`git-receive-pack\z`, contentEncodingHandler(git.ReceivePack(api)), withMatcher(isContentType("application/x-git-receive-pack-request"))), - u.route("PUT", gitProjectPattern+`gitlab-lfs/objects/([0-9a-f]{64})/([0-9]+)\z`, lfs.PutStore(api, signingProxy, preparers.lfs), withMatcher(isContentType("application/octet-stream"))), + u.route("GET", gitRepositoryPattern+`info/refs\z`, git.GetInfoRefsHandler(api), withMatcher(git.IsSmartInfoRefs)), + u.route("POST", gitRepositoryPattern+`git-upload-pack\z`, contentEncodingHandler(git.UploadPack(api)), withMatcher(isContentType("application/x-git-upload-pack-request"))), + u.route("POST", gitRepositoryPattern+`git-receive-pack\z`, contentEncodingHandler(git.ReceivePack(api)), withMatcher(isContentType("application/x-git-receive-pack-request"))), + u.route("PUT", gitRepositoryPattern+`gitlab-lfs/objects/([0-9a-f]{64})/([0-9]+)\z`, lfs.PutStore(api, signingProxy, preparers.lfs), withMatcher(isContentType("application/octet-stream"))), // CI Artifacts u.route("POST", apiPattern+`v4/jobs/[0-9]+/artifacts\z`, contentEncodingHandler(artifacts.UploadArtifacts(api, signingProxy, preparers.artifacts))), |