Commit 75923f93 authored by mo khan's avatar mo khan Committed by James Lopez

License Compliance: Ignore invalid reports

parent ca66f712
---
title: Ignore invalid license_scanning reports
merge_request: 30114
author:
type: fixed
...@@ -10,7 +10,9 @@ module Gitlab ...@@ -10,7 +10,9 @@ module Gitlab
PARSERS = { '1' => V1, '2' => V2 }.freeze PARSERS = { '1' => V1, '2' => V2 }.freeze
def parse!(json_data, report) def parse!(json_data, report)
json = JSON.parse(json_data, symbolize_names: true) json = JSON.parse(json_data, symbolize_names: true, object_class: Hash)
return unless json.is_a?(Hash)
report.version = json[:version].presence || DEFAULT_VERSION report.version = json[:version].presence || DEFAULT_VERSION
parser = PARSERS.fetch(report.major_version) parser = PARSERS.fetch(report.major_version)
......
...@@ -162,6 +162,16 @@ describe Gitlab::Ci::Parsers::LicenseCompliance::LicenseScanning do ...@@ -162,6 +162,16 @@ describe Gitlab::Ci::Parsers::LicenseCompliance::LicenseScanning do
it { expect(report).to be_empty } it { expect(report).to be_empty }
end end
context 'when the report is structured as an array' do
let(:invalid_json) { JSON.pretty_generate([]) }
before do
subject.parse!(invalid_json, report)
end
it { expect(report).to be_empty }
end
context 'when the report is not a valid JSON document' do context 'when the report is not a valid JSON document' do
it do it do
expect do expect do
......
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