Merge pull request #49 from benbalter/better-blacklisting

Better blacklist support through regex
This commit is contained in:
Aidan Feldman 2014-04-14 19:14:32 -04:00
commit 6da1bcba05
2 changed files with 3 additions and 3 deletions

View File

@ -125,7 +125,7 @@ module Swot
# These are domains that snuck into the edu registry,
# but don't pass the education sniff test
# Note: domain must be a direct match
# Note: validated domain must not end with the blacklisted string
BLACKLIST = [
'si.edu',
]
@ -142,7 +142,7 @@ module Swot
domain = get_domain(text)
return false if domain.nil?
if BLACKLIST.include? domain.name
if BLACKLIST.any? { |d| domain.name =~ /(\A|\.)#{Regexp.escape(d)}\z/ }
false
elsif ACADEMIC_TLDS[domain.tld]
true

View File

@ -60,7 +60,7 @@ class TestEmail < Test::Unit::TestCase
end
should "fail blacklisted domains" do
["si.edu", " si.edu ", "imposter@si.edu"].each do |domain|
["si.edu", " si.edu ", "imposter@si.edu", "foo.si.edu"].each do |domain|
assert_equal false, Swot::is_academic?(domain), "#{domain} should be denied"
end
end