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
79447268
Commit
79447268
authored
May 14, 2020
by
Kirstie Cook
Committed by
Stan Hu
May 14, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Decode dashboard_path when creating annotations
parent
172fed32
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
51 additions
and
11 deletions
+51
-11
changelogs/unreleased/kc-escape-dashboard-path-annotations.yml
...elogs/unreleased/kc-escape-dashboard-path-annotations.yml
+5
-0
lib/api/metrics/dashboard/annotations.rb
lib/api/metrics/dashboard/annotations.rb
+10
-10
spec/requests/api/metrics/dashboard/annotations_spec.rb
spec/requests/api/metrics/dashboard/annotations_spec.rb
+36
-1
No files found.
changelogs/unreleased/kc-escape-dashboard-path-annotations.yml
0 → 100644
View file @
79447268
---
title
:
Decode dashboard_path when creating annotations
merge_request
:
31665
author
:
type
:
fixed
lib/api/metrics/dashboard/annotations.rb
View file @
79447268
...
@@ -8,16 +8,6 @@ module API
...
@@ -8,16 +8,6 @@ module API
success
Entities
::
Metrics
::
Dashboard
::
Annotation
success
Entities
::
Metrics
::
Dashboard
::
Annotation
end
end
params
do
requires
:starting_at
,
type:
DateTime
,
desc:
'Date time indicating starting moment to which the annotation relates.'
optional
:ending_at
,
type:
DateTime
,
desc:
'Date time indicating ending moment to which the annotation relates.'
requires
:dashboard_path
,
type:
String
,
desc:
'The path to a file defining the dashboard on which the annotation should be added'
requires
:description
,
type:
String
,
desc:
'The description of the annotation'
end
ANNOTATIONS_SOURCES
=
[
ANNOTATIONS_SOURCES
=
[
{
class:
::
Environment
,
resource: :environments
,
create_service_param_key: :environment
},
{
class:
::
Environment
,
resource: :environments
,
create_service_param_key: :environment
},
{
class:
Clusters
::
Cluster
,
resource: :clusters
,
create_service_param_key: :cluster
}
{
class:
Clusters
::
Cluster
,
resource: :clusters
,
create_service_param_key: :cluster
}
...
@@ -25,6 +15,16 @@ module API
...
@@ -25,6 +15,16 @@ module API
ANNOTATIONS_SOURCES
.
each
do
|
annotations_source
|
ANNOTATIONS_SOURCES
.
each
do
|
annotations_source
|
resource
annotations_source
[
:resource
]
do
resource
annotations_source
[
:resource
]
do
params
do
requires
:starting_at
,
type:
DateTime
,
desc:
'Date time indicating starting moment to which the annotation relates.'
optional
:ending_at
,
type:
DateTime
,
desc:
'Date time indicating ending moment to which the annotation relates.'
requires
:dashboard_path
,
type:
String
,
coerce_with:
->
(
val
)
{
CGI
.
unescape
(
val
)
},
desc:
'The path to a file defining the dashboard on which the annotation should be added'
requires
:description
,
type:
String
,
desc:
'The description of the annotation'
end
post
':id/metrics_dashboard/annotations'
do
post
':id/metrics_dashboard/annotations'
do
annotations_source_object
=
annotations_source
[
:class
].
find
(
params
[
:id
])
annotations_source_object
=
annotations_source
[
:class
].
find
(
params
[
:id
])
...
...
spec/requests/api/metrics/dashboard/annotations_spec.rb
View file @
79447268
...
@@ -35,7 +35,7 @@ describe API::Metrics::Dashboard::Annotations do
...
@@ -35,7 +35,7 @@ describe API::Metrics::Dashboard::Annotations do
context
'with invalid parameters'
do
context
'with invalid parameters'
do
it
'returns error messsage'
do
it
'returns error messsage'
do
post
api
(
url
,
user
),
params:
{
dashboard_path:
nil
,
starting_at:
nil
,
description:
nil
}
post
api
(
url
,
user
),
params:
{
dashboard_path:
''
,
starting_at:
nil
,
description:
nil
}
expect
(
response
).
to
have_gitlab_http_status
(
:bad_request
)
expect
(
response
).
to
have_gitlab_http_status
(
:bad_request
)
expect
(
json_response
[
'message'
]).
to
include
({
"starting_at"
=>
[
"can't be blank"
],
"description"
=>
[
"can't be blank"
],
"dashboard_path"
=>
[
"can't be blank"
]
})
expect
(
json_response
[
'message'
]).
to
include
({
"starting_at"
=>
[
"can't be blank"
],
"description"
=>
[
"can't be blank"
],
"dashboard_path"
=>
[
"can't be blank"
]
})
...
@@ -53,6 +53,41 @@ describe API::Metrics::Dashboard::Annotations do
...
@@ -53,6 +53,41 @@ describe API::Metrics::Dashboard::Annotations do
post
api
(
url
,
user
),
params:
params
post
api
(
url
,
user
),
params:
params
end
end
end
end
context
'with special characers in dashboard_path in request body'
do
let
(
:dashboard_escaped
)
{
'config/prometheus/common_metrics%26copy.yml'
}
let
(
:dashboard_unescaped
)
{
'config/prometheus/common_metrics©.yml'
}
shared_examples
'special characters unescaped'
do
let
(
:expected_params
)
do
{
'starting_at'
=>
starting_at
.
to_time
,
'ending_at'
=>
ending_at
.
to_time
,
"
#{
source_type
}
"
=>
source
,
'dashboard_path'
=>
dashboard_unescaped
,
'description'
=>
params
[
:description
]
}
end
it
'unescapes the dashboard_path'
,
:aggregate_failures
do
expect
(
::
Metrics
::
Dashboard
::
Annotations
::
CreateService
).
to
receive
(
:new
).
with
(
user
,
expected_params
)
post
api
(
url
,
user
),
params:
params
end
end
context
'with escaped characters'
do
it_behaves_like
'special characters unescaped'
do
let
(
:dashboard
)
{
dashboard_escaped
}
end
end
context
'with unescaped characers'
do
it_behaves_like
'special characters unescaped'
do
let
(
:dashboard
)
{
dashboard_unescaped
}
end
end
end
end
end
context
'without correct permissions'
do
context
'without correct permissions'
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