Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
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-ce
Commits
2841b478
Commit
2841b478
authored
Mar 07, 2022
by
Catalin Irimie
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add Geo assets proxy test, move static file setup to testhelper
parent
c3501224
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
42 additions
and
27 deletions
+42
-27
workhorse/internal/testhelper/testhelper.go
workhorse/internal/testhelper/testhelper.go
+13
-0
workhorse/internal/upstream/.gitignore
workhorse/internal/upstream/.gitignore
+1
-0
workhorse/internal/upstream/routes_test.go
workhorse/internal/upstream/routes_test.go
+14
-0
workhorse/main_test.go
workhorse/main_test.go
+14
-27
No files found.
workhorse/internal/testhelper/testhelper.go
View file @
2841b478
...
@@ -167,3 +167,16 @@ func Retry(t testing.TB, timeout time.Duration, fn func() error) {
...
@@ -167,3 +167,16 @@ func Retry(t testing.TB, timeout time.Duration, fn func() error) {
}
}
t
.
Fatalf
(
"test timeout after %v; last error: %v"
,
timeout
,
err
)
t
.
Fatalf
(
"test timeout after %v; last error: %v"
,
timeout
,
err
)
}
}
func
SetupStaticFileHelper
(
t
*
testing
.
T
,
fpath
,
content
,
directory
string
)
string
{
cwd
,
err
:=
os
.
Getwd
()
require
.
NoError
(
t
,
err
,
"get working directory"
)
absDocumentRoot
:=
path
.
Join
(
cwd
,
directory
)
require
.
NoError
(
t
,
os
.
MkdirAll
(
path
.
Join
(
absDocumentRoot
,
path
.
Dir
(
fpath
)),
0755
),
"create document root"
)
staticFile
:=
path
.
Join
(
absDocumentRoot
,
fpath
)
require
.
NoError
(
t
,
ioutil
.
WriteFile
(
staticFile
,
[]
byte
(
content
),
0666
),
"write file content"
)
return
absDocumentRoot
}
workhorse/internal/upstream/.gitignore
0 → 100644
View file @
2841b478
testdata/public
workhorse/internal/upstream/routes_test.go
View file @
2841b478
...
@@ -2,6 +2,8 @@ package upstream
...
@@ -2,6 +2,8 @@ package upstream
import
(
import
(
"testing"
"testing"
"gitlab.com/gitlab-org/gitlab/workhorse/internal/testhelper"
)
)
func
TestProjectNotExistingGitHttpPullWithGeoProxy
(
t
*
testing
.
T
)
{
func
TestProjectNotExistingGitHttpPullWithGeoProxy
(
t
*
testing
.
T
)
{
...
@@ -45,3 +47,15 @@ func TestProjectNotExistingGitSSHPushWithGeoProxy(t *testing.T) {
...
@@ -45,3 +47,15 @@ func TestProjectNotExistingGitSSHPushWithGeoProxy(t *testing.T) {
runTestCasesWithGeoProxyEnabled
(
t
,
testCases
)
runTestCasesWithGeoProxyEnabled
(
t
,
testCases
)
}
}
func
TestAssetsServedLocallyWithGeoProxy
(
t
*
testing
.
T
)
{
path
:=
"/assets/static.txt"
content
:=
"local geo asset"
testhelper
.
SetupStaticFileHelper
(
t
,
path
,
content
,
testDocumentRoot
)
testCases
:=
[]
testCase
{
{
"assets path"
,
"/assets/static.txt"
,
"local geo asset"
},
}
runTestCasesWithGeoProxyEnabled
(
t
,
testCases
)
}
workhorse/main_test.go
View file @
2841b478
...
@@ -138,7 +138,7 @@ func TestDeniedXSendfileDownload(t *testing.T) {
...
@@ -138,7 +138,7 @@ func TestDeniedXSendfileDownload(t *testing.T) {
func
TestAllowedStaticFile
(
t
*
testing
.
T
)
{
func
TestAllowedStaticFile
(
t
*
testing
.
T
)
{
content
:=
"PUBLIC"
content
:=
"PUBLIC"
require
.
NoError
(
t
,
setupStaticFile
(
"static file.txt"
,
content
)
)
setupStaticFile
(
t
,
"static file.txt"
,
content
)
proxied
:=
false
proxied
:=
false
ts
:=
testhelper
.
TestServerWithHandler
(
regexp
.
MustCompile
(
`.`
),
func
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
ts
:=
testhelper
.
TestServerWithHandler
(
regexp
.
MustCompile
(
`.`
),
func
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
...
@@ -164,7 +164,7 @@ func TestAllowedStaticFile(t *testing.T) {
...
@@ -164,7 +164,7 @@ func TestAllowedStaticFile(t *testing.T) {
func
TestStaticFileRelativeURL
(
t
*
testing
.
T
)
{
func
TestStaticFileRelativeURL
(
t
*
testing
.
T
)
{
content
:=
"PUBLIC"
content
:=
"PUBLIC"
require
.
NoError
(
t
,
setupStaticFile
(
"static.txt"
,
content
),
"create public/static.txt"
)
setupStaticFile
(
t
,
"static.txt"
,
content
)
ts
:=
testhelper
.
TestServerWithHandler
(
regexp
.
MustCompile
(
`.`
),
http
.
HandlerFunc
(
http
.
NotFound
))
ts
:=
testhelper
.
TestServerWithHandler
(
regexp
.
MustCompile
(
`.`
),
http
.
HandlerFunc
(
http
.
NotFound
))
defer
ts
.
Close
()
defer
ts
.
Close
()
...
@@ -182,7 +182,7 @@ func TestStaticFileRelativeURL(t *testing.T) {
...
@@ -182,7 +182,7 @@ func TestStaticFileRelativeURL(t *testing.T) {
func
TestAllowedPublicUploadsFile
(
t
*
testing
.
T
)
{
func
TestAllowedPublicUploadsFile
(
t
*
testing
.
T
)
{
content
:=
"PRIVATE but allowed"
content
:=
"PRIVATE but allowed"
require
.
NoError
(
t
,
setupStaticFile
(
"uploads/static file.txt"
,
content
),
"create public/uploads/static file.txt"
)
setupStaticFile
(
t
,
"uploads/static file.txt"
,
content
)
proxied
:=
false
proxied
:=
false
ts
:=
testhelper
.
TestServerWithHandler
(
regexp
.
MustCompile
(
`.`
),
func
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
ts
:=
testhelper
.
TestServerWithHandler
(
regexp
.
MustCompile
(
`.`
),
func
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
...
@@ -208,7 +208,7 @@ func TestAllowedPublicUploadsFile(t *testing.T) {
...
@@ -208,7 +208,7 @@ func TestAllowedPublicUploadsFile(t *testing.T) {
func
TestDeniedPublicUploadsFile
(
t
*
testing
.
T
)
{
func
TestDeniedPublicUploadsFile
(
t
*
testing
.
T
)
{
content
:=
"PRIVATE"
content
:=
"PRIVATE"
require
.
NoError
(
t
,
setupStaticFile
(
"uploads/static.txt"
,
content
),
"create public/uploads/static.txt"
)
setupStaticFile
(
t
,
"uploads/static.txt"
,
content
)
proxied
:=
false
proxied
:=
false
ts
:=
testhelper
.
TestServerWithHandler
(
regexp
.
MustCompile
(
`.`
),
func
(
w
http
.
ResponseWriter
,
_
*
http
.
Request
)
{
ts
:=
testhelper
.
TestServerWithHandler
(
regexp
.
MustCompile
(
`.`
),
func
(
w
http
.
ResponseWriter
,
_
*
http
.
Request
)
{
...
@@ -241,7 +241,7 @@ This is a static error page for code 499
...
@@ -241,7 +241,7 @@ This is a static error page for code 499
</body>
</body>
</html>
</html>
`
`
require
.
NoError
(
t
,
setupStaticFile
(
"499.html"
,
errorPageBody
)
)
setupStaticFile
(
t
,
"499.html"
,
errorPageBody
)
ts
:=
testhelper
.
TestServerWithHandler
(
nil
,
func
(
w
http
.
ResponseWriter
,
_
*
http
.
Request
)
{
ts
:=
testhelper
.
TestServerWithHandler
(
nil
,
func
(
w
http
.
ResponseWriter
,
_
*
http
.
Request
)
{
upstreamError
:=
"499"
upstreamError
:=
"499"
// This is the point of the test: the size of the upstream response body
// This is the point of the test: the size of the upstream response body
...
@@ -266,7 +266,7 @@ This is a static error page for code 499
...
@@ -266,7 +266,7 @@ This is a static error page for code 499
func
TestGzipAssets
(
t
*
testing
.
T
)
{
func
TestGzipAssets
(
t
*
testing
.
T
)
{
path
:=
"/assets/static.txt"
path
:=
"/assets/static.txt"
content
:=
"asset"
content
:=
"asset"
require
.
NoError
(
t
,
setupStaticFile
(
path
,
content
)
)
setupStaticFile
(
t
,
path
,
content
)
buf
:=
&
bytes
.
Buffer
{}
buf
:=
&
bytes
.
Buffer
{}
gzipWriter
:=
gzip
.
NewWriter
(
buf
)
gzipWriter
:=
gzip
.
NewWriter
(
buf
)
...
@@ -274,7 +274,7 @@ func TestGzipAssets(t *testing.T) {
...
@@ -274,7 +274,7 @@ func TestGzipAssets(t *testing.T) {
require
.
NoError
(
t
,
err
)
require
.
NoError
(
t
,
err
)
require
.
NoError
(
t
,
gzipWriter
.
Close
())
require
.
NoError
(
t
,
gzipWriter
.
Close
())
contentGzip
:=
buf
.
String
()
contentGzip
:=
buf
.
String
()
require
.
NoError
(
t
,
setupStaticFile
(
path
+
".gz"
,
contentGzip
)
)
setupStaticFile
(
t
,
path
+
".gz"
,
contentGzip
)
proxied
:=
false
proxied
:=
false
ts
:=
testhelper
.
TestServerWithHandler
(
regexp
.
MustCompile
(
`.`
),
func
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
ts
:=
testhelper
.
TestServerWithHandler
(
regexp
.
MustCompile
(
`.`
),
func
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
...
@@ -319,7 +319,7 @@ func TestGzipAssets(t *testing.T) {
...
@@ -319,7 +319,7 @@ func TestGzipAssets(t *testing.T) {
func
TestAltDocumentAssets
(
t
*
testing
.
T
)
{
func
TestAltDocumentAssets
(
t
*
testing
.
T
)
{
path
:=
"/assets/static.txt"
path
:=
"/assets/static.txt"
content
:=
"asset"
content
:=
"asset"
require
.
NoError
(
t
,
setupAltStaticFile
(
path
,
content
)
)
setupAltStaticFile
(
t
,
path
,
content
)
buf
:=
&
bytes
.
Buffer
{}
buf
:=
&
bytes
.
Buffer
{}
gzipWriter
:=
gzip
.
NewWriter
(
buf
)
gzipWriter
:=
gzip
.
NewWriter
(
buf
)
...
@@ -327,7 +327,7 @@ func TestAltDocumentAssets(t *testing.T) {
...
@@ -327,7 +327,7 @@ func TestAltDocumentAssets(t *testing.T) {
require
.
NoError
(
t
,
err
)
require
.
NoError
(
t
,
err
)
require
.
NoError
(
t
,
gzipWriter
.
Close
())
require
.
NoError
(
t
,
gzipWriter
.
Close
())
contentGzip
:=
buf
.
String
()
contentGzip
:=
buf
.
String
()
require
.
NoError
(
t
,
setupAltStaticFile
(
path
+
".gz"
,
contentGzip
)
)
setupAltStaticFile
(
t
,
path
+
".gz"
,
contentGzip
)
proxied
:=
false
proxied
:=
false
ts
:=
testhelper
.
TestServerWithHandler
(
regexp
.
MustCompile
(
`.`
),
func
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
ts
:=
testhelper
.
TestServerWithHandler
(
regexp
.
MustCompile
(
`.`
),
func
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
...
@@ -712,25 +712,12 @@ func TestRejectUnknownMethod(t *testing.T) {
...
@@ -712,25 +712,12 @@ func TestRejectUnknownMethod(t *testing.T) {
require
.
Equal
(
t
,
http
.
StatusMethodNotAllowed
,
resp
.
StatusCode
)
require
.
Equal
(
t
,
http
.
StatusMethodNotAllowed
,
resp
.
StatusCode
)
}
}
func
setupStaticFile
(
fpath
,
content
string
)
error
{
func
setupStaticFile
(
t
*
testing
.
T
,
fpath
,
content
string
)
{
return
setupStaticFileHelper
(
fpath
,
content
,
testDocumentRoot
)
absDocumentRoot
=
testhelper
.
SetupStaticFileHelper
(
t
,
fpath
,
content
,
testDocumentRoot
)
}
}
func
setupAltStaticFile
(
fpath
,
content
string
)
error
{
func
setupAltStaticFile
(
t
*
testing
.
T
,
fpath
,
content
string
)
{
return
setupStaticFileHelper
(
fpath
,
content
,
testAltDocumentRoot
)
absDocumentRoot
=
testhelper
.
SetupStaticFileHelper
(
t
,
fpath
,
content
,
testAltDocumentRoot
)
}
func
setupStaticFileHelper
(
fpath
,
content
,
directory
string
)
error
{
cwd
,
err
:=
os
.
Getwd
()
if
err
!=
nil
{
return
err
}
absDocumentRoot
=
path
.
Join
(
cwd
,
directory
)
if
err
:=
os
.
MkdirAll
(
path
.
Join
(
absDocumentRoot
,
path
.
Dir
(
fpath
)),
0755
);
err
!=
nil
{
return
err
}
staticFile
:=
path
.
Join
(
absDocumentRoot
,
fpath
)
return
ioutil
.
WriteFile
(
staticFile
,
[]
byte
(
content
),
0666
)
}
}
func
prepareDownloadDir
(
t
*
testing
.
T
)
{
func
prepareDownloadDir
(
t
*
testing
.
T
)
{
...
@@ -896,7 +883,7 @@ This is a static error page for code 503
...
@@ -896,7 +883,7 @@ This is a static error page for code 503
</body>
</body>
</html>
</html>
`
`
require
.
NoError
(
t
,
setupStaticFile
(
"503.html"
,
errorPageBody
)
)
setupStaticFile
(
t
,
"503.html"
,
errorPageBody
)
ts
:=
testhelper
.
TestServerWithHandler
(
regexp
.
MustCompile
(
`.`
),
func
(
w
http
.
ResponseWriter
,
_
*
http
.
Request
)
{
ts
:=
testhelper
.
TestServerWithHandler
(
regexp
.
MustCompile
(
`.`
),
func
(
w
http
.
ResponseWriter
,
_
*
http
.
Request
)
{
w
.
Header
()
.
Set
(
"X-Gitlab-Custom-Error"
,
"1"
)
w
.
Header
()
.
Set
(
"X-Gitlab-Custom-Error"
,
"1"
)
...
...
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