2019-08-22 06:57:44 -04:00
|
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
2020-06-10 05:08:35 -04:00
|
|
|
|
require 'fast_spec_helper'
|
2014-07-08 11:15:23 -04:00
|
|
|
|
|
2017-07-10 10:24:02 -04:00
|
|
|
|
describe Gitlab::Regex do
|
2020-03-26 14:08:03 -04:00
|
|
|
|
shared_examples_for 'project/group name regex' do
|
2016-11-30 02:13:42 -05:00
|
|
|
|
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 10:20:49 -05:00
|
|
|
|
end
|
|
|
|
|
|
2020-03-26 14:08:03 -04:00
|
|
|
|
describe '.project_name_regex' do
|
|
|
|
|
subject { described_class.project_name_regex }
|
|
|
|
|
|
|
|
|
|
it_behaves_like 'project/group name regex'
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
describe '.group_name_regex' do
|
|
|
|
|
subject { described_class.group_name_regex }
|
|
|
|
|
|
|
|
|
|
it_behaves_like 'project/group name regex'
|
2020-03-30 14:08:07 -04:00
|
|
|
|
|
|
|
|
|
it 'allows parenthesis' do
|
|
|
|
|
is_expected.to match('Group One (Test)')
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it 'does not start with parenthesis' do
|
|
|
|
|
is_expected.not_to match('(Invalid Group name)')
|
|
|
|
|
end
|
2020-03-26 14:08:03 -04:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
describe '.project_name_regex_message' do
|
|
|
|
|
subject { described_class.project_name_regex_message }
|
|
|
|
|
|
2020-03-30 14:08:07 -04:00
|
|
|
|
it { is_expected.to eq("can contain only letters, digits, emojis, '_', '.', dash, space. It must start with letter, digit, emoji or '_'.") }
|
2020-03-26 14:08:03 -04:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
describe '.group_name_regex_message' do
|
|
|
|
|
subject { described_class.group_name_regex_message }
|
|
|
|
|
|
2020-03-30 14:08:07 -04:00
|
|
|
|
it { is_expected.to eq("can contain only letters, digits, emojis, '_', '.', dash, space, parenthesis. It must start with letter, digit, emoji or '_'.") }
|
2020-03-26 14:08:03 -04:00
|
|
|
|
end
|
|
|
|
|
|
2017-12-20 07:12:34 -05:00
|
|
|
|
describe '.environment_name_regex' do
|
2017-06-21 07:16:38 -04:00
|
|
|
|
subject { described_class.environment_name_regex }
|
|
|
|
|
|
|
|
|
|
it { is_expected.to match('foo') }
|
2017-11-18 22:01:01 -05:00
|
|
|
|
it { is_expected.to match('a') }
|
2017-06-21 07:16:38 -04: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 07:12:34 -05:00
|
|
|
|
it { is_expected.not_to match('!!()()') }
|
2017-11-18 22:01:01 -05: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 07:16:38 -04:00
|
|
|
|
end
|
|
|
|
|
|
2019-08-08 14:51:52 -04: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 02:13:42 -05:00
|
|
|
|
describe '.environment_slug_regex' do
|
|
|
|
|
subject { described_class.environment_slug_regex }
|
2016-12-07 20:09:18 -05:00
|
|
|
|
|
2016-11-30 02:13:42 -05: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-07 20:09:18 -05:00
|
|
|
|
end
|
2017-07-19 04:52:03 -04: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 10:06:39 -05: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 04:52:03 -04:00
|
|
|
|
it { is_expected.not_to match('.my/image') }
|
|
|
|
|
it { is_expected.not_to match('my/image.') }
|
|
|
|
|
end
|
2019-10-16 17:07:22 -04:00
|
|
|
|
|
|
|
|
|
describe '.aws_account_id_regex' do
|
2019-11-08 01:06:24 -05: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 17:07:22 -04: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 14:06:53 -04: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
|
2020-05-07 05:09:51 -04:00
|
|
|
|
|
|
|
|
|
describe '.kubernetes_namespace_regex' do
|
|
|
|
|
subject { described_class.kubernetes_namespace_regex }
|
|
|
|
|
|
|
|
|
|
it { is_expected.to match('foo') }
|
|
|
|
|
it { is_expected.to match('foo-bar') }
|
|
|
|
|
it { is_expected.to match('1foo-bar') }
|
|
|
|
|
it { is_expected.to match('foo-bar2') }
|
|
|
|
|
it { is_expected.to match('foo-1bar') }
|
|
|
|
|
it { is_expected.not_to match('foo.bar') }
|
|
|
|
|
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('-foo-') }
|
|
|
|
|
it { is_expected.not_to match('foo/bar') }
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
describe '.kubernetes_dns_subdomain_regex' do
|
|
|
|
|
subject { described_class.kubernetes_dns_subdomain_regex }
|
|
|
|
|
|
|
|
|
|
it { is_expected.to match('foo') }
|
|
|
|
|
it { is_expected.to match('foo-bar') }
|
|
|
|
|
it { is_expected.to match('foo.bar') }
|
|
|
|
|
it { is_expected.to match('foo1.bar') }
|
|
|
|
|
it { is_expected.to match('foo1.2bar') }
|
|
|
|
|
it { is_expected.to match('foo.bar1') }
|
|
|
|
|
it { is_expected.to match('1foo.bar1') }
|
|
|
|
|
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('-foo-') }
|
|
|
|
|
it { is_expected.not_to match('foo/bar') }
|
|
|
|
|
end
|
2020-06-09 08:08:55 -04:00
|
|
|
|
|
|
|
|
|
describe '.conan_file_name_regex' do
|
|
|
|
|
subject { described_class.conan_file_name_regex }
|
|
|
|
|
|
|
|
|
|
it { is_expected.to match('conanfile.py') }
|
|
|
|
|
it { is_expected.to match('conan_package.tgz') }
|
|
|
|
|
it { is_expected.not_to match('foo.txt') }
|
|
|
|
|
it { is_expected.not_to match('!!()()') }
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
describe '.conan_package_reference_regex' do
|
|
|
|
|
subject { described_class.conan_package_reference_regex }
|
|
|
|
|
|
|
|
|
|
it { is_expected.to match('123456789') }
|
|
|
|
|
it { is_expected.to match('asdf1234') }
|
|
|
|
|
it { is_expected.not_to match('@foo') }
|
|
|
|
|
it { is_expected.not_to match('0/pack+age/1@1/0') }
|
|
|
|
|
it { is_expected.not_to match('!!()()') }
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
describe '.conan_revision_regex' do
|
|
|
|
|
subject { described_class.conan_revision_regex }
|
|
|
|
|
|
|
|
|
|
it { is_expected.to match('0') }
|
|
|
|
|
it { is_expected.not_to match('foo') }
|
|
|
|
|
it { is_expected.not_to match('!!()()') }
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
describe '.conan_recipe_component_regex' do
|
|
|
|
|
subject { described_class.conan_recipe_component_regex }
|
|
|
|
|
|
|
|
|
|
let(:fifty_one_characters) { 'f_a' * 17}
|
|
|
|
|
|
|
|
|
|
it { is_expected.to match('foobar') }
|
|
|
|
|
it { is_expected.to match('foo_bar') }
|
|
|
|
|
it { is_expected.to match('foo+bar') }
|
|
|
|
|
it { is_expected.to match('_foo+bar-baz+1.0') }
|
|
|
|
|
it { is_expected.to match('1.0.0') }
|
|
|
|
|
it { is_expected.not_to match('-foo_bar') }
|
|
|
|
|
it { is_expected.not_to match('+foo_bar') }
|
|
|
|
|
it { is_expected.not_to match('.foo_bar') }
|
|
|
|
|
it { is_expected.not_to match('foo@bar') }
|
|
|
|
|
it { is_expected.not_to match('foo/bar') }
|
|
|
|
|
it { is_expected.not_to match('!!()()') }
|
|
|
|
|
it { is_expected.not_to match(fifty_one_characters) }
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
describe '.package_name_regex' do
|
|
|
|
|
subject { described_class.package_name_regex }
|
|
|
|
|
|
|
|
|
|
it { is_expected.to match('123') }
|
|
|
|
|
it { is_expected.to match('foo') }
|
|
|
|
|
it { is_expected.to match('foo/bar') }
|
|
|
|
|
it { is_expected.to match('@foo/bar') }
|
|
|
|
|
it { is_expected.to match('com/mycompany/app/my-app') }
|
|
|
|
|
it { is_expected.to match('my-package/1.0.0@my+project+path/beta') }
|
|
|
|
|
it { is_expected.not_to match('my-package/1.0.0@@@@@my+project+path/beta') }
|
|
|
|
|
it { is_expected.not_to match('$foo/bar') }
|
|
|
|
|
it { is_expected.not_to match('@foo/@/bar') }
|
|
|
|
|
it { is_expected.not_to match('@@foo/bar') }
|
|
|
|
|
it { is_expected.not_to match('my package name') }
|
|
|
|
|
it { is_expected.not_to match('!!()()') }
|
|
|
|
|
it { is_expected.not_to match("..\n..\foo") }
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
describe '.maven_file_name_regex' do
|
|
|
|
|
subject { described_class.maven_file_name_regex }
|
|
|
|
|
|
|
|
|
|
it { is_expected.to match('123') }
|
|
|
|
|
it { is_expected.to match('foo') }
|
|
|
|
|
it { is_expected.to match('foo+bar-2_0.pom') }
|
|
|
|
|
it { is_expected.to match('foo.bar.baz-2.0-20190901.47283-1.jar') }
|
|
|
|
|
it { is_expected.to match('maven-metadata.xml') }
|
|
|
|
|
it { is_expected.to match('1.0-SNAPSHOT') }
|
|
|
|
|
it { is_expected.not_to match('../../foo') }
|
|
|
|
|
it { is_expected.not_to match('..\..\foo') }
|
|
|
|
|
it { is_expected.not_to match('%2f%2e%2e%2f%2essh%2fauthorized_keys') }
|
|
|
|
|
it { is_expected.not_to match('$foo/bar') }
|
|
|
|
|
it { is_expected.not_to match('my file name') }
|
|
|
|
|
it { is_expected.not_to match('!!()()') }
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
describe '.maven_path_regex' do
|
|
|
|
|
subject { described_class.maven_path_regex }
|
|
|
|
|
|
|
|
|
|
it { is_expected.to match('123') }
|
|
|
|
|
it { is_expected.to match('foo') }
|
|
|
|
|
it { is_expected.to match('foo/bar') }
|
|
|
|
|
it { is_expected.to match('@foo/bar') }
|
|
|
|
|
it { is_expected.to match('com/mycompany/app/my-app') }
|
|
|
|
|
it { is_expected.to match('com/mycompany/app/my-app/1.0-SNAPSHOT') }
|
|
|
|
|
it { is_expected.to match('com/mycompany/app/my-app/1.0-SNAPSHOT+debian64') }
|
|
|
|
|
it { is_expected.not_to match('com/mycompany/app/my+app/1.0-SNAPSHOT') }
|
|
|
|
|
it { is_expected.not_to match('$foo/bar') }
|
|
|
|
|
it { is_expected.not_to match('@foo/@/bar') }
|
|
|
|
|
it { is_expected.not_to match('my package name') }
|
|
|
|
|
it { is_expected.not_to match('!!()()') }
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
describe '.semver_regex' do
|
|
|
|
|
subject { described_class.semver_regex }
|
|
|
|
|
|
|
|
|
|
it { is_expected.to match('1.2.3') }
|
|
|
|
|
it { is_expected.to match('1.2.3-beta') }
|
|
|
|
|
it { is_expected.to match('1.2.3-alpha.3') }
|
|
|
|
|
it { is_expected.not_to match('1') }
|
|
|
|
|
it { is_expected.not_to match('1.2') }
|
|
|
|
|
it { is_expected.not_to match('1./2.3') }
|
|
|
|
|
it { is_expected.not_to match('../../../../../1.2.3') }
|
|
|
|
|
it { is_expected.not_to match('%2e%2e%2f1.2.3') }
|
|
|
|
|
end
|
2020-06-10 05:08:35 -04:00
|
|
|
|
|
|
|
|
|
describe '.go_package_regex' do
|
|
|
|
|
subject { described_class.go_package_regex }
|
|
|
|
|
|
|
|
|
|
it { is_expected.to match('example.com') }
|
|
|
|
|
it { is_expected.to match('example.com/foo') }
|
|
|
|
|
it { is_expected.to match('example.com/foo/bar') }
|
|
|
|
|
it { is_expected.to match('example.com/foo/bar/baz') }
|
|
|
|
|
it { is_expected.to match('tl.dr.foo.bar.baz') }
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
describe '.unbounded_semver_regex' do
|
|
|
|
|
subject { described_class.unbounded_semver_regex }
|
|
|
|
|
|
|
|
|
|
it { is_expected.to match('1.2.3') }
|
|
|
|
|
it { is_expected.to match('1.2.3-beta') }
|
|
|
|
|
it { is_expected.to match('1.2.3-alpha.3') }
|
|
|
|
|
it { is_expected.not_to match('1') }
|
|
|
|
|
it { is_expected.not_to match('1.2') }
|
|
|
|
|
it { is_expected.not_to match('1./2.3') }
|
|
|
|
|
end
|
2014-07-08 11:15:23 -04:00
|
|
|
|
end
|