Commit 0826891c authored by Mehmet Emin INAC's avatar Mehmet Emin INAC

Add info column into security_scans table

This new JSONB column will be used to store error information
parent f98e6652
{
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"title": "Security::Scan#info schema",
"description": "The schema validates the content of the Security::Scan#info attribute",
"additionalProperties": false,
"properties": {
"errors": {
"type": "array",
"items": {
"type": "object",
"additionalProperties": false,
"properties": {
"type": {
"type": "string"
},
"message": {
"type": "string"
}
},
"required": [
"type",
"message"
]
}
}
}
}
# frozen_string_literal: true
class AddInfoColumnIntoSecurityScansTable < ActiveRecord::Migration[6.0]
DOWNTIME = false
def change
add_column :security_scans, :info, :jsonb, null: false, default: {}
end
end
a81f3555d0e1159569687d4967edcd2b5706cdafd5defb8dc725e295eb969861
\ No newline at end of file
...@@ -17243,7 +17243,8 @@ CREATE TABLE security_scans ( ...@@ -17243,7 +17243,8 @@ CREATE TABLE security_scans (
created_at timestamp with time zone NOT NULL, created_at timestamp with time zone NOT NULL,
updated_at timestamp with time zone NOT NULL, updated_at timestamp with time zone NOT NULL,
build_id bigint NOT NULL, build_id bigint NOT NULL,
scan_type smallint NOT NULL scan_type smallint NOT NULL,
info jsonb DEFAULT '{}'::jsonb NOT NULL
); );
CREATE SEQUENCE security_scans_id_seq CREATE SEQUENCE security_scans_id_seq
...@@ -8,6 +8,7 @@ module Security ...@@ -8,6 +8,7 @@ module Security
validates :build_id, presence: true validates :build_id, presence: true
validates :scan_type, presence: true validates :scan_type, presence: true
validates :info, json_schema: { filename: 'security_scan_info', draft: 7 }
belongs_to :build, class_name: 'Ci::Build' belongs_to :build, class_name: 'Ci::Build'
......
...@@ -12,6 +12,28 @@ RSpec.describe Security::Scan do ...@@ -12,6 +12,28 @@ RSpec.describe Security::Scan do
describe 'validations' do describe 'validations' do
it { is_expected.to validate_presence_of(:build_id) } it { is_expected.to validate_presence_of(:build_id) }
it { is_expected.to validate_presence_of(:scan_type) } it { is_expected.to validate_presence_of(:scan_type) }
describe 'info' do
let(:scan) { build(:security_scan, info: info) }
subject { scan.errors.details[:info] }
before do
scan.validate
end
context 'when the value for info field is valid' do
let(:info) { { errors: [{ type: 'Foo', message: 'Message' }] } }
it { is_expected.to be_empty }
end
context 'when the value for info field is invalid' do
let(:info) { { errors: [{ type: 'Foo' }] } }
it { is_expected.not_to be_empty }
end
end
end end
describe '#project' do describe '#project' 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