Commit f15ab356 authored by Alain Takoudjou's avatar Alain Takoudjou

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

parent 1b9ca318
......@@ -33,12 +33,19 @@ func GetBlobRaw(a *api.API, repoPath string) http.Handler {
}
var rawRe = regexp.MustCompile(`/raw/`)
var rawReDash = regexp.MustCompile(`/-/raw/`)
func handleGetBlobRaw(a *api.API, w http.ResponseWriter, r *http.Request, repoPath string) {
// Extract project & refpath
// <project>/-/raw/branch/file -> <project>, branch/file or
// <project>/raw/branch/file -> <project>, branch/file
u := r.URL
rawLoc := rawRe.FindStringIndex(u.Path)
if rawLoc != nil && u.Path[rawLoc[0]-1:rawLoc[0]] == "-" {
rawLoc = rawReDash.FindStringIndex(u.Path)
}
if rawLoc == nil {
helper.Fail500(w, r, errors.New("extract project name"))
return
......
......@@ -923,7 +923,7 @@ func TestBlobDownload(t *testing.T) {
defer ts.Close()
ws := startWorkhorseServer(ts.URL)
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.ExpectSha1("/5f923865/README.md", "5f7af35c185a9e5face2f4afb6d7c4f00328d04c")
......@@ -945,13 +945,24 @@ func TestBlobDownload(t *testing.T) {
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) {
// Prepare test server and "all-deny" auth backend
ts := testAuthServer(nil, nil, 403, "Access denied")
defer ts.Close()
ws := startWorkhorseServer(ts.URL)
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/files/ruby/popen.rb", 403)
......@@ -1014,7 +1025,7 @@ func TestPrivateBlobDownload(t *testing.T) {
defer ts.Close()
ws := startWorkhorseServer(ts.URL)
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?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