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
8d8534d7
Commit
8d8534d7
authored
May 06, 2018
by
Kamil Trzciński
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Enforce proper 416 support for runner trace patch endpoint
parent
1f39fcd1
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
21 additions
and
12 deletions
+21
-12
lib/api/runner.rb
lib/api/runner.rb
+14
-3
lib/gitlab/ci/trace.rb
lib/gitlab/ci/trace.rb
+1
-1
spec/requests/api/runner_spec.rb
spec/requests/api/runner_spec.rb
+6
-8
spec/support/shared_examples/ci_trace_shared_examples.rb
spec/support/shared_examples/ci_trace_shared_examples.rb
+0
-0
No files found.
lib/api/runner.rb
View file @
8d8534d7
...
...
@@ -153,9 +153,20 @@ module API
content_range
=
request
.
headers
[
'Content-Range'
]
content_range
=
content_range
.
split
(
'-'
)
stream_size
=
job
.
trace
.
append
(
request
.
body
.
read
,
content_range
[
0
].
to_i
)
if
stream_size
<
0
break
error!
(
'416 Range Not Satisfiable'
,
416
,
{
'Range'
=>
"0-
#{
-
stream_size
}
"
})
# TODO:
# it seems that `Content-Range` as formatted by runner is wrong,
# the `byte_end` should point to final byte, but it points byte+1
# that means that we have to calculate end of body,
# as we cannot use `content_length[1]`
# Issue: https://gitlab.com/gitlab-org/gitlab-runner/issues/3275
body_data
=
request
.
body
.
read
body_start
=
content_range
[
0
].
to_i
body_end
=
body_start
+
body_data
.
bytesize
stream_size
=
job
.
trace
.
append
(
body_data
,
body_start
)
unless
stream_size
==
body_end
break
error!
(
'416 Range Not Satisfiable'
,
416
,
{
'Range'
=>
"0-
#{
stream_size
}
"
})
end
status
202
...
...
lib/gitlab/ci/trace.rb
View file @
8d8534d7
...
...
@@ -45,7 +45,7 @@ module Gitlab
def
append
(
data
,
offset
)
write
(
'a+b'
)
do
|
stream
|
current_length
=
stream
.
size
break
-
current_length
unless
current_length
==
offset
break
current_length
unless
current_length
==
offset
data
=
job
.
hide_secrets
(
data
)
stream
.
append
(
data
,
offset
)
...
...
spec/requests/api/runner_spec.rb
View file @
8d8534d7
...
...
@@ -906,20 +906,18 @@ describe API::Runner, :clean_gitlab_redis_shared_state do
context
'when we perform partial patch'
do
before
do
patch_the_trace
(
'hello'
,
headers
.
merge
({
'Content-Range'
=>
"28-32"
}))
patch_the_trace
(
'hello'
,
headers
.
merge
({
'Content-Range'
=>
"28-32
/5
"
}))
end
it
'returns an error'
do
expect
(
response
.
status
).
to
eq
(
202
)
expect
(
response
.
header
).
to
have_key
'Range'
expect
(
response
.
header
[
'Range'
]).
to
eq
'0-0'
expect
(
job
.
reload
.
trace
.
raw
).
to
eq
''
expect
(
response
.
status
).
to
eq
(
416
)
expect
(
response
.
header
[
'Range'
]).
to
eq
(
'0-0'
)
end
end
context
'when we resend full trace'
do
before
do
patch_the_trace
(
'BUILD TRACE appended appended hello'
,
headers
.
merge
({
'Content-Range'
=>
"0-3
2
"
}))
patch_the_trace
(
'BUILD TRACE appended appended hello'
,
headers
.
merge
({
'Content-Range'
=>
"0-3
4/35
"
}))
end
it
'succeeds with updating trace'
do
...
...
@@ -945,7 +943,7 @@ describe API::Runner, :clean_gitlab_redis_shared_state do
end
context
'when content-range start is too big'
do
let
(
:headers_with_range
)
{
headers
.
merge
({
'Content-Range'
=>
'15-20'
})
}
let
(
:headers_with_range
)
{
headers
.
merge
({
'Content-Range'
=>
'15-20
/6
'
})
}
it
'gets 416 error response with range headers'
do
expect
(
response
.
status
).
to
eq
416
...
...
@@ -955,7 +953,7 @@ describe API::Runner, :clean_gitlab_redis_shared_state do
end
context
'when content-range start is too small'
do
let
(
:headers_with_range
)
{
headers
.
merge
({
'Content-Range'
=>
'8-20'
})
}
let
(
:headers_with_range
)
{
headers
.
merge
({
'Content-Range'
=>
'8-20
/13
'
})
}
it
'gets 416 error response with range headers'
do
expect
(
response
.
status
).
to
eq
416
...
...
spec/support/shared_examples/ci_trace_shared_ex
ma
ples.rb
→
spec/support/shared_examples/ci_trace_shared_ex
am
ples.rb
View file @
8d8534d7
File moved
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