diff options
author | Patricio Cano <suprnova32@gmail.com> | 2016-07-18 17:49:33 -0500 |
---|---|---|
committer | Patricio Cano <suprnova32@gmail.com> | 2016-07-18 17:53:43 -0500 |
commit | 6b8eceda395ae25b7ea189627b04da1f223c57d7 (patch) | |
tree | 89e7030c542055743f67bedfa7f8a35bb540b3ca | |
parent | 23afb02aaa957dd1a5ce35a141e4e8ecd80052ca (diff) | |
download | gitlab-ce-6b8eceda395ae25b7ea189627b04da1f223c57d7.tar.gz |
Default to manual input for `domain_whitelist`, syntax fixes and added new tests.
-rw-r--r-- | app/assets/javascripts/admin.js.coffee | 3 | ||||
-rw-r--r-- | app/models/application_setting.rb | 2 | ||||
-rw-r--r-- | app/views/admin/application_settings/_form.html.haml | 8 | ||||
-rw-r--r-- | spec/fixtures/domain_blacklist.txt (renamed from spec/fixtures/blacklist.txt) | 0 | ||||
-rw-r--r-- | spec/models/application_setting_spec.rb | 12 | ||||
-rw-r--r-- | spec/models/user_spec.rb | 4 |
6 files changed, 19 insertions, 10 deletions
diff --git a/app/assets/javascripts/admin.js.coffee b/app/assets/javascripts/admin.js.coffee index 4dd30973d11..d5d34e6eca6 100644 --- a/app/assets/javascripts/admin.js.coffee +++ b/app/assets/javascripts/admin.js.coffee @@ -46,7 +46,6 @@ class @Admin else $('.blacklist-file').hide() $('.blacklist-raw').show() - return - $('input[name=\'blacklist_type\']').click showBlacklistType + $("input[name='blacklist_type']").click showBlacklistType showBlacklistType() diff --git a/app/models/application_setting.rb b/app/models/application_setting.rb index d923b4d5235..8c19d9dc9c8 100644 --- a/app/models/application_setting.rb +++ b/app/models/application_setting.rb @@ -71,7 +71,7 @@ class ApplicationSetting < ActiveRecord::Base inclusion: { in: %w(ssh http), allow_blank: true, allow_nil: true } validates :domain_blacklist, - presence: true, + presence: { message: 'Domain blacklist cannot be empty if Blacklist is enabled.' }, if: :domain_blacklist_enabled? validates_each :restricted_visibility_levels do |record, attr, value| diff --git a/app/views/admin/application_settings/_form.html.haml b/app/views/admin/application_settings/_form.html.haml index 35fea2d8fa9..23b52d08df7 100644 --- a/app/views/admin/application_settings/_form.html.haml +++ b/app/views/admin/application_settings/_form.html.haml @@ -125,7 +125,7 @@ .form-group = f.label :domain_whitelist, 'Whitelisted domains for sign-ups', class: 'control-label col-sm-2' .col-sm-10 - = f.text_area :domain_whitelist_raw, placeholder: 'domain.com', class: 'form-control' + = f.text_area :domain_whitelist_raw, placeholder: 'domain.com', class: 'form-control', rows: 8 .help-block ONLY users with e-mail addresses that match these domain(s) will be able to sign-up. Wildcards allowed. Use separate lines for multiple entries. Ex: domain.com, *.domain.com .form-group = f.label :domain_blacklist_enabled, 'Domain Blacklist', class: 'control-label col-sm-2' @@ -138,12 +138,12 @@ .col-sm-offset-2.col-sm-10 .radio = label_tag :blacklist_type_file do - = radio_button_tag :blacklist_type, :file, @application_setting.domain_blacklist.blank? + = radio_button_tag :blacklist_type, :file .option-title Upload blacklist file .radio = label_tag :blacklist_type_raw do - = radio_button_tag :blacklist_type, :raw, @application_setting.domain_blacklist.present? + = radio_button_tag :blacklist_type, :raw, @application_setting.domain_blacklist.present? || @application_setting.domain_blacklist.blank? .option-title Enter blacklist manually .form-group.blacklist-file @@ -154,7 +154,7 @@ .form-group.blacklist-raw = f.label :domain_blacklist, 'Blacklisted domains for sign-ups', class: 'control-label col-sm-2' .col-sm-10 - = f.text_area :domain_blacklist_raw, placeholder: 'domain.com', class: 'form-control', rows: 10 + = f.text_area :domain_blacklist_raw, placeholder: 'domain.com', class: 'form-control', rows: 8 .help-block Users with e-mail addresses that match these domain(s) will NOT be able to sign-up. Wildcards allowed. Use separate lines for multiple entries. Ex: domain.com, *.domain.com .form-group diff --git a/spec/fixtures/blacklist.txt b/spec/fixtures/domain_blacklist.txt index baeb11eda9a..baeb11eda9a 100644 --- a/spec/fixtures/blacklist.txt +++ b/spec/fixtures/domain_blacklist.txt diff --git a/spec/models/application_setting_spec.rb b/spec/models/application_setting_spec.rb index a780c04abde..fb040ba82bc 100644 --- a/spec/models/application_setting_spec.rb +++ b/spec/models/application_setting_spec.rb @@ -95,8 +95,18 @@ describe ApplicationSetting, models: true do expect(setting.domain_blacklist).to contain_exactly('example.com', '*.example.com') end + it 'set multiple domains with semicolon' do + setting.domain_blacklist_raw = "example.com; *.example.com" + expect(setting.domain_blacklist).to contain_exactly('example.com', '*.example.com') + end + + it 'set multiple domains with mixture of everything' do + setting.domain_blacklist_raw = "example.com; *.example.com\n test.com\sblock.com yes.com" + expect(setting.domain_blacklist).to contain_exactly('example.com', '*.example.com', 'test.com', 'block.com', 'yes.com') + end + it 'set multiple domain with file' do - setting.domain_blacklist_file = File.open(Rails.root.join('spec/fixtures/', 'blacklist.txt')) + setting.domain_blacklist_file = File.open(Rails.root.join('spec/fixtures/', 'domain_blacklist.txt')) expect(setting.domain_blacklist).to contain_exactly('example.com', 'test.com', 'foo.bar') end end diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index 41e531c684b..8dacd1db447 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -148,7 +148,7 @@ describe User, models: true do allow_any_instance_of(ApplicationSetting).to receive(:domain_blacklist).and_return(['example.com']) end - context 'when a signup domain is black listed' do + context 'when a signup domain is blacklisted' do it 'accepts info@test.com' do user = build(:user, email: 'info@test.com') expect(user).to be_valid @@ -160,7 +160,7 @@ describe User, models: true do end end - context 'when a signup domain is black listed but a wildcard subdomain is allowed' do + context 'when a signup domain is blacklisted but a wildcard subdomain is allowed' do before do allow_any_instance_of(ApplicationSetting).to receive(:domain_blacklist).and_return(['test.example.com']) allow_any_instance_of(ApplicationSetting).to receive(:domain_whitelist).and_return(['*.example.com']) |