Commit 6e96907b authored by Shinya Maeda's avatar Shinya Maeda

Merge branch 'move-maskable-concern-to-ci-namespace' into 'master'

Move Maskable concern to Ci namespace

See merge request gitlab-org/gitlab!27305
parents bcbafd93 0f036967
......@@ -45,6 +45,6 @@ module CiVariablesHelper
end
def ci_variable_maskable_regex
Maskable::REGEX.inspect.sub('\\A', '^').sub('\\z', '$').sub(/^\//, '').sub(/\/[a-z]*$/, '').gsub('\/', '/')
Ci::Maskable::REGEX.inspect.sub('\\A', '^').sub('\\z', '$').sub(/^\//, '').sub(/\/[a-z]*$/, '').gsub('\/', '/')
end
end
......@@ -5,7 +5,7 @@ module Ci
extend Gitlab::Ci::Model
include Ci::HasVariable
include Presentable
include Maskable
include Ci::Maskable
belongs_to :group, class_name: "::Group"
......
......@@ -5,7 +5,7 @@ module Ci
extend Gitlab::Ci::Model
include Ci::HasVariable
include Presentable
include Maskable
include Ci::Maskable
prepend HasEnvironmentScope
belongs_to :project
......
# frozen_string_literal: true
module Ci
module Maskable
extend ActiveSupport::Concern
# * Single line
# * No escape characters
# * No variables
# * No spaces
# * Minimal length of 8 characters
# * Characters must be from the Base64 alphabet (RFC4648) with the addition of @ and :
# * Absolutely no fun is allowed
REGEX = /\A[a-zA-Z0-9_+=\/@:-]{8,}\z/.freeze
included do
validates :masked, inclusion: { in: [true, false] }
validates :value, format: { with: REGEX }, if: :masked?
end
def to_runner_variable
super.merge(masked: masked?)
end
end
end
# frozen_string_literal: true
module Maskable
extend ActiveSupport::Concern
# * Single line
# * No escape characters
# * No variables
# * No spaces
# * Minimal length of 8 characters
# * Characters must be from the Base64 alphabet (RFC4648) with the addition of @ and :
# * Absolutely no fun is allowed
REGEX = /\A[a-zA-Z0-9_+=\/@:-]{8,}\z/.freeze
included do
validates :masked, inclusion: { in: [true, false] }
validates :value, format: { with: REGEX }, if: :masked?
end
def to_runner_variable
super.merge(masked: masked?)
end
end
......@@ -8,7 +8,7 @@ describe Ci::GroupVariable do
it_behaves_like "CI variable"
it { is_expected.to include_module(Presentable) }
it { is_expected.to include_module(Maskable) }
it { is_expected.to include_module(Ci::Maskable) }
it { is_expected.to validate_uniqueness_of(:key).scoped_to(:group_id).with_message(/\(\w+\) has already been taken/) }
describe '.unprotected' do
......
......@@ -9,7 +9,7 @@ describe Ci::Variable do
describe 'validations' do
it { is_expected.to include_module(Presentable) }
it { is_expected.to include_module(Maskable) }
it { is_expected.to include_module(Ci::Maskable) }
it { is_expected.to include_module(HasEnvironmentScope) }
it { is_expected.to validate_uniqueness_of(:key).scoped_to(:project_id, :environment_scope).with_message(/\(\w+\) has already been taken/) }
end
......
......@@ -2,7 +2,7 @@
require 'spec_helper'
describe Maskable do
describe Ci::Maskable do
let(:variable) { build(:ci_variable) }
describe 'masked value validations' do
......@@ -34,7 +34,7 @@ describe Maskable do
end
describe 'REGEX' do
subject { Maskable::REGEX }
subject { Ci::Maskable::REGEX }
it 'does not match strings shorter than 8 letters' do
expect(subject.match?('hello')).to eq(false)
......
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