Skip to content

Commit

Permalink
Technical/Move Truemail::Validator::Result#domain assigning to Domain…
Browse files Browse the repository at this point in the history
…ListMatch layer (#174)

* Updated Truemail::Validate::DomainListMatch#email_domain, tests
* Updated Truemail::Validate::Mx#domain, tests
* Added Truemail::DnsHelper#dns_mock_gateway, tests
* Updated tests with new test helper
* Updated gem development dependencies
* Updated rubocop/codeclimate configs
* Updated gem version, changelog
  • Loading branch information
bestwebua authored Aug 20, 2021
1 parent d2c143a commit eeda011
Show file tree
Hide file tree
Showing 15 changed files with 113 additions and 64 deletions.
2 changes: 1 addition & 1 deletion .codeclimate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ checks:
plugins:
rubocop:
enabled: true
channel: rubocop-1-18
channel: rubocop-1-19

reek:
enabled: true
6 changes: 6 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,9 @@ Style/MultilineInPatternThen:
Style/QuotedSymbols:
Enabled: true

Style/RedundantSelfAssignmentBranch:
Enabled: true

Layout/LineLength:
Max: 140

Expand Down Expand Up @@ -326,6 +329,9 @@ Lint/TripleQuotes:
Lint/EmptyInPattern:
Enabled: true

Lint/AmbiguousRange:
Enabled: true

Gemspec/DateAssignment:
Enabled: true

Expand Down
11 changes: 10 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@

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.9] - 2021.08.20

### Updated

- Updated `Truemail::Validate::DomainListMatch#email_domain`, tests
- Updated `Truemail::Validate::Mx#domain`, tests
- Updated gem development dependencies
- Updated gem version

## [2.4.8] - 2021.08.12

### Updated
Expand All @@ -18,7 +27,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
### Updated

- Updated gem codebase, refactored `Truemail::ContextHelper`
- Updated tests
- Updated tests with `Truemail::DnsHelper#dns_mock_gateway`
- Updated gem development dependencies
- Updated gem version

Expand Down
32 changes: 15 additions & 17 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
truemail (2.4.8)
truemail (2.4.9)
simpleidn (~> 0.2.1)

GEM
Expand All @@ -20,13 +20,13 @@ GEM
crack (0.4.5)
rexml
diff-lcs (1.4.4)
dns_mock (1.4.0)
dns_mock (1.4.1)
simpleidn (~> 0.2.1)
docile (1.4.0)
fasterer (0.9.0)
colorize (~> 0.7)
ruby_parser (>= 3.14.1)
ffaker (2.18.0)
ffaker (2.19.0)
hashdiff (1.0.1)
iniparse (1.5.0)
json (2.5.1)
Expand All @@ -48,14 +48,12 @@ GEM
pry-byebug (3.9.0)
byebug (~> 11.0)
pry (~> 0.13.0)
psych (4.0.1)
public_suffix (4.0.6)
rainbow (3.0.0)
rake (13.0.6)
reek (6.0.5)
reek (6.0.6)
kwalify (~> 0.7.0)
parser (~> 3.0.0)
psych (>= 3.1, < 5.0)
rainbow (>= 2.0, < 4.0)
regexp_parser (2.1.1)
rexml (3.2.5)
Expand All @@ -72,18 +70,18 @@ GEM
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.10.0)
rspec-support (3.10.2)
rubocop (1.18.4)
rubocop (1.19.1)
parallel (~> 1.10)
parser (>= 3.0.0.0)
rainbow (>= 2.2.2, < 4.0)
regexp_parser (>= 1.8, < 3.0)
rexml
rubocop-ast (>= 1.8.0, < 2.0)
rubocop-ast (>= 1.9.1, < 2.0)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 1.4.0, < 3.0)
rubocop-ast (1.9.1)
rubocop-ast (1.10.0)
parser (>= 3.0.1.1)
rubocop-performance (1.11.4)
rubocop-performance (1.11.5)
rubocop (>= 1.7.0, < 2.0)
rubocop-ast (>= 0.4.0)
rubocop-rspec (2.4.0)
Expand Down Expand Up @@ -118,24 +116,24 @@ PLATFORMS
x86_64-darwin-20

DEPENDENCIES
bundler (~> 2.2, >= 2.2.25)
bundler (~> 2.2, >= 2.2.26)
bundler-audit (~> 0.8.0)
dns_mock (~> 1.4)
dns_mock (~> 1.4, >= 1.4.1)
fasterer (~> 0.9.0)
ffaker (~> 2.18)
ffaker (~> 2.19)
json_matchers (~> 0.11.1)
overcommit (~> 0.58.0)
pry-byebug (~> 3.9)
rake (~> 13.0, >= 13.0.6)
reek (~> 6.0, >= 6.0.5)
reek (~> 6.0, >= 6.0.6)
rspec (~> 3.10)
rubocop (~> 1.18, >= 1.18.4)
rubocop-performance (~> 1.11, >= 1.11.4)
rubocop (~> 1.19, >= 1.19.1)
rubocop-performance (~> 1.11, >= 1.11.5)
rubocop-rspec (~> 2.4)
simplecov (~> 0.17.1)
truemail!
truemail-rspec (~> 0.7.0)
webmock (~> 3.14)

BUNDLED WITH
2.2.25
2.2.26
3 changes: 2 additions & 1 deletion lib/truemail/validate/domain_list_match.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ def run
private

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

def whitelisted_domain?
Expand Down
5 changes: 1 addition & 4 deletions lib/truemail/validate/mx.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,7 @@ def mail_servers_found?
end

def domain
@domain ||= begin
result.domain = result.email[Truemail::RegexConstant::REGEX_DOMAIN_FROM_EMAIL, 1]
result.punycode_email[Truemail::RegexConstant::REGEX_DOMAIN_FROM_EMAIL, 1]
end
@domain ||= result.punycode_email[Truemail::RegexConstant::REGEX_DOMAIN_FROM_EMAIL, 1]
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.8'
VERSION = '2.4.9'
end
1 change: 1 addition & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
RSpec::Mocks.configuration.allow_message_expectations_on_nil = true
RSpec.configure do |config|
config.include Truemail::ContextHelper
config.include Truemail::DnsHelper
config.include Truemail::IpifyHelper
config.order = :random
config.example_status_persistence_file_path = '.rspec_status'
Expand Down
11 changes: 11 additions & 0 deletions spec/support/helpers/dns_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# frozen_string_literal: true

module Truemail
module DnsHelper
LOCALHOST_IP_ADDRESS = '127.0.0.1'

def dns_mock_gateway
["#{Truemail::DnsHelper::LOCALHOST_IP_ADDRESS}:#{dns_mock_server.port}"]
end
end
end
13 changes: 13 additions & 0 deletions spec/support/helpers/dns_helper_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# frozen_string_literal: true

RSpec.describe Truemail::DnsHelper, type: :helper do # rubocop:disable RSpec/FilePath
describe 'defined constants' do
specify { expect(described_class).to be_const_defined(:LOCALHOST_IP_ADDRESS) }
end

describe '#dns_mock_gateway' do
specify do
expect(dns_mock_gateway).to eq(["#{described_class::LOCALHOST_IP_ADDRESS}:#{dns_mock_server.port}"])
end
end
end
2 changes: 1 addition & 1 deletion spec/truemail/audit/dns_spec.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

RSpec.describe Truemail::Audit::Dns do
let(:configuration_instance) { create_configuration(dns: ["127.0.0.1:#{dns_mock_server.port}"]) }
let(:configuration_instance) { create_configuration(dns: dns_mock_gateway) }
let(:verifier_domain) { configuration_instance.verifier_domain }
let(:current_host_ip) { random_ip_address }
let(:result_instance) { create_auditor(current_host_ip: current_host_ip, configuration: configuration_instance).result }
Expand Down
2 changes: 1 addition & 1 deletion spec/truemail/audit/ptr_spec.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

RSpec.describe Truemail::Audit::Ptr do
let(:configuration_instance) { create_configuration(dns: ["127.0.0.1:#{dns_mock_server.port}"]) }
let(:configuration_instance) { create_configuration(dns: dns_mock_gateway) }
let(:verifier_domain) { configuration_instance.verifier_domain }
let(:current_host_ip) { random_ip_address }
let(:result_instance) { create_auditor(current_host_ip: current_host_ip, configuration: configuration_instance).result }
Expand Down
44 changes: 36 additions & 8 deletions spec/truemail/validate/domain_list_match_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,34 +28,48 @@
specify do
allow(configuration_instance).to receive(:whitelisted_domains).and_return([domain])
allow(configuration_instance).to receive(:blacklisted_domains).and_return([])
expect { domain_list_match_validator }.to change(result_instance, :success).from(nil).to(true)
expect { domain_list_match_validator }
.to change(result_instance, :success)
.from(nil).to(true)
.and change(result_instance, :domain)
.from(nil).to(domain_from_email(email))
end
end

context 'when email domain in black list' do
specify do
allow(configuration_instance).to receive(:whitelisted_domains).and_return([])
allow(configuration_instance).to receive(:blacklisted_domains).and_return([domain])
expect { domain_list_match_validator }.to change(result_instance, :success)
expect { domain_list_match_validator }
.to change(result_instance, :success)
.from(nil).to(false)
.and change(result_instance, :errors)
.from({}).to(domain_list_match: Truemail::Validate::DomainListMatch::ERROR)
.and change(result_instance, :domain)
.from(nil).to(domain_from_email(email))
end
end

context 'when email domain exists on both lists' do
specify do
allow(configuration_instance).to receive(:whitelisted_domains).and_return([domain])
allow(configuration_instance).to receive(:blacklisted_domains).and_return([domain])
expect { domain_list_match_validator }.to change(result_instance, :success).from(nil).to(true)
expect { domain_list_match_validator }
.to change(result_instance, :success)
.from(nil).to(true)
.and change(result_instance, :domain)
.from(nil).to(domain_from_email(email))
end
end

context 'when email domain exists not on both lists' do
specify do
allow(configuration_instance).to receive(:whitelisted_domains).and_return([])
allow(configuration_instance).to receive(:blacklisted_domains).and_return([])
expect { domain_list_match_validator }.not_to change(result_instance, :success)
expect { domain_list_match_validator }
.to not_change(result_instance, :success)
.and change(result_instance, :domain)
.from(nil).to(domain_from_email(email))
end
end
end
Expand All @@ -67,16 +81,24 @@
before { allow(configuration_instance).to receive(:whitelisted_domains).and_return([domain]) }

context 'when email domain in white list' do
specify { expect { domain_list_match_validator }.not_to change(result_instance, :success) }
specify do
expect { domain_list_match_validator }
.to not_change(result_instance, :success)
.and change(result_instance, :domain)
.from(nil).to(domain_from_email(email))
end
end

context 'when email domain exists on both lists' do
specify do
allow(configuration_instance).to receive(:blacklisted_domains).and_return([domain])
expect { domain_list_match_validator }.to change(result_instance, :success)
expect { domain_list_match_validator }
.to change(result_instance, :success)
.from(nil).to(false)
.and change(result_instance, :errors)
.from({}).to(domain_list_match: Truemail::Validate::DomainListMatch::ERROR)
.and change(result_instance, :domain)
.from(nil).to(domain_from_email(email))
end
end
end
Expand All @@ -87,20 +109,26 @@
context 'when email domain in black list' do
specify do
allow(configuration_instance).to receive(:blacklisted_domains).and_return([domain])
expect { domain_list_match_validator }.to change(result_instance, :success)
expect { domain_list_match_validator }
.to change(result_instance, :success)
.from(nil).to(false)
.and change(result_instance, :errors)
.from({}).to(domain_list_match: Truemail::Validate::DomainListMatch::ERROR)
.and change(result_instance, :domain)
.from(nil).to(domain_from_email(email))
end
end

context 'when email domain not exists on both lists' do
specify do
allow(configuration_instance).to receive(:blacklisted_domains).and_return([])
expect { domain_list_match_validator }.to change(result_instance, :success)
expect { domain_list_match_validator }
.to change(result_instance, :success)
.from(nil).to(false)
.and change(result_instance, :errors)
.from({}).to(domain_list_match: Truemail::Validate::DomainListMatch::ERROR)
.and change(result_instance, :domain)
.from(nil).to(domain_from_email(email))
end
end
end
Expand Down
Loading

0 comments on commit eeda011

Please sign in to comment.