Commit 755601ec authored by Mayra Cabrera's avatar Mayra Cabrera

Merge branch 'sy-add-status-page-url-field' into 'master'

Add status page url field to DB and setting model

See merge request gitlab-org/gitlab!29357
parents cfea7834 3842fd57
---
title: Add status page url field to DB and setting model
merge_request: 29357
author:
type: added
# frozen_string_literal: true
class AddStatusPageUrlToStatusPageSettings < ActiveRecord::Migration[6.0]
include Gitlab::Database::MigrationHelpers
DOWNTIME = false
disable_ddl_transaction!
def up
add_column :status_page_settings, :status_page_url, :text
add_text_limit :status_page_settings, :status_page_url, 1024
end
def down
remove_column :status_page_settings, :status_page_url
end
end
......@@ -6003,7 +6003,9 @@ CREATE TABLE public.status_page_settings (
aws_region character varying(255) NOT NULL,
aws_access_key character varying(255) NOT NULL,
encrypted_aws_secret_key character varying(255) NOT NULL,
encrypted_aws_secret_key_iv character varying(255) NOT NULL
encrypted_aws_secret_key_iv character varying(255) NOT NULL,
status_page_url text,
CONSTRAINT check_75a79cd992 CHECK ((char_length(status_page_url) <= 1024))
);
CREATE SEQUENCE public.status_page_settings_project_id_seq
......@@ -13199,6 +13201,7 @@ COPY "schema_migrations" (version) FROM STDIN;
20200408154604
20200408154624
20200408175424
20200408212219
20200409085956
20200409211607
20200410232012
......
......@@ -54,7 +54,7 @@ module EE
end
def status_page_setting_params
{ status_page_setting_attributes: [:aws_s3_bucket_name, :aws_region, :aws_access_key, :aws_secret_key, :enabled] }
{ status_page_setting_attributes: [:status_page_url, :aws_s3_bucket_name, :aws_region, :aws_access_key, :aws_secret_key, :enabled] }
end
override :track_events
......
......@@ -24,6 +24,7 @@ module OperationsHelper
{
'operations-settings-endpoint' => project_settings_operations_path(@project),
'enabled' => status_page_setting.enabled?.to_s,
'url' => status_page_setting&.status_page_url,
'bucket-name' => status_page_setting.aws_s3_bucket_name,
'region' => status_page_setting.aws_region,
'aws-access-key' => status_page_setting.aws_access_key,
......
......@@ -18,6 +18,10 @@ module StatusPage
before_validation :check_secret_changes
validates :status_page_url,
length: { maximum: 1024 },
addressable_url: { enforce_sanitization: true, ascii_only: true },
allow_nil: true
validates :aws_s3_bucket_name,
length: { minimum: 3, maximum: 63 },
presence: true,
......
......@@ -36,7 +36,8 @@ module EE
destroy = attrs[:aws_s3_bucket_name].blank? &&
attrs[:aws_region].blank? &&
attrs[:aws_access_key].blank? &&
attrs[:aws_secret_key].blank?
attrs[:aws_secret_key].blank? &&
attrs[:status_page_url].blank?
{ status_page_setting_attributes: attrs.merge(_destroy: destroy) }
end
......
......@@ -334,7 +334,8 @@ describe Projects::Settings::OperationsController do
status_page_params: status_page_attributes.merge(aws_access_key: '',
aws_secret_key: '',
aws_s3_bucket_name: '',
aws_region: '')
aws_region: '',
status_page_url: '')
)
expect(project.status_page_setting).to be_nil
end
......
......@@ -7,6 +7,7 @@ FactoryBot.define do
aws_region { 'ap-southeast-2' }
aws_access_key { FFaker::String.from_regexp(StatusPage::ProjectSetting::AWS_ACCESS_KEY_REGEXP) }
aws_secret_key { FFaker::String.from_regexp(StatusPage::ProjectSetting::AWS_SECRET_KEY_REGEXP) }
status_page_url { 'https://status.gitlab.com' }
enabled { false }
trait :enabled do
......
......@@ -23,6 +23,7 @@ describe OperationsHelper do
expect(subject).to eq(
'operations-settings-endpoint' => project_settings_operations_path(project),
'enabled' => 'false',
'url' => nil,
'aws-access-key' => nil,
'aws-secret-key' => nil,
'region' => nil,
......@@ -40,6 +41,7 @@ describe OperationsHelper do
expect(subject).to eq(
'operations-settings-endpoint' => project_settings_operations_path(project),
'enabled' => 'false',
'url' => nil,
'aws-access-key' => nil,
'aws-secret-key' => nil,
'region' => nil,
......@@ -56,6 +58,7 @@ describe OperationsHelper do
expect(subject).to eq(
'operations-settings-endpoint' => project_settings_operations_path(project),
'enabled' => status_page_setting.enabled.to_s,
'url' => status_page_setting.status_page_url,
'aws-access-key' => status_page_setting.aws_access_key,
'aws-secret-key' => status_page_setting.masked_aws_secret_key,
'region' => status_page_setting.aws_region,
......
......@@ -8,12 +8,39 @@ describe StatusPage::ProjectSetting do
end
describe 'validations' do
it { is_expected.not_to validate_presence_of(:status_page_url) }
it { is_expected.to validate_presence_of(:aws_s3_bucket_name) }
it { is_expected.to validate_length_of(:aws_s3_bucket_name).is_at_least(3).is_at_most(63) }
it { is_expected.to validate_presence_of(:aws_region) }
it { is_expected.to validate_presence_of(:aws_access_key) }
it { is_expected.to validate_presence_of(:encrypted_aws_secret_key) }
describe 'status_page_url' do
it 'disallows invalid urls for status_page_url' do
unsafe_url = %{https://replaceme.com/'><script>alert(document.cookie)</script>}
non_ascii_url = 'http://status€.gitlab.com'
blank_url = ''
excessively_long_url = 'https://statu' + 's' * 1024 + '.com'
is_expected.not_to allow_values(
unsafe_url,
non_ascii_url,
blank_url,
excessively_long_url
).for(:status_page_url)
end
it 'allows valid urls for status_page_url' do
external_url = 'http://status.gitlab.com/'
internal_url = 'http://192.168.1.1'
is_expected.to allow_value(
external_url,
internal_url
).for(:status_page_url)
end
end
describe 'aws_s3_bucket_name' do
it { is_expected.to allow_value('bucket-name').for(:aws_s3_bucket_name) }
it { is_expected.to allow_value('3ucket-name').for(:aws_s3_bucket_name) }
......
......@@ -138,7 +138,8 @@ describe Projects::Operations::UpdateService do
aws_access_key: '',
aws_secret_key: '',
aws_s3_bucket_name: '',
aws_region: ''
aws_region: '',
status_page_url: ''
}
}
end
......@@ -157,7 +158,8 @@ describe Projects::Operations::UpdateService do
aws_s3_bucket_name: 'test',
aws_region: 'ap-southeast-2',
aws_access_key: '',
aws_secret_key: project.reload.status_page_setting.masked_aws_secret_key
aws_secret_key: project.reload.status_page_setting.masked_aws_secret_key,
status_page_url: 'https://status.gitlab.com'
}
}
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