From ba4e256662ad2f45319ab7c594f67fa227311237 Mon Sep 17 00:00:00 2001 From: Alex Sherman Date: Wed, 3 Jun 2020 17:07:19 +0500 Subject: [PATCH] Add test domains whitelist & fix tests --- Gemfile | 3 ++- app/models/nameserver.rb | 2 +- config/initializers/truemail.rb | 5 +++++ 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/Gemfile b/Gemfile index 46f507614..050c95ba0 100644 --- a/Gemfile +++ b/Gemfile @@ -15,8 +15,9 @@ gem 'paper_trail', '~> 10.3' gem 'pg', '1.2.2' # 1.8 is for Rails < 5.0 gem 'ransack', '~> 2.3' -gem 'validates_email_format_of', '1.6.3' # validates email against RFC 2822 and RFC 3696 gem 'truemail', '~> 1.7' # validates email by regexp, mail server existence and address existence +gem 'validates_email_format_of', '1.6.3' # validates email against RFC 2822 and RFC 3696 + # 0.7.3 is the latest for Rails 4.2, however, it is absent on Rubygems server # https://github.com/huacnlee/rails-settings-cached/issues/165 diff --git a/app/models/nameserver.rb b/app/models/nameserver.rb index 3ddf1d1c5..3e4051165 100644 --- a/app/models/nameserver.rb +++ b/app/models/nameserver.rb @@ -88,7 +88,7 @@ class Nameserver < ApplicationRecord end def normalize_attributes - self.hostname = hostname.try(:strip).try(:downcase) + self.hostname = hostname.try(:strip).try(:downcase).gsub(/\.$/, '') self.ipv4 = Array(ipv4).reject(&:blank?).map(&:strip) self.ipv6 = Array(ipv6).reject(&:blank?).map(&:strip).map(&:upcase) end diff --git a/config/initializers/truemail.rb b/config/initializers/truemail.rb index f43b73479..efcecd508 100644 --- a/config/initializers/truemail.rb +++ b/config/initializers/truemail.rb @@ -43,6 +43,11 @@ Truemail.configure do |config| # It is equal to empty array by default. # config.whitelisted_domains = [] + unless Rails.env.production? + config.whitelisted_domains = %w[bestnames.test goodnames.test example.com inbox.test mail.test + outlook.test invalid.test email.test] + end + # Optional parameter. With this option Truemail will validate email which contains whitelisted # domain only, i.e. if domain whitelisted, validation will passed to Regex, MX or SMTP validators. # Validation of email which not contains whitelisted domain always will return false.