diff options
Diffstat (limited to 'spec/lib/gitlab/regex_spec.rb')
-rw-r--r-- | spec/lib/gitlab/regex_spec.rb | 99 |
1 files changed, 83 insertions, 16 deletions
diff --git a/spec/lib/gitlab/regex_spec.rb b/spec/lib/gitlab/regex_spec.rb index bc0f9e22d50..5e58282ff92 100644 --- a/spec/lib/gitlab/regex_spec.rb +++ b/spec/lib/gitlab/regex_spec.rb @@ -79,10 +79,10 @@ RSpec.describe Gitlab::Regex, feature_category: :tooling do it { is_expected - .to eq("cannot start with a non-alphanumeric character except for periods or underscores, " \ - "can contain only alphanumeric characters, forward slashes, periods, and underscores, " \ - "cannot end with a period or forward slash, and has a relative path structure " \ - "with no http protocol chars or leading or trailing forward slashes") + .to eq("must have a relative path structure with no HTTP " \ + "protocol characters, or leading or trailing forward slashes. Path segments must not start or " \ + "end with a special character, and must not contain consecutive special characters." + ) } end @@ -101,22 +101,37 @@ RSpec.describe Gitlab::Regex, feature_category: :tooling do it { is_expected.not_to match('good_for+you') } it { is_expected.not_to match('source/') } it { is_expected.not_to match('.source/full./path') } + it { is_expected.not_to match('.source/.full/.path') } + it { is_expected.not_to match('_source') } + it { is_expected.not_to match('.source') } it { is_expected.to match('source') } - it { is_expected.to match('.source') } - it { is_expected.to match('_source') } it { is_expected.to match('source/full') } it { is_expected.to match('source/full/path') } - it { is_expected.to match('.source/.full/.path') } + it { is_expected.to match('sou_rce/fu-ll/pa.th') } it { is_expected.to match('domain_namespace') } it { is_expected.to match('gitlab-migration-test') } + it { is_expected.to match('1-project-path') } + it { is_expected.to match('e-project-path') } it { is_expected.to match('') } # it is possible to pass an empty string for destination_namespace in bulk_import POST request end + describe '.bulk_import_source_full_path_regex_message' do + subject { described_class.bulk_import_source_full_path_regex_message } + + it { + is_expected + .to eq( + "must have a relative path structure with no HTTP " \ + "protocol characters, or leading or trailing forward slashes. Path segments must not start or " \ + "end with a special character, and must not contain consecutive special characters." + ) + } + end + describe '.bulk_import_source_full_path_regex' do subject { described_class.bulk_import_source_full_path_regex } - it { is_expected.not_to match('?gitlab') } it { is_expected.not_to match("Users's something") } it { is_expected.not_to match('/source') } it { is_expected.not_to match('http:') } @@ -124,20 +139,32 @@ RSpec.describe Gitlab::Regex, feature_category: :tooling do it { is_expected.not_to match('example.com/?stuff=true') } it { is_expected.not_to match('example.com:5000/?stuff=true') } it { is_expected.not_to match('http://gitlab.example/gitlab-org/manage/import/gitlab-migration-test') } - it { is_expected.not_to match('_good_for_me!') } - it { is_expected.not_to match('good_for+you') } it { is_expected.not_to match('source/') } - it { is_expected.not_to match('.source/full./path') } it { is_expected.not_to match('') } + it { is_expected.not_to match('.source/full./path') } + it { is_expected.not_to match('?gitlab') } + it { is_expected.not_to match('_good_for_me!') } + it { is_expected.not_to match('group/@*%_my_other-project-----') } + it { is_expected.not_to match('_foog-for-me!') } + it { is_expected.not_to match('.source/full/path.') } + it { is_expected.to match('good_for+you') } it { is_expected.to match('source') } it { is_expected.to match('.source') } it { is_expected.to match('_source') } it { is_expected.to match('source/full') } it { is_expected.to match('source/full/path') } - it { is_expected.to match('.source/.full/.path') } it { is_expected.to match('domain_namespace') } it { is_expected.to match('gitlab-migration-test') } + it { is_expected.to match('source/full/path-') } + it { is_expected.to match('.source/full/path') } + it { is_expected.to match('.source/.full/.path') } + it { is_expected.to match('source/full/.path') } + it { is_expected.to match('source/full/..path') } + it { is_expected.to match('source/full/---1path') } + it { is_expected.to match('source/full/-___path') } + it { is_expected.to match('source/full/path---') } + it { is_expected.to match('group/__my_other-project-----') } end describe '.group_path_regex' do @@ -710,6 +737,7 @@ RSpec.describe Gitlab::Regex, feature_category: :tooling do it { is_expected.to match('libsample0_1.2.3~alpha2_amd64.deb') } it { is_expected.to match('sample-dev_1.2.3~binary_amd64.deb') } it { is_expected.to match('sample-udeb_1.2.3~alpha2_amd64.udeb') } + it { is_expected.to match('sample-ddeb_1.2.3~alpha2_amd64.ddeb') } it { is_expected.not_to match('sample_1.2.3~alpha2_amd64.buildinfo') } it { is_expected.not_to match('sample_1.2.3~alpha2_amd64.changes') } @@ -1015,6 +1043,34 @@ RSpec.describe Gitlab::Regex, feature_category: :tooling do it { is_expected.not_to match('/api/v4/groups/1234/packages/debian/pool/compon/a/pkg/file.name') } end + describe 'Packages::MAVEN_SNAPSHOT_DYNAMIC_PARTS' do + subject { described_class::Packages::MAVEN_SNAPSHOT_DYNAMIC_PARTS } + + it { is_expected.to match('test-2.11-20230303.163304-1.jar') } + it { is_expected.to match('test-2.11-20230303.163304-1-javadoc.jar') } + it { is_expected.to match('test-2.11-20230303.163304-1-sources.jar') } + it { is_expected.to match('test-2.11-20230303.163304-1-20230303.163304-1.jar') } + it { is_expected.to match('test-2.11-20230303.163304-1-20230303.163304-1-javadoc.jar') } + it { is_expected.to match('test-2.11-20230303.163304-1-20230303.163304-1-sources.jar') } + it { is_expected.to match("#{'a' * 500}-20230303.163304-1-sources.jar") } + it { is_expected.to match("test-2.11-20230303.163304-1-#{'a' * 500}.jar") } + it { is_expected.to match("#{'a' * 500}-20230303.163304-1-#{'a' * 500}.jar") } + + it { is_expected.not_to match('') } + it { is_expected.not_to match(nil) } + it { is_expected.not_to match('test') } + it { is_expected.not_to match('1.2.3') } + it { is_expected.not_to match('1.2.3-javadoc.jar') } + it { is_expected.not_to match('-202303039.163304-1.jar') } + it { is_expected.not_to match('test-2.11-202303039.163304-1.jar') } + it { is_expected.not_to match('test-2.11-20230303.16330-1.jar') } + it { is_expected.not_to match('test-2.11-202303039.163304.jar') } + it { is_expected.not_to match('test-2.11-202303039.163304-.jar') } + it { is_expected.not_to match("#{'a' * 2000}-20230303.163304-1-sources.jar") } + it { is_expected.not_to match("test-2.11-20230303.163304-1-#{'a' * 2000}.jar") } + it { is_expected.not_to match("#{'a' * 2000}-20230303.163304-1-#{'a' * 2000}.jar") } + end + describe '.composer_package_version_regex' do subject { described_class.composer_package_version_regex } @@ -1133,10 +1189,21 @@ RSpec.describe Gitlab::Regex, feature_category: :tooling do MARKDOWN end - it { is_expected.to match(%(<section>\nsomething\n</section>)) } - it { is_expected.not_to match(%(must start in first column <section>\nsomething\n</section>)) } - it { is_expected.not_to match(%(<section>must be multi-line</section>)) } - it { expect(subject.match(markdown)[:html]).to eq expected } + describe 'normal regular expression' do + it { is_expected.to match(%(<section>\nsomething\n</section>)) } + it { is_expected.not_to match(%(must start in first column <section>\nsomething\n</section>)) } + it { is_expected.not_to match(%(<section>must be multi-line</section>)) } + it { expect(subject.match(markdown)[:html]).to eq expected } + end + + describe 'untrusted regular expression' do + subject { Gitlab::UntrustedRegexp.new(described_class::MARKDOWN_HTML_BLOCK_REGEX_UNTRUSTED, multiline: true) } + + it { is_expected.to match(%(<section>\nsomething\n</section>)) } + it { is_expected.not_to match(%(must start in first column <section>\nsomething\n</section>)) } + it { is_expected.not_to match(%(<section>must be multi-line</section>)) } + it { expect(subject.match(markdown)[:html]).to eq expected } + end end context 'HTML comment lines' do |