truemail 2.7.5 → 3.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1e06a06a5475f233ad747c59b77d50aac4465e231aaf9fef7cd40bed66fb4282
4
- data.tar.gz: d5ebb376ee5b00dc9100373f733afd8af5c5bdcaf0a11c1c467b6b996320950a
3
+ metadata.gz: 14cf6d4a2b730702849ca49317fdb3a054562f3e41de01b4e88737dc1da09ff8
4
+ data.tar.gz: b07cf758750e1532189f57e88ba61b06f4a2c5b9c570f76187c52d2e38c1e2f6
5
5
  SHA512:
6
- metadata.gz: '0696f4165309a5a9b82e337c3c1efd813de5da1c136c2015dae539e30e2a3e3f4aabd46920eab38051fa093be6c1af8845412545f8a7ab91e5b5ee233f639390'
7
- data.tar.gz: 958d4e6999f596d056cfe8a75fc058ce417e14f7cc0de500848d9f0ed7e8a250fad435f62f546282dd196a136c30a04556bef7c884933dcc375e4bb4f95a87af
6
+ metadata.gz: 665f453be4cd3bfbc10a66dfce4cc41b842ef1e36fdd22f8aacbe2def6f1ca542043647f528910320fa498d10c31cabc86d74b9fb5a8f5f4d79b6b02ae34eff6
7
+ data.tar.gz: 7f229a5a880117b42d7a070a83d5040e147402db193139929ea192f0451e2c7934f81b048146ed79369a2b0d985dab2f82dd80ee750f58ae452472254a2ddf95
data/.circleci/config.yml CHANGED
@@ -6,7 +6,7 @@ defaults: &defaults
6
6
  - image: cimg/ruby:<< parameters.ruby-version >>
7
7
 
8
8
  orbs:
9
- ruby: circleci/ruby@1.8.0
9
+ ruby: circleci/ruby@2.0.0
10
10
 
11
11
  references:
12
12
  restore_bundle_cache: &restore_bundle_cache
@@ -122,7 +122,7 @@ jobs:
122
122
  - checkout
123
123
  - <<: *use_compatible_gemspec
124
124
  - ruby/install-deps:
125
- bundler-version: "2.3.23"
125
+ bundler-version: "2.3.24"
126
126
  with-cache: false
127
127
  path: './vendor/custom_bundle'
128
128
  - <<: *install_system_dependencies
@@ -35,8 +35,8 @@ Gem::Specification.new do |spec|
35
35
  spec.add_development_dependency 'ffaker', '~> 2.21'
36
36
  spec.add_development_dependency 'json_matchers', '~> 0.11.1'
37
37
  spec.add_development_dependency 'rake', '~> 13.0', '>= 13.0.6'
38
- spec.add_development_dependency 'rspec', '~> 3.11'
38
+ spec.add_development_dependency 'rspec', '~> 3.12'
39
39
  spec.add_development_dependency 'smtp_mock', '~> 1.2', '>= 1.2.2'
40
- spec.add_development_dependency 'truemail-rspec', '~> 0.9.2'
40
+ spec.add_development_dependency 'truemail-rspec', '~> 1.0'
41
41
  spec.add_development_dependency 'webmock', '~> 3.18', '>= 3.18.1'
42
42
  end
@@ -41,12 +41,12 @@ Gem::Specification.new do |spec|
41
41
  spec.add_development_dependency 'pry-byebug', '~> 3.10', '>= 3.10.1'
42
42
  spec.add_development_dependency 'rake', '~> 13.0', '>= 13.0.6'
43
43
  spec.add_development_dependency 'reek', '~> 6.1', '>= 6.1.1'
44
- spec.add_development_dependency 'rspec', '~> 3.11'
45
- spec.add_development_dependency 'rubocop', '~> 1.36'
44
+ spec.add_development_dependency 'rspec', '~> 3.12'
45
+ spec.add_development_dependency 'rubocop', '~> 1.37', '>= 1.37.1'
46
46
  spec.add_development_dependency 'rubocop-performance', '~> 1.15'
47
- spec.add_development_dependency 'rubocop-rspec', '~> 2.13', '>= 2.13.2'
47
+ spec.add_development_dependency 'rubocop-rspec', '~> 2.14', '>= 2.14.2'
48
48
  spec.add_development_dependency 'simplecov', '~> 0.21.2'
49
49
  spec.add_development_dependency 'smtp_mock', '~> 1.2', '>= 1.2.2'
50
- spec.add_development_dependency 'truemail-rspec', '~> 0.9.2'
50
+ spec.add_development_dependency 'truemail-rspec', '~> 1.0'
51
51
  spec.add_development_dependency 'webmock', '~> 3.18', '>= 3.18.1'
52
52
  end
data/.codeclimate.yml CHANGED
@@ -7,7 +7,7 @@ checks:
7
7
  plugins:
8
8
  rubocop:
9
9
  enabled: true
10
- channel: rubocop-1-36
10
+ channel: rubocop-1-37
11
11
 
12
12
  reek:
13
13
  enabled: true
data/.reek.yml CHANGED
@@ -15,6 +15,7 @@ detectors:
15
15
  - Truemail::Configuration#logger=
16
16
  - Truemail::Validate::Smtp::Request#initialize
17
17
  - Truemail::Validate::Smtp::Request::Session#initialize
18
+ - Truemail::RSpec::ValidatorHelper::ValidatorFactory#process_validator_params
18
19
 
19
20
  TooManyInstanceVariables:
20
21
  exclude:
data/CHANGELOG.md CHANGED
@@ -2,6 +2,49 @@
2
2
 
3
3
  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).
4
4
 
5
+ ## [3.0.1] - 2022.11.01
6
+
7
+ ### Fixed
8
+
9
+ - Fixed wrong semantic version comparison in gemspec runtime dependency definition
10
+
11
+ ### Updated
12
+
13
+ - Updated RSpec helpers
14
+ - Updated gemspecs, circleci config
15
+ - Updated gem version
16
+
17
+ ## [3.0.0] - 2022.10.24
18
+
19
+ ### Added
20
+
21
+ - Added ability to specify whitelisted/blacklisted emails by complete match
22
+
23
+ ```ruby
24
+ Truemail.configure do |config|
25
+ # Optional parameter. Validation of email which contains whitelisted emails always will
26
+ # return true. Other validations will not processed even if it was defined in validation_type_for
27
+ # It is equal to empty array by default.
28
+ config.whitelisted_emails = %w[user@somedomain1.com user@somedomain2.com]
29
+
30
+ # Optional parameter. Validation of email which contains blacklisted emails always will
31
+ # return false. Other validations will not processed even if it was defined in validation_type_for
32
+ # It is equal to empty array by default.
33
+ config.blacklisted_emails = %w[user@somedomain3.com user@somedomain4.com]
34
+ end
35
+ ```
36
+
37
+ ### Updated
38
+
39
+ - Updated `Truemail::Configuration`, tests
40
+ - Updated namespace from `Truemail::Validate::DomainListMatch` to `Truemail::Validate::ListMatch`
41
+ - Updated `Truemail::Validator#run, tests
42
+ - Updated `Truemail::Log::Serializer::ValidatorJson`, tests
43
+ - Updated `Truemail::Log::Serializer::ValidatorText`, tests
44
+ - Updated `Truemail::Log::Serializer::AuditorJson`, tests
45
+ - Updated schemas, gemspecs, circleci/codeclimate config
46
+ - Updated docs, gem version
47
+
5
48
  ## [2.7.5] - 2022.10.10
6
49
 
7
50
  ### Updated
data/README.md CHANGED
@@ -130,9 +130,11 @@ You can use global gem configuration or custom independent configuration. Availa
130
130
  - connection attempts
131
131
  - default validation type
132
132
  - validation type for domains
133
+ - whitelisted emails
134
+ - blacklisted emails
133
135
  - whitelisted domains
134
- - whitelist validation
135
136
  - blacklisted domains
137
+ - whitelist validation
136
138
  - blacklisted mx ip-addresses
137
139
  - custom DNS gateway(s)
138
140
  - RFC MX lookup flow
@@ -190,22 +192,32 @@ Truemail.configure do |config|
190
192
  # It is equal to empty hash by default.
191
193
  config.validation_type_for = { 'somedomain.com' => :regex, 'otherdomain.com' => :mx }
192
194
 
195
+ # Optional parameter. Validation of email which contains whitelisted emails always will
196
+ # return true. Other validations will not processed even if it was defined in validation_type_for
197
+ # It is equal to empty array by default.
198
+ config.whitelisted_emails = %w[user@somedomain1.com user@somedomain2.com]
199
+
200
+ # Optional parameter. Validation of email which contains blacklisted emails always will
201
+ # return false. Other validations will not processed even if it was defined in validation_type_for
202
+ # It is equal to empty array by default.
203
+ config.blacklisted_emails = %w[user@somedomain3.com user@somedomain4.com]
204
+
193
205
  # Optional parameter. Validation of email which contains whitelisted domain always will
194
206
  # return true. Other validations will not processed even if it was defined in validation_type_for
195
207
  # It is equal to empty array by default.
196
208
  config.whitelisted_domains = %w[somedomain1.com somedomain2.com]
197
209
 
210
+ # Optional parameter. Validation of email which contains blacklisted domain always will
211
+ # return false. Other validations will not processed even if it was defined in validation_type_for
212
+ # It is equal to empty array by default.
213
+ config.blacklisted_domains = %w[somedomain3.com somedomain4.com]
214
+
198
215
  # Optional parameter. With this option Truemail will validate email which contains whitelisted
199
216
  # domain only, i.e. if domain whitelisted, validation will passed to Regex, MX or SMTP validators.
200
217
  # Validation of email which not contains whitelisted domain always will return false.
201
218
  # It is equal false by default.
202
219
  config.whitelist_validation = true
203
220
 
204
- # Optional parameter. Validation of email which contains blacklisted domain always will
205
- # return false. Other validations will not processed even if it was defined in validation_type_for
206
- # It is equal to empty array by default.
207
- config.blacklisted_domains = %w[somedomain3.com somedomain4.com]
208
-
209
221
  # Optional parameter. With this option Truemail will filter out unwanted mx servers via
210
222
  # predefined list of ip addresses. It can be used as a part of DEA (disposable email
211
223
  # address) validations. It is equal to empty array by default.
@@ -259,9 +271,11 @@ Truemail.configuration
259
271
  @connection_attempts=3,
260
272
  @default_validation_type=:mx,
261
273
  @validation_type_by_domain={"somedomain.com" => :regex, "otherdomain.com" => :mx},
274
+ @whitelisted_emails=["user@somedomain1.com", "user@somedomain2.com"],
275
+ @blacklisted_emails=["user@somedomain3.com", "user@somedomain4.com"],
262
276
  @whitelisted_domains=["somedomain1.com", "somedomain2.com"],
263
- @whitelist_validation=true,
264
277
  @blacklisted_domains=["somedomain3.com", "somedomain4.com"],
278
+ @whitelist_validation=true,
265
279
  @blacklisted_mx_ip_addresses=["1.1.1.1", "2.2.2.2"],
266
280
  @dns=["10.0.0.1", "10.0.0.2:54"],
267
281
  @verifier_domain="somedomain.com",
@@ -293,9 +307,11 @@ Truemail.configuration
293
307
  @connection_attempts=1,
294
308
  @default_validation_type=:mx,
295
309
  @validation_type_by_domain={"somedomain.com" => :regex, "otherdomain.com" => :mx},
310
+ @whitelisted_emails=["user@somedomain1.com", "user@somedomain2.com"],
311
+ @blacklisted_emails=["user@somedomain3.com", "user@somedomain4.com"],
296
312
  @whitelisted_domains=["somedomain1.com", "somedomain2.com"],
297
- @whitelist_validation=true,
298
313
  @blacklisted_domains=["somedomain3.com", "somedomain4.com"],
314
+ @whitelist_validation=true,
299
315
  @blacklisted_mx_ip_addresses=["1.1.1.1", "2.2.2.2"],
300
316
  @dns=["10.0.0.1", "10.0.0.2:54"],
301
317
  @verifier_domain="somedomain.com",
@@ -339,7 +355,7 @@ Please note, you should have global or custom configuration for use Truemail gem
339
355
 
340
356
  #### Whitelist/Blacklist check
341
357
 
342
- Whitelist/Blacklist check is zero validation level. You can define white and black list domains. It means that validation of email which contains whitelisted domain always will return `true`, and for blacklisted domain will return `false`.
358
+ Whitelist/Blacklist check is zero validation level. You can define white and black emails/domains lists. It means that validation of email which contains whitelisted email or domain always will return `true`, and for blacklisted email or domain will return `false`.
343
359
 
344
360
  Please note, other validations will not processed even if it was defined in `validation_type_for`.
345
361
 
@@ -356,6 +372,8 @@ require 'truemail'
356
372
 
357
373
  Truemail.configure do |config|
358
374
  config.verifier_email = 'verifier@example.com'
375
+ config.whitelisted_emails = %w[user@somedomain1.com user@somedomain2.com]
376
+ config.blacklisted_emails = %w[user@somedomain3.com user@somedomain4.com]
359
377
  config.whitelisted_domains = %w[white-domain.com somedomain.com]
360
378
  config.blacklisted_domains = %w[black-domain.com somedomain.com]
361
379
  config.validation_type_for = { 'somedomain.com' => :mx }
@@ -378,6 +396,8 @@ Truemail.validate('email@white-domain.com')
378
396
  errors={},
379
397
  smtp_debug=nil>,
380
398
  configuration=#<Truemail::Configuration:0x00005629f801bd28
399
+ @whitelisted_emails=["user@somedomain1.com", "user@somedomain2.com"],
400
+ @blacklisted_emails=["user@somedomain3.com", "user@somedomain4.com"],
381
401
  @blacklisted_domains=["black-domain.com", "somedomain.com"],
382
402
  @blacklisted_mx_ip_addresses=[],
383
403
  @dns=[],
@@ -428,6 +448,8 @@ Truemail.validate('email@white-domain.com', with: :regex)
428
448
  smtp_debug=nil>,
429
449
  configuration=
430
450
  #<Truemail::Configuration:0x0000563f0d2605c8
451
+ @whitelisted_emails=[],
452
+ @blacklisted_emails=[],
431
453
  @blacklisted_domains=[],
432
454
  @blacklisted_mx_ip_addresses=[],
433
455
  @dns=[],
@@ -464,6 +486,8 @@ Truemail.validate('email@domain.com', with: :regex)
464
486
  smtp_debug=nil>,
465
487
  configuration=
466
488
  #<Truemail::Configuration:0x0000563f0cd82ab0
489
+ @whitelisted_emails=[],
490
+ @blacklisted_emails=[],
467
491
  @blacklisted_domains=[],
468
492
  @blacklisted_mx_ip_addresses=[],
469
493
  @dns=[],
@@ -502,6 +526,8 @@ Truemail.validate('email@black-domain.com')
502
526
  smtp_debug=nil>,
503
527
  configuration=
504
528
  #<Truemail::Configuration:0x0000563f0d36f4f0
529
+ @whitelisted_emails=[],
530
+ @blacklisted_emails=[],
505
531
  @blacklisted_domains=[],
506
532
  @blacklisted_mx_ip_addresses=[],
507
533
  @dns=[],
@@ -540,6 +566,8 @@ Truemail.validate('email@somedomain.com')
540
566
  smtp_debug=nil>,
541
567
  configuration=
542
568
  #<Truemail::Configuration:0x0000563f0d3f8fc0
569
+ @whitelisted_emails=[],
570
+ @blacklisted_emails=[],
543
571
  @blacklisted_domains=[],
544
572
  @blacklisted_mx_ip_addresses=[],
545
573
  @dns=[],
@@ -595,6 +623,8 @@ Truemail.validate('email@example.com', with: :regex)
595
623
  smtp_debug=nil>,
596
624
  configuration=
597
625
  #<Truemail::Configuration:0x000055aa56a54d48
626
+ @whitelisted_emails=[],
627
+ @blacklisted_emails=[],
598
628
  @blacklisted_domains=[],
599
629
  @blacklisted_mx_ip_addresses=[],
600
630
  @dns=[],
@@ -641,6 +671,8 @@ Truemail.validate('email@example.com', with: :regex)
641
671
  smtp_debug=nil>,
642
672
  configuration=
643
673
  #<Truemail::Configuration:0x0000560e58d80830
674
+ @whitelisted_emails=[],
675
+ @blacklisted_emails=[],
644
676
  @blacklisted_domains=[],
645
677
  @blacklisted_mx_ip_addresses=[],
646
678
  @dns=[],
@@ -698,6 +730,8 @@ Truemail.validate('email@example.com', with: :mx)
698
730
  smtp_debug=nil>,
699
731
  configuration=
700
732
  #<Truemail::Configuration:0x0000559b6e44af70
733
+ @whitelisted_emails=[],
734
+ @blacklisted_emails=[],
701
735
  @blacklisted_domains=[],
702
736
  @blacklisted_mx_ip_addresses=[],
703
737
  @dns=[],
@@ -746,6 +780,8 @@ Truemail.validate('email@example.com', with: :mx)
746
780
  smtp_debug=nil>,
747
781
  configuration=
748
782
  #<Truemail::Configuration:0x0000559b6e44af70
783
+ @whitelisted_emails=[],
784
+ @blacklisted_emails=[],
749
785
  @blacklisted_domains=[],
750
786
  @blacklisted_mx_ip_addresses=[],
751
787
  @dns=[],
@@ -798,6 +834,8 @@ Truemail.validate('email@example.com', with: :mx_blacklist)
798
834
  smtp_debug=nil,
799
835
  configuration=
800
836
  #<Truemail::Configuration:0x00007fca0c8aeb38
837
+ @whitelisted_emails=[],
838
+ @blacklisted_emails=[],
801
839
  @blacklisted_domains=[],
802
840
  @blacklisted_mx_ip_addresses=["127.0.1.2"],
803
841
  @connection_attempts=2,
@@ -875,6 +913,8 @@ Truemail.validate('email@example.com')
875
913
  errors={}>>],
876
914
  configuration=
877
915
  #<Truemail::Configuration:0x00007fdc4504f5c8
916
+ @whitelisted_emails=[],
917
+ @blacklisted_emails=[],
878
918
  @blacklisted_domains=[],
879
919
  @blacklisted_mx_ip_addresses=[],
880
920
  @dns=[],
@@ -921,6 +961,8 @@ Truemail.validate('email@example.com')
921
961
  smtp_debug=nil>,
922
962
  configuration=
923
963
  #<Truemail::Configuration:0x00005615e87b9298
964
+ @whitelisted_emails=[],
965
+ @blacklisted_emails=[],
924
966
  @blacklisted_domains=[],
925
967
  @blacklisted_mx_ip_addresses=[],
926
968
  @dns=[],
@@ -973,6 +1015,8 @@ Truemail.validate('email@example.com')
973
1015
  errors={:rcptto=>"550 User not found\n"}>>]>,
974
1016
  configuration=
975
1017
  #<Truemail::Configuration:0x00005615e87b9298
1018
+ @whitelisted_emails=[],
1019
+ @blacklisted_emails=[],
976
1020
  @blacklisted_domains=[],
977
1021
  @blacklisted_mx_ip_addresses=[],
978
1022
  @dns=[],
@@ -1038,6 +1082,8 @@ Truemail.validate('email@example.com')
1038
1082
  errors={:mailfrom=>"554 5.7.1 Client host blocked\n", :connection=>"server dropped connection after response"}>>,]>,
1039
1083
  configuration=
1040
1084
  #<Truemail::Configuration:0x00005615e87b9298
1085
+ @whitelisted_emails=[],
1086
+ @blacklisted_emails=[],
1041
1087
  @blacklisted_domains=[],
1042
1088
  @blacklisted_mx_ip_addresses=[],
1043
1089
  @dns=[],
@@ -1087,6 +1133,8 @@ Truemail.validate('email@example.com')
1087
1133
  errors={:rcptto=>"550 User not found\n"}>>]>,
1088
1134
  configuration=
1089
1135
  #<Truemail::Configuration:0x00005615e87b9298
1136
+ @whitelisted_emails=[],
1137
+ @blacklisted_emails=[],
1090
1138
  @blacklisted_domains=[],
1091
1139
  @blacklisted_mx_ip_addresses=[],
1092
1140
  @dns=[],
@@ -1138,6 +1186,8 @@ Truemail.host_audit
1138
1186
  warnings={}>,
1139
1187
  configuration=
1140
1188
  #<Truemail::Configuration:0x00005615e86327a8
1189
+ @whitelisted_emails=[],
1190
+ @blacklisted_emails=[],
1141
1191
  @blacklisted_domains=[],
1142
1192
  @blacklisted_mx_ip_addresses=[],
1143
1193
  @dns=[],
@@ -1168,6 +1218,8 @@ Truemail.host_audit
1168
1218
  },
1169
1219
  configuration=
1170
1220
  #<Truemail::Configuration:0x00005615e86327a8
1221
+ @whitelisted_emails=[],
1222
+ @blacklisted_emails=[],
1171
1223
  @blacklisted_domains=[],
1172
1224
  @blacklisted_mx_ip_addresses=[],
1173
1225
  @dns=[],
@@ -1223,6 +1275,8 @@ Truemail::Log::Serializer::AuditorJson.call(Truemail.host_audit)
1223
1275
  "dns": "A-record of verifier domain not refers to current host ip address", "ptr": "PTR-record does not reference to current verifier domain"
1224
1276
  },
1225
1277
  "configuration": {
1278
+ "whitelisted_emails": null,
1279
+ "blacklisted_emails": null,
1226
1280
  "blacklisted_domains": null,
1227
1281
  "blacklisted_mx_ip_addresses": null,
1228
1282
  "dns": null,
@@ -1264,6 +1318,8 @@ Truemail::Log::Serializer::ValidatorJson.call(Truemail.validate('nonexistent_ema
1264
1318
  }
1265
1319
  ],
1266
1320
  "configuration": {
1321
+ "whitelisted_emails": null,
1322
+ "blacklisted_emails": null,
1267
1323
  "blacklisted_domains": null,
1268
1324
  "blacklisted_mx_ip_addresses": null,
1269
1325
  "dns": null,
@@ -1307,6 +1363,8 @@ Truemail.host_audit.as_json
1307
1363
  "dns": "A-record of verifier domain not refers to current host ip address", "ptr": "PTR-record does not reference to current verifier domain"
1308
1364
  },
1309
1365
  "configuration": {
1366
+ "whitelisted_emails": null,
1367
+ "blacklisted_emails": null,
1310
1368
  "blacklisted_domains": null,
1311
1369
  "blacklisted_mx_ip_addresses": null,
1312
1370
  "dns": null,
@@ -1345,6 +1403,8 @@ Truemail.validate('nonexistent_email@bestweb.com.ua').as_json
1345
1403
  }
1346
1404
  ],
1347
1405
  "configuration": {
1406
+ "whitelisted_emails": null,
1407
+ "blacklisted_emails": null,
1348
1408
  "blacklisted_domains": null,
1349
1409
  "blacklisted_mx_ip_addresses": null,
1350
1410
  "dns": null,
@@ -1391,6 +1451,56 @@ Truemail.configure do |config|
1391
1451
  end
1392
1452
  ```
1393
1453
 
1454
+ Or you can use end-to-end approach and mock DNS and SMTP services with [`dns_mock`](https://github.com/mocktools/ruby-dns-mock), [`smtp_mock`](https://github.com/mocktools/ruby-smtp-mock) for your test environment like in example below:
1455
+
1456
+ ```ruby
1457
+ # Gemfile
1458
+
1459
+ group :test do
1460
+ gem 'dns_mock', require: false
1461
+ gem 'smtp_mock', require: false
1462
+ end
1463
+
1464
+ # spec/spec_helper.rb
1465
+
1466
+ require 'dns_mock/test_framework/rspec'
1467
+ require 'smtp_mock/test_framework/rspec'
1468
+
1469
+ RSpec.configure do |config|
1470
+ config.include DnsMock::TestFramework::RSpec::Helper
1471
+ config.include SmtpMock::TestFramework::RSpec::Helper
1472
+ end
1473
+
1474
+ # spec/integration_spec.rb
1475
+
1476
+ RSpec.describe 'integration tests' do
1477
+ let(:target_email) { random_email }
1478
+ let(:dns_mock_records) { dns_mock_records_by_email(target_email, dimension: 2) }
1479
+
1480
+ before do
1481
+ dns_mock_server.assign_mocks(dns_mock_records)
1482
+ smtp_mock_server(**smtp_mock_server_options)
1483
+
1484
+ Truemail.configuration.tap do |config|
1485
+ config.dns = %W[127.0.0.1:#{dns_mock_server.port}]
1486
+ config.smtp_port = smtp_mock_server.port
1487
+ end
1488
+ end
1489
+
1490
+ context 'when checks real email' do
1491
+ let(:smtp_mock_server_options) { {} }
1492
+
1493
+ it { expect(Truemail.validate(target_email).result).to be_valid }
1494
+ end
1495
+
1496
+ context 'when checks fake email' do
1497
+ let(:smtp_mock_server_options) { { not_registered_emails: [target_email] } }
1498
+
1499
+ it { expect(Truemail.validate(target_email).result).not_to be_valid }
1500
+ end
1501
+ end
1502
+ ```
1503
+
1394
1504
  ---
1395
1505
 
1396
1506
  ## Truemail family
@@ -14,6 +14,8 @@ module Truemail
14
14
  connection_timeout
15
15
  response_timeout
16
16
  connection_attempts
17
+ whitelisted_emails
18
+ blacklisted_emails
17
19
  whitelisted_domains
18
20
  blacklisted_domains
19
21
  blacklisted_mx_ip_addresses
@@ -100,6 +102,8 @@ module Truemail
100
102
  default_validation_type: Truemail::Configuration::DEFAULT_VALIDATION_TYPE,
101
103
  smtp_port: Truemail::Configuration::DEFAULT_SMTP_PORT,
102
104
  validation_type_by_domain: {},
105
+ whitelisted_emails: [],
106
+ blacklisted_emails: [],
103
107
  whitelisted_domains: [],
104
108
  whitelist_validation: false,
105
109
  blacklisted_domains: [],
@@ -131,6 +135,7 @@ module Truemail
131
135
  def regex_by_method(method)
132
136
  return Truemail::RegexConstant::REGEX_IP_ADDRESS_PATTERN if method.eql?(:blacklisted_mx_ip_addresses)
133
137
  return Truemail::RegexConstant::REGEX_DNS_SERVER_ADDRESS_PATTERN if method.eql?(:dns)
138
+ return Truemail::RegexConstant::REGEX_SIMPLE_EMAIL_PATTERN if method[/email/]
134
139
  Truemail::RegexConstant::REGEX_DOMAIN_PATTERN
135
140
  end
136
141
 
data/lib/truemail/core.rb CHANGED
@@ -20,6 +20,7 @@ module Truemail
20
20
 
21
21
  module RegexConstant
22
22
  REGEX_DOMAIN = /[\p{L}0-9]+([\-.]{1}[\p{L}0-9]+)*\.\p{L}{2,63}/i.freeze
23
+ REGEX_SIMPLE_EMAIL_PATTERN = /\w+@\w+/.freeze
23
24
  REGEX_EMAIL_PATTERN = %r{(?=\A.{6,255}\z)(\A([\p{L}0-9]+[\w\p{L}.+!~,'&%#*^`{}|\-/?=$]*)@(#{REGEX_DOMAIN})\z)}.freeze
24
25
  REGEX_DOMAIN_PATTERN = /(?=\A.{4,255}\z)(\A#{REGEX_DOMAIN}\z)/.freeze
25
26
  REGEX_DOMAIN_FROM_EMAIL = /\A.+@(.+)\z/.freeze
@@ -45,7 +46,7 @@ module Truemail
45
46
 
46
47
  module Validate
47
48
  require_relative '../truemail/validate/base'
48
- require_relative '../truemail/validate/domain_list_match'
49
+ require_relative '../truemail/validate/list_match'
49
50
  require_relative '../truemail/validate/regex'
50
51
  require_relative '../truemail/validate/mx'
51
52
  require_relative '../truemail/validate/mx_blacklist'
@@ -8,6 +8,8 @@ module Truemail
8
8
 
9
9
  CONFIGURATION_ARRAY_ATTRS = %i[
10
10
  validation_type_by_domain
11
+ whitelisted_emails
12
+ blacklisted_emails
11
13
  whitelisted_domains
12
14
  blacklisted_domains
13
15
  blacklisted_mx_ip_addresses
@@ -61,6 +63,8 @@ module Truemail
61
63
  {
62
64
  validation_type_by_domain: validation_type_by_domain,
63
65
  whitelist_validation: executor_configuration.whitelist_validation,
66
+ whitelisted_emails: whitelisted_emails,
67
+ blacklisted_emails: blacklisted_emails,
64
68
  whitelisted_domains: whitelisted_domains,
65
69
  blacklisted_domains: blacklisted_domains,
66
70
  blacklisted_mx_ip_addresses: blacklisted_mx_ip_addresses,
@@ -0,0 +1,45 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Truemail
4
+ module Validate
5
+ class ListMatch < Truemail::Validate::Base
6
+ ERROR = 'blacklisted email'
7
+
8
+ def run
9
+ return success(true) if whitelisted? && !whitelist_validation?
10
+ return unless whitelist_validation_case? || blacklisted?
11
+ success(false)
12
+ add_error(Truemail::Validate::ListMatch::ERROR)
13
+ end
14
+
15
+ private
16
+
17
+ def email
18
+ @email ||= result.email
19
+ end
20
+
21
+ def email_domain
22
+ @email_domain ||=
23
+ result.domain = email[Truemail::RegexConstant::REGEX_DOMAIN_FROM_EMAIL, 1]
24
+ end
25
+
26
+ def whitelisted?
27
+ configuration.whitelisted_emails.include?(email) ||
28
+ configuration.whitelisted_domains.include?(email_domain)
29
+ end
30
+
31
+ def whitelist_validation?
32
+ configuration.whitelist_validation
33
+ end
34
+
35
+ def whitelist_validation_case?
36
+ whitelist_validation? && !whitelisted?
37
+ end
38
+
39
+ def blacklisted?
40
+ configuration.blacklisted_emails.include?(email) ||
41
+ configuration.blacklisted_domains.include?(email_domain)
42
+ end
43
+ end
44
+ end
45
+ end
@@ -26,7 +26,7 @@ module Truemail
26
26
  end
27
27
 
28
28
  def run
29
- Truemail::Validate::DomainListMatch.check(result)
29
+ Truemail::Validate::ListMatch.check(result)
30
30
  result_not_changed? ? Truemail::Validate.const_get(constantize(validation_type)).check(result) : update_validation_type
31
31
  logger&.push(self)
32
32
  self
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Truemail
4
- VERSION = '2.7.5'
4
+ VERSION = '3.0.1'
5
5
  end
data/truemail.gemspec CHANGED
@@ -29,15 +29,15 @@ Gem::Specification.new do |spec|
29
29
  spec.executables = spec.files.grep(%r{^exe/}) { |f| ::File.basename(f) }
30
30
  spec.require_paths = ['lib']
31
31
 
32
- spec.add_runtime_dependency 'net-smtp', '~> 0.3.2' if ::RUBY_VERSION >= '3.1.0'
32
+ spec.add_runtime_dependency 'net-smtp', '~> 0.3.2' if ::Gem::Version.new(::RUBY_VERSION) >= ::Gem::Version.new('3.1.0')
33
33
  spec.add_runtime_dependency 'simpleidn', '~> 0.2.1'
34
34
 
35
35
  spec.add_development_dependency 'dns_mock', '~> 1.5', '>= 1.5.5'
36
36
  spec.add_development_dependency 'ffaker', '~> 2.21'
37
37
  spec.add_development_dependency 'json_matchers', '~> 0.11.1'
38
38
  spec.add_development_dependency 'rake', '~> 13.0', '>= 13.0.6'
39
- spec.add_development_dependency 'rspec', '~> 3.11'
39
+ spec.add_development_dependency 'rspec', '~> 3.12'
40
40
  spec.add_development_dependency 'smtp_mock', '~> 1.2', '>= 1.2.2'
41
- spec.add_development_dependency 'truemail-rspec', '~> 0.9.2'
41
+ spec.add_development_dependency 'truemail-rspec', '~> 1.0'
42
42
  spec.add_development_dependency 'webmock', '~> 3.18', '>= 3.18.1'
43
43
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: truemail
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.7.5
4
+ version: 3.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vladislav Trotsenko
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-10-10 00:00:00.000000000 Z
11
+ date: 2022-11-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: simpleidn
@@ -98,14 +98,14 @@ dependencies:
98
98
  requirements:
99
99
  - - "~>"
100
100
  - !ruby/object:Gem::Version
101
- version: '3.11'
101
+ version: '3.12'
102
102
  type: :development
103
103
  prerelease: false
104
104
  version_requirements: !ruby/object:Gem::Requirement
105
105
  requirements:
106
106
  - - "~>"
107
107
  - !ruby/object:Gem::Version
108
- version: '3.11'
108
+ version: '3.12'
109
109
  - !ruby/object:Gem::Dependency
110
110
  name: smtp_mock
111
111
  requirement: !ruby/object:Gem::Requirement
@@ -132,14 +132,14 @@ dependencies:
132
132
  requirements:
133
133
  - - "~>"
134
134
  - !ruby/object:Gem::Version
135
- version: 0.9.2
135
+ version: '1.0'
136
136
  type: :development
137
137
  prerelease: false
138
138
  version_requirements: !ruby/object:Gem::Requirement
139
139
  requirements:
140
140
  - - "~>"
141
141
  - !ruby/object:Gem::Version
142
- version: 0.9.2
142
+ version: '1.0'
143
143
  - !ruby/object:Gem::Dependency
144
144
  name: webmock
145
145
  requirement: !ruby/object:Gem::Requirement
@@ -216,7 +216,7 @@ files:
216
216
  - lib/truemail/log/serializer/validator_text.rb
217
217
  - lib/truemail/logger.rb
218
218
  - lib/truemail/validate/base.rb
219
- - lib/truemail/validate/domain_list_match.rb
219
+ - lib/truemail/validate/list_match.rb
220
220
  - lib/truemail/validate/mx.rb
221
221
  - lib/truemail/validate/mx_blacklist.rb
222
222
  - lib/truemail/validate/regex.rb
@@ -1,39 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Truemail
4
- module Validate
5
- class DomainListMatch < Truemail::Validate::Base
6
- ERROR = 'blacklisted email'
7
-
8
- def run
9
- return success(true) if whitelisted_domain? && !whitelist_validation?
10
- return unless whitelist_validation_case? || blacklisted_domain?
11
- success(false)
12
- add_error(Truemail::Validate::DomainListMatch::ERROR)
13
- end
14
-
15
- private
16
-
17
- def email_domain
18
- @email_domain ||=
19
- result.domain = result.email[Truemail::RegexConstant::REGEX_DOMAIN_FROM_EMAIL, 1]
20
- end
21
-
22
- def whitelisted_domain?
23
- configuration.whitelisted_domains.include?(email_domain)
24
- end
25
-
26
- def whitelist_validation?
27
- configuration.whitelist_validation
28
- end
29
-
30
- def whitelist_validation_case?
31
- whitelist_validation? && !whitelisted_domain?
32
- end
33
-
34
- def blacklisted_domain?
35
- configuration.blacklisted_domains.include?(email_domain)
36
- end
37
- end
38
- end
39
- end