Commit c94d4075 authored by Jan Provaznik's avatar Jan Provaznik

Merge branch '210327-add-scanner-vendor-field' into 'master'

Add Vendor to Vulnerability Scanners

See merge request gitlab-org/gitlab!35004
parents 3f12ba02 27db17fd
# frozen_string_literal: true
class AddVendorToVulnerabilityScanners < ActiveRecord::Migration[6.0]
include Gitlab::Database::MigrationHelpers
DOWNTIME = false
DEFAULT_SCANNER_VENDOR = 'GitLab'
# rubocop:disable Migration/AddLimitToTextColumns
# limit is added in 20200622070620_add_limit_to_vulnerability_scanners_vendor
def up
with_lock_retries do
add_column :vulnerability_scanners, :vendor, :text, default: DEFAULT_SCANNER_VENDOR, null: false
end
end
def down
with_lock_retries do
remove_column :vulnerability_scanners, :vendor
end
end
# rubocop:enable Migration/AddLimitToTextColumns
end
# frozen_string_literal: true
class AddLimitToVulnerabilityScannersVendor < ActiveRecord::Migration[6.0]
include Gitlab::Database::MigrationHelpers
DOWNTIME = false
disable_ddl_transaction!
def up
add_text_limit :vulnerability_scanners, :vendor, 255, validate: false
end
def down
remove_text_limit :vulnerability_scanners, :vendor
end
end
......@@ -7306,7 +7306,8 @@ CREATE TABLE public.vulnerability_scanners (
updated_at timestamp with time zone NOT NULL,
project_id integer NOT NULL,
external_id character varying NOT NULL,
name character varying NOT NULL
name character varying NOT NULL,
vendor text DEFAULT 'GitLab'::text NOT NULL
);
CREATE SEQUENCE public.vulnerability_scanners_id_seq
......@@ -8296,6 +8297,9 @@ ALTER TABLE ONLY public.chat_teams
ALTER TABLE public.design_management_designs
ADD CONSTRAINT check_07155e2715 CHECK ((char_length((filename)::text) <= 255)) NOT VALID;
ALTER TABLE public.vulnerability_scanners
ADD CONSTRAINT check_37608c9db5 CHECK ((char_length(vendor) <= 255)) NOT VALID;
ALTER TABLE ONLY public.ci_build_needs
ADD CONSTRAINT ci_build_needs_pkey PRIMARY KEY (id);
......@@ -14151,6 +14155,8 @@ COPY "schema_migrations" (version) FROM STDIN;
20200618134723
20200619154527
20200619154528
20200622070606
20200622070620
20200622095419
20200622103836
20200622235737
......
......@@ -11,6 +11,7 @@ module Vulnerabilities
validates :project, presence: true
validates :external_id, presence: true, uniqueness: { scope: :project_id }
validates :name, presence: true
validates :vendor, presence: true, length: { maximum: 255 }
scope :with_external_id, -> (external_ids) { where(external_id: external_ids) }
end
......
---
title: Add vendor to Vulnerability Scanners
merge_request: 35004
author:
type: added
......@@ -8,6 +8,7 @@ FactoryBot.define do
factory :vulnerabilities_scanner, class: 'Vulnerabilities::Scanner' do
sequence(:external_id) { generate(:vulnerability_scanner_external_id) }
name { 'Find Security Bugs' }
vendor { 'Security Vendor' }
project
end
end
......@@ -15,6 +15,8 @@ RSpec.describe Vulnerabilities::Scanner do
it { is_expected.to validate_presence_of(:project) }
it { is_expected.to validate_presence_of(:external_id) }
it { is_expected.to validate_uniqueness_of(:external_id).scoped_to(:project_id) }
it { is_expected.to validate_presence_of(:vendor) }
it { is_expected.to validate_length_of(:vendor).is_at_most(255) }
end
describe '.with_external_id' do
......
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