From 167cad2d169015112a05008e47c0fc6e26b9841b Mon Sep 17 00:00:00 2001 From: Lawrence Chou Date: Tue, 2 Nov 2021 10:19:35 +0800 Subject: [PATCH] feat(ruby): add add_custom_domains --- platform/ruby/mail_checker.rb | 6 ++++++ platform/ruby/mail_checker.tmpl.rb | 6 ++++++ test/platform.ruby.test.rb | 12 ++++++++++++ 3 files changed, 24 insertions(+) diff --git a/platform/ruby/mail_checker.rb b/platform/ruby/mail_checker.rb index fe8238d2..68c83254 100644 --- a/platform/ruby/mail_checker.rb +++ b/platform/ruby/mail_checker.rb @@ -17,6 +17,12 @@ def self.blacklisted?(email) extract_all_domain_suffixes(email).any? { |domain| BLACKLIST.include?(domain) } end + def self.add_custom_domains(domains) + domains.each do |domain| + BLACKLIST.add(domain) + end + end + def self.extract_all_domain_suffixes(email) domain = email.to_s.gsub(/.+@([^.]+)/, '\1').downcase diff --git a/platform/ruby/mail_checker.tmpl.rb b/platform/ruby/mail_checker.tmpl.rb index 2812658e..39fedec7 100644 --- a/platform/ruby/mail_checker.tmpl.rb +++ b/platform/ruby/mail_checker.tmpl.rb @@ -17,6 +17,12 @@ def self.blacklisted?(email) extract_all_domain_suffixes(email).any? { |domain| BLACKLIST.include?(domain) } end + def self.add_custom_domains(domains) + domains.each do |domain| + BLACKLIST.add(domain) + end + end + def self.extract_all_domain_suffixes(email) domain = email.to_s.gsub(/.+@([^.]+)/, '\1').downcase diff --git a/test/platform.ruby.test.rb b/test/platform.ruby.test.rb index d6faf156..16bba7aa 100644 --- a/test/platform.ruby.test.rb +++ b/test/platform.ruby.test.rb @@ -60,4 +60,16 @@ def test_extract_all_domain_suffixes expected = %w(sub.example.org example.org org) assert_equal expected, MailChecker.extract_all_domain_suffixes('test@sub.example.org') end + + def test_add_custom_domains + valid!('foo@youtube.com') + valid!('foo@google.com') + valid!('ok@gmail.com') + + MailChecker.add_custom_domains(['youtube.com', 'google.com']) + + invalid!('foo@youtube.com') + invalid!('foo@google.com') + valid!('ok@gmail.com') + end end