Skip to content

Commit

Permalink
Merge pull request #271 from truemail-rb/develop
Browse files Browse the repository at this point in the history
Truemail v3.1.0
  • Loading branch information
bestwebua authored Oct 31, 2023
2 parents e36c009 + 1a2fd19 commit 3009794
Show file tree
Hide file tree
Showing 25 changed files with 219 additions and 201 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ defaults: &defaults
- image: cimg/ruby:<< parameters.ruby-version >>

orbs:
ruby: circleci/ruby@2.0.0
ruby: circleci/ruby@2.1.0

references:
bundle_install: &bundle_install
Expand Down
2 changes: 1 addition & 1 deletion .circleci/gemspecs/compatible
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Gem::Specification.new do |spec|
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
spec.require_paths = %w[lib]

spec.add_runtime_dependency 'net-smtp', '~> 0.3.3' if ::Gem::Version.new(::RUBY_VERSION) >= ::Gem::Version.new('3.1.0')
spec.add_runtime_dependency 'net-smtp', '~> 0.4.0' if ::Gem::Version.new(::RUBY_VERSION) >= ::Gem::Version.new('3.1.0')
spec.add_runtime_dependency 'simpleidn', '~> 0.2.1'

spec.add_development_dependency 'dns_mock'
Expand Down
20 changes: 10 additions & 10 deletions .circleci/gemspecs/latest
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,23 @@ Gem::Specification.new do |spec|
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
spec.require_paths = %w[lib]

spec.add_runtime_dependency 'net-smtp', '~> 0.3.3'
spec.add_runtime_dependency 'net-smtp', '~> 0.4.0'
spec.add_runtime_dependency 'simpleidn', '~> 0.2.1'

spec.add_development_dependency 'bundler-audit', '~> 0.9.1'
spec.add_development_dependency 'dns_mock', '~> 1.5', '>= 1.5.15'
spec.add_development_dependency 'dns_mock', '~> 1.5', '>= 1.5.16'
spec.add_development_dependency 'fasterer', '~> 0.10.1'
spec.add_development_dependency 'ffaker', '~> 2.21'
spec.add_development_dependency 'ffaker', '~> 2.23'
spec.add_development_dependency 'json_matchers', '~> 0.11.1'
spec.add_development_dependency 'pry-byebug', '~> 3.10', '>= 3.10.1'
spec.add_development_dependency 'rake', '~> 13.0', '>= 13.0.6'
spec.add_development_dependency 'rake', '~> 13.1'
spec.add_development_dependency 'reek', '~> 6.1', '>= 6.1.4'
spec.add_development_dependency 'rspec', '~> 3.12'
spec.add_development_dependency 'rubocop', '~> 1.54', '>= 1.54.2'
spec.add_development_dependency 'rubocop-performance', '~> 1.18'
spec.add_development_dependency 'rubocop-rspec', '~> 2.22'
spec.add_development_dependency 'rubocop', '~> 1.57', '>= 1.57.2'
spec.add_development_dependency 'rubocop-performance', '~> 1.19', '>= 1.19.1'
spec.add_development_dependency 'rubocop-rspec', '~> 2.25'
spec.add_development_dependency 'simplecov', '~> 0.22.0'
spec.add_development_dependency 'smtp_mock', '~> 1.3', '>= 1.3.4'
spec.add_development_dependency 'truemail-rspec', '~> 1.1'
spec.add_development_dependency 'webmock', '~> 3.18', '>= 3.18.1'
spec.add_development_dependency 'smtp_mock', '~> 1.3', '>= 1.3.5'
spec.add_development_dependency 'truemail-rspec', '~> 1.2'
spec.add_development_dependency 'webmock', '~> 3.19', '>= 3.19.1'
end
2 changes: 1 addition & 1 deletion .codeclimate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ checks:
plugins:
rubocop:
enabled: true
channel: rubocop-1-54
channel: rubocop-1-57
config:
file: .circleci/linter_configs/.rubocop.yml

Expand Down
5 changes: 3 additions & 2 deletions .reek.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ detectors:
exclude:
- Truemail::Validate::Smtp::Request#run
- Truemail::Validate::Smtp#run
- Truemail::Validate::Smtp#not_includes_user_not_found_errors?
- Truemail::Validate::Mx#hosts_from_cname_records
- Truemail::Configuration#logger=
- Truemail::Validate::Smtp::Request#initialize
Expand Down Expand Up @@ -55,7 +56,7 @@ detectors:

ControlParameter:
exclude:
- Truemail::GenerateEmailHelper#calculate_email_size
- Truemail::RspecHelper::GenerateEmail#calculate_email_size
- Truemail::Worker#success
- Truemail#raise_unless
- Truemail::Configuration#raise_unless
Expand All @@ -64,7 +65,7 @@ detectors:
FeatureEnvy:
exclude:
- Truemail::Validate::Smtp#not_includes_user_not_found_errors
- Truemail::GenerateEmailHelper#prepare_user_name
- Truemail::RspecHelper::GenerateEmail#prepare_user_name
- Truemail::ConfigurationHelper#create_configuration
- Truemail::Log::Serializer::Base#smtp_debug
- Truemail::Log::Serializer::Text#data_composer
Expand Down
14 changes: 12 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,16 @@

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).

## [3.1.0] - 2023.10.31

### Updated

- Updated runtime/development dependencies
- Updated gemspecs
- Updated RSpec helpers namespaces
- Updated `codeclimate`/`reek` configs
- Updated gem version

## [3.0.9] - 2023.07.19

### Fixed
Expand Down Expand Up @@ -356,8 +366,8 @@ Optimized DNS (MX) validation flow. Removed needless DNS request for case when c

### Updated

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

Expand Down
2 changes: 1 addition & 1 deletion lib/truemail/validate/smtp.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def success_response?

def not_includes_user_not_found_errors?
return false unless configuration.smtp_safe_check
result.smtp_debug.map(&:response).map(&:errors).all? do |errors|
result.smtp_debug.map { |request| request.response.errors }.all? do |errors|
next true unless errors.key?(:rcptto)
errors.slice(:rcptto).values.none? do |error|
configuration.smtp_error_body_pattern.match?(error)
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 = '3.0.9'
VERSION = '3.1.0'
end
6 changes: 3 additions & 3 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@

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.include Truemail::RspecHelper::Context
config.include Truemail::RspecHelper::Dns
config.include Truemail::RspecHelper::Ipify
config.order = :random
config.example_status_persistence_file_path = '.rspec_status'
config.disable_monkey_patching!
Expand Down
55 changes: 55 additions & 0 deletions spec/support/helpers/context.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# frozen_string_literal: true

module Truemail
module RspecHelper
module Context
NON_ASCII_WORDS = %w[mañana ĉapelo dấu παράδειγμα 屋企].freeze

def random_email
ffaker.email
end

def random_uniq_email
ffaker.unique.email
end

def random_internationalized_email
"#{ffaker.user_name}@#{Truemail::RspecHelper::Context::NON_ASCII_WORDS.sample}.#{ffaker.domain_suffix}"
end

def random_ip_address
ffaker.ip_v4_address
end

def random_domain_name
ffaker.domain_name
end

def random_uniq_domain_name
ffaker.unique.domain_name
end

def rdns_lookup_host_address(host_address)
DnsMock::Representer::RdnsLookup.call(host_address)
end

def domain_from_email(email)
email[Truemail::RegexConstant::REGEX_DOMAIN_FROM_EMAIL, 1]
end

def email_punycode_domain(email)
DnsMock::Representer::Punycode.call(domain_from_email(email))
end

def attempts_getter
->(smtp_request_instance) { smtp_request_instance.send(:attempts) }
end

private

def ffaker
FFaker::Internet
end
end
end
end
53 changes: 0 additions & 53 deletions spec/support/helpers/context_helper.rb

This file was deleted.

20 changes: 20 additions & 0 deletions spec/support/helpers/dns.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# frozen_string_literal: true

module Truemail
module RspecHelper
module Dns
LOCALHOST_IP_ADDRESS = '127.0.0.1'

def dns_mock_gateway
["#{Truemail::RspecHelper::Dns::LOCALHOST_IP_ADDRESS}:#{dns_mock_server.port}"]
end

def dns_mock_records_by_email(email, dimension: 1)
mx_records = ::Array.new(dimension) { random_domain_name }
a_records = ::Array.new(dimension) { [Truemail::RspecHelper::Dns::LOCALHOST_IP_ADDRESS] }
mx_records_dns_mock = mx_records.zip(a_records).to_h.transform_values { |value| { a: value } }
{ domain_from_email(email) => { mx: mx_records } }.merge(mx_records_dns_mock)
end
end
end
end
18 changes: 0 additions & 18 deletions spec/support/helpers/dns_helper.rb

This file was deleted.

71 changes: 71 additions & 0 deletions spec/support/helpers/generate_email.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# frozen_string_literal: true

module Truemail
module RspecHelper
class GenerateEmail
def self.call(**options)
new(**options).call
end

def initialize(size: :auto, symbols: %w[- _ . +], invalid_email_with: [])
@size = calculate_email_size(size)
@symbols = symbols
@invalid_symbols = invalid_email_with
user_name
end

def call
"#{user_name}@#{('a'..'z').zip(0..Float::INFINITY).flatten.shuffle.sample[0]}.#{('aa'..'zz').to_a.sample}"
end

private

attr_reader :size, :symbols, :invalid_symbols

def calculate_email_size(size)
case size
when :auto then rand(15..250)
when :min then 1
when :max then 250
when :out_of_range then rand(251..300)
end
end

def sample_size
symbols_size = symbols.size
invalid_symbols_size = invalid_symbols.size
size < (symbols_size + invalid_symbols_size + 1) ? 1 : size - symbols_size - invalid_symbols_size - 1
end

def invalid_symbols_empty?
invalid_symbols.empty?
end

def size_one?
size == 1
end

def user_name
@user_name ||=
if size_one? && !invalid_symbols_empty?
invalid_symbols.sample
elsif size_one? && invalid_symbols_empty?
('a'..'z').to_a.sample
else
prepare_user_name(randomizer)
end
end

def randomizer # rubocop:disable Metrics/AbcSize
(
('Aa'..'Zz').to_a.shuffle.join.chars.sample(sample_size).push(*symbols.shuffle) << rand(0..9)
).shuffle.push(*invalid_symbols.sample(size)).shuffle[0...size]
end

def prepare_user_name(sample)
sample.rotate!(1) while symbols.include?(sample.first)
sample.join
end
end
end
end
Loading

0 comments on commit 3009794

Please sign in to comment.