Commit b898ff1d authored by Dylan Griffith's avatar Dylan Griffith

Merge branch 'json-cop-autocorrects-ee' into 'master'

Gitlab/Json autocorrects in /ee

See merge request gitlab-org/gitlab!30625
parents 8b21eacf 5a367ce2
...@@ -75,7 +75,7 @@ module EE ...@@ -75,7 +75,7 @@ module EE
respond_to do |format| respond_to do |format|
format.html do format.html do
seat_link_json = JSON.pretty_generate(data) seat_link_json = ::Gitlab::Json.pretty_generate(data)
render html: ::Gitlab::Highlight.highlight('payload.json', seat_link_json, language: 'json') render html: ::Gitlab::Highlight.highlight('payload.json', seat_link_json, language: 'json')
end end
......
...@@ -17,7 +17,7 @@ module EE ...@@ -17,7 +17,7 @@ module EE
def rollout_status_instances def rollout_status_instances
data = File.read(Rails.root.join('spec', 'fixtures', 'rollout_status_instances.json')) data = File.read(Rails.root.join('spec', 'fixtures', 'rollout_status_instances.json'))
JSON.parse(data) Gitlab::Json.parse(data)
end end
def rollout_status_deployments def rollout_status_deployments
......
...@@ -228,7 +228,7 @@ module Vulnerabilities ...@@ -228,7 +228,7 @@ module Vulnerabilities
def metadata def metadata
strong_memoize(:metadata) do strong_memoize(:metadata) do
JSON.parse(raw_metadata) Gitlab::Json.parse(raw_metadata)
rescue JSON::ParserError rescue JSON::ParserError
{} {}
end end
......
...@@ -10,7 +10,7 @@ module DependencyProxy ...@@ -10,7 +10,7 @@ module DependencyProxy
response = Gitlab::HTTP.get(auth_url) response = Gitlab::HTTP.get(auth_url)
if response.success? if response.success?
success(token: JSON.parse(response.body)['token']) success(token: Gitlab::Json.parse(response.body)['token'])
else else
error('Expected 200 response code for an access token', response.code) error('Expected 200 response code for an access token', response.code)
end end
......
...@@ -19,7 +19,7 @@ class FetchSubscriptionPlansService ...@@ -19,7 +19,7 @@ class FetchSubscriptionPlansService
query: { plan: @plan }, query: { plan: @plan },
headers: { 'Accept' => 'application/json' }) headers: { 'Accept' => 'application/json' })
JSON.parse(response.body).map { |plan| Hashie::Mash.new(plan) } Gitlab::Json.parse(response.body).map { |plan| Hashie::Mash.new(plan) }
rescue => e rescue => e
Rails.logger.info "Unable to connect to GitLab Customers App #{e}" # rubocop:disable Gitlab/RailsLogger Rails.logger.info "Unable to connect to GitLab Customers App #{e}" # rubocop:disable Gitlab/RailsLogger
......
...@@ -30,7 +30,7 @@ module Geo ...@@ -30,7 +30,7 @@ module Geo
def sync_tag(tag) def sync_tag(tag)
file = nil file = nil
manifest = client.repository_raw_manifest(name, tag) manifest = client.repository_raw_manifest(name, tag)
manifest_parsed = JSON.parse(manifest) manifest_parsed = Gitlab::Json.parse(manifest)
list_blobs(manifest_parsed).each do |digest| list_blobs(manifest_parsed).each do |digest|
next if container_repository.blob_exists?(digest) next if container_repository.blob_exists?(digest)
......
...@@ -16,8 +16,7 @@ class Gitlab::Seeder::Packages ...@@ -16,8 +16,7 @@ class Gitlab::Seeder::Packages
name = "@#{@project.root_namespace.path}/npm_package_#{SecureRandom.hex}" name = "@#{@project.root_namespace.path}/npm_package_#{SecureRandom.hex}"
version = "1.12.#{i}" version = "1.12.#{i}"
params = JSON.parse( params = Gitlab::Json.parse(read_fixture_file('npm', 'payload.json')
read_fixture_file('npm', 'payload.json')
.gsub('@root/npm-test', name) .gsub('@root/npm-test', name)
.gsub('1.0.1', version)) .gsub('1.0.1', version))
.with_indifferent_access .with_indifferent_access
......
...@@ -10,7 +10,7 @@ module Gitlab ...@@ -10,7 +10,7 @@ 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, object_class: Hash) json = Gitlab::Json.parse(json_data, symbolize_names: true, object_class: Hash)
return unless json.is_a?(Hash) return unless json.is_a?(Hash)
report.version = json[:version].presence || DEFAULT_VERSION report.version = json[:version].presence || DEFAULT_VERSION
......
...@@ -24,7 +24,7 @@ module Gitlab ...@@ -24,7 +24,7 @@ module Gitlab
protected protected
def parse_report(json_data) def parse_report(json_data)
JSON.parse!(json_data) Gitlab::Json.parse!(json_data)
end end
# map remediations to relevant vulnerabilities # map remediations to relevant vulnerabilities
......
...@@ -10,7 +10,7 @@ module Gitlab ...@@ -10,7 +10,7 @@ module Gitlab
end end
def parse!(json_data, report) def parse!(json_data, report)
report_data = JSON.parse(json_data) report_data = Gitlab::Json.parse(json_data)
report_data.fetch('dependency_files', []).each do |file| report_data.fetch('dependency_files', []).each do |file|
file['dependencies'].each do |dependency| file['dependencies'].each do |dependency|
report.add_dependency(formatter.format(dependency, report.add_dependency(formatter.format(dependency,
......
...@@ -16,7 +16,7 @@ module Gitlab ...@@ -16,7 +16,7 @@ module Gitlab
private private
def parse_report_json(blob) def parse_report_json(blob)
JSON.parse!(blob) Gitlab::Json.parse!(blob)
rescue JSON::ParserError rescue JSON::ParserError
{} {}
end end
......
...@@ -70,7 +70,7 @@ module Gitlab ...@@ -70,7 +70,7 @@ module Gitlab
) )
message = decoded.first message = decoded.first
data = JSON.parse(message['data']) if message data = Gitlab::Json.parse(message['data']) if message
data&.deep_symbolize_keys! data&.deep_symbolize_keys!
data data
rescue JWT::ImmatureSignature, JWT::ExpiredSignature rescue JWT::ImmatureSignature, JWT::ExpiredSignature
......
...@@ -22,7 +22,7 @@ module Gitlab ...@@ -22,7 +22,7 @@ module Gitlab
private private
def parse(json) def parse(json)
build_catalogue(JSON.parse(json, symbolize_names: true)) build_catalogue(Gitlab::Json.parse(json, symbolize_names: true))
end end
def record_failure(tags = {}) def record_failure(tags = {})
......
...@@ -74,7 +74,7 @@ describe Projects::PipelinesController do ...@@ -74,7 +74,7 @@ describe Projects::PipelinesController do
let!(:mit_license) { create(:software_license, :mit) } let!(:mit_license) { create(:software_license, :mit) }
let!(:software_license_policy) { create(:software_license_policy, software_license: mit_license, project: project) } let!(:software_license_policy) { create(:software_license_policy, software_license: mit_license, project: project) }
let(:payload) { JSON.parse(licenses_with_json.body) } let(:payload) { Gitlab::Json.parse(licenses_with_json.body) }
context 'with a license scanning artifact' do context 'with a license scanning artifact' do
before do before do
......
...@@ -48,7 +48,7 @@ describe Projects::ServiceDeskController do ...@@ -48,7 +48,7 @@ describe Projects::ServiceDeskController do
get :show, params: { namespace_id: project.namespace.to_param, project_id: project }, format: :json get :show, params: { namespace_id: project.namespace.to_param, project_id: project }, format: :json
response_hash = JSON.parse(response.body) response_hash = Gitlab::Json.parse(response.body)
expect(response_hash['template_file_missing']).to eq(false) expect(response_hash['template_file_missing']).to eq(false)
end end
end end
......
...@@ -4,7 +4,7 @@ FactoryBot.define do ...@@ -4,7 +4,7 @@ FactoryBot.define do
factory :spdx_catalogue, class: '::Gitlab::SPDX::Catalogue' do factory :spdx_catalogue, class: '::Gitlab::SPDX::Catalogue' do
initialize_with do initialize_with do
content = IO.read(Rails.root.join('spec', 'fixtures', 'spdx.json')) content = IO.read(Rails.root.join('spec', 'fixtures', 'spdx.json'))
::Gitlab::SPDX::Catalogue.new(JSON.parse(content, symbolize_names: true)) ::Gitlab::SPDX::Catalogue.new(Gitlab::Json.parse(content, symbolize_names: true))
end end
end end
end end
...@@ -12,7 +12,7 @@ FactoryBot.define do ...@@ -12,7 +12,7 @@ FactoryBot.define do
after(:build) do |finding, evaluator| after(:build) do |finding, evaluator|
if evaluator.summary if evaluator.summary
raw_metadata = JSON.parse(finding.raw_metadata) raw_metadata = Gitlab::Json.parse(finding.raw_metadata)
raw_metadata.delete("solution") raw_metadata.delete("solution")
raw_metadata["remediations"] = [ raw_metadata["remediations"] = [
{ {
...@@ -93,7 +93,7 @@ FactoryBot.define do ...@@ -93,7 +93,7 @@ FactoryBot.define do
trait :with_remediation do trait :with_remediation do
after(:build) do |finding| after(:build) do |finding|
raw_metadata = JSON.parse(finding.raw_metadata) raw_metadata = Gitlab::Json.parse(finding.raw_metadata)
raw_metadata.delete(:solution) raw_metadata.delete(:solution)
raw_metadata[:remediations] = [ raw_metadata[:remediations] = [
{ {
......
...@@ -12,7 +12,7 @@ describe 'Billing plan pages', :feature do ...@@ -12,7 +12,7 @@ describe 'Billing plan pages', :feature do
let(:silver_plan) { create(:silver_plan) } let(:silver_plan) { create(:silver_plan) }
let(:gold_plan) { create(:gold_plan) } let(:gold_plan) { create(:gold_plan) }
let(:plans_data) do let(:plans_data) do
JSON.parse(File.read(Rails.root.join('ee/spec/fixtures/gitlab_com_plans.json'))).map do |data| Gitlab::Json.parse(File.read(Rails.root.join('ee/spec/fixtures/gitlab_com_plans.json'))).map do |data|
data.deep_symbolize_keys data.deep_symbolize_keys
end end
end end
......
...@@ -29,7 +29,7 @@ describe 'EE > Projects > Licenses > Maintainer views policies', :js do ...@@ -29,7 +29,7 @@ describe 'EE > Projects > Licenses > Maintainer views policies', :js do
let_it_be(:mit) { create(:software_license, :mit) } let_it_be(:mit) { create(:software_license, :mit) }
let_it_be(:mit_policy) { create(:software_license_policy, :denied, software_license: mit, project: project) } let_it_be(:mit_policy) { create(:software_license_policy, :denied, software_license: mit, project: project) }
let_it_be(:pipeline) { create(:ee_ci_pipeline, project: project, builds: [create(:ee_ci_build, :license_scan_v2, :success)]) } let_it_be(:pipeline) { create(:ee_ci_pipeline, project: project, builds: [create(:ee_ci_build, :license_scan_v2, :success)]) }
let(:report) { JSON.parse(fixture_file('security_reports/gl-license-scanning-report-v2.json', dir: 'ee')) } let(:report) { Gitlab::Json.parse(fixture_file('security_reports/gl-license-scanning-report-v2.json', dir: 'ee')) }
let(:known_licenses) { report['licenses'].find_all { |license| license['url'].present? } } let(:known_licenses) { report['licenses'].find_all { |license| license['url'].present? } }
it 'displays licenses detected in the most recent scan report' do it 'displays licenses detected in the most recent scan report' do
......
...@@ -9,7 +9,7 @@ describe 'Show trial banner', :js do ...@@ -9,7 +9,7 @@ describe 'Show trial banner', :js do
let!(:group) { create(:group) } let!(:group) { create(:group) }
let!(:gold_plan) { create(:gold_plan) } let!(:gold_plan) { create(:gold_plan) }
let(:plans_data) do let(:plans_data) do
JSON.parse(File.read(Rails.root.join('ee/spec/fixtures/gitlab_com_plans.json'))).map do |data| Gitlab::Json.parse(File.read(Rails.root.join('ee/spec/fixtures/gitlab_com_plans.json'))).map do |data|
data.deep_symbolize_keys data.deep_symbolize_keys
end end
end end
......
...@@ -299,7 +299,7 @@ describe Security::PipelineVulnerabilitiesFinder do ...@@ -299,7 +299,7 @@ describe Security::PipelineVulnerabilitiesFinder do
end end
def read_fixture(fixture) def read_fixture(fixture)
JSON.parse(File.read(fixture.file.path)) Gitlab::Json.parse(File.read(fixture.file.path))
end end
end end
end end
......
...@@ -47,7 +47,7 @@ describe StatusPage::IncidentCommentsFinder do ...@@ -47,7 +47,7 @@ describe StatusPage::IncidentCommentsFinder do
describe 'award emoji' do describe 'award emoji' do
let(:digest_path) { Rails.root.join(*%w[fixtures emojis digests.json]) } let(:digest_path) { Rails.root.join(*%w[fixtures emojis digests.json]) }
let(:digest_json) { JSON.parse(File.read(digest_path)) } let(:digest_json) { Gitlab::Json.parse(File.read(digest_path)) }
it 'ensures that emoji exists' do it 'ensures that emoji exists' do
expect(digest_json).to include(visible_emoji) expect(digest_json).to include(visible_emoji)
......
...@@ -84,7 +84,7 @@ describe GitlabSchema.types['Vulnerability'] do ...@@ -84,7 +84,7 @@ describe GitlabSchema.types['Vulnerability'] do
it "is the JSON metadata for the vulnerability's location" do it "is the JSON metadata for the vulnerability's location" do
vulnerabilities = subject.dig('data', 'project', 'vulnerabilities', 'nodes') vulnerabilities = subject.dig('data', 'project', 'vulnerabilities', 'nodes')
expect(JSON.parse(vulnerabilities.first['location'])).to eq(location) expect(Gitlab::Json.parse(vulnerabilities.first['location'])).to eq(location)
end end
end end
end end
...@@ -74,7 +74,7 @@ describe VulnerabilitiesHelper do ...@@ -74,7 +74,7 @@ describe VulnerabilitiesHelper do
describe 'when pipeline exists' do describe 'when pipeline exists' do
let(:pipeline) { create(:ci_pipeline) } let(:pipeline) { create(:ci_pipeline) }
let(:pipelineData) { JSON.parse(subject[:pipeline_json]) } let(:pipelineData) { Gitlab::Json.parse(subject[:pipeline_json]) }
include_examples 'vulnerability properties' include_examples 'vulnerability properties'
......
...@@ -41,7 +41,7 @@ describe EE::API::Helpers do ...@@ -41,7 +41,7 @@ describe EE::API::Helpers do
get 'user' get 'user'
expect(JSON.parse(last_response.body)).to eq({ 'id' => user.id }) expect(Gitlab::Json.parse(last_response.body)).to eq({ 'id' => user.id })
end end
it 'does not handle sticking if no user could be found' do it 'does not handle sticking if no user could be found' do
...@@ -52,7 +52,7 @@ describe EE::API::Helpers do ...@@ -52,7 +52,7 @@ describe EE::API::Helpers do
get 'user' get 'user'
expect(JSON.parse(last_response.body)).to eq({ 'found' => false }) expect(Gitlab::Json.parse(last_response.body)).to eq({ 'found' => false })
end end
it 'returns the user if one could be found' do it 'returns the user if one could be found' do
...@@ -60,7 +60,7 @@ describe EE::API::Helpers do ...@@ -60,7 +60,7 @@ describe EE::API::Helpers do
get 'user' get 'user'
expect(JSON.parse(last_response.body)).to eq({ 'id' => user.id }) expect(Gitlab::Json.parse(last_response.body)).to eq({ 'id' => user.id })
end end
end end
...@@ -71,7 +71,7 @@ describe EE::API::Helpers do ...@@ -71,7 +71,7 @@ describe EE::API::Helpers do
header 'Authorization', 'test' header 'Authorization', 'test'
get 'protected', params: { current_user: 'test' } get 'protected', params: { current_user: 'test' }
expect(JSON.parse(last_response.body)).to eq({ 'message' => 'Gitlab::Geo::InvalidDecryptionKeyError' }) expect(Gitlab::Json.parse(last_response.body)).to eq({ 'message' => 'Gitlab::Geo::InvalidDecryptionKeyError' })
end end
it 'rescues from ::Gitlab::Geo::InvalidSignatureTimeError' do it 'rescues from ::Gitlab::Geo::InvalidSignatureTimeError' do
...@@ -80,7 +80,7 @@ describe EE::API::Helpers do ...@@ -80,7 +80,7 @@ describe EE::API::Helpers do
header 'Authorization', 'test' header 'Authorization', 'test'
get 'protected', params: { current_user: 'test' } get 'protected', params: { current_user: 'test' }
expect(JSON.parse(last_response.body)).to eq({ 'message' => 'Gitlab::Geo::InvalidSignatureTimeError' }) expect(Gitlab::Json.parse(last_response.body)).to eq({ 'message' => 'Gitlab::Geo::InvalidSignatureTimeError' })
end end
it 'returns unauthorized response when scope is not valid' do it 'returns unauthorized response when scope is not valid' do
...@@ -89,7 +89,7 @@ describe EE::API::Helpers do ...@@ -89,7 +89,7 @@ describe EE::API::Helpers do
header 'Authorization', 'test' header 'Authorization', 'test'
get 'protected', params: { current_user: 'test' } get 'protected', params: { current_user: 'test' }
expect(JSON.parse(last_response.body)).to eq({ 'message' => '401 Unauthorized' }) expect(Gitlab::Json.parse(last_response.body)).to eq({ 'message' => '401 Unauthorized' })
end end
end end
......
...@@ -180,7 +180,7 @@ describe Gitlab::ImportExport::Group::TreeSaver do ...@@ -180,7 +180,7 @@ describe Gitlab::ImportExport::Group::TreeSaver do
def read_association(group, association) def read_association(group, association)
path = exported_path_for(File.join("#{group.id}", "#{association}.ndjson")) path = exported_path_for(File.join("#{group.id}", "#{association}.ndjson"))
File.foreach(path).map {|line| JSON.parse(line) } File.foreach(path).map {|line| Gitlab::Json.parse(line) }
end end
def expect_successful_save(group_tree_saver) def expect_successful_save(group_tree_saver)
......
...@@ -130,14 +130,14 @@ describe Gitlab::Ci::Parsers::LicenseCompliance::LicenseScanning do ...@@ -130,14 +130,14 @@ describe Gitlab::Ci::Parsers::LicenseCompliance::LicenseScanning do
context 'when the report version is not recognized' do context 'when the report version is not recognized' do
it do it do
expect do expect do
subject.parse!(JSON.pretty_generate({ version: 'x' }), report) subject.parse!(Gitlab::Json.pretty_generate({ version: 'x' }), report)
end.to raise_error(KeyError) end.to raise_error(KeyError)
end end
end end
context 'when the report version is missing' do context 'when the report version is missing' do
before do before do
subject.parse!(JSON.pretty_generate({}), report) subject.parse!(Gitlab::Json.pretty_generate({}), report)
end end
it { expect(report.version).to eq('1.0') } it { expect(report.version).to eq('1.0') }
...@@ -146,7 +146,7 @@ describe Gitlab::Ci::Parsers::LicenseCompliance::LicenseScanning do ...@@ -146,7 +146,7 @@ describe Gitlab::Ci::Parsers::LicenseCompliance::LicenseScanning do
context 'when the report version is nil' do context 'when the report version is nil' do
before do before do
subject.parse!(JSON.pretty_generate({ version: nil }), report) subject.parse!(Gitlab::Json.pretty_generate({ version: nil }), report)
end end
it { expect(report.version).to eq('1.0') } it { expect(report.version).to eq('1.0') }
...@@ -155,7 +155,7 @@ describe Gitlab::Ci::Parsers::LicenseCompliance::LicenseScanning do ...@@ -155,7 +155,7 @@ describe Gitlab::Ci::Parsers::LicenseCompliance::LicenseScanning do
context 'when the report version is blank' do context 'when the report version is blank' do
before do before do
subject.parse!(JSON.pretty_generate({ version: '' }), report) subject.parse!(Gitlab::Json.pretty_generate({ version: '' }), report)
end end
it { expect(report.version).to eq('1.0') } it { expect(report.version).to eq('1.0') }
...@@ -163,7 +163,7 @@ describe Gitlab::Ci::Parsers::LicenseCompliance::LicenseScanning do ...@@ -163,7 +163,7 @@ describe Gitlab::Ci::Parsers::LicenseCompliance::LicenseScanning do
end end
context 'when the report is structured as an array' do context 'when the report is structured as an array' do
let(:invalid_json) { JSON.pretty_generate([]) } let(:invalid_json) { Gitlab::Json.pretty_generate([]) }
before do before do
subject.parse!(invalid_json, report) subject.parse!(invalid_json, report)
......
...@@ -48,7 +48,7 @@ describe Gitlab::Ci::Parsers::Security::ContainerScanning do ...@@ -48,7 +48,7 @@ describe Gitlab::Ci::Parsers::Security::ContainerScanning do
end end
it "adds report image's name to raw_metadata" do it "adds report image's name to raw_metadata" do
expect(JSON.parse(report.occurrences.first.raw_metadata).dig('location', 'image')).to eq(image) expect(Gitlab::Json.parse(report.occurrences.first.raw_metadata).dig('location', 'image')).to eq(image)
end end
end end
end end
......
...@@ -50,7 +50,7 @@ describe Gitlab::Ci::Parsers::Security::DependencyScanning do ...@@ -50,7 +50,7 @@ describe Gitlab::Ci::Parsers::Security::DependencyScanning do
end end
context "when parsing a vulnerability with a missing location" do context "when parsing a vulnerability with a missing location" do
let(:report_hash) { JSON.parse(fixture_file('security_reports/master/gl-sast-report.json', dir: 'ee'), symbolize_names: true) } let(:report_hash) { Gitlab::Json.parse(fixture_file('security_reports/master/gl-sast-report.json', dir: 'ee'), symbolize_names: true) }
before do before do
report_hash[:vulnerabilities][0][:location] = nil report_hash[:vulnerabilities][0][:location] = nil
...@@ -60,7 +60,7 @@ describe Gitlab::Ci::Parsers::Security::DependencyScanning do ...@@ -60,7 +60,7 @@ describe Gitlab::Ci::Parsers::Security::DependencyScanning do
end end
context "when parsing a vulnerability with a missing cve" do context "when parsing a vulnerability with a missing cve" do
let(:report_hash) { JSON.parse(fixture_file('security_reports/master/gl-sast-report.json', dir: 'ee'), symbolize_names: true) } let(:report_hash) { Gitlab::Json.parse(fixture_file('security_reports/master/gl-sast-report.json', dir: 'ee'), symbolize_names: true) }
before do before do
report_hash[:vulnerabilities][0][:cve] = nil report_hash[:vulnerabilities][0][:cve] = nil
...@@ -80,7 +80,7 @@ describe Gitlab::Ci::Parsers::Security::DependencyScanning do ...@@ -80,7 +80,7 @@ describe Gitlab::Ci::Parsers::Security::DependencyScanning do
it "generates occurrence with expected remediation" do it "generates occurrence with expected remediation" do
occurrence = report.occurrences.last occurrence = report.occurrences.last
raw_metadata = JSON.parse!(occurrence.raw_metadata) raw_metadata = Gitlab::Json.parse!(occurrence.raw_metadata)
expect(occurrence.name).to eq("Authentication bypass via incorrect DOM traversal and canonicalization in saml2-js") expect(occurrence.name).to eq("Authentication bypass via incorrect DOM traversal and canonicalization in saml2-js")
expect(raw_metadata["remediations"].first["summary"]).to eq("Upgrade saml2-js") expect(raw_metadata["remediations"].first["summary"]).to eq("Upgrade saml2-js")
......
...@@ -6,7 +6,7 @@ describe Gitlab::Ci::Parsers::Security::Formatters::Dast do ...@@ -6,7 +6,7 @@ describe Gitlab::Ci::Parsers::Security::Formatters::Dast do
let(:formatter) { described_class.new(parsed_report) } let(:formatter) { described_class.new(parsed_report) }
let(:parsed_report) do let(:parsed_report) do
JSON.parse!( Gitlab::Json.parse!(
File.read( File.read(
Rails.root.join('ee/spec/fixtures/security_reports/deprecated/gl-dast-report-no-common-fields.json') Rails.root.join('ee/spec/fixtures/security_reports/deprecated/gl-dast-report-no-common-fields.json')
) )
......
...@@ -8,7 +8,7 @@ describe Gitlab::Ci::Parsers::Security::Formatters::DependencyList do ...@@ -8,7 +8,7 @@ describe Gitlab::Ci::Parsers::Security::Formatters::DependencyList do
let(:sha) { '4242424242424242' } let(:sha) { '4242424242424242' }
let(:parsed_report) do let(:parsed_report) do
JSON.parse!( Gitlab::Json.parse!(
File.read( File.read(
Rails.root.join('ee/spec/fixtures/security_reports/dependency_list/gl-dependency-scanning-report.json') Rails.root.join('ee/spec/fixtures/security_reports/dependency_list/gl-dependency-scanning-report.json')
) )
......
...@@ -7,7 +7,7 @@ describe Gitlab::Ci::Parsers::Security::Formatters::DeprecatedContainerScanning ...@@ -7,7 +7,7 @@ describe Gitlab::Ci::Parsers::Security::Formatters::DeprecatedContainerScanning
describe '#format' do describe '#format' do
let(:raw_report) do let(:raw_report) do
JSON.parse!( Gitlab::Json.parse!(
File.read( File.read(
Rails.root.join('ee/spec/fixtures/security_reports/deprecated/gl-container-scanning-report.json') Rails.root.join('ee/spec/fixtures/security_reports/deprecated/gl-container-scanning-report.json')
) )
......
...@@ -4,7 +4,7 @@ require 'spec_helper' ...@@ -4,7 +4,7 @@ require 'spec_helper'
describe Gitlab::Ci::Parsers::Security::Formatters::DeprecatedFormattedContainerScanningVulnerability do describe Gitlab::Ci::Parsers::Security::Formatters::DeprecatedFormattedContainerScanningVulnerability do
let(:raw_report) do let(:raw_report) do
JSON.parse!( Gitlab::Json.parse!(
File.read( File.read(
Rails.root.join('ee/spec/fixtures/security_reports/deprecated/gl-container-scanning-report.json') Rails.root.join('ee/spec/fixtures/security_reports/deprecated/gl-container-scanning-report.json')
) )
......
...@@ -49,7 +49,7 @@ describe Gitlab::Ci::Parsers::Security::Sast do ...@@ -49,7 +49,7 @@ describe Gitlab::Ci::Parsers::Security::Sast do
context "when parsing an empty report" do context "when parsing an empty report" do
let(:report) { Gitlab::Ci::Reports::Security::Report.new('sast', commit_sha, created_at) } let(:report) { Gitlab::Ci::Reports::Security::Report.new('sast', commit_sha, created_at) }
let(:blob) { JSON.generate({}) } let(:blob) { Gitlab::Json.generate({}) }
it { expect(parser.parse!(blob, report)).to be_empty } it { expect(parser.parse!(blob, report)).to be_empty }
end end
......
...@@ -53,7 +53,7 @@ describe Gitlab::Database::LoadBalancing::SrvResolver do ...@@ -53,7 +53,7 @@ describe Gitlab::Database::LoadBalancing::SrvResolver do
def dns_response_packet_from_fixture(fixture_name) def dns_response_packet_from_fixture(fixture_name)
fixture = File.read(Rails.root + "ee/spec/fixtures/dns/#{fixture_name}.json") fixture = File.read(Rails.root + "ee/spec/fixtures/dns/#{fixture_name}.json")
encoded_payload = JSON.parse(fixture)['payload'] encoded_payload = Gitlab::Json.parse(fixture)['payload']
payload = Base64.decode64(encoded_payload) payload = Base64.decode64(encoded_payload)
Net::DNS::Packet.parse(payload) Net::DNS::Packet.parse(payload)
......
...@@ -34,7 +34,7 @@ describe Gitlab::Geo::Oauth::Session, :geo do ...@@ -34,7 +34,7 @@ describe Gitlab::Geo::Oauth::Session, :geo do
end end
it 'returns hashed user data' do it 'returns hashed user data' do
parsed_json = JSON.parse(user_json) parsed_json = Gitlab::Json.parse(user_json)
expect(subject.authenticate(access_token.token)).to eq(parsed_json) expect(subject.authenticate(access_token.token)).to eq(parsed_json)
end end
......
...@@ -11,7 +11,7 @@ describe Gitlab::SPDX::CatalogueGateway do ...@@ -11,7 +11,7 @@ describe Gitlab::SPDX::CatalogueGateway do
context "when the licenses.json endpoint is healthy" do context "when the licenses.json endpoint is healthy" do
let(:spdx_json) { IO.read(Rails.root.join("spec", "fixtures", "spdx.json")) } let(:spdx_json) { IO.read(Rails.root.join("spec", "fixtures", "spdx.json")) }
let(:catalogue_hash) { JSON.parse(spdx_json, symbolize_names: true) } let(:catalogue_hash) { Gitlab::Json.parse(spdx_json, symbolize_names: true) }
before do before do
stub_full_request(url, method: :get).to_return(status: 200, body: spdx_json) stub_full_request(url, method: :get).to_return(status: 200, body: spdx_json)
......
...@@ -6,7 +6,7 @@ RSpec.describe Gitlab::SPDX::Catalogue do ...@@ -6,7 +6,7 @@ RSpec.describe Gitlab::SPDX::Catalogue do
subject { described_class.new(catalogue_hash) } subject { described_class.new(catalogue_hash) }
let(:spdx_json) { IO.read(Rails.root.join("spec", "fixtures", "spdx.json")) } let(:spdx_json) { IO.read(Rails.root.join("spec", "fixtures", "spdx.json")) }
let(:catalogue_hash) { JSON.parse(spdx_json, symbolize_names: true) } let(:catalogue_hash) { Gitlab::Json.parse(spdx_json, symbolize_names: true) }
describe "#version" do describe "#version" do
let(:version) { SecureRandom.uuid } let(:version) { SecureRandom.uuid }
......
...@@ -30,7 +30,7 @@ describe EpicPresenter do ...@@ -30,7 +30,7 @@ describe EpicPresenter do
end end
it 'has correct ancestors' do it 'has correct ancestors' do
metadata = JSON.parse(presenter.show_data[:meta]) metadata = Gitlab::Json.parse(presenter.show_data[:meta])
ancestor_url = metadata['ancestors'].first['url'] ancestor_url = metadata['ancestors'].first['url']
expect(ancestor_url).to eq "/groups/#{parent_epic.group.full_path}/-/epics/#{parent_epic.iid}" expect(ancestor_url).to eq "/groups/#{parent_epic.group.full_path}/-/epics/#{parent_epic.iid}"
......
...@@ -37,7 +37,7 @@ describe Projects::Security::ConfigurationPresenter do ...@@ -37,7 +37,7 @@ describe Projects::Security::ConfigurationPresenter do
end end
it 'reports that all security jobs are configured' do it 'reports that all security jobs are configured' do
expect(JSON.parse(subject[:features])).to contain_exactly( expect(Gitlab::Json.parse(subject[:features])).to contain_exactly(
security_scan(:dast, configured: true), security_scan(:dast, configured: true),
security_scan(:sast, configured: true), security_scan(:sast, configured: true),
security_scan(:container_scanning, configured: true), security_scan(:container_scanning, configured: true),
...@@ -57,7 +57,7 @@ describe Projects::Security::ConfigurationPresenter do ...@@ -57,7 +57,7 @@ describe Projects::Security::ConfigurationPresenter do
end end
it 'reports all security jobs as unconfigured' do it 'reports all security jobs as unconfigured' do
expect(JSON.parse(subject[:features])).to contain_exactly( expect(Gitlab::Json.parse(subject[:features])).to contain_exactly(
security_scan(:dast, configured: false), security_scan(:dast, configured: false),
security_scan(:sast, configured: false), security_scan(:sast, configured: false),
security_scan(:container_scanning, configured: false), security_scan(:container_scanning, configured: false),
...@@ -83,7 +83,7 @@ describe Projects::Security::ConfigurationPresenter do ...@@ -83,7 +83,7 @@ describe Projects::Security::ConfigurationPresenter do
end end
it 'uses the latest default branch pipeline to determine whether a security job is configured' do it 'uses the latest default branch pipeline to determine whether a security job is configured' do
expect(JSON.parse(subject[:features])).to contain_exactly( expect(Gitlab::Json.parse(subject[:features])).to contain_exactly(
security_scan(:dast, configured: true), security_scan(:dast, configured: true),
security_scan(:sast, configured: true), security_scan(:sast, configured: true),
security_scan(:container_scanning, configured: false), security_scan(:container_scanning, configured: false),
...@@ -97,7 +97,7 @@ describe Projects::Security::ConfigurationPresenter do ...@@ -97,7 +97,7 @@ describe Projects::Security::ConfigurationPresenter do
create(:ci_build, :sast, pipeline: pipeline) create(:ci_build, :sast, pipeline: pipeline)
expect(JSON.parse(subject[:features])).to contain_exactly( expect(Gitlab::Json.parse(subject[:features])).to contain_exactly(
security_scan(:dast, configured: false), security_scan(:dast, configured: false),
security_scan(:sast, configured: true), security_scan(:sast, configured: true),
security_scan(:container_scanning, configured: false), security_scan(:container_scanning, configured: false),
...@@ -117,7 +117,7 @@ describe Projects::Security::ConfigurationPresenter do ...@@ -117,7 +117,7 @@ describe Projects::Security::ConfigurationPresenter do
subject subject
expect(JSON.parse(subject[:features])).to contain_exactly( expect(Gitlab::Json.parse(subject[:features])).to contain_exactly(
security_scan(:dast, configured: false), security_scan(:dast, configured: false),
security_scan(:sast, configured: true), security_scan(:sast, configured: true),
security_scan(:container_scanning, configured: false), security_scan(:container_scanning, configured: false),
...@@ -129,7 +129,7 @@ describe Projects::Security::ConfigurationPresenter do ...@@ -129,7 +129,7 @@ describe Projects::Security::ConfigurationPresenter do
it 'detect new license compliance job' do it 'detect new license compliance job' do
create(:ci_build, :license_scanning, pipeline: pipeline) create(:ci_build, :license_scanning, pipeline: pipeline)
expect(JSON.parse(subject[:features])).to contain_exactly( expect(Gitlab::Json.parse(subject[:features])).to contain_exactly(
security_scan(:dast, configured: true), security_scan(:dast, configured: true),
security_scan(:sast, configured: true), security_scan(:sast, configured: true),
security_scan(:container_scanning, configured: false), security_scan(:container_scanning, configured: false),
......
...@@ -158,7 +158,7 @@ describe API::FeatureFlagScopes do ...@@ -158,7 +158,7 @@ describe API::FeatureFlagScopes do
expect(response).to match_response_schema('public_api/v4/feature_flag_scope', dir: 'ee') expect(response).to match_response_schema('public_api/v4/feature_flag_scope', dir: 'ee')
expect(json_response['environment_scope']).to eq(params[:environment_scope]) expect(json_response['environment_scope']).to eq(params[:environment_scope])
expect(json_response['active']).to eq(params[:active]) expect(json_response['active']).to eq(params[:active])
expect(json_response['strategies']).to eq(JSON.parse(params[:strategies])) expect(json_response['strategies']).to eq(Gitlab::Json.parse(params[:strategies]))
end end
context 'when the scope already exists' do context 'when the scope already exists' do
...@@ -258,7 +258,7 @@ describe API::FeatureFlagScopes do ...@@ -258,7 +258,7 @@ describe API::FeatureFlagScopes do
expect(response).to match_response_schema('public_api/v4/feature_flag_scope', dir: 'ee') expect(response).to match_response_schema('public_api/v4/feature_flag_scope', dir: 'ee')
expect(json_response['id']).to eq(scope.id) expect(json_response['id']).to eq(scope.id)
expect(json_response['active']).to eq(params[:active]) expect(json_response['active']).to eq(params[:active])
expect(json_response['strategies']).to eq(JSON.parse(params[:strategies])) expect(json_response['strategies']).to eq(Gitlab::Json.parse(params[:strategies]))
end end
context 'when there are no corresponding feature flag scopes' do context 'when there are no corresponding feature flag scopes' do
......
...@@ -354,7 +354,7 @@ describe API::FeatureFlags do ...@@ -354,7 +354,7 @@ describe API::FeatureFlags do
feature_flag.scopes.ordered.each_with_index do |scope, index| feature_flag.scopes.ordered.each_with_index do |scope, index|
expect(scope.environment_scope).to eq(params[:scopes][index][:environment_scope]) expect(scope.environment_scope).to eq(params[:scopes][index][:environment_scope])
expect(scope.active).to eq(params[:scopes][index][:active]) expect(scope.active).to eq(params[:scopes][index][:active])
expect(scope.strategies).to eq(JSON.parse(params[:scopes][index][:strategies])) expect(scope.strategies).to eq(Gitlab::Json.parse(params[:scopes][index][:strategies]))
end end
end end
end end
...@@ -480,7 +480,7 @@ describe API::FeatureFlags do ...@@ -480,7 +480,7 @@ describe API::FeatureFlags do
expect(response).to have_gitlab_http_status(:ok) expect(response).to have_gitlab_http_status(:ok)
expect(response).to match_response_schema('public_api/v4/feature_flag', dir: 'ee') expect(response).to match_response_schema('public_api/v4/feature_flag', dir: 'ee')
expect(feature_flag.name).to eq(params[:name]) expect(feature_flag.name).to eq(params[:name])
expect(scope.strategies).to eq([JSON.parse(params[:strategy])]) expect(scope.strategies).to eq([Gitlab::Json.parse(params[:strategy])])
expect(feature_flag.version).to eq('legacy_flag') expect(feature_flag.version).to eq('legacy_flag')
end end
...@@ -507,7 +507,7 @@ describe API::FeatureFlags do ...@@ -507,7 +507,7 @@ describe API::FeatureFlags do
scope = feature_flag.scopes.find_by_environment_scope(params[:environment_scope]) scope = feature_flag.scopes.find_by_environment_scope(params[:environment_scope])
expect(response).to have_gitlab_http_status(:ok) expect(response).to have_gitlab_http_status(:ok)
expect(scope.strategies).to eq([JSON.parse(params[:strategy])]) expect(scope.strategies).to eq([Gitlab::Json.parse(params[:strategy])])
end end
it_behaves_like 'check user permission' it_behaves_like 'check user permission'
...@@ -525,11 +525,11 @@ describe API::FeatureFlags do ...@@ -525,11 +525,11 @@ describe API::FeatureFlags do
scope = feature_flag.scopes.find_by_environment_scope(params[:environment_scope]) scope = feature_flag.scopes.find_by_environment_scope(params[:environment_scope])
expect(response).to have_gitlab_http_status(:ok) expect(response).to have_gitlab_http_status(:ok)
expect(scope.strategies).to eq([defined_strategy.deep_stringify_keys, JSON.parse(params[:strategy])]) expect(scope.strategies).to eq([defined_strategy.deep_stringify_keys, Gitlab::Json.parse(params[:strategy])])
end end
context 'when the specified strategy exists already' do context 'when the specified strategy exists already' do
let(:defined_strategy) { JSON.parse(params[:strategy]) } let(:defined_strategy) { Gitlab::Json.parse(params[:strategy]) }
it 'does not add a duplicate strategy' do it 'does not add a duplicate strategy' do
subject subject
......
...@@ -149,6 +149,6 @@ describe 'get board lists' do ...@@ -149,6 +149,6 @@ describe 'get board lists' do
end end
def grab_list_data(response_body) def grab_list_data(response_body)
JSON.parse(response_body)['data'][board_parent_type]['boards']['edges'][0]['node']['lists']['edges'] Gitlab::Json.parse(response_body)['data'][board_parent_type]['boards']['edges'][0]['node']['lists']['edges']
end end
end end
...@@ -188,7 +188,7 @@ describe 'Query.project(fullPath).issue(iid).designCollection.version(sha)' do ...@@ -188,7 +188,7 @@ describe 'Query.project(fullPath).issue(iid).designCollection.version(sha)' do
post_graphql(cursored_query, current_user: current_user) post_graphql(cursored_query, current_user: current_user)
new_data = JSON.parse(response.body).fetch('data') new_data = Gitlab::Json.parse(response.body).fetch('data')
expect(response_values(new_data)).to match_array(ids.drop(2)) expect(response_values(new_data)).to match_array(ids.drop(2))
end end
......
...@@ -105,7 +105,7 @@ describe 'Getting versions related to an issue' do ...@@ -105,7 +105,7 @@ describe 'Getting versions related to an issue' do
post_graphql(cursored_query, current_user: current_user) post_graphql(cursored_query, current_user: current_user)
new_data = JSON.parse(response.body).fetch('data') new_data = Gitlab::Json.parse(response.body).fetch('data')
expect(response_values(new_data)).to match_array(ids.drop(2)) expect(response_values(new_data)).to match_array(ids.drop(2))
end end
......
...@@ -114,7 +114,7 @@ describe 'Getting designs related to an issue' do ...@@ -114,7 +114,7 @@ describe 'Getting designs related to an issue' do
post_graphql(cursored_query, current_user: current_user) post_graphql(cursored_query, current_user: current_user)
new_data = JSON.parse(response.body).fetch('data') new_data = Gitlab::Json.parse(response.body).fetch('data')
expect(response_ids(new_data)).to match_array(ids.drop(2)) expect(response_ids(new_data)).to match_array(ids.drop(2))
end end
......
...@@ -107,7 +107,7 @@ describe 'getting a requirement list for a project' do ...@@ -107,7 +107,7 @@ describe 'getting a requirement list for a project' do
cursored_query = query("sort: #{sort_by}, after: \"#{end_cursor}\"") cursored_query = query("sort: #{sort_by}, after: \"#{end_cursor}\"")
post_graphql(cursored_query, current_user: current_user) post_graphql(cursored_query, current_user: current_user)
JSON.parse(response.body)['data']['project']['requirements']['edges'] Gitlab::Json.parse(response.body)['data']['project']['requirements']['edges']
end end
before do before do
......
...@@ -395,8 +395,7 @@ describe API::NpmPackages do ...@@ -395,8 +395,7 @@ describe API::NpmPackages do
end end
def upload_params(package_name:, package_version: '1.0.1', file: 'npm/payload.json') def upload_params(package_name:, package_version: '1.0.1', file: 'npm/payload.json')
JSON.parse( Gitlab::Json.parse(fixture_file(file, dir: 'ee')
fixture_file(file, dir: 'ee')
.gsub('@root/npm-test', package_name) .gsub('@root/npm-test', package_name)
.gsub('1.0.1', package_version)) .gsub('1.0.1', package_version))
end end
......
...@@ -31,7 +31,7 @@ describe Geo::ContainerRepositorySync, :geo do ...@@ -31,7 +31,7 @@ describe Geo::ContainerRepositorySync, :geo do
}) })
.to_return( .to_return(
status: 200, status: 200,
body: JSON.dump(tags: %w(obsolete)), body: Gitlab::Json.dump(tags: %w(obsolete)),
headers: { 'Content-Type' => 'application/json' }) headers: { 'Content-Type' => 'application/json' })
stub_request(:get, "http://primary.registry.gitlab/v2/group/test/my_image/tags/list") stub_request(:get, "http://primary.registry.gitlab/v2/group/test/my_image/tags/list")
...@@ -39,7 +39,7 @@ describe Geo::ContainerRepositorySync, :geo do ...@@ -39,7 +39,7 @@ describe Geo::ContainerRepositorySync, :geo do
headers: { 'Authorization' => 'bearer pull-token' }) headers: { 'Authorization' => 'bearer pull-token' })
.to_return( .to_return(
status: 200, status: 200,
body: JSON.dump(tags: %w(tag-to-sync)), body: Gitlab::Json.dump(tags: %w(tag-to-sync)),
headers: { 'Content-Type' => 'application/json' }) headers: { 'Content-Type' => 'application/json' })
stub_request(:head, "http://primary.registry.gitlab/v2/group/test/my_image/manifests/tag-to-sync") stub_request(:head, "http://primary.registry.gitlab/v2/group/test/my_image/manifests/tag-to-sync")
......
...@@ -10,7 +10,7 @@ describe Packages::CreateDependencyService do ...@@ -10,7 +10,7 @@ describe Packages::CreateDependencyService do
context 'when packages are published' do context 'when packages are published' do
let(:json_file) { 'npm/payload.json' } let(:json_file) { 'npm/payload.json' }
let(:params) do let(:params) do
JSON.parse(fixture_file(json_file, dir: 'ee') Gitlab::Json.parse(fixture_file(json_file, dir: 'ee')
.gsub('@root/npm-test', package_name) .gsub('@root/npm-test', package_name)
.gsub('1.0.1', version)) .gsub('1.0.1', version))
.with_indifferent_access .with_indifferent_access
......
...@@ -8,11 +8,9 @@ describe Packages::Npm::CreatePackageService do ...@@ -8,11 +8,9 @@ describe Packages::Npm::CreatePackageService do
let(:version) { '1.0.1' } let(:version) { '1.0.1' }
let(:params) do let(:params) do
JSON.parse( Gitlab::Json.parse(fixture_file('npm/payload.json', dir: 'ee')
fixture_file('npm/payload.json', dir: 'ee')
.gsub('@root/npm-test', package_name) .gsub('@root/npm-test', package_name)
.gsub('1.0.1', version) .gsub('1.0.1', version)).with_indifferent_access
).with_indifferent_access
.merge!(override) .merge!(override)
end end
let(:override) { {} } let(:override) { {} }
......
...@@ -29,7 +29,7 @@ describe Subscriptions::CreateService do ...@@ -29,7 +29,7 @@ describe Subscriptions::CreateService do
end end
let_it_be(:client) { Gitlab::SubscriptionPortal::Client } let_it_be(:client) { Gitlab::SubscriptionPortal::Client }
let_it_be(:create_service_params) { JSON.parse(fixture_file('create_service_params.json', dir: 'ee')).deep_symbolize_keys } let_it_be(:create_service_params) { Gitlab::Json.parse(fixture_file('create_service_params.json', dir: 'ee')).deep_symbolize_keys }
describe '#execute' do describe '#execute' do
context 'when failing to create a customer' do context 'when failing to create a customer' do
......
...@@ -105,7 +105,7 @@ RSpec.shared_examples 'cluster metrics' do ...@@ -105,7 +105,7 @@ RSpec.shared_examples 'cluster metrics' do
let(:prometheus_body) { '{"status":"success"}' } let(:prometheus_body) { '{"status":"success"}' }
it 'returns prometheus response' do it 'returns prometheus response' do
prometheus_json_body = JSON.parse(prometheus_body) prometheus_json_body = Gitlab::Json.parse(prometheus_body)
get :prometheus_proxy, params: prometheus_proxy_params get :prometheus_proxy, params: prometheus_proxy_params
......
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