Commit cd2bffd6 authored by Jacob Vosmaer's avatar Jacob Vosmaer

Fix /api/v3/projects routing error

Non-special API requests were getting special treatment, which
resulted in 500 errors. This change avoids the special treatment and
adds tests that assert that regular API requests should be left alone
by gitlab-workhorse.
parent cf809cbc
...@@ -52,7 +52,7 @@ const gitProjectPattern = `^/[^/]+/[^/]+\.git/` ...@@ -52,7 +52,7 @@ const gitProjectPattern = `^/[^/]+/[^/]+\.git/`
const apiPattern = `^/api/` const apiPattern = `^/api/`
// A project ID in an API request is either a number or two strings 'namespace/project' // A project ID in an API request is either a number or two strings 'namespace/project'
const projectsAPIPattern = `^/api/v3/projects/(\d+)|([^/]+/[^/]+)/` const projectsAPIPattern = `^/api/v3/projects/((\d+)|([^/]+/[^/]+))/`
const ciAPIPattern = `^/ci/api/` const ciAPIPattern = `^/ci/api/`
......
...@@ -273,6 +273,37 @@ func TestDownloadCacheCreate(t *testing.T) { ...@@ -273,6 +273,37 @@ func TestDownloadCacheCreate(t *testing.T) {
} }
} }
func TestRegularProjectsAPI(t *testing.T) {
apiResponse := "API RESPONSE"
ts := testAuthServer(nil, 200, apiResponse)
defer ts.Close()
ws := startWorkhorseServer(ts.URL)
defer ws.Close()
for _, resource := range []string{
"/api/v3/projects/123/repository/not/special",
"/api/v3/projects/foo/bar/repository/not/special",
"/api/v3/projects/123/not/special",
"/api/v3/projects/foo/bar/not/special",
} {
resp, err := http.Get(ws.URL + resource)
if err != nil {
t.Fatal(err)
}
defer resp.Body.Close()
buf := &bytes.Buffer{}
if _, err := io.Copy(buf, resp.Body); err != nil {
t.Error(err)
}
if buf.String() != apiResponse {
t.Errorf("GET %q: Expected %q, got %q", resource, apiResponse, buf.String())
}
if resp.StatusCode != 200 {
t.Errorf("GET %q: expected 200, got %d", resource, resp.StatusCode)
}
}
}
func TestAllowedXSendfileDownload(t *testing.T) { func TestAllowedXSendfileDownload(t *testing.T) {
contentFilename := "my-content" contentFilename := "my-content"
prepareDownloadDir(t) prepareDownloadDir(t)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment