Skip to content

Commit

Permalink
Bugfix/UndefinedConversionError in ValidatorJson (#121)
Browse files Browse the repository at this point in the history
* Updated Truemail::Log::Serializer::Base
* Updated Truemail::Log::Serializer::ValidatorBase
* Refactored Truemail::Configuration
* Updated gem development depemdencies
* Updated linters/codeclimate configs
* Updated JSON auditor/validator schemas
* Updated gem version, changelog
  • Loading branch information
bestwebua authored Dec 6, 2020
1 parent a72374f commit 235e2e8
Show file tree
Hide file tree
Showing 26 changed files with 210 additions and 74 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-3
channel: rubocop-1-5

reek:
enabled: true
1 change: 1 addition & 0 deletions .reek.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ detectors:
- Truemail::Configuration#domain_matcher
- Truemail::Configuration#logger_options
- Truemail::Log::Serializer::Base#errors
- Truemail::Log::Serializer::ValidatorBase#replace_invalid_chars

ControlParameter:
exclude:
Expand Down
18 changes: 18 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,9 @@ Style/NilLambda:
Style/SwapValues:
Enabled: true

Style/RedundantArgument:
Enabled: true

Layout/LineLength:
Max: 140

Expand Down Expand Up @@ -260,6 +263,9 @@ Lint/ToEnumArguments:
Lint/UnmodifiedReduceAccumulator:
Enabled: true

Lint/UnexpectedBlockArity:
Enabled: true

Performance/AncestorsInclude:
Enabled: true

Expand Down Expand Up @@ -287,6 +293,18 @@ Performance/StringInclude:
Performance/Sum:
Enabled: true

Performance/BlockGivenWithExplicitBlock:
Enabled: true

Performance/CollectionLiteralInLoop:
Enabled: true

Performance/ConstantRegexp:
Enabled: true

Performance/MethodObjectAsBlock:
Enabled: true

RSpec/ExampleLength:
Enabled: false

Expand Down
17 changes: 17 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,23 @@

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.2.1] - 2020.12.06

### Fixed

- Filter out ASCII-8BIT chars for serialized SMTP response errors. Fixed `Encoding::UndefinedConversionError` in `Truemail::Log::Serializer::ValidatorJson#serialize`. Thanks to [@eni9889](https://github.com/eni9889) for report
- Added missed `smtp_fail_fast` attribute to serialized validator and auditor results

### Added

- Added `Truemail::Log::Serializer::ValidatorBase#replace_invalid_chars`

### Changed

- Updated `Truemail::Log::Serializer::Base`
- Updated `Truemail::Log::Serializer::ValidatorBase`
- Updated gem development dependencies

## [2.2.0] - 2020.12.01

Ability to use fail fast behaviour for SMTP validation layer. When `smtp_fail_fast = true` it means that `truemail` ends smtp validation session after first attempt on the first mx server in any fail cases (network connection/timeout error, smtp validation error). This feature helps to reduce total time of SMTP validation session up to 1 second.
Expand Down
43 changes: 24 additions & 19 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
truemail (2.2.0)
truemail (2.2.1)
simpleidn (~> 0.1.1)

GEM
Expand All @@ -15,12 +15,16 @@ GEM
childprocess (4.0.0)
coderay (1.1.3)
colorize (0.8.1)
concurrent-ruby (1.1.7)
diff-lcs (1.4.4)
docile (1.3.2)
faker (2.15.1)
i18n (>= 1.6, < 2)
fasterer (0.8.3)
colorize (~> 0.7)
ruby_parser (>= 3.14.1)
ffaker (2.17.0)
i18n (1.8.5)
concurrent-ruby (~> 1.0)
iniparse (1.5.0)
json (2.3.1)
json_matchers (0.11.1)
Expand All @@ -31,7 +35,7 @@ GEM
overcommit (0.57.0)
childprocess (>= 0.6.3, < 5)
iniparse (~> 1.4)
parallel (1.20.0)
parallel (1.20.1)
parser (2.7.2.0)
ast (~> 2.4.1)
pry (0.13.1)
Expand All @@ -48,7 +52,7 @@ GEM
parser (>= 2.5.0.0, < 2.8, != 2.5.1.1)
psych (~> 3.1)
rainbow (>= 2.0, < 4.0)
regexp_parser (1.8.2)
regexp_parser (2.0.0)
rexml (3.2.4)
rspec (3.10.0)
rspec-core (~> 3.10.0)
Expand All @@ -63,21 +67,21 @@ GEM
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.10.0)
rspec-support (3.10.0)
rubocop (1.3.0)
rubocop (1.5.2)
parallel (~> 1.10)
parser (>= 2.7.1.5)
rainbow (>= 2.2.2, < 4.0)
regexp_parser (>= 1.8)
regexp_parser (>= 1.8, < 3.0)
rexml
rubocop-ast (>= 1.1.1)
rubocop-ast (>= 1.2.0, < 2.0)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 1.4.0, < 2.0)
rubocop-ast (1.1.1)
rubocop-ast (1.3.0)
parser (>= 2.7.1.5)
rubocop-performance (1.8.1)
rubocop (>= 0.87.0)
rubocop-performance (1.9.1)
rubocop (>= 0.90.0, < 2.0)
rubocop-ast (>= 0.4.0)
rubocop-rspec (2.0.0)
rubocop-rspec (2.0.1)
rubocop (~> 1.0)
rubocop-ast (>= 1.1.0)
ruby-progressbar (1.10.1)
Expand All @@ -92,9 +96,10 @@ GEM
simpleidn (0.1.1)
unf (~> 0.1.4)
thor (1.0.1)
truemail-rspec (0.2.1)
rspec (~> 3.9)
truemail (~> 1.4, >= 1.4.1)
truemail-rspec (0.3.3)
faker (~> 2.15, >= 2.15.1)
rspec (~> 3.10)
truemail (~> 2.2)
unf (0.1.4)
unf_ext
unf_ext (0.0.7.7)
Expand All @@ -106,20 +111,20 @@ PLATFORMS
DEPENDENCIES
bundler (~> 1.16)
bundler-audit (~> 0.7.0.1)
faker (~> 2.15, >= 2.15.1)
fasterer (~> 0.8.3)
ffaker (~> 2.17)
json_matchers (~> 0.11.1)
overcommit (~> 0.57.0)
pry-byebug (~> 3.9)
rake (~> 13.0, >= 13.0.1)
reek (~> 6.0, >= 6.0.2)
rspec (~> 3.10)
rubocop (~> 1.3)
rubocop-performance (~> 1.8, >= 1.8.1)
rubocop-rspec (~> 2.0)
rubocop (~> 1.5, >= 1.5.2)
rubocop-performance (~> 1.9, >= 1.9.1)
rubocop-rspec (~> 2.0, >= 2.0.1)
simplecov (~> 0.17.1)
truemail!
truemail-rspec (~> 0.2.1)
truemail-rspec (~> 0.3.3)

BUNDLED WITH
1.16.6
2 changes: 1 addition & 1 deletion lib/truemail.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ module Truemail
class << self
def configuration(&block)
@configuration ||= begin
return unless block_given?
return unless block
configuration = Truemail::Configuration.new(&block)
raise_unless(configuration.complete?, Truemail::INCOMPLETE_CONFIG)
configuration
Expand Down
2 changes: 1 addition & 1 deletion lib/truemail/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def initialize(&block)
instance_initializer.each do |instace_variable, value|
instance_variable_set(:"@#{instace_variable}", value)
end
tap(&block) if block_given?
tap(&block) if block
end

%i[email_pattern smtp_error_body_pattern].each do |method|
Expand Down
1 change: 1 addition & 0 deletions lib/truemail/log/serializer/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ def configuration
whitelisted_domains: whitelisted_domains,
blacklisted_domains: blacklisted_domains,
not_rfc_mx_lookup_flow: executor_configuration.not_rfc_mx_lookup_flow,
smtp_fail_fast: executor_configuration.smtp_fail_fast,
smtp_safe_check: executor_configuration.smtp_safe_check,
email_pattern: email_pattern,
smtp_error_body_pattern: smtp_error_body_pattern
Expand Down
6 changes: 5 additions & 1 deletion lib/truemail/log/serializer/validator_base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ def initialize(executor_instance)

attr_reader :validation_type

def replace_invalid_chars
->(value) { value.encode('UTF-8', invalid: :replace) }
end

def smtp_debug
validation_smtp_debug = executor_result.smtp_debug
return unless validation_smtp_debug
Expand All @@ -22,7 +26,7 @@ def smtp_debug
mail_host: smtp_request.host,
port_opened: smtp_response.port_opened,
connection: smtp_response.connection,
errors: smtp_response.errors
errors: smtp_response.errors.transform_values(&replace_invalid_chars)
}
end
end
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.2.0'
VERSION = '2.2.1'
end
2 changes: 1 addition & 1 deletion spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

require 'bundler/setup'
require 'simplecov'
require 'ffaker'
require 'faker'
require 'json_matchers/rspec'
require 'pry'
require 'truemail'
Expand Down
13 changes: 13 additions & 0 deletions spec/support/schemas/auditor.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"whitelisted_domains": null,
"blacklisted_domains": null,
"not_rfc_mx_lookup_flow": false,
"smtp_fail_fast": false,
"smtp_safe_check": false,
"email_pattern": "default gem value",
"smtp_error_body_pattern": "default gem value"
Expand Down Expand Up @@ -95,6 +96,7 @@
"whitelisted_domains": null,
"blacklisted_domains": null,
"not_rfc_mx_lookup_flow": false,
"smtp_fail_fast": false,
"smtp_safe_check": false,
"email_pattern": "default gem value",
"smtp_error_body_pattern": "default gem value"
Expand All @@ -106,6 +108,7 @@
"whitelisted_domains",
"blacklisted_domains",
"not_rfc_mx_lookup_flow",
"smtp_fail_fast",
"smtp_safe_check",
"email_pattern",
"smtp_error_body_pattern"
Expand Down Expand Up @@ -161,6 +164,16 @@
false
]
},
"smtp_fail_fast": {
"$id": "#/properties/configuration/properties/smtp_fail_fast",
"type": "boolean",
"title": "The smtp_fail_fast schema",
"description": "An explanation about the purpose of this instance.",
"default": false,
"examples": [
false
]
},
"smtp_safe_check": {
"$id": "#/properties/configuration/properties/smtp_safe_check",
"type": "boolean",
Expand Down
14 changes: 13 additions & 1 deletion spec/support/schemas/validator.json
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,8 @@
"smtp_safe_check": false,
"whitelisted_domains": null,
"email_pattern": "default gem value",
"not_rfc_mx_lookup_flow": false
"not_rfc_mx_lookup_flow": false,
"smtp_fail_fast": false
}
],
"required": [
Expand All @@ -250,6 +251,7 @@
"whitelisted_domains",
"blacklisted_domains",
"not_rfc_mx_lookup_flow",
"smtp_fail_fast",
"smtp_safe_check",
"email_pattern",
"smtp_error_body_pattern"
Expand Down Expand Up @@ -315,6 +317,16 @@
false
]
},
"smtp_fail_fast": {
"$id": "#/properties/configuration/properties/smtp_fail_fast",
"type": "boolean",
"title": "The smtp_fail_fast schema",
"description": "An explanation about the purpose of this instance.",
"default": false,
"examples": [
false
]
},
"smtp_safe_check": {
"$id": "#/properties/configuration/properties/smtp_safe_check",
"type": "boolean",
Expand Down
2 changes: 1 addition & 1 deletion spec/truemail/audit/ip_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@

describe 'Success' do
context 'when determination of host ip address was successful' do
let(:host_address) { FFaker::Internet.ip_v4_address }
let(:host_address) { Faker::Internet.ip_v4_address }

it 'save host address to result, not changes warnings' do
expect(ip_auditor_instance).to receive(:detect_ip_via_ipify).and_return(host_address)
Expand Down
10 changes: 5 additions & 5 deletions spec/truemail/configuration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
RSpec.describe Truemail::Configuration do
subject(:configuration_instance) { described_class.new }

let(:valid_email) { FFaker::Internet.email }
let(:valid_email) { Faker::Internet.email }

describe 'class constants' do
context 'DEFAULT_CONNECTION_TIMEOUT' do
Expand Down Expand Up @@ -186,7 +186,7 @@
end

context 'when manual independent configuration' do
let(:valid_domain) { FFaker::Internet.domain_name }
let(:valid_domain) { Faker::Internet.domain_name }

describe '#verifier_email=' do
context 'with valid email' do
Expand Down Expand Up @@ -357,7 +357,7 @@
describe '#validation_type_for=' do
context 'with valid validation type attributes' do
let(:domains_config) do
(1..3).map { FFaker::Internet.unique.domain_name }.zip(%i[regex mx smtp]).to_h
(1..3).map { Faker::Internet.unique.domain_name }.zip(%i[regex mx smtp]).to_h
end

it 'sets validation type for domain' do
Expand Down Expand Up @@ -386,7 +386,7 @@
end

context 'with invalid validation type' do
let(:domain) { FFaker::Internet.domain_name }
let(:domain) { Faker::Internet.domain_name }
let(:validation_type) { 'wrong_validation_type' }

specify do
Expand All @@ -398,7 +398,7 @@

%i[whitelisted_domains= blacklisted_domains=].each do |domain_list_type|
describe "##{domain_list_type}" do
let(:domains_list) { (1..3).map { FFaker::Internet.unique.domain_name } }
let(:domains_list) { (1..3).map { Faker::Internet.unique.domain_name } }

context "with valid #{domain_list_type} parameter type and context" do
it 'sets whitelisted domains list' do
Expand Down
2 changes: 1 addition & 1 deletion spec/truemail/core_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
end

context 'when email not includes ascii chars' do
let(:email) { FFaker::Internet.email }
let(:email) { Faker::Internet.email }

it 'returns not changed email' do
expect(SimpleIDN).not_to receive(:to_ascii)
Expand Down
Loading

0 comments on commit 235e2e8

Please sign in to comment.