Commit c836dd98 authored by Heinrich Lee Yu's avatar Heinrich Lee Yu

Merge branch '343284-remove-unneeded-vuln-evidence-models' into 'master'

Remove unneeded Vulnerability Finding Evidence models

See merge request gitlab-org/gitlab!74741
parents 6b9da990 596fd5ee
......@@ -11,27 +11,6 @@ module Vulnerabilities
foreign_key: 'vulnerability_occurrence_id',
optional: false
has_one :request,
class_name: 'Vulnerabilities::Finding::Evidence::Request',
inverse_of: :evidence,
foreign_key: 'vulnerability_finding_evidence_id'
has_one :response,
class_name: 'Vulnerabilities::Finding::Evidence::Response',
inverse_of: :evidence,
foreign_key: 'vulnerability_finding_evidence_id'
has_one :source,
class_name: 'Vulnerabilities::Finding::Evidence::Source',
inverse_of: :evidence,
foreign_key: 'vulnerability_finding_evidence_id'
has_many :supporting_messages,
class_name: 'Vulnerabilities::Finding::Evidence::SupportingMessage',
inverse_of: :evidence,
foreign_key: 'vulnerability_finding_evidence_id'
has_many :assets,
class_name: 'Vulnerabilities::Finding::Evidence::Asset',
inverse_of: :evidence,
foreign_key: 'vulnerability_finding_evidence_id'
validates :summary, length: { maximum: 8_000_000 }
validates :data, length: { maximum: 16_000_000 }, presence: true
end
......
# frozen_string_literal: true
module Vulnerabilities
class Finding
class Evidence
class Asset < ApplicationRecord
self.table_name = 'vulnerability_finding_evidence_assets'
DATA_FIELDS = %w[type name url].freeze
belongs_to :evidence,
class_name: 'Vulnerabilities::Finding::Evidence',
inverse_of: :assets,
foreign_key: 'vulnerability_finding_evidence_id',
optional: false
validates :type, length: { maximum: 2048 }
validates :name, length: { maximum: 2048 }
validates :url, length: { maximum: 2048 }
validates_with AnyFieldValidator, fields: DATA_FIELDS
end
end
end
end
# frozen_string_literal: true
module Vulnerabilities
class Finding
class Evidence
class Header < ApplicationRecord
self.table_name = 'vulnerability_finding_evidence_headers'
belongs_to :request, class_name: 'Vulnerabilities::Finding::Evidence::Request', inverse_of: :headers, foreign_key: 'vulnerability_finding_evidence_request_id'
belongs_to :response, class_name: 'Vulnerabilities::Finding::Evidence::Response', inverse_of: :headers, foreign_key: 'vulnerability_finding_evidence_response_id'
validates :name, length: { maximum: 255 }, presence: true
validates :value, length: { maximum: 8192 }, presence: true
validate :request_or_response_is_set
validate :request_and_response_cannot_be_set
private
def request_or_response_is_set
errors.add(:header, _('Header must be associated with a request or response')) unless request.present? || response.present?
end
def request_and_response_cannot_be_set
errors.add(:header, _('Header cannot be associated with both a request and a response')) if request.present? && response.present?
end
end
end
end
end
# frozen_string_literal: true
module Vulnerabilities
class Finding
class Evidence
class Request < ApplicationRecord
include WithBody
self.table_name = 'vulnerability_finding_evidence_requests'
DATA_FIELDS = %w[method url].freeze
belongs_to :evidence,
class_name: 'Vulnerabilities::Finding::Evidence',
inverse_of: :request,
foreign_key: 'vulnerability_finding_evidence_id',
optional: true
belongs_to :supporting_message,
class_name: 'Vulnerabilities::Finding::Evidence::SupportingMessage',
inverse_of: :request,
foreign_key: 'vulnerability_finding_evidence_supporting_message_id',
optional: true
has_many :headers,
class_name: 'Vulnerabilities::Finding::Evidence::Header',
inverse_of: :request,
foreign_key: 'vulnerability_finding_evidence_request_id'
validates :method, length: { maximum: 32 }
validates :url, length: { maximum: 2048 }
validates_with AnyFieldValidator, fields: DATA_FIELDS
end
end
end
end
# frozen_string_literal: true
module Vulnerabilities
class Finding
class Evidence
class Response < ApplicationRecord
include WithBody
self.table_name = 'vulnerability_finding_evidence_responses'
belongs_to :evidence,
class_name: 'Vulnerabilities::Finding::Evidence',
inverse_of: :response,
foreign_key: 'vulnerability_finding_evidence_id',
optional: true
belongs_to :supporting_message,
class_name: 'Vulnerabilities::Finding::Evidence::SupportingMessage',
inverse_of: :response,
foreign_key: 'vulnerability_finding_evidence_supporting_message_id',
optional: true
has_many :headers,
class_name: 'Vulnerabilities::Finding::Evidence::Header',
inverse_of: :response,
foreign_key: 'vulnerability_finding_evidence_response_id'
validates :reason_phrase, length: { maximum: 2048 }, presence: true
end
end
end
end
# frozen_string_literal: true
module Vulnerabilities
class Finding
class Evidence
class Source < ApplicationRecord
self.table_name = 'vulnerability_finding_evidence_sources'
DATA_FIELDS = %w[name url].freeze
belongs_to :evidence, class_name: 'Vulnerabilities::Finding::Evidence', inverse_of: :source, foreign_key: 'vulnerability_finding_evidence_id', optional: false
validates :name, length: { maximum: 2048 }
validates :url, length: { maximum: 2048 }
validates_with AnyFieldValidator, fields: DATA_FIELDS
end
end
end
end
# frozen_string_literal: true
module Vulnerabilities
class Finding
class Evidence
class SupportingMessage < ApplicationRecord
self.table_name = 'vulnerability_finding_evidence_supporting_messages'
belongs_to :evidence,
class_name: 'Vulnerabilities::Finding::Evidence',
inverse_of: :supporting_messages,
foreign_key: 'vulnerability_finding_evidence_id',
optional: false
has_one :request,
class_name: 'Vulnerabilities::Finding::Evidence::Request',
inverse_of: :supporting_message,
foreign_key: 'vulnerability_finding_evidence_supporting_message_id'
has_one :response,
class_name: 'Vulnerabilities::Finding::Evidence::Response',
inverse_of: :supporting_message,
foreign_key: 'vulnerability_finding_evidence_supporting_message_id'
validates :name, length: { maximum: 2048 }, presence: true
end
end
end
end
# frozen_string_literal: true
module Vulnerabilities
class Finding
class Evidence
module WithBody
extend ActiveSupport::Concern
MAX_BODY_LENGTH = 2048
included do
before_validation :truncate_body
validates :body, length: { maximum: MAX_BODY_LENGTH }
end
private
def truncate_body
return unless self.body
self.body = self.body.truncate(MAX_BODY_LENGTH, omission: "---- TRUNCATED(Total Length: #{self.body.length} characters) ----")
end
end
end
end
end
# frozen_string_literal: true
FactoryBot.define do
factory :vulnerabilties_finding_evidence_header, class: 'Vulnerabilities::Finding::Evidence::Header' do
name { 'HEADER-NAME' }
value { 'header-value' }
end
end
# frozen_string_literal: true
FactoryBot.define do
factory :vulnerabilties_finding_evidence_request, class: 'Vulnerabilities::Finding::Evidence::Request' do
url { 'https://www.example.com' }
body { 'Request body' }
end
end
# frozen_string_literal: true
FactoryBot.define do
factory :vulnerabilties_finding_evidence_response, class: 'Vulnerabilities::Finding::Evidence::Response' do
reason_phrase { 'Response reason' }
body { 'Response body' }
end
end
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Vulnerabilities::Finding::Evidence::Asset do
it { is_expected.to belong_to(:evidence).class_name('Vulnerabilities::Finding::Evidence').inverse_of(:assets).required }
it { is_expected.to validate_length_of(:type).is_at_most(2048) }
it { is_expected.to validate_length_of(:name).is_at_most(2048) }
it { is_expected.to validate_length_of(:url).is_at_most(2048) }
it_behaves_like 'validates presence of any field'
end
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Vulnerabilities::Finding::Evidence::Header do
it { is_expected.to belong_to(:request).class_name('Vulnerabilities::Finding::Evidence::Request').inverse_of(:headers).optional }
it { is_expected.to belong_to(:response).class_name('Vulnerabilities::Finding::Evidence::Response').inverse_of(:headers).optional }
it { is_expected.to validate_length_of(:name).is_at_most(255) }
it { is_expected.to validate_presence_of(:name) }
it { is_expected.to validate_length_of(:value).is_at_most(8192) }
it { is_expected.to validate_presence_of(:value) }
end
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Vulnerabilities::Finding::Evidence::Request do
it { is_expected.to belong_to(:evidence).class_name('Vulnerabilities::Finding::Evidence').inverse_of(:request) }
it { is_expected.to belong_to(:supporting_message).class_name('Vulnerabilities::Finding::Evidence::SupportingMessage').inverse_of(:request) }
it { is_expected.to have_many(:headers).class_name('Vulnerabilities::Finding::Evidence::Header').with_foreign_key('vulnerability_finding_evidence_request_id').inverse_of(:request) }
it { is_expected.to validate_length_of(:method).is_at_most(32) }
it { is_expected.to validate_length_of(:url).is_at_most(2048) }
it_behaves_like 'body shared examples', :vulnerabilties_finding_evidence_request
it_behaves_like 'validates presence of any field'
end
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Vulnerabilities::Finding::Evidence::Response do
it { is_expected.to belong_to(:evidence).class_name('Vulnerabilities::Finding::Evidence').inverse_of(:response) }
it { is_expected.to belong_to(:supporting_message).class_name('Vulnerabilities::Finding::Evidence::SupportingMessage').inverse_of(:response) }
it { is_expected.to have_many(:headers).class_name('Vulnerabilities::Finding::Evidence::Header').with_foreign_key('vulnerability_finding_evidence_response_id').inverse_of(:response) }
it { is_expected.to validate_length_of(:reason_phrase).is_at_most(2048) }
it { is_expected.to validate_presence_of(:reason_phrase) }
it_behaves_like 'body shared examples', :vulnerabilties_finding_evidence_response
end
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Vulnerabilities::Finding::Evidence::Source do
it { is_expected.to belong_to(:evidence).class_name('Vulnerabilities::Finding::Evidence').inverse_of(:source).required }
it { is_expected.to validate_length_of(:name).is_at_most(2048) }
it { is_expected.to validate_length_of(:url).is_at_most(2048) }
it_behaves_like 'validates presence of any field'
end
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Vulnerabilities::Finding::Evidence::SupportingMessage do
it {
is_expected
.to belong_to(:evidence)
.class_name('Vulnerabilities::Finding::Evidence')
.inverse_of(:supporting_messages)
.required
}
it {
is_expected
.to have_one(:request)
.class_name('Vulnerabilities::Finding::Evidence::Request')
.with_foreign_key('vulnerability_finding_evidence_supporting_message_id')
.inverse_of(:supporting_message)
}
it {
is_expected
.to have_one(:response)
.class_name('Vulnerabilities::Finding::Evidence::Response')
.with_foreign_key('vulnerability_finding_evidence_supporting_message_id')
.inverse_of(:supporting_message)
}
it { is_expected.to validate_length_of(:name).is_at_most(2048) }
it { is_expected.to validate_presence_of(:name) }
end
......@@ -3,48 +3,6 @@
require 'spec_helper'
RSpec.describe Vulnerabilities::Finding::Evidence do
it {
is_expected
.to belong_to(:finding)
.class_name('Vulnerabilities::Finding')
.required
}
it {
is_expected
.to have_one(:request)
.class_name('Vulnerabilities::Finding::Evidence::Request')
.with_foreign_key('vulnerability_finding_evidence_id')
.inverse_of(:evidence)
}
it {
is_expected
.to have_one(:response)
.class_name('Vulnerabilities::Finding::Evidence::Response')
.with_foreign_key('vulnerability_finding_evidence_id')
.inverse_of(:evidence)
}
it {
is_expected
.to have_one(:source)
.class_name('Vulnerabilities::Finding::Evidence::Source')
.with_foreign_key('vulnerability_finding_evidence_id')
.inverse_of(:evidence)
}
it {
is_expected
.to have_many(:supporting_messages)
.class_name('Vulnerabilities::Finding::Evidence::SupportingMessage')
.with_foreign_key('vulnerability_finding_evidence_id')
.inverse_of(:evidence)
}
it {
is_expected
.to have_many(:assets)
.class_name('Vulnerabilities::Finding::Evidence::Asset')
.with_foreign_key('vulnerability_finding_evidence_id')
.inverse_of(:evidence)
}
it { is_expected.to validate_length_of(:summary).is_at_most(8_000_000) }
it { is_expected.to validate_presence_of(:data) }
it { is_expected.to validate_length_of(:data).is_at_most(16_000_000) }
......
......@@ -16999,9 +16999,6 @@ msgstr ""
msgid "Have more to say about GitLab?"
msgstr ""
msgid "Header cannot be associated with both a request and a response"
msgstr ""
msgid "Header logo"
msgstr ""
......@@ -17014,9 +17011,6 @@ msgstr ""
msgid "Header message"
msgstr ""
msgid "Header must be associated with a request or response"
msgstr ""
msgid "Headers"
msgstr ""
......
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