Commit 6a03dc87 authored by Rémy Coutable's avatar Rémy Coutable

Merge branch...

Merge branch '212983-the-resolved_on_default_branch-data-point-is-not-available-on-the-standalone-vulnerability' into 'master'

Create VulnerabilitySerializer

See merge request gitlab-org/gitlab!28543
parents 9a3de96f 94c29a86
......@@ -5,7 +5,7 @@ module VulnerabilitiesHelper
return unless vulnerability
{
vulnerability_json: vulnerability.to_json,
vulnerability_json: VulnerabilitySerializer.new.represent(vulnerability).to_json,
project_fingerprint: vulnerability.finding.project_fingerprint,
create_issue_url: create_vulnerability_feedback_issue_path(vulnerability.finding.project),
pipeline_json: vulnerability_pipeline_data(pipeline).to_json,
......
# frozen_string_literal: true
class VulnerabilityEntity < Grape::Entity
include RequestAwareEntity
expose :id,
:title,
:state,
:severity,
:confidence,
:report_type,
:resolved_on_default_branch,
:project_default_branch,
:resolved_by_id,
:dismissed_by_id,
:confirmed_by_id
end
# frozen_string_literal: true
class VulnerabilitySerializer < BaseSerializer
entity VulnerabilityEntity
end
......@@ -3,17 +3,34 @@
require 'spec_helper'
describe VulnerabilitiesHelper do
RSpec.shared_examples 'vulnerability properties' do
it 'has expected vulnerability properties' do
expect(subject).to include(
vulnerability_json: vulnerability.to_json,
project_fingerprint: vulnerability.finding.project_fingerprint,
create_issue_url: anything,
has_mr: anything,
vulnerability_feedback_help_path: anything,
finding_json: anything
let_it_be(:user) { build(:user) }
let_it_be(:vulnerability) { create(:vulnerability, :with_findings, title: "My vulnerability") }
let_it_be(:finding) { vulnerability.finding }
let(:vulnerability_serializer_hash) do
vulnerability.slice(
:id,
:title,
:state,
:severity,
:confidence,
:report_type,
:resolved_on_default_branch,
:project_default_branch,
:resolved_by_id,
:dismissed_by_id,
:confirmed_by_id
)
end
let(:occurrence_serializer_hash) do
finding.slice(:description,
:identifiers,
:links,
:location,
:name,
:issue_feedback,
:project,
:solution
)
end
before do
......@@ -21,11 +38,30 @@ describe VulnerabilitiesHelper do
allow(helper).to receive(:current_user).and_return(user)
end
let(:user) { build(:user) }
RSpec.shared_examples 'vulnerability properties' do
before do
vulnerability_serializer_stub = instance_double("VulnerabilitySerializer")
expect(VulnerabilitySerializer).to receive(:new).and_return(vulnerability_serializer_stub)
expect(vulnerability_serializer_stub).to receive(:represent).with(vulnerability).and_return(vulnerability_serializer_hash)
describe '#vulnerability_data' do
let(:vulnerability) { create(:vulnerability, :with_findings) }
occurrence_serializer_stub = instance_double("Vulnerabilities::OccurrenceSerializer")
expect(Vulnerabilities::OccurrenceSerializer).to receive(:new).and_return(occurrence_serializer_stub)
expect(occurrence_serializer_stub).to receive(:represent).with(finding).and_return(occurrence_serializer_hash)
end
it 'has expected vulnerability properties' do
expect(subject).to include(
vulnerability_json: kind_of(String),
project_fingerprint: vulnerability.finding.project_fingerprint,
create_issue_url: kind_of(String),
has_mr: anything,
vulnerability_feedback_help_path: kind_of(String),
finding_json: kind_of(String)
)
end
end
describe '#vulnerability_data' do
subject { helper.vulnerability_data(vulnerability, pipeline) }
describe 'when pipeline exists' do
......@@ -55,9 +91,6 @@ describe VulnerabilitiesHelper do
end
describe '#vulnerability_finding_data' do
let(:vulnerability) { create(:vulnerability, :with_findings) }
let(:finding) { vulnerability.finding }
subject { helper.vulnerability_finding_data(finding) }
it "returns finding information" do
......
# frozen_string_literal: true
require 'spec_helper'
describe VulnerabilityEntity do
let(:vulnerability) { create(:vulnerability, project: project, author: user) }
let(:project) { create(:project) }
let(:user) { create(:user) }
subject { described_class.new(vulnerability).as_json }
it 'exposes vulnerability-specific elements' do
expect(subject).to match(
id: vulnerability.id,
title: vulnerability.title,
state: vulnerability.state,
severity: vulnerability.severity,
confidence: vulnerability.confidence,
report_type: vulnerability.report_type,
resolved_on_default_branch: vulnerability.resolved_on_default_branch,
project_default_branch: vulnerability.project_default_branch,
resolved_by_id: vulnerability.resolved_by_id,
dismissed_by_id: vulnerability.dismissed_by_id,
confirmed_by_id: vulnerability.confirmed_by_id
)
end
end
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