Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 0a3c354

Browse files
author
nikobee
committedNov 20, 2023
AO3-6626 test all forbidden characters
1 parent 250b48f commit 0a3c354

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed
 

‎spec/models/tag_spec.rb

+10-6
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
expect(@fandom_tag.taggings_count).to eq 1
5050
end
5151

52-
it 'will start caching a when tag when that tag is used significantly' do
52+
it 'will start caching a tag when that tag is used significantly' do
5353
(1..ArchiveConfig.TAGGINGS_COUNT_MIN_CACHE_COUNT).each do |try|
5454
FactoryBot.create(:work, fandom_string: @fandom_tag.name)
5555
RedisJobSpawner.perform_now("TagCountUpdateJob")
@@ -168,11 +168,15 @@ def expect_tag_update_flag_in_redis_to_be(flag)
168168
expect(tag.errors[:name].join).to match(/too long/)
169169
end
170170

171-
it "should not be valid with disallowed characters" do
172-
tag = Tag.new
173-
tag.name = "bad<tag"
174-
expect(tag.save).to be_falsey
175-
expect(tag.errors[:name].join).to match(/restricted characters/)
171+
context "tags using restricted characters should not be saved" do
172+
BAD_TAGS.each do |tag|
173+
forbidden_tag = Tag.new
174+
forbidden_tag.name = tag
175+
it "is not saved and receives an error message about restricted characters" do
176+
expect(forbidden_tag.save).to be_falsey
177+
expect(forbidden_tag.errors[:name].join).to match(/restricted characters/)
178+
end
179+
end
176180
end
177181

178182
context "unwrangleable" do

‎spec/spec_helper.rb

+1
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@
137137
config.use_transactional_fixtures = true
138138

139139
BAD_EMAILS = ["Abc.example.com", "A@b@c@example.com", 'a\"b(c)d,e:f;g<h>i[j\k]l@example.com', 'this is"not\allowed@example.com', 'this\ still\"not/\/\allowed@example.com', "nodomain", "foo@oops", "ast*risk@example.com", "asterisk@ex*ample.com"].freeze
140+
BAD_TAGS = ["bad, tag", "also, bad", "no、good", "wild*card", "lesser<tag", "greater>tag", "^tag", "{open", "close}", "not=allowed", "suspicious`character", "no%maths"].freeze
140141
INVALID_URLS = %w[no_scheme.com ftp://ftp.address.com http://www.b@d!35.com https://www.b@d!35.com http://b@d!35.com https://www.b@d!35.com].freeze
141142
VALID_URLS = %w[http://rocksalt-recs.livejournal.com/196316.html https://rocksalt-recs.livejournal.com/196316.html].freeze
142143
INACTIVE_URLS = %w[https://www.iaminactive.com http://www.iaminactive.com https://iaminactive.com http://iaminactive.com].freeze

0 commit comments

Comments
 (0)
Please sign in to comment.