Commit 919c9b53 authored by Alain Takoudjou's avatar Alain Takoudjou

fixup! NXD Teach gitlab-workhorse to serve requests to get raw blobs

parent 4cb92622
...@@ -33,12 +33,19 @@ func GetBlobRaw(a *api.API, repoPath string) http.Handler { ...@@ -33,12 +33,19 @@ func GetBlobRaw(a *api.API, repoPath string) http.Handler {
} }
var rawRe = regexp.MustCompile(`/raw/`) var rawRe = regexp.MustCompile(`/raw/`)
var rawReDash = regexp.MustCompile(`/-/raw/`)
func handleGetBlobRaw(a *api.API, w http.ResponseWriter, r *http.Request, repoPath string) { func handleGetBlobRaw(a *api.API, w http.ResponseWriter, r *http.Request, repoPath string) {
// Extract project & refpath // Extract project & refpath
// <project>/-/raw/branch/file -> <project>, branch/file or
// <project>/raw/branch/file -> <project>, branch/file // <project>/raw/branch/file -> <project>, branch/file
u := r.URL u := r.URL
rawLoc := rawRe.FindStringIndex(u.Path) rawLoc := rawRe.FindStringIndex(u.Path)
if rawLoc != nil && u.Path[rawLoc[0]-1:rawLoc[0]] == "-" {
rawLoc = rawReDash.FindStringIndex(u.Path)
}
if rawLoc == nil { if rawLoc == nil {
helper.Fail500(w, r, errors.New("extract project name")) helper.Fail500(w, r, errors.New("extract project name"))
return return
......
...@@ -752,7 +752,7 @@ func TestBlobDownload(t *testing.T) { ...@@ -752,7 +752,7 @@ func TestBlobDownload(t *testing.T) {
defer ts.Close() defer ts.Close()
ws := startWorkhorseServer(ts.URL) ws := startWorkhorseServer(ts.URL)
defer ws.Close() defer ws.Close()
dl := NewDownloadContext(t, fmt.Sprintf("%s/%s/raw", ws.URL, testProject)) dl := NewDownloadContext(t, fmt.Sprintf("%s/%s/-/raw", ws.URL, testProject))
dl.Expect("/5f923865/README.md", "testme\n======\n\nSample repo for testing gitlab features\n") dl.Expect("/5f923865/README.md", "testme\n======\n\nSample repo for testing gitlab features\n")
dl.ExpectSha1("/5f923865/README.md", "5f7af35c185a9e5face2f4afb6d7c4f00328d04c") dl.ExpectSha1("/5f923865/README.md", "5f7af35c185a9e5face2f4afb6d7c4f00328d04c")
...@@ -774,13 +774,24 @@ func TestBlobDownload(t *testing.T) { ...@@ -774,13 +774,24 @@ func TestBlobDownload(t *testing.T) {
dl.ExpectHeader("/5f923865/files/flat/path/correct/content.txt", "content-type", "text/plain; charset=utf-8") dl.ExpectHeader("/5f923865/files/flat/path/correct/content.txt", "content-type", "text/plain; charset=utf-8")
} }
func TestBlobDownloadWithoutDash(t *testing.T) {
// Prepare test server and "all-ok" auth backend
ts := testhelper.TestServerWithHandler(regexp.MustCompile("."), func(w http.ResponseWriter, r *http.Request) {})
defer ts.Close()
ws := startWorkhorseServer(ts.URL)
defer ws.Close()
dl := NewDownloadContext(t, fmt.Sprintf("%s/%s/raw", ws.URL, testProject))
dl.Expect("/5f923865/README.md", "testme\n======\n\nSample repo for testing gitlab features\n")
}
func TestDeniedBlobDownload(t *testing.T) { func TestDeniedBlobDownload(t *testing.T) {
// Prepare test server and "all-deny" auth backend // Prepare test server and "all-deny" auth backend
ts := testAuthServer(nil, nil, 403, "Access denied") ts := testAuthServer(nil, nil, 403, "Access denied")
defer ts.Close() defer ts.Close()
ws := startWorkhorseServer(ts.URL) ws := startWorkhorseServer(ts.URL)
defer ws.Close() defer ws.Close()
dl := NewDownloadContext(t, fmt.Sprintf("%s/%s/raw", ws.URL, testProject)) dl := NewDownloadContext(t, fmt.Sprintf("%s/%s/-/raw", ws.URL, testProject))
dl.ExpectCode("/5f923865/README.md", 403) dl.ExpectCode("/5f923865/README.md", 403)
dl.ExpectCode("/5f923865/files/ruby/popen.rb", 403) dl.ExpectCode("/5f923865/files/ruby/popen.rb", 403)
...@@ -843,7 +854,7 @@ func TestPrivateBlobDownload(t *testing.T) { ...@@ -843,7 +854,7 @@ func TestPrivateBlobDownload(t *testing.T) {
defer ts.Close() defer ts.Close()
ws := startWorkhorseServer(ts.URL) ws := startWorkhorseServer(ts.URL)
defer ws.Close() defer ws.Close()
dl := NewDownloadContext(t, fmt.Sprintf("%s/%s/raw", ws.URL, testProject)) dl := NewDownloadContext(t, fmt.Sprintf("%s/%s/-/raw", ws.URL, testProject))
dl.ExpectCode("/5f923865/README.md", 401) dl.ExpectCode("/5f923865/README.md", 401)
dl.ExpectCode("/5f923865/README.md?bbb_token=TOKEN-4BBB", 302) dl.ExpectCode("/5f923865/README.md?bbb_token=TOKEN-4BBB", 302)
......
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