Commit 3d8eb2da authored by Mehmet Emin INAC's avatar Mehmet Emin INAC

Introduce Reports::Security::Remediation entity

This entity will provide us the interface to store remediation records
in database.
parent e56279d0
# frozen_string_literal: true
module Gitlab
module Ci
module Reports
module Security
class Remediation
attr_reader :summary, :diff
def initialize(summary, diff)
@summary = summary
@diff = diff
end
def diff_file
@diff_file ||= DiffFile.new(diff)
end
delegate :checksum, to: :diff_file
class DiffFile < StringIO
# This method is used by the `carrierwave` gem
def original_filename
"#{checksum}.diff"
end
def checksum
@checksum ||= Digest::SHA256.hexdigest(string)
end
end
end
end
end
end
end
# frozen_string_literal: true
FactoryBot.define do
factory :ci_reports_security_remediation, class: '::Gitlab::Ci::Reports::Security::Remediation' do
summary { 'Remediation summary' }
diff { 'foo' }
skip_create
initialize_with do
::Gitlab::Ci::Reports::Security::Remediation.new(summary, diff)
end
end
end
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Gitlab::Ci::Reports::Security::Remediation do
let(:remediation) { build(:ci_reports_security_remediation) }
describe '#diff_file' do
subject { remediation.diff_file.read }
it { is_expected.to eq('foo') }
end
describe '#checksum' do
subject { remediation.checksum }
it { is_expected.to eq('2c26b46b68ffc68ff99b453c1d30413413422d706483bfa0f98a5e886266e7ae') }
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