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
iv
gitlab-ce
Commits
360bd831
Commit
360bd831
authored
Mar 31, 2016
by
Tomasz Maczukin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add range checking
parent
38a1378e
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
57 additions
and
11 deletions
+57
-11
app/models/ci/build.rb
app/models/ci/build.rb
+8
-0
lib/ci/api/api.rb
lib/ci/api/api.rb
+2
-0
lib/ci/api/builds.rb
lib/ci/api/builds.rb
+16
-4
spec/requests/ci/api/builds_spec.rb
spec/requests/ci/api/builds_spec.rb
+31
-7
No files found.
app/models/ci/build.rb
View file @
360bd831
...
...
@@ -230,6 +230,14 @@ module Ci
end
end
def
trace_length
unless
trace
.
present?
0
else
trace
.
length
end
end
def
trace
=
(
trace
)
recreate_trace_dir
File
.
write
(
path_to_trace
,
trace
)
...
...
lib/ci/api/api.rb
View file @
360bd831
...
...
@@ -23,6 +23,8 @@ module Ci
rack_response
({
'message'
=>
'500 Internal Server Error'
},
500
)
end
content_type
:txt
,
'text/plain'
content_type
:json
,
'application/json'
format
:json
helpers
::
Ci
::
API
::
Helpers
...
...
lib/ci/api/builds.rb
View file @
360bd831
...
...
@@ -51,12 +51,24 @@ module Ci
end
patch
":id/trace.txt"
do
authenticate_runner!
update_runner_last_contact
build
=
Ci
::
Build
.
where
(
runner_id:
current_runner
.
id
).
running
.
find
(
params
[
:id
]
)
build
=
Ci
::
Build
.
find_by_id
(
params
[
:id
])
not_found!
unless
build
authenticate_build_token!
(
build
)
forbidden!
(
'Build has been erased!'
)
if
build
.
erased?
build
.
append_trace
(
params
[
:trace_part
])
error!
(
'400 Missing header Content-Range'
,
400
)
unless
request
.
headers
.
has_key?
(
'Content-Range'
)
content_range
=
request
.
headers
[
'Content-Range'
]
content_range
=
content_range
.
split
(
'-'
)
unless
build
.
trace_length
==
content_range
[
0
].
to_i
return
error!
(
'416 Range Not Satisfiable'
,
416
,
{
'Range'
=>
"0-
#{
build
.
trace_length
}
"
})
end
build
.
append_trace
(
request
.
body
.
read
)
status
202
header
'Build-Status'
,
build
.
status
header
'Range'
,
"0-
#{
build
.
trace_length
}
"
end
# Authorize artifacts uploading for build - Runners only
...
...
spec/requests/ci/api/builds_spec.rb
View file @
360bd831
...
...
@@ -158,23 +158,47 @@ describe Ci::API::API do
describe
'PATCH /builds/:id/trace.txt'
do
let
(
:build
)
{
create
(
:ci_build
,
:trace
,
runner_id:
runner
.
id
)
}
let
(
:headers
)
{
{
Ci
::
API
::
Helpers
::
BUILD_TOKEN_HEADER
=>
build
.
token
,
'Content-Type'
=>
'text/plain'
}
}
let
(
:headers_with_range
)
{
headers
.
merge
({
'Content-Range'
=>
'11-20'
})
}
before
do
build
.
run!
patch
ci_api
(
"/builds/
#{
build
.
id
}
/trace.txt"
),
trace_part:
' appended'
,
token:
runner
.
token
patch
ci_api
(
"/builds/
#{
build
.
id
}
/trace.txt"
),
' appended'
,
headers_with_range
end
it
'should append trace part to the trace'
do
expect
(
response
.
status
).
to
eq
200
expect
(
build
.
reload
.
trace
).
to
eq
'BUILD TRACE appended'
context
'when request is valid'
do
it
{
expect
(
response
.
status
).
to
eq
202
}
it
{
expect
(
build
.
reload
.
trace
).
to
eq
'BUILD TRACE appended'
}
it
{
expect
(
response
.
header
).
to
have_key
'Range'
}
it
{
expect
(
response
.
header
).
to
have_key
'Build-Status'
}
end
context
'when content-range start is too big'
do
let
(
:headers_with_range
)
{
headers
.
merge
({
'Content-Range'
=>
'15-20'
})
}
it
{
expect
(
response
.
status
).
to
eq
416
}
it
{
expect
(
response
.
header
).
to
have_key
'Range'
}
it
{
expect
(
response
.
header
[
'Range'
]).
to
eq
'0-11'
}
end
context
'when content-range start is too small'
do
let
(
:headers_with_range
)
{
headers
.
merge
({
'Content-Range'
=>
'8-20'
})
}
it
{
expect
(
response
.
status
).
to
eq
416
}
it
{
expect
(
response
.
header
).
to
have_key
'Range'
}
it
{
expect
(
response
.
header
[
'Range'
]).
to
eq
'0-11'
}
end
context
'when Content-Range header is missing'
do
let
(
:headers_with_range
)
{
headers
.
merge
({})
}
it
{
expect
(
response
.
status
).
to
eq
400
}
end
context
'when build has been erased'
do
let
(
:build
)
{
create
(
:ci_build
,
runner_id:
runner
.
id
,
erased_at:
Time
.
now
)
}
it
'should respond with forbidden'
do
expect
(
response
.
status
).
to
eq
403
end
it
{
expect
(
response
.
status
).
to
eq
403
}
end
end
...
...
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