2019-08-22 10:57:44 +00:00
|
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
2014-07-08 15:15:23 +00:00
|
|
|
|
require 'spec_helper'
|
|
|
|
|
|
2017-07-10 14:24:02 +00:00
|
|
|
|
describe Gitlab::Regex do
|
2016-11-30 07:13:42 +00:00
|
|
|
|
describe '.project_name_regex' do
|
|
|
|
|
subject { described_class.project_name_regex }
|
|
|
|
|
|
|
|
|
|
it { is_expected.to match('gitlab-ce') }
|
|
|
|
|
it { is_expected.to match('GitLab CE') }
|
|
|
|
|
it { is_expected.to match('100 lines') }
|
|
|
|
|
it { is_expected.to match('gitlab.git') }
|
|
|
|
|
it { is_expected.to match('Český název') }
|
|
|
|
|
it { is_expected.to match('Dash – is this') }
|
|
|
|
|
it { is_expected.not_to match('?gitlab') }
|
2016-02-01 15:20:49 +00:00
|
|
|
|
end
|
|
|
|
|
|
2017-12-20 12:12:34 +00:00
|
|
|
|
describe '.environment_name_regex' do
|
2017-06-21 11:16:38 +00:00
|
|
|
|
subject { described_class.environment_name_regex }
|
|
|
|
|
|
|
|
|
|
it { is_expected.to match('foo') }
|
2017-11-19 03:01:01 +00:00
|
|
|
|
it { is_expected.to match('a') }
|
2017-06-21 11:16:38 +00:00
|
|
|
|
it { is_expected.to match('foo-1') }
|
|
|
|
|
it { is_expected.to match('FOO') }
|
|
|
|
|
it { is_expected.to match('foo/1') }
|
|
|
|
|
it { is_expected.to match('foo.1') }
|
|
|
|
|
it { is_expected.not_to match('9&foo') }
|
|
|
|
|
it { is_expected.not_to match('foo-^') }
|
2017-12-20 12:12:34 +00:00
|
|
|
|
it { is_expected.not_to match('!!()()') }
|
2017-11-19 03:01:01 +00:00
|
|
|
|
it { is_expected.not_to match('/foo') }
|
|
|
|
|
it { is_expected.not_to match('foo/') }
|
|
|
|
|
it { is_expected.not_to match('/foo/') }
|
|
|
|
|
it { is_expected.not_to match('/') }
|
2017-06-21 11:16:38 +00:00
|
|
|
|
end
|
|
|
|
|
|
2019-08-08 18:51:52 +00:00
|
|
|
|
describe '.environment_scope_regex' do
|
|
|
|
|
subject { described_class.environment_scope_regex }
|
|
|
|
|
|
|
|
|
|
it { is_expected.to match('foo') }
|
|
|
|
|
it { is_expected.to match('foo*Z') }
|
|
|
|
|
it { is_expected.not_to match('!!()()') }
|
|
|
|
|
end
|
|
|
|
|
|
2016-11-30 07:13:42 +00:00
|
|
|
|
describe '.environment_slug_regex' do
|
|
|
|
|
subject { described_class.environment_slug_regex }
|
2016-12-08 01:09:18 +00:00
|
|
|
|
|
2016-11-30 07:13:42 +00:00
|
|
|
|
it { is_expected.to match('foo') }
|
|
|
|
|
it { is_expected.to match('foo-1') }
|
|
|
|
|
it { is_expected.not_to match('FOO') }
|
|
|
|
|
it { is_expected.not_to match('foo/1') }
|
|
|
|
|
it { is_expected.not_to match('foo.1') }
|
|
|
|
|
it { is_expected.not_to match('foo*1') }
|
|
|
|
|
it { is_expected.not_to match('9foo') }
|
|
|
|
|
it { is_expected.not_to match('foo-') }
|
2016-12-08 01:09:18 +00:00
|
|
|
|
end
|
2017-07-19 08:52:03 +00:00
|
|
|
|
|
|
|
|
|
describe '.container_repository_name_regex' do
|
|
|
|
|
subject { described_class.container_repository_name_regex }
|
|
|
|
|
|
|
|
|
|
it { is_expected.to match('image') }
|
|
|
|
|
it { is_expected.to match('my/image') }
|
|
|
|
|
it { is_expected.to match('my/awesome/image-1') }
|
|
|
|
|
it { is_expected.to match('my/awesome/image.test') }
|
2019-11-22 15:06:39 +00:00
|
|
|
|
it { is_expected.to match('my/awesome/image--test') }
|
|
|
|
|
# docker distribution allows for infinite `-`
|
|
|
|
|
# https://github.com/docker/distribution/blob/master/reference/regexp.go#L13
|
|
|
|
|
# but we have a range of 0,10 to add a reasonable limit.
|
|
|
|
|
it { is_expected.not_to match('my/image-----------test') }
|
|
|
|
|
it { is_expected.not_to match('my/image-.test') }
|
2017-07-19 08:52:03 +00:00
|
|
|
|
it { is_expected.not_to match('.my/image') }
|
|
|
|
|
it { is_expected.not_to match('my/image.') }
|
|
|
|
|
end
|
2019-10-16 21:07:22 +00:00
|
|
|
|
|
|
|
|
|
describe '.aws_account_id_regex' do
|
2019-11-08 06:06:24 +00:00
|
|
|
|
subject { described_class.aws_account_id_regex }
|
|
|
|
|
|
|
|
|
|
it { is_expected.to match('123456789012') }
|
|
|
|
|
it { is_expected.not_to match('12345678901') }
|
|
|
|
|
it { is_expected.not_to match('1234567890123') }
|
|
|
|
|
it { is_expected.not_to match('12345678901a') }
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
describe '.aws_arn_regex' do
|
2019-10-16 21:07:22 +00:00
|
|
|
|
subject { described_class.aws_arn_regex }
|
|
|
|
|
|
|
|
|
|
it { is_expected.to match('arn:aws:iam::123456789012:role/role-name') }
|
|
|
|
|
it { is_expected.to match('arn:aws:s3:::bucket/key') }
|
|
|
|
|
it { is_expected.to match('arn:aws:ec2:us-east-1:123456789012:volume/vol-1') }
|
|
|
|
|
it { is_expected.to match('arn:aws:rds:us-east-1:123456789012:pg:prod') }
|
|
|
|
|
it { is_expected.not_to match('123456789012') }
|
|
|
|
|
it { is_expected.not_to match('role/role-name') }
|
|
|
|
|
end
|
2019-10-31 18:06:53 +00:00
|
|
|
|
|
|
|
|
|
describe '.utc_date_regex' do
|
|
|
|
|
subject { described_class.utc_date_regex }
|
|
|
|
|
|
|
|
|
|
it { is_expected.to match('2019-10-20') }
|
|
|
|
|
it { is_expected.to match('1990-01-01') }
|
|
|
|
|
it { is_expected.not_to match('11-1234-90') }
|
|
|
|
|
it { is_expected.not_to match('aa-1234-cc') }
|
|
|
|
|
it { is_expected.not_to match('9/9/2018') }
|
|
|
|
|
end
|
2014-07-08 15:15:23 +00:00
|
|
|
|
end
|