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
8a1dcaa6
Commit
8a1dcaa6
authored
Apr 08, 2022
by
Erick Bajao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improve readability of content type override test
parent
68de0104
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
15 additions
and
12 deletions
+15
-12
workhorse/internal/senddata/contentprocessor/contentprocessor_test.go
...ternal/senddata/contentprocessor/contentprocessor_test.go
+15
-12
No files found.
workhorse/internal/senddata/contentprocessor/contentprocessor_test.go
View file @
8a1dcaa6
...
...
@@ -177,35 +177,38 @@ func TestSetProperContentTypeAndDisposition(t *testing.T) {
func
TestFailOverrideContentType
(
t
*
testing
.
T
)
{
testCases
:=
[]
struct
{
contentTypeOverride
string
contentType
string
body
string
desc
string
overrideFromUpstream
string
responseContentType
string
body
string
}{
{
contentType
:
"text/plain; charset=utf-8"
,
contentTypeOverride
:
"text/html; charset=utf-8"
,
body
:
"<html><body>Hello world!</body></html>"
,
desc
:
"Force text/html into text/plain"
,
responseContentType
:
"text/plain; charset=utf-8"
,
overrideFromUpstream
:
"text/html; charset=utf-8"
,
body
:
"<html><body>Hello world!</body></html>"
,
},
{
contentType
:
"text/plain; charset=utf-8"
,
contentTypeOverride
:
"application/javascript; charset=utf-8"
,
body
:
"alert(1);"
,
desc
:
"Force application/javascript into text/plain"
,
responseContentType
:
"text/plain; charset=utf-8"
,
overrideFromUpstream
:
"application/javascript; charset=utf-8"
,
body
:
"alert(1);"
,
},
}
for
_
,
tc
:=
range
testCases
{
t
.
Run
(
tc
.
contentTypeOverride
,
func
(
t
*
testing
.
T
)
{
t
.
Run
(
tc
.
desc
,
func
(
t
*
testing
.
T
)
{
h
:=
http
.
HandlerFunc
(
func
(
w
http
.
ResponseWriter
,
_
*
http
.
Request
)
{
// We are pretending to be upstream or an inner layer of the ResponseWriter chain
w
.
Header
()
.
Set
(
headers
.
GitlabWorkhorseDetectContentTypeHeader
,
"true"
)
w
.
Header
()
.
Set
(
headers
.
ContentTypeHeader
,
tc
.
contentTypeOverride
)
w
.
Header
()
.
Set
(
headers
.
ContentTypeHeader
,
tc
.
overrideFromUpstream
)
_
,
err
:=
io
.
WriteString
(
w
,
tc
.
body
)
require
.
NoError
(
t
,
err
)
})
resp
:=
makeRequest
(
t
,
h
,
tc
.
body
,
""
)
require
.
Equal
(
t
,
tc
.
c
ontentType
,
resp
.
Header
.
Get
(
headers
.
ContentTypeHeader
))
require
.
Equal
(
t
,
tc
.
responseC
ontentType
,
resp
.
Header
.
Get
(
headers
.
ContentTypeHeader
))
})
}
}
...
...
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