Commit 065416b8 authored by Jonathan Schafer's avatar Jonathan Schafer Committed by Adam Hegyi

Add Finding Evidence Supporting Messages

DB migrations and updated tests

Changelog: changed
parent d03ac05c
# frozen_string_literal: true
class CreateVulnerabilityFindingEvidenceSupportingMessages < ActiveRecord::Migration[6.1]
include Gitlab::Database::MigrationHelpers
DOWNTIME = false
disable_ddl_transaction!
def up
create_table_with_constraints :vulnerability_finding_evidence_supporting_messages do |t|
t.timestamps_with_timezone null: false
t.references :vulnerability_finding_evidence, index: { name: 'finding_evidence_supporting_messages_on_finding_evidence_id' }, null: false, foreign_key: { on_delete: :cascade }
t.text :name
t.text_limit :name, 2048
end
end
def down
with_lock_retries do
drop_table :vulnerability_finding_evidence_supporting_messages
end
end
end
0c25d19d03bce4f145eca271c852aad6a8327821a8f5ff0aa2f0286f4a65b328
\ No newline at end of file
...@@ -19187,6 +19187,24 @@ CREATE SEQUENCE vulnerability_finding_evidence_responses_id_seq ...@@ -19187,6 +19187,24 @@ CREATE SEQUENCE vulnerability_finding_evidence_responses_id_seq
ALTER SEQUENCE vulnerability_finding_evidence_responses_id_seq OWNED BY vulnerability_finding_evidence_responses.id; ALTER SEQUENCE vulnerability_finding_evidence_responses_id_seq OWNED BY vulnerability_finding_evidence_responses.id;
CREATE TABLE vulnerability_finding_evidence_supporting_messages (
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,
name text,
CONSTRAINT check_fa33b9ae85 CHECK ((char_length(name) <= 2048))
);
CREATE SEQUENCE vulnerability_finding_evidence_supporting_messages_id_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
ALTER SEQUENCE vulnerability_finding_evidence_supporting_messages_id_seq OWNED BY vulnerability_finding_evidence_supporting_messages.id;
CREATE TABLE vulnerability_finding_evidences ( CREATE TABLE vulnerability_finding_evidences (
id bigint NOT NULL, id bigint NOT NULL,
created_at timestamp with time zone NOT NULL, created_at timestamp with time zone NOT NULL,
...@@ -20527,6 +20545,8 @@ ALTER TABLE ONLY vulnerability_finding_evidence_requests ALTER COLUMN id SET DEF ...@@ -20527,6 +20545,8 @@ ALTER TABLE ONLY vulnerability_finding_evidence_requests ALTER COLUMN id SET DEF
ALTER TABLE ONLY vulnerability_finding_evidence_responses ALTER COLUMN id SET DEFAULT nextval('vulnerability_finding_evidence_responses_id_seq'::regclass); ALTER TABLE ONLY vulnerability_finding_evidence_responses ALTER COLUMN id SET DEFAULT nextval('vulnerability_finding_evidence_responses_id_seq'::regclass);
ALTER TABLE ONLY vulnerability_finding_evidence_supporting_messages ALTER COLUMN id SET DEFAULT nextval('vulnerability_finding_evidence_supporting_messages_id_seq'::regclass);
ALTER TABLE ONLY vulnerability_finding_evidences ALTER COLUMN id SET DEFAULT nextval('vulnerability_finding_evidences_id_seq'::regclass); ALTER TABLE ONLY vulnerability_finding_evidences ALTER COLUMN id SET DEFAULT nextval('vulnerability_finding_evidences_id_seq'::regclass);
ALTER TABLE ONLY vulnerability_finding_links ALTER COLUMN id SET DEFAULT nextval('vulnerability_finding_links_id_seq'::regclass); ALTER TABLE ONLY vulnerability_finding_links ALTER COLUMN id SET DEFAULT nextval('vulnerability_finding_links_id_seq'::regclass);
...@@ -22244,6 +22264,9 @@ ALTER TABLE ONLY vulnerability_finding_evidence_requests ...@@ -22244,6 +22264,9 @@ ALTER TABLE ONLY vulnerability_finding_evidence_requests
ALTER TABLE ONLY vulnerability_finding_evidence_responses ALTER TABLE ONLY vulnerability_finding_evidence_responses
ADD CONSTRAINT vulnerability_finding_evidence_responses_pkey PRIMARY KEY (id); ADD CONSTRAINT vulnerability_finding_evidence_responses_pkey PRIMARY KEY (id);
ALTER TABLE ONLY vulnerability_finding_evidence_supporting_messages
ADD CONSTRAINT vulnerability_finding_evidence_supporting_messages_pkey PRIMARY KEY (id);
ALTER TABLE ONLY vulnerability_finding_evidences ALTER TABLE ONLY vulnerability_finding_evidences
ADD CONSTRAINT vulnerability_finding_evidences_pkey PRIMARY KEY (id); ADD CONSTRAINT vulnerability_finding_evidences_pkey PRIMARY KEY (id);
...@@ -22489,6 +22512,8 @@ CREATE INDEX finding_evidence_requests_on_finding_evidence_id ON vulnerability_f ...@@ -22489,6 +22512,8 @@ CREATE INDEX finding_evidence_requests_on_finding_evidence_id ON vulnerability_f
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_finding_evidences_id ON vulnerability_finding_evidence_responses 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);
CREATE INDEX finding_evidences_on_vulnerability_occurrence_id ON vulnerability_finding_evidences USING btree (vulnerability_occurrence_id); CREATE INDEX finding_evidences_on_vulnerability_occurrence_id ON vulnerability_finding_evidences USING btree (vulnerability_occurrence_id);
CREATE INDEX finding_links_on_vulnerability_occurrence_id ON vulnerability_finding_links USING btree (vulnerability_occurrence_id); CREATE INDEX finding_links_on_vulnerability_occurrence_id ON vulnerability_finding_links USING btree (vulnerability_occurrence_id);
...@@ -27208,6 +27233,9 @@ ALTER TABLE ONLY terraform_states ...@@ -27208,6 +27233,9 @@ ALTER TABLE ONLY terraform_states
ALTER TABLE ONLY analytics_cycle_analytics_project_stages ALTER TABLE ONLY analytics_cycle_analytics_project_stages
ADD CONSTRAINT fk_rails_796a7dbc9c FOREIGN KEY (project_value_stream_id) REFERENCES analytics_cycle_analytics_project_value_streams(id) ON DELETE CASCADE; ADD CONSTRAINT fk_rails_796a7dbc9c FOREIGN KEY (project_value_stream_id) REFERENCES analytics_cycle_analytics_project_value_streams(id) ON DELETE CASCADE;
ALTER TABLE ONLY vulnerability_finding_evidence_supporting_messages
ADD CONSTRAINT fk_rails_79e77f6c5c FOREIGN KEY (vulnerability_finding_evidence_id) REFERENCES vulnerability_finding_evidences(id) ON DELETE CASCADE;
ALTER TABLE ONLY software_license_policies ALTER TABLE ONLY software_license_policies
ADD CONSTRAINT fk_rails_7a7a2a92de FOREIGN KEY (software_license_id) REFERENCES software_licenses(id) ON DELETE CASCADE; ADD CONSTRAINT fk_rails_7a7a2a92de FOREIGN KEY (software_license_id) REFERENCES software_licenses(id) ON DELETE CASCADE;
...@@ -9,6 +9,7 @@ module Vulnerabilities ...@@ -9,6 +9,7 @@ module Vulnerabilities
has_one :request, class_name: 'Vulnerabilities::Finding::Evidence::Request', inverse_of: :evidence, foreign_key: 'vulnerability_finding_evidence_id' 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 :response, class_name: 'Vulnerabilities::Finding::Evidence::Response', inverse_of: :evidence, foreign_key: 'vulnerability_finding_evidence_id'
has_one :supporting_message, class_name: 'Vulnerabilities::Finding::Evidence::SupportingMessage', inverse_of: :evidence, foreign_key: 'vulnerability_finding_evidence_id'
validates :summary, length: { maximum: 8_000_000 } validates :summary, length: { maximum: 8_000_000 }
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_message, foreign_key: 'vulnerability_finding_evidence_id', optional: false
validates :name, length: { maximum: 2048 }
end
end
end
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_message).required }
it { is_expected.to validate_length_of(:name).is_at_most(2048) }
end
...@@ -6,6 +6,7 @@ RSpec.describe Vulnerabilities::Finding::Evidence do ...@@ -6,6 +6,7 @@ RSpec.describe Vulnerabilities::Finding::Evidence do
it { is_expected.to belong_to(:finding).class_name('Vulnerabilities::Finding').required } 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(: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(:response).class_name('Vulnerabilities::Finding::Evidence::Response').with_foreign_key('vulnerability_finding_evidence_id').inverse_of(:evidence) }
it { is_expected.to have_one(:supporting_message).class_name('Vulnerabilities::Finding::Evidence::SupportingMessage').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_length_of(:summary).is_at_most(8_000_000) }
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