summaryrefslogtreecommitdiff
path: root/spec/validators
diff options
context:
space:
mode:
authorJames Edwards-Jones <jedwardsjones@gitlab.com>2018-12-05 20:14:09 +0000
committerJames Edwards-Jones <jedwardsjones@gitlab.com>2018-12-06 15:18:18 +0000
commit72c00594070dfd1a778c2e03ff400b478e6c3774 (patch)
treed8fd26536ef6c5e4a2e3ef02ea7785537d34d93b /spec/validators
parent8cd5004b350ef342f66956c11272dad1328f6526 (diff)
downloadgitlab-ce-72c00594070dfd1a778c2e03ff400b478e6c3774.tar.gz
Allow URLs to be validated as ascii_only
Restricts unicode characters and IDNA deviations which could be used in a phishing attack
Diffstat (limited to 'spec/validators')
-rw-r--r--spec/validators/url_validator_spec.rb29
1 files changed, 29 insertions, 0 deletions
diff --git a/spec/validators/url_validator_spec.rb b/spec/validators/url_validator_spec.rb
index 082d09d3f16..f3f3386382f 100644
--- a/spec/validators/url_validator_spec.rb
+++ b/spec/validators/url_validator_spec.rb
@@ -143,4 +143,33 @@ describe UrlValidator do
end
end
end
+
+ context 'when ascii_only is' do
+ let(:url) { 'https://𝕘itⅼαƄ.com/foo/foo.bar'}
+ let(:validator) { described_class.new(attributes: [:link_url], ascii_only: ascii_only) }
+
+ context 'true' do
+ let(:ascii_only) { true }
+
+ it 'prevents unicode characters' do
+ badge.link_url = url
+
+ subject
+
+ expect(badge.errors.empty?).to be false
+ end
+ end
+
+ context 'false (default)' do
+ let(:ascii_only) { false }
+
+ it 'does not prevent unicode characters' do
+ badge.link_url = url
+
+ subject
+
+ expect(badge.errors.empty?).to be true
+ end
+ end
+ end
end