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
a5177ac3
Commit
a5177ac3
authored
Mar 16, 2021
by
Piotr Skorupa
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add usage_data_id validation from version app response
parent
25c14848
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
27 additions
and
5 deletions
+27
-5
app/services/submit_usage_ping_service.rb
app/services/submit_usage_ping_service.rb
+7
-1
spec/services/submit_usage_ping_service_spec.rb
spec/services/submit_usage_ping_service_spec.rb
+20
-4
No files found.
app/services/submit_usage_ping_service.rb
View file @
a5177ac3
...
...
@@ -35,7 +35,13 @@ class SubmitUsagePingService
raise
SubmissionError
.
new
(
"Unsuccessful response code:
#{
response
.
code
}
"
)
unless
response
.
success?
raw_usage_data
.
update_version_metadata!
(
usage_data_id:
response
.
dig
(
'conv_index'
,
'usage_data_id'
))
version_usage_data_id
=
response
.
dig
(
'conv_index'
,
'usage_data_id'
)
||
response
.
dig
(
'dev_ops_score'
,
'usage_data_id'
)
unless
version_usage_data_id
.
is_a?
(
Integer
)
&&
version_usage_data_id
>
0
raise
SubmissionError
.
new
(
"Invalid usage_data_id in response:
#{
version_usage_data_id
}
"
)
end
raw_usage_data
.
update_version_metadata!
(
usage_data_id:
version_usage_data_id
)
store_metrics
(
response
)
end
...
...
spec/services/submit_usage_ping_service_spec.rb
View file @
a5177ac3
...
...
@@ -6,6 +6,7 @@ RSpec.describe SubmitUsagePingService do
include
StubRequests
include
UsageDataHelpers
let
(
:usage_data_id
)
{
31643
}
let
(
:score_params
)
do
{
score:
{
...
...
@@ -40,14 +41,15 @@ RSpec.describe SubmitUsagePingService do
leader_service_desk_issues:
15.8
,
instance_service_desk_issues:
15.1
,
usage_data_id:
usage_data_id
,
non_existing_column:
'value'
}
}
end
let
(
:with_dev_ops_score_params
)
{
{
dev_ops_score:
score_params
[
:score
]
}
}
let
(
:with_conv_index_params
)
{
{
conv_index:
score_params
[
:score
].
merge
(
usage_data_id:
31643
)
}
}
let
(
:without_dev_ops_score_params
)
{
{
dev_ops_score:
{}
}
}
let
(
:with_conv_index_params
)
{
{
conv_index:
score_params
[
:score
]
}
}
shared_examples
'does not run'
do
it
do
...
...
@@ -103,7 +105,7 @@ RSpec.describe SubmitUsagePingService do
end
it
'sends a POST request'
do
response
=
stub_response
(
body:
with
out
_dev_ops_score_params
)
response
=
stub_response
(
body:
with_dev_ops_score_params
)
subject
.
execute
...
...
@@ -111,7 +113,7 @@ RSpec.describe SubmitUsagePingService do
end
it
'forces a refresh of usage data statistics before submitting'
do
stub_response
(
body:
with
out
_dev_ops_score_params
)
stub_response
(
body:
with_dev_ops_score_params
)
expect
(
Gitlab
::
UsageData
).
to
receive
(
:data
).
with
(
force_refresh:
true
).
and_call_original
...
...
@@ -139,6 +141,20 @@ RSpec.describe SubmitUsagePingService do
end
end
context
'when version app usage_data_id is invalid'
do
let
(
:usage_data_id
)
{
-
1000
}
before
do
stub_response
(
body:
with_conv_index_params
)
end
it
'raises an exception'
do
expect
{
subject
.
execute
}.
to
raise_error
(
described_class
::
SubmissionError
)
do
|
error
|
expect
(
error
.
message
).
to
include
(
'Invalid usage_data_id in response: -1000'
)
end
end
end
context
'when DevOps report data is passed'
do
before
do
stub_response
(
body:
with_dev_ops_score_params
)
...
...
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