Commit 7c5a5558 authored by Michał Zając's avatar Michał Zając

Check that all properties are returned correctly

parent c0f4f041
...@@ -43,12 +43,20 @@ FactoryBot.define do ...@@ -43,12 +43,20 @@ FactoryBot.define do
trait :with_findings do trait :with_findings do
after(:build) do |vulnerability| after(:build) do |vulnerability|
vulnerability.findings = build_list( occurrences_with_solution = build_list(
:vulnerabilities_occurrence, :vulnerabilities_occurrence,
2, 2,
vulnerability: vulnerability, vulnerability: vulnerability,
report_type: vulnerability.report_type, report_type: vulnerability.report_type,
project: vulnerability.project) project: vulnerability.project)
occurrences_with_remediation = build_list(
:vulnerabilities_occurrence,
2,
:with_remediation,
vulnerability: vulnerability,
report_type: vulnerability.report_type,
project: vulnerability.project)
vulnerability.findings = occurrences_with_solution + occurrences_with_remediation
end end
end end
......
...@@ -69,6 +69,19 @@ FactoryBot.define do ...@@ -69,6 +69,19 @@ FactoryBot.define do
end end
end end
trait :with_remediation do
after(:build) do |finding|
raw_metadata = JSON.parse(finding.raw_metadata)
raw_metadata.delete(:solution)
raw_metadata[:remediations] = [
{
summary: "Use GCM mode which includes HMAC in the resulting encrypted data, providing integrity of the result."
}
]
finding.raw_metadata = raw_metadata.to_json
end
end
::Vulnerabilities::Occurrence::REPORT_TYPES.keys.each do |security_report_type| ::Vulnerabilities::Occurrence::REPORT_TYPES.keys.each do |security_report_type|
trait security_report_type do trait security_report_type do
report_type { security_report_type } report_type { security_report_type }
......
...@@ -57,21 +57,30 @@ describe VulnerabilitiesHelper do ...@@ -57,21 +57,30 @@ describe VulnerabilitiesHelper do
subject { helper.vulnerability_finding_data(finding) } subject { helper.vulnerability_finding_data(finding) }
it 'returns finding information' do it "returns finding information" do
puts finding.to_json
expect(subject[:name]).not_to be_nil
expect(subject[:description]).not_to be_nil
expect(subject).to include( expect(subject).to include(
:solution => finding.solution, description: finding.description,
:remediation => nil, identifiers: finding.identifiers,
:issue_feedback => finding.issue_feedback, links: finding.links,
:project => finding.project, location: finding.location,
:description => finding.description, name: finding.name
:identifiers => finding.identifiers,
:links => finding.links,
:location => finding.location,
:name => finding.name
) )
end end
context "when finding has a remediations key" do
let(:finding) { vulnerability.findings.select { |finding| finding.raw_metadata.include?("remediations") }.first }
it "uses the first remediation summary" do
expect(subject[:solution]).to start_with "Use GCM mode"
end
end
context "when finding has a solution key" do
let(:finding) { vulnerability.findings.select { |finding| finding.raw_metadata.include?("solution") }.first }
it "uses the solution key" do
expect(subject[:solution]).to start_with "GCM mode"
end
end
end end
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