Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-workhorse
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-workhorse
Commits
919c9b53
Commit
919c9b53
authored
Jan 11, 2024
by
Alain Takoudjou
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fixup! NXD Teach gitlab-workhorse to serve requests to get raw blobs
parent
4cb92622
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
21 additions
and
3 deletions
+21
-3
internal/git/xblob.go
internal/git/xblob.go
+7
-0
main_test.go
main_test.go
+14
-3
No files found.
internal/git/xblob.go
View file @
919c9b53
...
...
@@ -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
...
...
main_test.go
View file @
919c9b53
...
...
@@ -752,7 +752,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\n
Sample repo for testing gitlab features
\n
"
)
dl
.
ExpectSha1
(
"/5f923865/README.md"
,
"5f7af35c185a9e5face2f4afb6d7c4f00328d04c"
)
...
...
@@ -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"
)
}
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\n
Sample 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
)
...
...
@@ -843,7 +854,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
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment