Skip to content

Commit

Permalink
Technical/Refactor codebase (#162)
Browse files Browse the repository at this point in the history
* Removed Truemail::RegexConstant::REGEX_DOMAIN_FROM_EMAIL
* Updated Truemail::Validate::Mx
* Updated gem development dependencies
* Updated gem version
  • Loading branch information
bestwebua authored Jul 9, 2021
1 parent 1439d71 commit f63b1f9
Show file tree
Hide file tree
Showing 12 changed files with 49 additions and 39 deletions.
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,18 @@

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [2.4.5] - 2021.07.09

### Removed

- `Truemail::RegexConstant::REGEX_DOMAIN_FROM_EMAIL`

### Updated

- `Truemail::Validate::Mx`
- Updated gem development dependencies
- Updated gem version

## [2.4.4] - 2021.06.29

### Updated
Expand Down
26 changes: 13 additions & 13 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
PATH
remote: .
specs:
truemail (2.4.4)
truemail (2.4.5)
simpleidn (~> 0.2.1)

GEM
remote: https://rubygems.org/
specs:
addressable (2.7.0)
addressable (2.8.0)
public_suffix (>= 2.0.2, < 5.0)
ast (2.4.2)
bundler-audit (0.8.0)
Expand All @@ -21,7 +21,7 @@ GEM
crack (0.4.5)
rexml
diff-lcs (1.4.4)
dns_mock (1.3.0)
dns_mock (1.3.1)
docile (1.4.0)
faker (2.18.0)
i18n (>= 1.6, < 2)
Expand All @@ -43,7 +43,7 @@ GEM
iniparse (~> 1.4)
rexml (~> 3.2)
parallel (1.20.1)
parser (3.0.1.1)
parser (3.0.2.0)
ast (~> 2.4.1)
pry (0.13.1)
coderay (~> 1.1)
Expand All @@ -54,7 +54,7 @@ GEM
psych (3.3.2)
public_suffix (4.0.6)
rainbow (3.0.0)
rake (13.0.3)
rake (13.0.6)
reek (6.0.4)
kwalify (~> 0.7.0)
parser (~> 3.0.0)
Expand All @@ -75,7 +75,7 @@ GEM
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.10.0)
rspec-support (3.10.2)
rubocop (1.18.0)
rubocop (1.18.3)
parallel (~> 1.10)
parser (>= 3.0.0.0)
rainbow (>= 2.2.2, < 4.0)
Expand All @@ -86,7 +86,7 @@ GEM
unicode-display_width (>= 1.4.0, < 3.0)
rubocop-ast (1.7.0)
parser (>= 3.0.1.1)
rubocop-performance (1.11.3)
rubocop-performance (1.11.4)
rubocop (>= 1.7.0, < 2.0)
rubocop-ast (>= 0.4.0)
rubocop-rspec (2.4.0)
Expand Down Expand Up @@ -121,24 +121,24 @@ PLATFORMS
x86_64-darwin-20

DEPENDENCIES
bundler (~> 2.2, >= 2.2.21)
bundler (~> 2.2, >= 2.2.23)
bundler-audit (~> 0.8.0)
dns_mock (~> 1.3)
dns_mock (~> 1.3, >= 1.3.1)
faker (~> 2.18)
fasterer (~> 0.9.0)
json_matchers (~> 0.11.1)
overcommit (~> 0.58.0)
pry-byebug (~> 3.9)
rake (~> 13.0, >= 13.0.3)
rake (~> 13.0, >= 13.0.6)
reek (~> 6.0, >= 6.0.4)
rspec (~> 3.10)
rubocop (~> 1.18)
rubocop-performance (~> 1.11, >= 1.11.3)
rubocop (~> 1.18, >= 1.18.3)
rubocop-performance (~> 1.11, >= 1.11.4)
rubocop-rspec (~> 2.4)
simplecov (~> 0.17.1)
truemail!
truemail-rspec (~> 0.6)
webmock (~> 3.13)

