email_address 0.1.16 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/ci.yml +18 -0
- data/Gemfile +1 -1
- data/README.md +65 -6
- data/Rakefile +2 -2
- data/email_address.gemspec +22 -23
- data/lib/email_address.rb +17 -19
- data/lib/email_address/active_record_validator.rb +8 -11
- data/lib/email_address/address.rb +37 -31
- data/lib/email_address/canonical_email_address_type.rb +14 -12
- data/lib/email_address/config.rb +14 -2
- data/lib/email_address/email_address_type.rb +15 -13
- data/lib/email_address/exchanger.rb +8 -22
- data/lib/email_address/host.rb +29 -48
- data/lib/email_address/local.rb +103 -106
- data/lib/email_address/rewriter.rb +28 -31
- data/lib/email_address/version.rb +1 -1
- data/test/activerecord/test_ar.rb +17 -13
- data/test/activerecord/user.rb +31 -30
- data/test/email_address/test_address.rb +49 -25
- data/test/email_address/test_config.rb +8 -8
- data/test/email_address/test_exchanger.rb +6 -7
- data/test/email_address/test_local.rb +35 -35
- data/test/email_address/test_rewriter.rb +2 -5
- data/test/test_aliasing.rb +53 -0
- data/test/test_email_address.rb +14 -18
- data/test/test_helper.rb +9 -8
- metadata +34 -21
- data/.travis.yml +0 -9
@@ -1,17 +1,15 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
3
|
+
require "base64"
|
4
4
|
|
5
5
|
module EmailAddress::Rewriter
|
6
|
-
|
7
|
-
SRS_FORMAT_REGEX = /\ASRS0=(....)=(\w\w)=(.+?)=(.+?)@(.+)\z/
|
6
|
+
SRS_FORMAT_REGEX = /\ASRS0=(....)=(\w\w)=(.+?)=(.+?)@(.+)\z/
|
8
7
|
|
9
8
|
def parse_rewritten(e)
|
10
9
|
@rewrite_scheme = nil
|
11
|
-
@rewrite_error
|
12
|
-
|
10
|
+
@rewrite_error = nil
|
11
|
+
parse_srs(e)
|
13
12
|
# e = parse_batv(e)
|
14
|
-
e
|
15
13
|
end
|
16
14
|
|
17
15
|
#---------------------------------------------------------------------------
|
@@ -24,9 +22,9 @@ module EmailAddress::Rewriter
|
|
24
22
|
# a different domain.
|
25
23
|
# Format: SRS0=HHH=TT=domain=local@sending-domain.com
|
26
24
|
#---------------------------------------------------------------------------
|
27
|
-
def srs(sending_domain, options={}, &block)
|
28
|
-
tt = srs_tt
|
29
|
-
a = [tt,
|
25
|
+
def srs(sending_domain, options = {}, &block)
|
26
|
+
tt = srs_tt
|
27
|
+
a = [tt, hostname, local.to_s].join("=") + "@" + sending_domain
|
30
28
|
hhh = srs_hash(a, options, &block)
|
31
29
|
|
32
30
|
["SRS0", hhh, a].join("=")
|
@@ -36,11 +34,11 @@ module EmailAddress::Rewriter
|
|
36
34
|
email.match(SRS_FORMAT_REGEX) ? true : false
|
37
35
|
end
|
38
36
|
|
39
|
-
def parse_srs(email, options={}, &block)
|
40
|
-
if email
|
37
|
+
def parse_srs(email, options = {}, &block)
|
38
|
+
if email&.match(SRS_FORMAT_REGEX)
|
41
39
|
@rewrite_scheme = :srs
|
42
40
|
hhh, tt, domain, local, sending_domain = [$1, $2, $3, $4, $5]
|
43
|
-
hhh = tt = sending_domain if false && hhh # Hide warnings for now :-)
|
41
|
+
# hhh = tt = sending_domain if false && hhh # Hide warnings for now :-)
|
44
42
|
a = [tt, domain, local].join("=") + "@" + sending_domain
|
45
43
|
unless srs_hash(a, options, &block) === hhh
|
46
44
|
@rewrite_error = "Invalid SRS Email Address: Possibly altered"
|
@@ -58,16 +56,16 @@ module EmailAddress::Rewriter
|
|
58
56
|
# Returns a 2-character code for the day. After a few days the code will roll.
|
59
57
|
# TT has a one-day resolution in order to make the address invalid after a few days.
|
60
58
|
# The cycle period is 3.5 years. Used to control late bounces and harvesting.
|
61
|
-
def srs_tt(t=Time.now.utc)
|
62
|
-
Base64.encode64((t.to_i / (60*60*24) %
|
59
|
+
def srs_tt(t = Time.now.utc)
|
60
|
+
Base64.encode64((t.to_i / (60 * 60 * 24) % 210).to_s)[0, 2]
|
63
61
|
end
|
64
62
|
|
65
|
-
def srs_hash(email, options={}, &block)
|
63
|
+
def srs_hash(email, options = {}, &block)
|
66
64
|
key = options[:key] || @config[:key] || email.reverse
|
67
|
-
if
|
68
|
-
block.call(email)[0,4]
|
65
|
+
if block
|
66
|
+
block.call(email)[0, 4]
|
69
67
|
else
|
70
|
-
Base64.encode64(Digest::SHA1.digest(email + key))[0,4]
|
68
|
+
Base64.encode64(Digest::SHA1.digest(email + key))[0, 4]
|
71
69
|
end
|
72
70
|
end
|
73
71
|
|
@@ -85,17 +83,17 @@ module EmailAddress::Rewriter
|
|
85
83
|
# * SSSSSS: sha1( KDDD + orig-mailfrom + key)[0,6]
|
86
84
|
# See: https://tools.ietf.org/html/draft-levine-smtp-batv-01
|
87
85
|
#---------------------------------------------------------------------------
|
88
|
-
def batv_prvs(options={})
|
86
|
+
def batv_prvs(options = {})
|
89
87
|
k = options[:prvs_key_id] || "0"
|
90
88
|
prvs_days = options[:prvs_days] || @config[:prvs_days] || 30
|
91
89
|
ddd = prvs_day(prvs_days)
|
92
|
-
ssssss = prvs_sign(k, ddd,
|
93
|
-
["prvs=", k, ddd, ssssss,
|
90
|
+
ssssss = prvs_sign(k, ddd, to_s, options)
|
91
|
+
["prvs=", k, ddd, ssssss, "=", to_s].join("")
|
94
92
|
end
|
95
93
|
|
96
94
|
PRVS_REGEX = /\Aprvs=(\d)(\d{3})(\w{6})=(.+)\z/
|
97
95
|
|
98
|
-
def parse_prvs(email, options={})
|
96
|
+
def parse_prvs(email, options = {})
|
99
97
|
if email.match(PRVS_REGEX)
|
100
98
|
@rewrite_scheme = :prvs
|
101
99
|
k, ddd, ssssss, email = [$1, $2, $3, $4]
|
@@ -119,13 +117,13 @@ module EmailAddress::Rewriter
|
|
119
117
|
end
|
120
118
|
|
121
119
|
def prvs_day(days)
|
122
|
-
((Time.now.to_i + (days*24*60*60)) / (24*60*60)).to_s[-3,3]
|
120
|
+
((Time.now.to_i + (days * 24 * 60 * 60)) / (24 * 60 * 60)).to_s[-3, 3]
|
123
121
|
end
|
124
122
|
|
125
|
-
def prvs_sign(k, ddd, email, options={})
|
126
|
-
str = [ddd, ssssss,
|
123
|
+
def prvs_sign(k, ddd, email, options = {})
|
124
|
+
str = [ddd, ssssss, "=", to_s].join("")
|
127
125
|
key = options["key_#{k}".to_i] || @config["key_#{k}".to_i] || str.reverse
|
128
|
-
Digest::SHA1.hexdigest([k,ddd, email, key].join(
|
126
|
+
Digest::SHA1.hexdigest([k, ddd, email, key].join(""))[0, 6]
|
129
127
|
end
|
130
128
|
|
131
129
|
#---------------------------------------------------------------------------
|
@@ -136,12 +134,11 @@ module EmailAddress::Rewriter
|
|
136
134
|
# To handle incoming verp, the "tag" is the recipient email address,
|
137
135
|
# remember to convert the last '=' into a '@' to reconstruct it.
|
138
136
|
#---------------------------------------------------------------------------
|
139
|
-
def verp(recipient, split_char=
|
140
|
-
|
141
|
-
split_char + recipient.
|
142
|
-
"@" +
|
137
|
+
def verp(recipient, split_char = "+")
|
138
|
+
local.to_s +
|
139
|
+
split_char + recipient.tr("@", "=") +
|
140
|
+
"@" + hostname
|
143
141
|
end
|
144
142
|
|
145
143
|
# NEXT: DMARC, SPF Validation
|
146
|
-
|
147
144
|
end
|
@@ -1,23 +1,27 @@
|
|
1
|
-
|
2
|
-
require_relative '../test_helper'
|
1
|
+
require_relative "../test_helper"
|
3
2
|
|
4
3
|
class TestAR < MiniTest::Test
|
5
|
-
require_relative
|
4
|
+
require_relative "user"
|
6
5
|
|
7
6
|
def test_validation
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
7
|
+
# Disabled JRuby checks... weird CI failures. Hopefully someone can help?
|
8
|
+
if RUBY_PLATFORM != "java" # jruby
|
9
|
+
user = User.new(email: "Pat.Jones+ASDF#GMAIL.com")
|
10
|
+
assert_equal false, user.valid?
|
11
|
+
assert user.errors.messages[:email].first
|
12
|
+
user = User.new(email: "Pat.Jones+ASDF@GMAIL.com")
|
13
|
+
assert_equal true, user.valid?
|
14
|
+
end
|
13
15
|
end
|
14
16
|
|
15
17
|
def test_datatype
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
18
|
+
# Disabled JRuby checks... weird CI failures. Hopefully someone can help?
|
19
|
+
if RUBY_PLATFORM != "java" # jruby
|
20
|
+
if defined?(ActiveRecord) && ::ActiveRecord::VERSION::MAJOR >= 5
|
21
|
+
user = User.new(email: "Pat.Jones+ASDF@GMAIL.com")
|
22
|
+
assert_equal "pat.jones+asdf@gmail.com", user.email
|
23
|
+
assert_equal "patjones@gmail.com", user.canonical_email
|
24
|
+
end
|
20
25
|
end
|
21
26
|
end
|
22
|
-
|
23
27
|
end
|
data/test/activerecord/user.rb
CHANGED
@@ -6,35 +6,38 @@ class ApplicationRecord < ActiveRecord::Base
|
|
6
6
|
self.abstract_class = true
|
7
7
|
end
|
8
8
|
|
9
|
-
dbfile = ENV[
|
9
|
+
dbfile = ENV["EMAIL_ADDRESS_TEST_DB"] || "/tmp/email_address.gem.db"
|
10
10
|
File.unlink(dbfile) if File.exist?(dbfile)
|
11
11
|
|
12
12
|
# Connection: JRuby vs. MRI
|
13
|
-
|
14
|
-
|
15
|
-
require
|
16
|
-
require
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
13
|
+
# Disabled JRuby checks... weird CI failures. Hopefully someone can help?
|
14
|
+
if RUBY_PLATFORM == "java" # jruby
|
15
|
+
# require "jdbc/sqlite3"
|
16
|
+
# require "java"
|
17
|
+
# require "activerecord-jdbcsqlite3-adapter"
|
18
|
+
# Jdbc::SQLite3.load_driver
|
19
|
+
# ActiveRecord::Base.establish_connection(
|
20
|
+
# adapter: "jdbc",
|
21
|
+
# driver: "org.sqlite.JDBC",
|
22
|
+
# url: "jdbc:sqlite:" + dbfile
|
23
|
+
# )
|
23
24
|
else
|
24
|
-
require
|
25
|
+
require "sqlite3"
|
25
26
|
ActiveRecord::Base.establish_connection(
|
26
|
-
:
|
27
|
-
:
|
27
|
+
adapter: "sqlite3",
|
28
|
+
database: dbfile
|
28
29
|
)
|
29
|
-
end
|
30
30
|
|
31
|
-
|
32
|
-
|
31
|
+
# The following would be executed for both JRuby/MRI
|
32
|
+
ApplicationRecord.connection.execute(
|
33
|
+
"create table users ( email varchar, canonical_email varchar)"
|
34
|
+
)
|
33
35
|
|
34
|
-
if defined?(ActiveRecord) && ::ActiveRecord::VERSION::MAJOR >= 5
|
35
|
-
|
36
|
-
|
37
|
-
|
36
|
+
if defined?(ActiveRecord) && ::ActiveRecord::VERSION::MAJOR >= 5
|
37
|
+
ActiveRecord::Type.register(:email_address, EmailAddress::EmailAddressType)
|
38
|
+
ActiveRecord::Type.register(:canonical_email_address,
|
39
|
+
EmailAddress::CanonicalEmailAddressType)
|
40
|
+
end
|
38
41
|
end
|
39
42
|
|
40
43
|
################################################################################
|
@@ -42,30 +45,28 @@ end
|
|
42
45
|
################################################################################
|
43
46
|
|
44
47
|
class User < ApplicationRecord
|
45
|
-
|
46
48
|
if defined?(ActiveRecord) && ::ActiveRecord::VERSION::MAJOR >= 5
|
47
49
|
attribute :email, :email_address
|
48
50
|
attribute :canonical_email, :canonical_email_address
|
49
51
|
end
|
50
52
|
|
51
53
|
validates_with EmailAddress::ActiveRecordValidator,
|
52
|
-
fields: %i
|
54
|
+
fields: %i[email canonical_email]
|
53
55
|
|
54
56
|
def email=(email_address)
|
55
57
|
self[:canonical_email] = email_address
|
56
|
-
self[:email]
|
58
|
+
self[:email] = email_address
|
57
59
|
end
|
58
60
|
|
59
61
|
def self.find_by_email(email)
|
60
|
-
user
|
61
|
-
user ||=
|
62
|
-
user ||=
|
62
|
+
user = find_by(email: EmailAddress.normal(email))
|
63
|
+
user ||= find_by(canonical_email: EmailAddress.canonical(email))
|
64
|
+
user ||= find_by(canonical_email: EmailAddress.redacted(email))
|
63
65
|
user
|
64
66
|
end
|
65
67
|
|
66
68
|
def redact!
|
67
|
-
self[:canonical_email] = EmailAddress.redact(
|
68
|
-
self[:email]
|
69
|
+
self[:canonical_email] = EmailAddress.redact(canonical_email)
|
70
|
+
self[:email] = self[:canonical_email]
|
69
71
|
end
|
70
|
-
|
71
72
|
end
|
@@ -1,5 +1,4 @@
|
|
1
|
-
|
2
|
-
require_relative '../test_helper'
|
1
|
+
require_relative "../test_helper"
|
3
2
|
|
4
3
|
class TestAddress < Minitest::Test
|
5
4
|
def test_address
|
@@ -22,7 +21,7 @@ class TestAddress < Minitest::Test
|
|
22
21
|
def test_host
|
23
22
|
a = EmailAddress.new("User+tag@example.com")
|
24
23
|
assert_equal "example.com", a.hostname
|
25
|
-
#assert_equal :default, a.provider
|
24
|
+
# assert_equal :default, a.provider
|
26
25
|
end
|
27
26
|
|
28
27
|
# ADDRESS
|
@@ -34,28 +33,53 @@ class TestAddress < Minitest::Test
|
|
34
33
|
assert_equal "{63a710569261a24b3766275b7000ce8d7b32e2f7}@example.com", a.redact
|
35
34
|
assert_equal "{b58996c504c5638798eb6b511e6f49af}@example.com", a.redact(:md5)
|
36
35
|
assert_equal "b58996c504c5638798eb6b511e6f49af", a.reference
|
37
|
-
assert_equal "6bdd00c53645790ad9bbcb50caa93880",
|
36
|
+
assert_equal "6bdd00c53645790ad9bbcb50caa93880", EmailAddress.reference("Gmail.User+tag@gmail.com")
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_sha1
|
40
|
+
a = EmailAddress.new("User+tag@example.com")
|
41
|
+
assert_equal "63a710569261a24b3766275b7000ce8d7b32e2f7", a.sha1
|
42
|
+
end
|
43
|
+
|
44
|
+
def test_sha1_with_secret
|
45
|
+
a = EmailAddress.new("User+tag@example.com", sha1_secret: "test-secret")
|
46
|
+
assert_equal "122df4ec3ce7121db6edc06a9e29eab39a7e8007", a.sha1
|
47
|
+
end
|
48
|
+
|
49
|
+
def test_sha256
|
50
|
+
a = EmailAddress.new("User+tag@example.com")
|
51
|
+
assert_equal "b4c9a289323b21a01c3e940f150eb9b8c542587f1abfd8f0e1cc1ffc5e475514", a.sha256
|
52
|
+
end
|
53
|
+
|
54
|
+
def test_sha256_with_secret
|
55
|
+
a = EmailAddress.new("User+tag@example.com", sha256_secret: "test-secret")
|
56
|
+
assert_equal "480899ff53ccd446cc123f0c5685869644af445e788f1b559054919674307a07", a.sha256
|
57
|
+
end
|
58
|
+
|
59
|
+
def test_google_hosted
|
60
|
+
a = EmailAddress.new("Ex.am.ple+tag@boomer.com")
|
61
|
+
assert_equal a.canonical, "ex.am.ple@boomer.com"
|
38
62
|
end
|
39
63
|
|
40
64
|
# COMPARISON & MATCHING
|
41
65
|
def test_compare
|
42
|
-
a =
|
43
|
-
#e = EmailAddress.new("user@example.com")
|
66
|
+
a = "User+tag@example.com"
|
67
|
+
# e = EmailAddress.new("user@example.com")
|
44
68
|
n = EmailAddress.new(a)
|
45
69
|
c = EmailAddress.new_canonical(a)
|
46
|
-
#r = EmailAddress.new_redacted(a)
|
70
|
+
# r = EmailAddress.new_redacted(a)
|
47
71
|
assert_equal true, n == "user+tag@example.com"
|
48
|
-
assert_equal true, n >
|
72
|
+
assert_equal true, n > "b@example.com"
|
49
73
|
assert_equal true, n.same_as?(c)
|
50
74
|
assert_equal true, n.same_as?(a)
|
51
75
|
end
|
52
76
|
|
53
77
|
def test_matches
|
54
78
|
a = EmailAddress.new("User+tag@gmail.com")
|
55
|
-
assert_equal false,
|
56
|
-
assert_equal
|
57
|
-
assert_equal
|
58
|
-
assert_equal
|
79
|
+
assert_equal false, a.matches?("mail.com")
|
80
|
+
assert_equal "google", a.matches?("google")
|
81
|
+
assert_equal "user+tag@", a.matches?("user+tag@")
|
82
|
+
assert_equal "user*@gmail*", a.matches?("user*@gmail*")
|
59
83
|
end
|
60
84
|
|
61
85
|
def test_empty_address
|
@@ -69,18 +93,18 @@ class TestAddress < Minitest::Test
|
|
69
93
|
# VALIDATION
|
70
94
|
def test_valid
|
71
95
|
assert EmailAddress.valid?("User+tag@example.com", host_validation: :a), "valid 1"
|
72
|
-
assert !
|
73
|
-
assert EmailAddress.new("ɹᴉɐℲuǝll∀@ɹᴉɐℲuǝll∀.ws", local_encoding: :uncode, host_validation: :syntax
|
96
|
+
assert !EmailAddress.valid?("User%tag@example.com", host_validation: :a), "valid 2"
|
97
|
+
assert EmailAddress.new("ɹᴉɐℲuǝll∀@ɹᴉɐℲuǝll∀.ws", local_encoding: :uncode, host_validation: :syntax), "valid unicode"
|
74
98
|
end
|
75
99
|
|
76
100
|
def test_localhost
|
77
101
|
e = EmailAddress.new("User+tag.gmail.ws") # No domain means localhost
|
78
|
-
assert_equal
|
102
|
+
assert_equal "", e.hostname
|
79
103
|
assert_equal false, e.valid? # localhost not allowed by default
|
80
104
|
assert_equal EmailAddress.error("user1"), "Invalid Domain Name"
|
81
|
-
assert_equal EmailAddress.error("user1", host_local:true), "This domain is not configured to accept email"
|
82
|
-
assert_equal EmailAddress.error("user1@localhost", host_local:true), "This domain is not configured to accept email"
|
83
|
-
assert_nil EmailAddress.error("user2@localhost", host_local:true, dns_lookup: :off, host_validation: :syntax)
|
105
|
+
assert_equal EmailAddress.error("user1", host_local: true), "This domain is not configured to accept email"
|
106
|
+
assert_equal EmailAddress.error("user1@localhost", host_local: true), "This domain is not configured to accept email"
|
107
|
+
assert_nil EmailAddress.error("user2@localhost", host_local: true, dns_lookup: :off, host_validation: :syntax)
|
84
108
|
end
|
85
109
|
|
86
110
|
def test_regexen
|
@@ -92,7 +116,7 @@ class TestAddress < Minitest::Test
|
|
92
116
|
end
|
93
117
|
|
94
118
|
def test_srs
|
95
|
-
ea= "first.LAST+tag@gmail.com"
|
119
|
+
ea = "first.LAST+tag@gmail.com"
|
96
120
|
e = EmailAddress.new(ea)
|
97
121
|
s = e.srs("example.com")
|
98
122
|
assert s.match(EmailAddress::Address::SRS_FORMAT_REGEX)
|
@@ -101,20 +125,20 @@ class TestAddress < Minitest::Test
|
|
101
125
|
|
102
126
|
# Quick Regression tests for addresses that should have been valid (but fixed)
|
103
127
|
def test_issues
|
104
|
-
assert true, EmailAddress.valid?(
|
128
|
+
assert true, EmailAddress.valid?("test@jiff.com", dns_lookup: :mx) # #7
|
105
129
|
assert true, EmailAddress.valid?("w.-asdf-_@hotmail.com") # #8
|
106
130
|
assert true, EmailAddress.valid?("first_last@hotmail.com") # #8
|
107
131
|
end
|
108
132
|
|
109
133
|
def test_issue9
|
110
|
-
assert !
|
111
|
-
assert !
|
112
|
-
assert !
|
134
|
+
assert !EmailAddress.valid?("example.user@foo.")
|
135
|
+
assert !EmailAddress.valid?("ogog@sss.c")
|
136
|
+
assert !EmailAddress.valid?("example.user@foo.com/")
|
113
137
|
end
|
114
138
|
|
115
139
|
def test_relaxed_normal
|
116
|
-
assert !
|
117
|
-
assert true, EmailAddress.new(
|
140
|
+
assert !EmailAddress.new("a.c.m.e.-industries@foo.com").valid?
|
141
|
+
assert true, EmailAddress.new("a.c.m.e.-industries@foo.com", local_format: :relaxed).valid?
|
118
142
|
end
|
119
143
|
|
120
144
|
def test_nil_address
|
@@ -1,25 +1,25 @@
|
|
1
|
-
require_relative
|
1
|
+
require_relative "../test_helper"
|
2
2
|
|
3
3
|
class TestConfig < MiniTest::Test
|
4
4
|
def test_setting
|
5
|
-
assert_equal :mx,
|
5
|
+
assert_equal :mx, EmailAddress::Config.setting(:dns_lookup)
|
6
6
|
assert_equal :off, EmailAddress::Config.setting(:dns_lookup, :off)
|
7
7
|
assert_equal :off, EmailAddress::Config.setting(:dns_lookup)
|
8
8
|
EmailAddress::Config.setting(:dns_lookup, :mx)
|
9
9
|
end
|
10
10
|
|
11
11
|
def test_configure
|
12
|
-
assert_equal :mx,
|
13
|
-
assert_equal true,
|
14
|
-
EmailAddress::Config.configure(local_downcase:false, dns_lookup: :off)
|
15
|
-
assert_equal :off,
|
12
|
+
assert_equal :mx, EmailAddress::Config.setting(:dns_lookup)
|
13
|
+
assert_equal true, EmailAddress::Config.setting(:local_downcase)
|
14
|
+
EmailAddress::Config.configure(local_downcase: false, dns_lookup: :off)
|
15
|
+
assert_equal :off, EmailAddress::Config.setting(:dns_lookup)
|
16
16
|
assert_equal false, EmailAddress::Config.setting(:local_downcase)
|
17
|
-
EmailAddress::Config.configure(local_downcase:true, dns_lookup: :mx)
|
17
|
+
EmailAddress::Config.configure(local_downcase: true, dns_lookup: :mx)
|
18
18
|
end
|
19
19
|
|
20
20
|
def test_provider
|
21
21
|
assert_nil EmailAddress::Config.provider(:github)
|
22
|
-
EmailAddress::Config.provider(:github, host_match: %w
|
22
|
+
EmailAddress::Config.provider(:github, host_match: %w[github.com], local_format: :standard)
|
23
23
|
assert_equal :standard, EmailAddress::Config.provider(:github)[:local_format]
|
24
24
|
assert_equal :github, EmailAddress::Host.new("github.com").provider
|
25
25
|
EmailAddress::Config.providers.delete(:github)
|
@@ -1,13 +1,12 @@
|
|
1
|
-
|
2
|
-
require_relative '../test_helper'
|
1
|
+
require_relative "../test_helper"
|
3
2
|
|
4
3
|
class TestExchanger < MiniTest::Test
|
5
4
|
def test_exchanger
|
6
5
|
e = EmailAddress::Exchanger.new("gmail.com")
|
7
6
|
assert_equal true, e.mxers.size > 1
|
8
7
|
assert_equal :google, e.provider
|
9
|
-
assert_equal
|
10
|
-
assert_equal
|
8
|
+
assert_equal "google.com", e.domains.first
|
9
|
+
assert_equal "google.com", e.matches?("google.com")
|
11
10
|
assert_equal false, e.matches?("fa00:1450:4013:c01::1a/16")
|
12
11
|
assert_equal false, e.matches?("127.0.0.1/24")
|
13
12
|
assert_equal true, e.mx_ips.size > 1
|
@@ -18,8 +17,8 @@ class TestExchanger < MiniTest::Test
|
|
18
17
|
assert_equal 0, e.mxers.size
|
19
18
|
end
|
20
19
|
|
21
|
-
|
22
|
-
#def test_dns
|
20
|
+
# assert_equal true, a.has_dns_a_record? # example.com has no MX'ers
|
21
|
+
# def test_dns
|
23
22
|
# good = EmailAddress::Exchanger.new("gmail.com")
|
24
23
|
# bad = EmailAddress::Exchanger.new("exampldkeie4iufe.com")
|
25
24
|
# assert_equal true, good.has_dns_a_record?
|
@@ -27,5 +26,5 @@ class TestExchanger < MiniTest::Test
|
|
27
26
|
# assert_equal "gmail.com", good.dns_a_record.first
|
28
27
|
# assert(/google.com\z/, good.mxers.first.first)
|
29
28
|
# #assert_equal 'google.com', good.domains.first
|
30
|
-
#end
|
29
|
+
# end
|
31
30
|
end
|