Commit f10d4e52 authored by Mark Chao's avatar Mark Chao

Merge branch '267489-finding-evidence-details-supmsg-resp-req' into 'master'

Add request and response to SupportingMessage

See merge request gitlab-org/gitlab!66398
parents bb978a91 91bbfbc3
# frozen_string_literal: true
class AddRequestResponseToSupporingMessage < ActiveRecord::Migration[6.1]
def change
change_column_null(:vulnerability_finding_evidence_requests, :vulnerability_finding_evidence_id, true)
change_column_null(:vulnerability_finding_evidence_responses, :vulnerability_finding_evidence_id, true)
# rubocop: disable Migration/AddReference
# Table is empty, so no need to use add_concurrent_foreign_key and add_concurrent_index
add_reference(:vulnerability_finding_evidence_requests,
:vulnerability_finding_evidence_supporting_message,
index: { name: 'finding_evidence_requests_on_supporting_evidence_id' },
foreign_key: { on_delete: :cascade })
add_reference(:vulnerability_finding_evidence_responses,
:vulnerability_finding_evidence_supporting_message,
index: { name: 'finding_evidence_responses_on_supporting_evidence_id' },
foreign_key: { on_delete: :cascade })
# rubocop:enable Migration/AddReference
end
end
9320dcd2a5bed122310aefd630f9c406a25b22767dba3bf118a30df044c2d6a7
\ No newline at end of file
......@@ -19239,10 +19239,11 @@ CREATE TABLE vulnerability_finding_evidence_requests (
id bigint NOT NULL,
created_at timestamp with time zone NOT NULL,
updated_at timestamp with time zone NOT NULL,
vulnerability_finding_evidence_id bigint NOT NULL,
vulnerability_finding_evidence_id bigint,
method text,
url text,
body text,
vulnerability_finding_evidence_supporting_message_id bigint,
CONSTRAINT check_7e37f2d01a CHECK ((char_length(body) <= 2048)),
CONSTRAINT check_8152fbb236 CHECK ((char_length(url) <= 2048)),
CONSTRAINT check_d9d11300f4 CHECK ((char_length(method) <= 32))
......@@ -19261,10 +19262,11 @@ CREATE TABLE vulnerability_finding_evidence_responses (
id bigint NOT NULL,
created_at timestamp with time zone NOT NULL,
updated_at timestamp with time zone NOT NULL,
vulnerability_finding_evidence_id bigint NOT NULL,
vulnerability_finding_evidence_id bigint,
status_code integer,
reason_phrase text,
body text,
vulnerability_finding_evidence_supporting_message_id bigint,
CONSTRAINT check_58b124ab48 CHECK ((char_length(reason_phrase) <= 2048)),
CONSTRAINT check_76bac0c32b CHECK ((char_length(body) <= 2048))
);
......@@ -22669,8 +22671,12 @@ CREATE INDEX finding_evidence_header_on_finding_evidence_response_id ON vulnerab
CREATE INDEX finding_evidence_requests_on_finding_evidence_id ON vulnerability_finding_evidence_requests USING btree (vulnerability_finding_evidence_id);
CREATE INDEX finding_evidence_requests_on_supporting_evidence_id ON vulnerability_finding_evidence_requests USING btree (vulnerability_finding_evidence_supporting_message_id);
CREATE INDEX finding_evidence_responses_on_finding_evidences_id ON vulnerability_finding_evidence_responses USING btree (vulnerability_finding_evidence_id);
CREATE INDEX finding_evidence_responses_on_supporting_evidence_id ON vulnerability_finding_evidence_responses USING btree (vulnerability_finding_evidence_supporting_message_id);
CREATE INDEX finding_evidence_sources_on_finding_evidence_id ON vulnerability_finding_evidence_sources USING btree (vulnerability_finding_evidence_id);
CREATE INDEX finding_evidence_supporting_messages_on_finding_evidence_id ON vulnerability_finding_evidence_supporting_messages USING btree (vulnerability_finding_evidence_id);
......@@ -27552,6 +27558,9 @@ ALTER TABLE ONLY project_error_tracking_settings
ALTER TABLE ONLY list_user_preferences
ADD CONSTRAINT fk_rails_916d72cafd FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE;
ALTER TABLE ONLY vulnerability_finding_evidence_responses
ADD CONSTRAINT fk_rails_929041a499 FOREIGN KEY (vulnerability_finding_evidence_supporting_message_id) REFERENCES vulnerability_finding_evidence_supporting_messages(id) ON DELETE CASCADE;
ALTER TABLE ONLY merge_request_cleanup_schedules
ADD CONSTRAINT fk_rails_92dd0e705c FOREIGN KEY (merge_request_id) REFERENCES merge_requests(id) ON DELETE CASCADE;
......@@ -27912,6 +27921,9 @@ ALTER TABLE ONLY resource_milestone_events
ALTER TABLE ONLY resource_iteration_events
ADD CONSTRAINT fk_rails_cee126f66c FOREIGN KEY (iteration_id) REFERENCES sprints(id) ON DELETE CASCADE;
ALTER TABLE ONLY vulnerability_finding_evidence_requests
ADD CONSTRAINT fk_rails_cf0f278cb0 FOREIGN KEY (vulnerability_finding_evidence_supporting_message_id) REFERENCES vulnerability_finding_evidence_supporting_messages(id) ON DELETE CASCADE;
ALTER TABLE ONLY epic_metrics
ADD CONSTRAINT fk_rails_d071904753 FOREIGN KEY (epic_id) REFERENCES epics(id) ON DELETE CASCADE;
......@@ -8,8 +8,21 @@ module Vulnerabilities
self.table_name = 'vulnerability_finding_evidence_requests'
belongs_to :evidence, class_name: 'Vulnerabilities::Finding::Evidence', inverse_of: :request, foreign_key: 'vulnerability_finding_evidence_id', optional: false
has_many :headers, class_name: 'Vulnerabilities::Finding::Evidence::Header', inverse_of: :request, foreign_key: 'vulnerability_finding_evidence_request_id'
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 }
......
......@@ -8,8 +8,21 @@ module Vulnerabilities
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: false
has_many :headers, class_name: 'Vulnerabilities::Finding::Evidence::Header', inverse_of: :response, foreign_key: 'vulnerability_finding_evidence_response_id'
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 }
end
......
......@@ -8,6 +8,9 @@ module Vulnerabilities
belongs_to :evidence, class_name: 'Vulnerabilities::Finding::Evidence', inverse_of: :supporting_message, 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 }
end
end
......
......@@ -3,7 +3,8 @@
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).required }
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) }
......
......@@ -3,7 +3,8 @@
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).required }
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) }
......
......@@ -4,6 +4,8 @@ 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_message).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) }
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