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
0
Merge Requests
0
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
Jérome Perrin
gitlab-ce
Commits
5445f839
Commit
5445f839
authored
Oct 30, 2017
by
Mike Greiling
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
allow inspect_request to inject request headers in order to test Sendfile requests in jobs_spec.rb
parent
e0ca65c5
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
31 additions
and
19 deletions
+31
-19
lib/gitlab/testing/request_inspector_middleware.rb
lib/gitlab/testing/request_inspector_middleware.rb
+11
-1
spec/features/projects/jobs_spec.rb
spec/features/projects/jobs_spec.rb
+18
-16
spec/support/inspect_requests.rb
spec/support/inspect_requests.rb
+2
-2
No files found.
lib/gitlab/testing/request_inspector_middleware.rb
View file @
5445f839
...
...
@@ -5,9 +5,11 @@ module Gitlab
class
RequestInspectorMiddleware
@@log_requests
=
Concurrent
::
AtomicBoolean
.
new
(
false
)
@@logged_requests
=
Concurrent
::
Array
.
new
@@inject_headers
=
Concurrent
::
Hash
.
new
# Resets the current request log and starts logging requests
def
self
.
log_requests!
def
self
.
log_requests!
(
headers
=
{})
@@inject_headers
.
replace
(
headers
)
@@logged_requests
.
replace
([])
@@log_requests
.
value
=
true
end
...
...
@@ -29,6 +31,7 @@ module Gitlab
return
@app
.
call
(
env
)
unless
@@log_requests
.
true?
url
=
env
[
'REQUEST_URI'
]
env
.
merge!
http_headers_env
(
@@inject_headers
)
if
@@inject_headers
.
any?
request_headers
=
env_http_headers
(
env
)
status
,
headers
,
body
=
@app
.
call
(
env
)
...
...
@@ -53,6 +56,13 @@ module Gitlab
.
flatten
]
end
def
http_headers_env
(
headers
)
Hash
[
*
headers
.
collect
{
|
k
,
v
|
[
k
.
split
(
'-'
).
collect
(
&
:upcase
).
join
(
'_'
),
v
]}
.
collect
{
|
k
,
v
|
[
k
.
prepend
(
'HTTP_'
),
v
]}
.
flatten
]
end
def
log_request
(
response
)
@@logged_requests
.
push
(
response
)
end
...
...
spec/features/projects/jobs_spec.rb
View file @
5445f839
...
...
@@ -2,6 +2,8 @@ require 'spec_helper'
require
'tempfile'
feature
'Jobs'
do
include
InspectRequests
let
(
:user
)
{
create
(
:user
)
}
let
(
:user_access_level
)
{
:developer
}
let
(
:project
)
{
create
(
:project
,
:repository
)
}
...
...
@@ -441,27 +443,30 @@ feature 'Jobs' do
context
'access source'
do
context
'job from project'
do
before
do
Capybara
.
current_session
.
driver
.
headers
=
{
'X-Sendfile-Type'
=>
'X-Sendfile'
}
job
.
run!
visit
project_job_path
(
project
,
job
)
find
(
'.js-raw-link-controller'
).
click
()
end
it
'sends the right headers'
do
expect
(
page
.
response_headers
[
'Content-Type'
]).
to
eq
(
'text/plain; charset=utf-8'
)
expect
(
page
.
response_headers
[
'X-Sendfile'
]).
to
eq
(
job
.
trace
.
send
(
:current_path
))
requests
=
inspect_requests
(
inject_headers:
{
'X-Sendfile-Type'
=>
'X-Sendfile'
})
do
visit
raw_project_job_path
(
project
,
job
)
end
expect
(
requests
.
first
.
status_code
).
to
eq
(
200
)
expect
(
requests
.
first
.
response_headers
[
'Content-Type'
]).
to
eq
(
'text/plain; charset=utf-8'
)
expect
(
requests
.
first
.
response_headers
[
'X-Sendfile'
]).
to
eq
(
job
.
trace
.
send
(
:current_path
))
end
end
context
'job from other project'
do
before
do
Capybara
.
current_session
.
driver
.
headers
=
{
'X-Sendfile-Type'
=>
'X-Sendfile'
}
job2
.
run!
visit
raw_project_job_path
(
project
,
job2
)
end
it
'sends the right headers'
do
expect
(
page
.
status_code
).
to
eq
(
404
)
requests
=
inspect_requests
(
inject_headers:
{
'X-Sendfile-Type'
=>
'X-Sendfile'
})
do
visit
raw_project_job_path
(
project
,
job2
)
end
expect
(
requests
.
first
.
status_code
).
to
eq
(
404
)
end
end
end
...
...
@@ -470,8 +475,6 @@ feature 'Jobs' do
let
(
:existing_file
)
{
Tempfile
.
new
(
'existing-trace-file'
).
path
}
before
do
Capybara
.
current_session
.
driver
.
headers
=
{
'X-Sendfile-Type'
=>
'X-Sendfile'
}
job
.
run!
end
...
...
@@ -480,15 +483,14 @@ feature 'Jobs' do
allow_any_instance_of
(
Gitlab
::
Ci
::
Trace
)
.
to
receive
(
:paths
)
.
and_return
([
existing_file
])
visit
project_job_path
(
project
,
job
)
find
(
'.js-raw-link-controller'
).
click
end
it
'sends the right headers'
do
expect
(
page
.
response_headers
[
'Content-Type'
]).
to
eq
(
'text/plain; charset=utf-8'
)
expect
(
page
.
response_headers
[
'X-Sendfile'
]).
to
eq
(
existing_file
)
requests
=
inspect_requests
(
inject_headers:
{
'X-Sendfile-Type'
=>
'X-Sendfile'
})
do
visit
raw_project_job_path
(
project
,
job
)
end
expect
(
requests
.
first
.
response_headers
[
'Content-Type'
]).
to
eq
(
'text/plain; charset=utf-8'
)
expect
(
requests
.
first
.
response_headers
[
'X-Sendfile'
]).
to
eq
(
existing_file
)
end
end
...
...
spec/support/inspect_requests.rb
View file @
5445f839
...
...
@@ -4,8 +4,8 @@ module InspectRequests
extend
self
include
WaitForRequests
def
inspect_requests
Gitlab
::
Testing
::
RequestInspectorMiddleware
.
log_requests!
def
inspect_requests
(
inject_headers:
{})
Gitlab
::
Testing
::
RequestInspectorMiddleware
.
log_requests!
(
inject_headers
)
yield
block_and_wait_for_requests_complete
Gitlab
::
Testing
::
RequestInspectorMiddleware
.
requests
...
...
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