Skip to content
代码片段 群组 项目
提交 cd2bffd6 编辑于 作者: 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.
上级 cf809cbc
No related branches found
No related tags found
无相关合并请求
...@@ -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)
......
0% 加载中 .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册