sanitize_email 1.2.0 → 1.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.ruby-version +1 -1
- data/.travis.yml +55 -14
- data/Appraisals +55 -0
- data/CHANGELOG.md +1 -1
- data/README.md +21 -2
- data/Rakefile +5 -38
- data/gemfiles/rails_3_0.gemfile +12 -0
- data/gemfiles/rails_3_1.gemfile +13 -0
- data/gemfiles/rails_3_2.gemfile +11 -0
- data/gemfiles/rails_4_0.gemfile +11 -0
- data/gemfiles/rails_4_1.gemfile +11 -0
- data/gemfiles/rails_4_2.gemfile +10 -0
- data/gemfiles/rails_5_0.gemfile +10 -0
- data/init.rb +1 -1
- data/lib/sanitize_email/config.rb +30 -13
- data/lib/sanitize_email/mail_header_tools.rb +30 -11
- data/lib/sanitize_email/overridden_addresses.rb +5 -5
- data/lib/sanitize_email/rspec_matchers.rb +48 -29
- data/lib/sanitize_email/test_helpers.rb +16 -10
- data/lib/sanitize_email/version.rb +1 -1
- data/lib/sanitize_email.rb +24 -21
- data/sanitize_email.gemspec +2 -0
- data/spec/sanitize_email_spec.rb +521 -220
- data/spec/spec_helper.rb +9 -9
- metadata +39 -9
- data/gemfiles/Gemfile.rails-3.0.x +0 -7
- data/gemfiles/Gemfile.rails-3.1.x +0 -8
- data/gemfiles/Gemfile.rails-3.2.x +0 -9
- data/gemfiles/Gemfile.rails-4.0.x +0 -9
- data/gemfiles/Gemfile.rails-4.1.x +0 -9
- data/gemfiles/Gemfile.rails-4.2.x +0 -6
@@ -1,24 +1,30 @@
|
|
1
1
|
# Copyright (c) 2008-16 Peter H. Boling of RailsBling.com
|
2
2
|
# Released under the MIT license
|
3
|
-
|
4
|
-
|
3
|
+
# Note: the RspecMatchers are composed matchers:
|
4
|
+
# See: http://www.relishapp.com/rspec/rspec-expectations/v/3-5/docs/composing-matchers
|
5
|
+
|
6
|
+
require "sanitize_email/mail_ext"
|
5
7
|
|
6
8
|
module SanitizeEmail
|
7
|
-
# Provides matchers that can be used in
|
9
|
+
# Provides matchers that can be used in
|
10
|
+
# Rspec tests to assert the behavior of email
|
8
11
|
module RspecMatchers
|
9
|
-
|
10
|
-
[:from, :to, :cc, :bcc, :reply_to].each do |attribute|
|
12
|
+
[:from, :to, :cc, :bcc, :subject, :reply_to].each do |attribute|
|
11
13
|
RSpec::Matchers.define "have_#{attribute}" do |matcher|
|
12
14
|
match do |actual|
|
13
|
-
|
15
|
+
@actual = actual.send(attribute)
|
16
|
+
@actual = @actual.join(", ") if @actual.respond_to?(:join)
|
17
|
+
expect(@actual).to match(matcher)
|
14
18
|
end
|
15
19
|
end
|
16
20
|
end
|
17
21
|
|
18
|
-
[:subject].each do |attribute|
|
19
|
-
RSpec::Matchers.define "
|
22
|
+
[:from, :to, :cc, :bcc, :subject, :reply_to].each do |attribute|
|
23
|
+
RSpec::Matchers.define "match_#{attribute}" do |matcher|
|
20
24
|
match do |actual|
|
21
|
-
|
25
|
+
@actual = actual.send(attribute)
|
26
|
+
@actual = @actual.join(", ") if @actual.respond_to?(:join)
|
27
|
+
expect(@actual).to match(matcher)
|
22
28
|
end
|
23
29
|
end
|
24
30
|
end
|
@@ -26,46 +32,59 @@ module SanitizeEmail
|
|
26
32
|
[:from, :to, :cc, :bcc, :subject, :reply_to].each do |attribute|
|
27
33
|
RSpec::Matchers.define "be_#{attribute}" do |matcher|
|
28
34
|
match do |actual|
|
29
|
-
|
35
|
+
@actual = actual.send(attribute)
|
36
|
+
@actual = @actual.join(", ") if @actual.respond_to?(:join)
|
37
|
+
expect(@actual).to be(matcher)
|
30
38
|
end
|
31
39
|
end
|
32
40
|
end
|
33
41
|
|
34
42
|
RSpec::Matchers.define "have_to_username" do |matcher|
|
35
|
-
def
|
43
|
+
def get_to_username(email_message)
|
44
|
+
username_header = email_message.header["X-Sanitize-Email-To"]
|
45
|
+
return username_header unless username_header.is_a?(Mail::Field)
|
36
46
|
email_message.header.fields[3].value
|
37
47
|
end
|
38
48
|
match do |actual|
|
39
|
-
|
49
|
+
@actual = get_to_username(actual)
|
50
|
+
expect(@actual).to match(matcher)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
RSpec::Matchers.define "have_cc_username" do |matcher|
|
55
|
+
def get_cc_username(email_message)
|
56
|
+
username_header = email_message.header["X-Sanitize-Email-Cc"]
|
57
|
+
return username_header unless username_header.is_a?(Mail::Field)
|
58
|
+
email_message.header.fields[3].value
|
59
|
+
end
|
60
|
+
match do |actual|
|
61
|
+
@actual = get_cc_username(actual)
|
62
|
+
expect(@actual).to match(matcher)
|
40
63
|
end
|
41
64
|
end
|
42
65
|
|
43
66
|
# Cribbed from email_spec gem
|
44
67
|
RSpec::Matchers.define "have_body_text" do |matcher|
|
68
|
+
def get_fuzzy_body(email_message)
|
69
|
+
email_message.default_part_body.to_s.gsub(/\s+/, " ")
|
70
|
+
end
|
71
|
+
|
72
|
+
def get_fuzzy_matcher(to_fuzz)
|
73
|
+
to_fuzz.gsub(/\s+/, " ")
|
74
|
+
end
|
45
75
|
match do |actual|
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
matcher_text = matcher.gsub(/\s+/, " ")
|
50
|
-
raise SanitizeEmail::TestHelpers::UnexpectedMailType, "Cannot find #{matcher} in body" unless actual_text.respond_to?(:include?)
|
51
|
-
actual_text.include?(matcher_text)
|
52
|
-
else
|
53
|
-
actual_text = actual.default_part_body.to_s
|
54
|
-
raise SanitizeEmail::TestHelpers::UnexpectedMailType, "Cannot find #{matcher} in body" unless actual_text.respond_to?(:=~)
|
55
|
-
!!(actual_text =~ matcher)
|
56
|
-
end
|
76
|
+
@actual = get_fuzzy_body(actual)
|
77
|
+
fuzzy_matcher = get_fuzzy_matcher(matcher)
|
78
|
+
expect(@actual).to match(fuzzy_matcher)
|
57
79
|
end
|
58
80
|
end
|
59
81
|
|
60
82
|
# Cribbed from email_spec gem
|
61
83
|
RSpec::Matchers.define "have_header" do |name, matcher|
|
62
84
|
match do |actual|
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
else
|
67
|
-
header[name].to_s =~ matcher
|
68
|
-
end
|
85
|
+
@actual = actual.header[name]
|
86
|
+
@actual = @actual.value unless @actual.nil?
|
87
|
+
expect(@actual).to match(matcher)
|
69
88
|
end
|
70
89
|
end
|
71
90
|
|
@@ -1,5 +1,7 @@
|
|
1
1
|
# Copyright (c) 2008-16 Peter H. Boling of RailsBling.com
|
2
2
|
# Released under the MIT license
|
3
|
+
# Note: the RspecMatchers no longer use these methods. Instead they are composed matchers:
|
4
|
+
# See: http://www.relishapp.com/rspec/rspec-expectations/v/3-5/docs/composing-matchers
|
3
5
|
|
4
6
|
module SanitizeEmail
|
5
7
|
# Helpers for test-unit
|
@@ -8,16 +10,16 @@ module SanitizeEmail
|
|
8
10
|
# Error raised when unable to match an expected part of email in order to fail the test
|
9
11
|
class UnexpectedMailType < StandardError; end
|
10
12
|
|
11
|
-
def string_matching_attribute(matcher, part,
|
12
|
-
string_matching(matcher, part,
|
13
|
+
def string_matching_attribute(matcher, part, attribute)
|
14
|
+
string_matching(matcher, part, attribute)
|
13
15
|
end
|
14
16
|
|
15
|
-
def string_matching(matcher, part,
|
16
|
-
if
|
17
|
+
def string_matching(matcher, part, attribute)
|
18
|
+
if attribute.respond_to?(:=~) # Can we match a regex against it?
|
17
19
|
if matcher.is_a?(Regexp)
|
18
|
-
|
20
|
+
attribute =~ matcher
|
19
21
|
else
|
20
|
-
|
22
|
+
attribute =~ Regexp.new(Regexp.escape(matcher))
|
21
23
|
end
|
22
24
|
else
|
23
25
|
raise UnexpectedMailType, "Cannot match #{matcher} for #{part}"
|
@@ -25,13 +27,17 @@ module SanitizeEmail
|
|
25
27
|
end
|
26
28
|
|
27
29
|
# Normalize arrays to strings
|
28
|
-
def array_matching(matcher, part,
|
29
|
-
|
30
|
-
string_matching(matcher, part,
|
30
|
+
def array_matching(matcher, part, attribute)
|
31
|
+
attribute = attribute.join(", ") if attribute.respond_to?(:join)
|
32
|
+
string_matching(matcher, part, attribute)
|
31
33
|
end
|
32
34
|
|
33
35
|
def email_matching(matcher, part, mail_or_part)
|
34
|
-
|
36
|
+
email_attribute_matching(matcher, part, mail_or_part.send(part))
|
37
|
+
end
|
38
|
+
|
39
|
+
def email_attribute_matching(matcher, part, attribute)
|
40
|
+
array_matching(matcher, part, attribute)
|
35
41
|
end
|
36
42
|
|
37
43
|
end
|
data/lib/sanitize_email.rb
CHANGED
@@ -2,12 +2,12 @@
|
|
2
2
|
# Released under the MIT license
|
3
3
|
|
4
4
|
module SanitizeEmail
|
5
|
-
require
|
6
|
-
require
|
7
|
-
require
|
8
|
-
require
|
9
|
-
require
|
10
|
-
require
|
5
|
+
require "sanitize_email/version"
|
6
|
+
require "sanitize_email/deprecation"
|
7
|
+
require "sanitize_email/config"
|
8
|
+
require "sanitize_email/mail_header_tools"
|
9
|
+
require "sanitize_email/overridden_addresses"
|
10
|
+
require "sanitize_email/bleach"
|
11
11
|
|
12
12
|
# Error is raised when a block parameter is required and not provided to a method
|
13
13
|
class MissingBlockParameter < StandardError; end
|
@@ -15,9 +15,9 @@ module SanitizeEmail
|
|
15
15
|
# Allow non-rails implementations to use this gem
|
16
16
|
if defined?(::Rails)
|
17
17
|
if defined?(::Rails::Engine)
|
18
|
-
require
|
18
|
+
require "sanitize_email/engine"
|
19
19
|
elsif ::Rails::VERSION::MAJOR == 3 && ::Rails::VERSION::MINOR == 0
|
20
|
-
require
|
20
|
+
require "sanitize_email/railtie"
|
21
21
|
else
|
22
22
|
raise "Please use the 0.X.X versions of sanitize_email for Rails 2.X and below."
|
23
23
|
end
|
@@ -65,16 +65,18 @@ module SanitizeEmail
|
|
65
65
|
end
|
66
66
|
@force_sanitize = nil
|
67
67
|
|
68
|
-
# Regardless of the Config settings of SanitizeEmail you can do a local
|
69
|
-
#
|
70
|
-
#
|
68
|
+
# Regardless of the Config settings of SanitizeEmail you can do a local
|
69
|
+
# override to send sanitary email in any environment.
|
70
|
+
# You have access to all the same configuration options in the parameter hash
|
71
|
+
# as you can set in the actual SanitizeEmail.configure block.
|
71
72
|
#
|
72
|
-
# SanitizeEmail.sanitary({:sanitized_to =>
|
73
|
+
# SanitizeEmail.sanitary({:sanitized_to => "boo@example.com"}) do
|
73
74
|
# Mail.deliver do
|
74
|
-
# from
|
75
|
-
#
|
76
|
-
#
|
77
|
-
#
|
75
|
+
# from "from@example.org"
|
76
|
+
# # Will actually be sent to the override addresses, not this one:
|
77
|
+
# to "to@example.org"
|
78
|
+
# reply_to "reply_to@example.org"
|
79
|
+
# subject "subject"
|
78
80
|
# end
|
79
81
|
# end
|
80
82
|
#
|
@@ -88,14 +90,15 @@ module SanitizeEmail
|
|
88
90
|
end
|
89
91
|
end
|
90
92
|
|
91
|
-
# Regardless of the Config settings of SanitizeEmail you can do a local
|
93
|
+
# Regardless of the Config settings of SanitizeEmail you can do a local
|
94
|
+
# override to force unsanitary email in any environment.
|
92
95
|
#
|
93
96
|
# SanitizeEmail.unsanitary do
|
94
97
|
# Mail.deliver do
|
95
|
-
# from
|
96
|
-
# to
|
97
|
-
# reply_to
|
98
|
-
# subject
|
98
|
+
# from "from@example.org"
|
99
|
+
# to "to@example.org"
|
100
|
+
# reply_to "reply_to@example.org"
|
101
|
+
# subject "subject"
|
99
102
|
# end
|
100
103
|
# end
|
101
104
|
#
|
data/sanitize_email.gemspec
CHANGED
@@ -45,5 +45,7 @@ EOS
|
|
45
45
|
s.add_development_dependency("roodi", [">= 2.1.0"])
|
46
46
|
s.add_development_dependency("rake", [">= 0"])
|
47
47
|
s.add_development_dependency("pry", [">= 0"])
|
48
|
+
s.add_development_dependency("appraisal")
|
49
|
+
s.add_development_dependency("wwtd")
|
48
50
|
s.add_development_dependency("coveralls")
|
49
51
|
end
|