Commit 39c5eed9 authored by Lin Jen-Shin's avatar Lin Jen-Shin

Merge branch 'sy-handle-empty-embed-json' into 'master'

Address invalid embed_json values

Closes #214760

See merge request gitlab-org/gitlab!29988
parents ae0b415f bc6e7e2c
...@@ -24,6 +24,8 @@ module Metrics ...@@ -24,6 +24,8 @@ module Metrics
override :get_raw_dashboard override :get_raw_dashboard
def get_raw_dashboard def get_raw_dashboard
JSON.parse(params[:embed_json]) JSON.parse(params[:embed_json])
rescue JSON::ParserError => e
invalid_embed_json!(e.message)
end end
override :sequence override :sequence
...@@ -35,6 +37,10 @@ module Metrics ...@@ -35,6 +37,10 @@ module Metrics
def identifiers def identifiers
Digest::SHA256.hexdigest(params[:embed_json]) Digest::SHA256.hexdigest(params[:embed_json])
end end
def invalid_embed_json!(message)
raise DashboardProcessingError.new("Parsing error for param :embed_json. #{message}")
end
end end
end end
end end
...@@ -67,6 +67,12 @@ describe Metrics::Dashboard::TransientEmbedService, :use_clean_rails_memory_stor ...@@ -67,6 +67,12 @@ describe Metrics::Dashboard::TransientEmbedService, :use_clean_rails_memory_stor
expect(get_type_for_embed(alt_embed)).to eq('area-chart') expect(get_type_for_embed(alt_embed)).to eq('area-chart')
end end
context 'when embed_json cannot be parsed as json' do
let(:embed_json) { '' }
it_behaves_like 'misconfigured dashboard service response', :unprocessable_entity
end
private private
def get_embed_json(type = 'line-graph') def get_embed_json(type = 'line-graph')
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment