Commit 4e5165e4 authored by Jonathan Schafer's avatar Jonathan Schafer

Changes from MR review

parent fc678af7
...@@ -8,8 +8,8 @@ module EE ...@@ -8,8 +8,8 @@ module EE
module UpdateVulnerabilitiesFromDismissalFeedback module UpdateVulnerabilitiesFromDismissalFeedback
extend ::Gitlab::Utils::Override extend ::Gitlab::Utils::Override
VULNERABILITY_DISMISSED = 2 VULNERABILITY_DISMISSED_STATE = 2
VULNERABILITY_FEEDBACK_DISMISSAL = 0 VULNERABILITY_FEEDBACK_DISMISSAL_TYPE = 0
class Project < ActiveRecord::Base class Project < ActiveRecord::Base
self.table_name = 'projects' self.table_name = 'projects'
...@@ -21,7 +21,7 @@ module EE ...@@ -21,7 +21,7 @@ module EE
project = Project.find_by(id: project_id) project = Project.find_by(id: project_id)
return unless project return unless project
return if project.archived? || project.pending_delete? return if project.pending_delete?
update_vulnerability_from_dismissal_feedback(project.id) update_vulnerability_from_dismissal_feedback(project.id)
end end
...@@ -34,12 +34,12 @@ module EE ...@@ -34,12 +34,12 @@ module EE
SET dismissed_by_id = vf.author_id, dismissed_at = vf.created_at SET dismissed_by_id = vf.author_id, dismissed_at = vf.created_at
FROM vulnerability_occurrences AS vo, vulnerability_feedback AS vf FROM vulnerability_occurrences AS vo, vulnerability_feedback AS vf
WHERE vo.vulnerability_id = v.id WHERE vo.vulnerability_id = v.id
AND v.state = #{VULNERABILITY_DISMISSED} AND v.state = #{VULNERABILITY_DISMISSED_STATE}
AND vo.project_id = vf.project_id AND vo.project_id = vf.project_id
AND ENCODE(vo.project_fingerprint, 'HEX') = vf.project_fingerprint AND ENCODE(vo.project_fingerprint, 'HEX') = vf.project_fingerprint
AND vo.project_id = #{project_id} AND vo.project_id = #{project_id}
AND vo.report_type = vf.category AND vo.report_type = vf.category
AND vf.feedback_type = #{VULNERABILITY_FEEDBACK_DISMISSAL}; AND vf.feedback_type = #{VULNERABILITY_FEEDBACK_DISMISSAL_TYPE};
SQL SQL
connection.execute(update_vulnerability_from_dismissal_feedback_sql) connection.execute(update_vulnerability_from_dismissal_feedback_sql)
rescue => e rescue => e
......
...@@ -72,22 +72,6 @@ describe Gitlab::BackgroundMigration::UpdateVulnerabilitiesFromDismissalFeedback ...@@ -72,22 +72,6 @@ describe Gitlab::BackgroundMigration::UpdateVulnerabilitiesFromDismissalFeedback
.to(dismiss_feedback.created_at) .to(dismiss_feedback.created_at)
end end
context 'project is archived' do
let!(:project) { projects.create!(namespace_id: namespace.id, name: 'gitlab', path: 'gitlab', archived: true) }
it 'vulnerability dismissed_by_id should remain nil' do
expect(vulnerability.dismissed_by_id).to eq(nil)
expect { described_class.new.perform(project.id) }.not_to change { vulnerability.reload.dismissed_by_id }.from(nil)
end
it 'vulnerability dismissed_at should remain nil' do
expect(vulnerability.dismissed_at).to eq(nil)
expect { described_class.new.perform(project.id) }.not_to change { vulnerability.reload.dismissed_at }.from(nil)
end
end
context 'project is set to be deleted' do context 'project is set to be deleted' do
let!(:project) { projects.create!(namespace_id: namespace.id, name: 'gitlab', path: 'gitlab', pending_delete: true) } let!(:project) { projects.create!(namespace_id: namespace.id, name: 'gitlab', path: 'gitlab', pending_delete: true) }
...@@ -124,7 +108,7 @@ describe Gitlab::BackgroundMigration::UpdateVulnerabilitiesFromDismissalFeedback ...@@ -124,7 +108,7 @@ describe Gitlab::BackgroundMigration::UpdateVulnerabilitiesFromDismissalFeedback
def vuln_params def vuln_params
{ {
title: 'title', title: 'title',
state: described_class::VULNERABILITY_DISMISSED, state: described_class::VULNERABILITY_DISMISSED_STATE,
severity: severity, severity: severity,
confidence: confidence, confidence: confidence,
report_type: report_type, report_type: report_type,
......
...@@ -15,7 +15,7 @@ describe MigrateVulnerabilityDismissalFeedback, :migration, :sidekiq do ...@@ -15,7 +15,7 @@ describe MigrateVulnerabilityDismissalFeedback, :migration, :sidekiq do
let(:vulnerabilities) { table(:vulnerabilities) } let(:vulnerabilities) { table(:vulnerabilities) }
let(:dismissed_state) { Gitlab::BackgroundMigration::UpdateVulnerabilitiesFromDismissalFeedback::VULNERABILITY_DISMISSED } let(:dismissed_state) { Gitlab::BackgroundMigration::UpdateVulnerabilitiesFromDismissalFeedback::VULNERABILITY_DISMISSED_STATE }
let(:severity) { Vulnerabilities::Occurrence::SEVERITY_LEVELS[:unknown] } let(:severity) { Vulnerabilities::Occurrence::SEVERITY_LEVELS[:unknown] }
let(:confidence) { Vulnerabilities::Occurrence::CONFIDENCE_LEVELS[:medium] } let(:confidence) { Vulnerabilities::Occurrence::CONFIDENCE_LEVELS[:medium] }
let(:report_type) { Vulnerabilities::Occurrence::REPORT_TYPES[:sast] } let(:report_type) { Vulnerabilities::Occurrence::REPORT_TYPES[:sast] }
......
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