BUNDLED WITH
2.2.21
2.2.23
1 change: 0 additions & 1 deletion lib/truemail/core.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ module RegexConstant
REGEX_DOMAIN = /[\p{L}0-9]+([\-.]{1}[\p{L}0-9]+)*\.\p{L}{2,63}/i.freeze
REGEX_EMAIL_PATTERN = /(?=\A.{6,255}\z)(\A([\p{L}0-9]+[\W\w]*)@(#{REGEX_DOMAIN})\z)/.freeze
REGEX_DOMAIN_PATTERN = /(?=\A.{4,255}\z)(\A#{REGEX_DOMAIN}\z)/.freeze
REGEX_DOMAIN_FROM_EMAIL = /\A.+@(.+)\z/.freeze
REGEX_SMTP_ERROR_BODY_PATTERN = /(?=.*550)(?=.*(user|account|customer|mailbox)).*/i.freeze
REGEX_IP_ADDRESS = /((1\d|[1-9]|2[0-4])?\d|25[0-5])(\.\g<1>){3}/.freeze
REGEX_IP_ADDRESS_PATTERN = /\A#{REGEX_IP_ADDRESS}\z/.freeze
Expand Down
2 changes: 1 addition & 1 deletion lib/truemail/validate/domain_list_match.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def run
private

def email_domain
@email_domain ||= result.email[Truemail::RegexConstant::REGEX_DOMAIN_FROM_EMAIL, 1]
@email_domain ||= result.email[Truemail::RegexConstant::REGEX_EMAIL_PATTERN, 3]
end

def whitelisted_domain?
Expand Down
6 changes: 4 additions & 2 deletions lib/truemail/validate/mx.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ class Mx < Truemail::Validate::Base

def run
return false unless Truemail::Validate::Regex.check(result)
result.domain = result.punycode_email[Truemail::RegexConstant::REGEX_DOMAIN_FROM_EMAIL, 1]
return true if success(mx_lookup && domain_not_include_null_mx)
mail_servers.clear && add_error(Truemail::Validate::Mx::ERROR)
false
Expand Down Expand Up @@ -53,7 +52,10 @@ def mail_servers_found?
end

def domain
result.domain
@domain ||= begin
result.domain = result.email[Truemail::RegexConstant::REGEX_EMAIL_PATTERN, 3]
result.punycode_email[Truemail::RegexConstant::REGEX_EMAIL_PATTERN, 3]
end
end

def hosts_from_mx_records?
Expand Down
2 changes: 1 addition & 1 deletion lib/truemail/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module Truemail
VERSION = '2.4.4'
VERSION = '2.4.5'
end
4 changes: 4 additions & 0 deletions spec/support/helpers/context_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ def random_uniq_domain_name
faker.unique.domain_name
end

def rdns_lookup_host_address(host_address)
host_address.gsub(/(\d+).(\d+).(\d+).(\d+)/, '\4.\3.\2.\1.in-addr.arpa')
end

private

def faker
Expand Down
6 changes: 6 additions & 0 deletions spec/support/helpers/context_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,10 @@
expect(random_ip_address).to match(Truemail::RegexConstant::REGEX_DNS_SERVER_ADDRESS_PATTERN)
end
end

describe '#rdns_lookup_host_address' do
specify do
expect(rdns_lookup_host_address('10.20.30.40')).to eq('40.30.20.10.in-addr.arpa')
end
end
end
10 changes: 0 additions & 10 deletions spec/truemail/core_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
specify { expect(described_class).to be_const_defined(:REGEX_DOMAIN) }
specify { expect(described_class).to be_const_defined(:REGEX_EMAIL_PATTERN) }
specify { expect(described_class).to be_const_defined(:REGEX_DOMAIN_PATTERN) }
specify { expect(described_class).to be_const_defined(:REGEX_DOMAIN_FROM_EMAIL) }
specify { expect(described_class).to be_const_defined(:REGEX_SMTP_ERROR_BODY_PATTERN) }
specify { expect(described_class).to be_const_defined(:REGEX_IP_ADDRESS) }
specify { expect(described_class).to be_const_defined(:REGEX_IP_ADDRESS_PATTERN) }
Expand Down Expand Up @@ -140,15 +139,6 @@
end
end

describe 'Truemail::RegexConstant::REGEX_DOMAIN_FROM_EMAIL' do
subject(:regex_pattern) { described_class::REGEX_DOMAIN_FROM_EMAIL }

let(:email) { 'i@domain' }

specify { expect(regex_pattern.match?(email)).to be(true) }
specify { expect(email[regex_pattern, 1]).to eq('domain') }
end

describe 'Truemail::RegexConstant::REGEX_SMTP_ERROR_BODY_PATTERN' do
subject(:regex_pattern) { described_class::REGEX_SMTP_ERROR_BODY_PATTERN }

Expand Down
7 changes: 2 additions & 5 deletions spec/truemail/dns/worker_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,9 @@ def dns_resolver_worker_instance
end

describe '#ptr_records' do
subject(:resolve_ptr_records) { dns_resolver_worker_instance.ptr_records(host_address) }
subject(:resolve_ptr_records) { dns_resolver_worker_instance.ptr_records(rdns_lookup_host_address(host_address)) }

# TODO: change it after update dns_mock
# let(:host_address) { random_ip_address }
# should works with 42.42.42.42 or 42.42.42.42.in-addr.arpa; request for 42.42.42.42
let(:host_address) { '42.42.42.42.in-addr.arpa' }
let(:host_address) { random_ip_address }
let(:ptr_records) { ::Array.new(2) { random_domain_name } }

before { dns_mock_server.assign_mocks(host_address => { ptr: ptr_records }) }
Expand Down
2 changes: 1 addition & 1 deletion spec/truemail/validate/domain_list_match_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
subject(:domain_list_match_validator) { described_class.check(result_instance) }

let(:email) { random_email }
let(:domain) { email[Truemail::RegexConstant::REGEX_DOMAIN_FROM_EMAIL, 1] }
let(:domain) { email[Truemail::RegexConstant::REGEX_EMAIL_PATTERN, 3] }
let(:configuration_instance) { create_configuration }
let(:result_instance) { Truemail::Validator::Result.new(email: email, configuration: configuration_instance) }

Expand Down
10 changes: 5 additions & 5 deletions truemail.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,19 @@ Gem::Specification.new do |spec|

spec.add_runtime_dependency 'simpleidn', '~> 0.2.1'

spec.add_development_dependency 'bundler', '~> 2.2', '>= 2.2.21'
spec.add_development_dependency 'bundler', '~> 2.2', '>= 2.2.23'
spec.add_development_dependency 'bundler-audit', '~> 0.8.0'
spec.add_development_dependency 'dns_mock', '~> 1.3'
spec.add_development_dependency 'dns_mock', '~> 1.3', '>= 1.3.1'
spec.add_development_dependency 'faker', '~> 2.18'
spec.add_development_dependency 'fasterer', '~> 0.9.0'
spec.add_development_dependency 'json_matchers', '~> 0.11.1'
spec.add_development_dependency 'overcommit', '~> 0.58.0'
spec.add_development_dependency 'pry-byebug', '~> 3.9'
spec.add_development_dependency 'rake', '~> 13.0', '>= 13.0.3'
spec.add_development_dependency 'rake', '~> 13.0', '>= 13.0.6'
spec.add_development_dependency 'reek', '~> 6.0', '>= 6.0.4'
spec.add_development_dependency 'rspec', '~> 3.10'
spec.add_development_dependency 'rubocop', '~> 1.18'
spec.add_development_dependency 'rubocop-performance', '~> 1.11', '>= 1.11.3'
spec.add_development_dependency 'rubocop', '~> 1.18', '>= 1.18.3'
spec.add_development_dependency 'rubocop-performance', '~> 1.11', '>= 1.11.4'
spec.add_development_dependency 'rubocop-rspec', '~> 2.4'
spec.add_development_dependency 'simplecov', '~> 0.17.1'
spec.add_development_dependency 'truemail-rspec', '~> 0.6'
Expand Down

0 comments on commit f63b1f9

Please sign in to comment.