diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-11-17 14:33:21 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-11-17 14:33:21 +0300 |
commit | 7021455bd1ed7b125c55eb1b33c5a01f2bc55ee0 (patch) | |
tree | 5bdc2229f5198d516781f8d24eace62fc7e589e9 /spec/validators/web_hooks/wildcard_branch_filter_validator_spec.rb | |
parent | 185b095e93520f96e9cfc31d9c3e69b498cdab7c (diff) |
Add latest changes from gitlab-org/gitlab@15-6-stable-eev15.6.0-rc42
Diffstat (limited to 'spec/validators/web_hooks/wildcard_branch_filter_validator_spec.rb')
-rw-r--r-- | spec/validators/web_hooks/wildcard_branch_filter_validator_spec.rb | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/spec/validators/web_hooks/wildcard_branch_filter_validator_spec.rb b/spec/validators/web_hooks/wildcard_branch_filter_validator_spec.rb new file mode 100644 index 00000000000..7f29e1df007 --- /dev/null +++ b/spec/validators/web_hooks/wildcard_branch_filter_validator_spec.rb @@ -0,0 +1,44 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe WebHooks::WildcardBranchFilterValidator do + let(:validator) { described_class.new(attributes: [:push_events_branch_filter]) } + let(:hook) { build(:project_hook) } + + describe '#validates_each' do + it 'allows valid branch names' do + validator.validate_each(hook, :push_events_branch_filter, +"good_branch_name") + validator.validate_each(hook, :push_events_branch_filter, +"another/good_branch_name") + expect(hook.errors.empty?).to be true + end + + it 'disallows bad branch names' do + validator.validate_each(hook, :push_events_branch_filter, +"bad branch~name") + expect(hook.errors[:push_events_branch_filter].empty?).to be false + end + + it 'allows wildcards' do + validator.validate_each(hook, :push_events_branch_filter, +"features/*") + validator.validate_each(hook, :push_events_branch_filter, +"features/*/bla") + validator.validate_each(hook, :push_events_branch_filter, +"*-stable") + expect(hook.errors.empty?).to be true + end + + it 'gets rid of whitespace' do + filter = +' master ' + validator.validate_each(hook, :push_events_branch_filter, filter) + + expect(filter).to eq 'master' + end + + # Branch names can be quite long but in practice aren't over 255 so 4000 should + # be enough space for a list of branch names but we can increase if needed. + it 'limits length to 4000 chars' do + filter = 'a' * 4001 + validator.validate_each(hook, :push_events_branch_filter, filter) + + expect(hook.errors[:push_events_branch_filter].empty?).to be false + end + end +end |