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
Tatuya Kamada
gitlab-ce
Commits
53f775ae
Commit
53f775ae
authored
Jan 29, 2016
by
Tomasz Maczukin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix runners filtering in API
parent
8c37f0ff
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
27 additions
and
20 deletions
+27
-20
lib/api/runners.rb
lib/api/runners.rb
+3
-3
spec/requests/api/runners_spec.rb
spec/requests/api/runners_spec.rb
+24
-17
No files found.
lib/api/runners.rb
View file @
53f775ae
...
@@ -121,11 +121,11 @@ module API
...
@@ -121,11 +121,11 @@ module API
return
runners
unless
scope
.
present?
return
runners
unless
scope
.
present?
available_scopes
=
::
Ci
::
Runner
::
AVAILABLE_SCOPES
available_scopes
=
::
Ci
::
Runner
::
AVAILABLE_SCOPES
unless
(
available_scopes
&&
scope
).
empty?
if
(
available_scopes
&
[
scope
]).
empty?
runners
.
send
(
scope
)
else
render_api_error!
(
'Scope contains invalid value'
,
400
)
render_api_error!
(
'Scope contains invalid value'
,
400
)
end
end
runners
.
send
(
scope
)
end
end
def
get_runner
(
id
)
def
get_runner
(
id
)
...
...
spec/requests/api/runners_spec.rb
View file @
53f775ae
...
@@ -22,35 +22,42 @@ describe API::API, api: true do
...
@@ -22,35 +22,42 @@ describe API::API, api: true do
let!
(
:two_projects_runner_project2
)
{
create
(
:ci_runner_project
,
runner:
two_projects_runner
,
project:
project2
)
}
let!
(
:two_projects_runner_project2
)
{
create
(
:ci_runner_project
,
runner:
two_projects_runner
,
project:
project2
)
}
describe
'GET /runners'
do
describe
'GET /runners'
do
context
'authorized user with admin privileges'
do
context
'authorized user'
do
it
'should return all runners'
do
context
'authorized user with admin privileges'
do
get
api
(
'/runners'
,
admin
)
it
'should return all runners'
do
shared
=
false
||
json_response
.
map
{
|
r
|
r
[
'is_shared'
]
}.
inject
{
|
sum
,
shr
|
sum
||
shr
}
get
api
(
'/runners'
,
admin
)
shared
=
false
||
json_response
.
map
{
|
r
|
r
[
'is_shared'
]
}.
inject
{
|
sum
,
shr
|
sum
||
shr
}
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
json_response
).
to
be_an
Array
expect
(
json_response
).
to
be_an
Array
expect
(
shared
).
to
be_truthy
expect
(
shared
).
to
be_truthy
end
end
end
it
'should filter runners by scope'
do
context
'authorized user without admin privileges'
do
get
api
(
'/runners?scope=specific'
,
admin
)
it
'should return user available runners'
do
shared
=
false
||
json_response
.
map
{
|
r
|
r
[
'is_shared'
]
}.
inject
{
|
sum
,
shr
|
sum
||
shr
}
get
api
(
'/runners'
,
user
)
shared
=
false
||
json_response
.
map
{
|
r
|
r
[
'is_shared'
]
}.
inject
{
|
sum
,
shr
|
sum
||
shr
}
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
json_response
).
to
be_an
Array
expect
(
json_response
).
to
be_an
Array
expect
(
shared
).
to
be_falsey
expect
(
shared
).
to
be_falsey
end
end
end
end
context
'authorized user without admin privileges'
do
it
'should filter runners by scope'
do
it
'should return user available runners'
do
get
api
(
'/runners?scope=specific'
,
user
)
get
api
(
'/runners'
,
user
)
shared
=
false
||
json_response
.
map
{
|
r
|
r
[
'is_shared'
]
}.
inject
{
|
sum
,
shr
|
sum
||
shr
}
shared
=
false
||
json_response
.
map
{
|
r
|
r
[
'is_shared'
]
}.
inject
{
|
sum
,
shr
|
sum
||
shr
}
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
json_response
).
to
be_an
Array
expect
(
json_response
).
to
be_an
Array
expect
(
shared
).
to
be_falsey
expect
(
shared
).
to
be_falsey
end
end
it
'should avoid filtering if scope is invalid'
do
get
api
(
'/runners?scope=unknown'
,
user
)
expect
(
response
.
status
).
to
eq
(
400
)
end
end
end
context
'unauthorized user'
do
context
'unauthorized user'
do
...
...
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