sanitize_email 1.0.2 → 1.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG +12 -2
- data/Gemfile.lock +1 -1
- data/lib/sanitize_email/bleach.rb +1 -0
- data/lib/sanitize_email/config.rb +14 -3
- data/lib/sanitize_email/deprecation.rb +11 -7
- data/lib/sanitize_email/rspec_matchers.rb +31 -0
- data/lib/sanitize_email/test_helpers.rb +24 -0
- data/lib/sanitize_email/version.rb +1 -1
- data/lib/sanitize_email.rb +1 -2
- data/spec/sanitize_email_spec.rb +224 -131
- data/spec/spec_helper.rb +2 -1
- metadata +3 -2
- data/lib/sanitize_email/email_matchers.rb +0 -51
data/CHANGELOG
CHANGED
@@ -1,4 +1,12 @@
|
|
1
|
-
Version 1.0.
|
1
|
+
Version 1.0.3 - AUG.12.2012
|
2
|
+
- Accidentally broke spec suite with 1.0.2 - fixed
|
3
|
+
- Expanded spec suite
|
4
|
+
- Split test_helpers from rspec_matchers (test_helpers may be useful in TestUnit
|
5
|
+
- Moving Examples from README to wiki
|
6
|
+
- Document and implement working deprecation of version 0's SanitizeEmail::Config.config[:force_sanitize] behavior
|
7
|
+
- Now use SanitizeEmail.force_sanitize = true # or false or nil
|
8
|
+
|
9
|
+
Version 1.0.2 - AUG.11.2012
|
2
10
|
- Massive improvement to spec suite, and found bleeding
|
3
11
|
- needed to unregister the interceptors:
|
4
12
|
- Mail.class_variable_get(:@@delivery_interceptors).pop
|
@@ -8,9 +16,11 @@ Version 1.0.0.rc4 - AUG.11.2012
|
|
8
16
|
- Force Sanitization On for a block
|
9
17
|
- Added SanitizeEmail.unsanitary &block
|
10
18
|
- Force Sanitization Off for a block
|
11
|
-
- Added SanitizeEmail.force_sanitize = true # or false
|
19
|
+
- Added SanitizeEmail.force_sanitize = true # or false or nil
|
12
20
|
- Force Sanitization On or Off
|
13
21
|
|
22
|
+
Version 1.0.1 - Unintentional, unexpected bump behavior from gem-release gem (Issues #24 & #25)
|
23
|
+
|
14
24
|
Version 1.0.0.rc3 - AUG.08.2012
|
15
25
|
- Forgot to switch from jeweler to gem-release, so making appropriate changes and bumping again
|
16
26
|
- Aligning closer to bundler gem defaults
|
data/Gemfile.lock
CHANGED
@@ -171,6 +171,7 @@ module SanitizeEmail
|
|
171
171
|
return sanitized_addresses unless SanitizeEmail.use_actual_email_as_sanitized_user_name
|
172
172
|
|
173
173
|
with_user_names = self.inject_user_names(real_addresses, sanitized_addresses)
|
174
|
+
#puts "real_addresses 2: #{real_addresses}"
|
174
175
|
#puts "override_email 5: #{type} - #{with_user_names}"
|
175
176
|
# Otherwise inject the email as the 'user name'
|
176
177
|
return with_user_names
|
@@ -3,10 +3,9 @@ require 'facets/module/mattr' # gives cattr
|
|
3
3
|
module SanitizeEmail
|
4
4
|
class Config
|
5
5
|
|
6
|
-
|
7
|
-
cattr_writer :config
|
6
|
+
extend SanitizeEmail::Deprecation
|
8
7
|
|
9
|
-
|
8
|
+
DEFAULTS = {
|
10
9
|
# Specify the BCC addresses for the messages that go out in 'local' environments
|
11
10
|
:sanitized_bcc => nil,
|
12
11
|
|
@@ -33,6 +32,11 @@ module SanitizeEmail
|
|
33
32
|
|
34
33
|
:activation_proc => Proc.new { false }
|
35
34
|
}
|
35
|
+
|
36
|
+
cattr_reader :config
|
37
|
+
cattr_writer :config
|
38
|
+
|
39
|
+
self.config ||= DEFAULTS
|
36
40
|
def self.configure &block
|
37
41
|
yield @@config
|
38
42
|
|
@@ -47,6 +51,13 @@ module SanitizeEmail
|
|
47
51
|
# because we are still inside the configure block.
|
48
52
|
@@config[:sanitized_to] = @@config[:sanitized_recipients]
|
49
53
|
end
|
54
|
+
if !@@config[:force_sanitize].nil?
|
55
|
+
replacement = "
|
56
|
+
Please use SanitizeEmail.force_sanitize or SanitizeEmail.sanitary instead.
|
57
|
+
Refer to https://github.com/pboling/sanitize_email/wiki for examples."
|
58
|
+
deprecation("SanitizeEmail::Config.config[:force_sanitize]", replacement)
|
59
|
+
SanitizeEmail.force_sanitize = @@config[:force_sanitize]
|
60
|
+
end
|
50
61
|
end
|
51
62
|
|
52
63
|
end
|
@@ -28,16 +28,20 @@ module SanitizeEmail
|
|
28
28
|
alias_method old_name, name
|
29
29
|
# And replace it with a wrapped version
|
30
30
|
define_method(name) do |*args, &block|
|
31
|
-
|
32
|
-
if replacement
|
33
|
-
warn "SanitizeEmail: ##{name} deprecated (please use ##{replacement})"
|
34
|
-
else
|
35
|
-
warn "SanitizeEmail: ##{name} deprecated"
|
36
|
-
end
|
37
|
-
end
|
31
|
+
self.deprecation(name, " (please use ##{replacement})")
|
38
32
|
send old_name, *args, &block
|
39
33
|
end
|
40
34
|
end
|
41
35
|
|
36
|
+
def deprecation(name, replacement = nil)
|
37
|
+
unless @@deprecate_in_silence
|
38
|
+
if replacement
|
39
|
+
warn "SanitizeEmail: ##{name} deprecated#{replacement}"
|
40
|
+
else
|
41
|
+
warn "SanitizeEmail: ##{name} deprecated"
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
42
46
|
end
|
43
47
|
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'sanitize_email/test_helpers'
|
2
|
+
|
3
|
+
module SanitizeEmail
|
4
|
+
module RspecMatchers
|
5
|
+
include SanitizeEmail::TestHelpers
|
6
|
+
[:from, :to, :cc, :bcc, :subject, :reply_to].each do |attribute|
|
7
|
+
RSpec::Matchers.define "have_#{attribute}" do |matcher|
|
8
|
+
match do |actual|
|
9
|
+
email_matching(matcher, attribute, actual)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
[:from, :to, :cc, :bcc, :subject, :reply_to].each do |attribute|
|
15
|
+
RSpec::Matchers.define "be_#{attribute}" do |matcher|
|
16
|
+
match do |actual|
|
17
|
+
string_matching(matcher, attribute, actual)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
RSpec::Matchers.define "have_to_username" do |matcher|
|
23
|
+
def get_username(email_message)
|
24
|
+
email_message.header.fields[3].value
|
25
|
+
end
|
26
|
+
match do |actual|
|
27
|
+
string_matching(matcher, :to_username, get_username(actual))
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module SanitizeEmail
|
2
|
+
module TestHelpers
|
3
|
+
class UnexpectedMailType < StandardError; end
|
4
|
+
|
5
|
+
def string_matching(matcher, part, mail_or_part)
|
6
|
+
if mail_or_part.respond_to?(:=~) # Can we match a regex against it?
|
7
|
+
mail_or_part =~ Regexp.new(Regexp.escape(matcher))
|
8
|
+
else
|
9
|
+
raise UnexpectedMailType, "Cannot match #{matcher} for #{part}"
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
# Normalize arrays to strings
|
14
|
+
def array_matching(matcher, part, mail_or_part)
|
15
|
+
mail_or_part = mail_or_part.join(', ') if mail_or_part.respond_to?(:join)
|
16
|
+
string_matching(matcher, part, mail_or_part)
|
17
|
+
end
|
18
|
+
|
19
|
+
def email_matching(matcher, part, mail_or_part)
|
20
|
+
array_matching(matcher, part, mail_or_part.send(part))
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
end
|
data/lib/sanitize_email.rb
CHANGED
@@ -3,10 +3,9 @@
|
|
3
3
|
|
4
4
|
module SanitizeEmail
|
5
5
|
require 'sanitize_email/version'
|
6
|
+
require 'sanitize_email/deprecation'
|
6
7
|
require 'sanitize_email/config'
|
7
8
|
require 'sanitize_email/bleach'
|
8
|
-
require 'sanitize_email/email_matchers'
|
9
|
-
require 'sanitize_email/deprecation'
|
10
9
|
|
11
10
|
# Allow non-rails implementations to use this gem
|
12
11
|
if defined?(Rails) && ::Rails::VERSION::MAJOR >= 3
|
data/spec/sanitize_email_spec.rb
CHANGED
@@ -18,14 +18,13 @@ describe SanitizeEmail do
|
|
18
18
|
|
19
19
|
# Cleanup, so tests don't bleed
|
20
20
|
after(:each) do
|
21
|
-
SanitizeEmail::Config.config =
|
21
|
+
SanitizeEmail::Config.config = SanitizeEmail::Config::DEFAULTS
|
22
22
|
SanitizeEmail.force_sanitize = nil
|
23
23
|
Mail.class_variable_get(:@@delivery_interceptors).pop
|
24
24
|
end
|
25
25
|
|
26
26
|
def sanitize_spec_dryer(rails_env = 'test')
|
27
27
|
Launchy.stub(:open)
|
28
|
-
Launchy.should_receive(:open)
|
29
28
|
location = File.expand_path('../tmp/mail_dump', __FILE__)
|
30
29
|
FileUtils.rm_rf(location)
|
31
30
|
Mail.defaults do
|
@@ -35,17 +34,20 @@ describe SanitizeEmail do
|
|
35
34
|
end
|
36
35
|
|
37
36
|
def configure_sanitize_email(sanitize_hash = {})
|
38
|
-
options = DEFAULT_TEST_CONFIG.merge(sanitize_hash)
|
37
|
+
options = DEFAULT_TEST_CONFIG.merge(sanitize_hash).dup
|
39
38
|
options.reverse_merge!({ :sanitized_to => 'to@sanitize_email.org' }) unless sanitize_hash.has_key?(:sanitized_recipients)
|
40
39
|
SanitizeEmail::Config.configure do |config|
|
40
|
+
config[:activation_proc] = options[:activation_proc]
|
41
41
|
config[:sanitized_to] = options[:sanitized_to]
|
42
42
|
config[:sanitized_cc] = options[:sanitized_cc]
|
43
43
|
config[:sanitized_bcc] = options[:sanitized_bcc]
|
44
44
|
config[:use_actual_email_prepended_to_subject] = options[:use_actual_email_prepended_to_subject]
|
45
45
|
config[:use_actual_email_as_sanitized_user_name] = options[:use_actual_email_as_sanitized_user_name]
|
46
|
-
|
46
|
+
|
47
|
+
# For testing *deprecated* configuration options:
|
47
48
|
config[:local_environments] = options[:local_environments] if options[:local_environments]
|
48
49
|
config[:sanitized_recipients] = options[:sanitized_recipients] if options[:sanitized_recipients]
|
50
|
+
config[:force_sanitize] = options[:force_sanitize] unless options[:force_sanitize].nil?
|
49
51
|
end
|
50
52
|
Mail.register_interceptor(SanitizeEmail::Bleach.new)
|
51
53
|
end
|
@@ -73,41 +75,147 @@ describe SanitizeEmail do
|
|
73
75
|
end
|
74
76
|
end
|
75
77
|
|
76
|
-
context "
|
77
|
-
|
78
|
+
context "module methods" do
|
79
|
+
before(:each) do
|
80
|
+
sanitize_spec_dryer
|
81
|
+
end
|
82
|
+
|
83
|
+
context "unsanitary" do
|
78
84
|
before(:each) do
|
79
|
-
sanitize_spec_dryer
|
80
85
|
configure_sanitize_email
|
86
|
+
unsanitary_mail_delivery
|
87
|
+
end
|
88
|
+
it "should not alter non-sanitized attributes" do
|
89
|
+
@email_message.should have_from('from@example.org')
|
90
|
+
@email_message.should have_reply_to('reply_to@example.org')
|
91
|
+
end
|
92
|
+
it "should not prepend overrides" do
|
93
|
+
@email_message.should_not have_to_username("to at sanitize_email.org")
|
94
|
+
@email_message.should_not have_subject("(to at sanitize_email.org)")
|
81
95
|
end
|
96
|
+
it "alters nothing" do
|
97
|
+
@email_message.should have_from('from@example.org')
|
98
|
+
@email_message.should have_reply_to('reply_to@example.org')
|
99
|
+
@email_message.should have_from("from@example.org")
|
100
|
+
@email_message.should have_to("to@example.org")
|
101
|
+
@email_message.should_not have_to_username("to at")
|
102
|
+
@email_message.should have_cc("cc@example.org")
|
103
|
+
@email_message.should have_bcc("bcc@example.org")
|
104
|
+
@email_message.should have_subject("original subject")
|
105
|
+
end
|
106
|
+
end
|
82
107
|
|
83
|
-
|
108
|
+
context "sanitary" do
|
109
|
+
before(:each) do
|
110
|
+
configure_sanitize_email
|
111
|
+
sanitary_mail_delivery
|
112
|
+
end
|
113
|
+
it "should not alter non-sanitized attributes" do
|
114
|
+
@email_message.should have_from('from@example.org')
|
115
|
+
@email_message.should have_reply_to('reply_to@example.org')
|
116
|
+
end
|
117
|
+
it "should not prepend overrides" do
|
118
|
+
@email_message.should_not have_to_username("to at sanitize_email.org")
|
119
|
+
@email_message.should_not have_subject("(to at sanitize_email.org)")
|
120
|
+
end
|
121
|
+
it "should override" do
|
122
|
+
@email_message.should have_to("to@sanitize_email.org")
|
123
|
+
@email_message.should have_cc("cc@sanitize_email.org")
|
124
|
+
@email_message.should have_bcc("bcc@sanitize_email.org")
|
125
|
+
end
|
126
|
+
it "should not prepend originals by default" do
|
127
|
+
@email_message.should_not have_to_username("to at example.org <to@sanitize_email.org>")
|
128
|
+
@email_message.should_not have_subject("(to at example.org) original subject")
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
context "force_sanitize" do
|
133
|
+
context "true" do
|
84
134
|
before(:each) do
|
85
|
-
|
135
|
+
# Should turn off sanitization using the force_sanitize
|
136
|
+
configure_sanitize_email({:activation_proc => Proc.new {true}})
|
137
|
+
SanitizeEmail.force_sanitize = true
|
138
|
+
mail_delivery
|
86
139
|
end
|
87
140
|
it "should not alter non-sanitized attributes" do
|
88
141
|
@email_message.should have_from('from@example.org')
|
89
142
|
@email_message.should have_reply_to('reply_to@example.org')
|
90
143
|
end
|
91
|
-
it "should
|
92
|
-
@email_message.
|
93
|
-
@email_message.
|
144
|
+
it "should override" do
|
145
|
+
@email_message.should have_to("to@sanitize_email.org")
|
146
|
+
@email_message.should have_cc("cc@sanitize_email.org")
|
147
|
+
@email_message.should have_bcc("bcc@sanitize_email.org")
|
148
|
+
end
|
149
|
+
end
|
150
|
+
context "false" do
|
151
|
+
before(:each) do
|
152
|
+
# Should turn off sanitization using the force_sanitize
|
153
|
+
configure_sanitize_email({:activation_proc => Proc.new {true}})
|
154
|
+
SanitizeEmail.force_sanitize = false
|
155
|
+
mail_delivery
|
94
156
|
end
|
95
|
-
it "
|
157
|
+
it "should not alter non-sanitized attributes" do
|
96
158
|
@email_message.should have_from('from@example.org')
|
97
159
|
@email_message.should have_reply_to('reply_to@example.org')
|
98
|
-
|
160
|
+
end
|
161
|
+
it "should not alter normally sanitized attributes" do
|
99
162
|
@email_message.should have_to("to@example.org")
|
100
|
-
@email_message.should_not have_to_username("to at")
|
101
163
|
@email_message.should have_cc("cc@example.org")
|
102
164
|
@email_message.should have_bcc("bcc@example.org")
|
103
|
-
@email_message.should have_subject("original subject")
|
104
165
|
end
|
105
166
|
end
|
167
|
+
context "nil" do
|
168
|
+
context "activation proc enables" do
|
169
|
+
before(:each) do
|
170
|
+
sanitize_spec_dryer
|
171
|
+
# Should ignore force_sanitize setting
|
172
|
+
configure_sanitize_email({:activation_proc => Proc.new {true}})
|
173
|
+
SanitizeEmail.force_sanitize = nil
|
174
|
+
mail_delivery
|
175
|
+
end
|
176
|
+
it "should not alter non-sanitized attributes" do
|
177
|
+
@email_message.should have_from('from@example.org')
|
178
|
+
@email_message.should have_reply_to('reply_to@example.org')
|
179
|
+
end
|
180
|
+
it "should override" do
|
181
|
+
@email_message.should have_to("to@sanitize_email.org")
|
182
|
+
@email_message.should have_cc("cc@sanitize_email.org")
|
183
|
+
@email_message.should have_bcc("bcc@sanitize_email.org")
|
184
|
+
end
|
185
|
+
end
|
186
|
+
context "activation proc disables" do
|
187
|
+
before(:each) do
|
188
|
+
sanitize_spec_dryer
|
189
|
+
# Should ignore force_sanitize setting
|
190
|
+
configure_sanitize_email({:activation_proc => Proc.new {false}})
|
191
|
+
SanitizeEmail.force_sanitize = nil
|
192
|
+
mail_delivery
|
193
|
+
end
|
194
|
+
it "should not alter non-sanitized attributes" do
|
195
|
+
@email_message.should have_from('from@example.org')
|
196
|
+
@email_message.should have_reply_to('reply_to@example.org')
|
197
|
+
end
|
198
|
+
it "should not alter normally sanitized attributes" do
|
199
|
+
@email_message.should have_to("to@example.org")
|
200
|
+
@email_message.should have_cc("cc@example.org")
|
201
|
+
@email_message.should have_bcc("bcc@example.org")
|
202
|
+
end
|
203
|
+
end
|
204
|
+
end
|
205
|
+
end
|
206
|
+
end
|
106
207
|
|
208
|
+
context "config options" do
|
209
|
+
context ":use_actual_email_prepended_to_subject" do
|
107
210
|
context "true" do
|
108
211
|
before(:each) do
|
212
|
+
sanitize_spec_dryer
|
213
|
+
configure_sanitize_email({:use_actual_email_prepended_to_subject => true})
|
109
214
|
sanitary_mail_delivery
|
110
215
|
end
|
216
|
+
it "original to is prepended" do
|
217
|
+
@email_message.should have_subject("(to at example.org) original subject")
|
218
|
+
end
|
111
219
|
it "should not alter non-sanitized attributes" do
|
112
220
|
@email_message.should have_from('from@example.org')
|
113
221
|
@email_message.should have_reply_to('reply_to@example.org')
|
@@ -116,153 +224,138 @@ describe SanitizeEmail do
|
|
116
224
|
@email_message.should_not have_to_username("to at sanitize_email.org")
|
117
225
|
@email_message.should_not have_subject("(to at sanitize_email.org)")
|
118
226
|
end
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
227
|
+
end
|
228
|
+
context "false" do
|
229
|
+
before(:each) do
|
230
|
+
sanitize_spec_dryer
|
231
|
+
configure_sanitize_email({:use_actual_email_prepended_to_subject => false})
|
232
|
+
sanitary_mail_delivery
|
123
233
|
end
|
124
|
-
it "
|
125
|
-
@email_message.should_not have_to_username("to at example.org <to@sanitize_email.org>")
|
234
|
+
it "original to is not prepended" do
|
126
235
|
@email_message.should_not have_subject("(to at example.org) original subject")
|
127
236
|
end
|
237
|
+
it "should not alter non-sanitized attributes" do
|
238
|
+
@email_message.should have_from('from@example.org')
|
239
|
+
@email_message.should have_reply_to('reply_to@example.org')
|
240
|
+
end
|
241
|
+
it "should not prepend overrides" do
|
242
|
+
@email_message.should_not have_to_username("to at sanitize_email.org")
|
243
|
+
@email_message.should_not have_subject("(to at sanitize_email.org)")
|
244
|
+
end
|
128
245
|
end
|
129
246
|
end
|
130
247
|
|
131
|
-
context "
|
132
|
-
context "
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
sanitary_mail_delivery
|
138
|
-
end
|
139
|
-
it "original to is prepended" do
|
140
|
-
@email_message.should have_subject("(to at example.org) original subject")
|
141
|
-
end
|
142
|
-
it "should not alter non-sanitized attributes" do
|
143
|
-
@email_message.should have_from('from@example.org')
|
144
|
-
@email_message.should have_reply_to('reply_to@example.org')
|
145
|
-
end
|
146
|
-
it "should not prepend overrides" do
|
147
|
-
@email_message.should_not have_to_username("to at sanitize_email.org")
|
148
|
-
@email_message.should_not have_subject("(to at sanitize_email.org)")
|
149
|
-
end
|
248
|
+
context ":use_actual_email_as_sanitized_user_name" do
|
249
|
+
context "true" do
|
250
|
+
before(:each) do
|
251
|
+
sanitize_spec_dryer
|
252
|
+
configure_sanitize_email({:use_actual_email_as_sanitized_user_name => true})
|
253
|
+
sanitary_mail_delivery
|
150
254
|
end
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
255
|
+
it "original to is munged and prepended" do
|
256
|
+
@email_message.should have_to_username("to at example.org <to@sanitize_email.org>")
|
257
|
+
end
|
258
|
+
it "should not alter non-sanitized attributes" do
|
259
|
+
@email_message.should have_from('from@example.org')
|
260
|
+
@email_message.should have_reply_to('reply_to@example.org')
|
261
|
+
end
|
262
|
+
it "should not prepend overrides" do
|
263
|
+
@email_message.should_not have_to_username("to at sanitize_email.org")
|
264
|
+
@email_message.should_not have_subject("(to at sanitize_email.org)")
|
265
|
+
end
|
266
|
+
end
|
267
|
+
context "false" do
|
268
|
+
before(:each) do
|
269
|
+
sanitize_spec_dryer
|
270
|
+
configure_sanitize_email({:use_actual_email_as_sanitized_user_name => false})
|
271
|
+
sanitary_mail_delivery
|
272
|
+
end
|
273
|
+
it "original to is not prepended" do
|
274
|
+
@email_message.should_not have_to_username("to at example.org <to@sanitize_email.org>")
|
275
|
+
end
|
276
|
+
it "should not alter non-sanitized attributes" do
|
277
|
+
@email_message.should have_from('from@example.org')
|
278
|
+
@email_message.should have_reply_to('reply_to@example.org')
|
279
|
+
end
|
280
|
+
it "should not prepend overrides" do
|
281
|
+
@email_message.should_not have_to_username("to at sanitize_email.org")
|
282
|
+
@email_message.should_not have_subject("(to at sanitize_email.org)")
|
168
283
|
end
|
169
284
|
end
|
285
|
+
end
|
170
286
|
|
171
|
-
|
172
|
-
|
287
|
+
context "deprecated" do
|
288
|
+
#before(:each) do
|
289
|
+
# SanitizeEmail::Deprecation.deprecate_in_silence = false
|
290
|
+
#end
|
291
|
+
context ":local_environments" do
|
292
|
+
context "matching" do
|
173
293
|
before(:each) do
|
174
|
-
sanitize_spec_dryer
|
175
|
-
configure_sanitize_email({:
|
176
|
-
|
177
|
-
|
178
|
-
it "original to is munged and prepended" do
|
179
|
-
@email_message.should have_to_username("to at example.org <to@sanitize_email.org>")
|
294
|
+
sanitize_spec_dryer('test')
|
295
|
+
configure_sanitize_email({:local_environments => ['test']})
|
296
|
+
SanitizeEmail[:activation_proc].call.should == true
|
297
|
+
mail_delivery
|
180
298
|
end
|
181
299
|
it "should not alter non-sanitized attributes" do
|
182
300
|
@email_message.should have_from('from@example.org')
|
183
301
|
@email_message.should have_reply_to('reply_to@example.org')
|
184
302
|
end
|
185
|
-
it "should
|
186
|
-
@email_message.
|
187
|
-
@email_message.
|
303
|
+
it "should use activation_proc for matching environment" do
|
304
|
+
@email_message.should have_to("to@sanitize_email.org")
|
305
|
+
@email_message.should have_cc("cc@sanitize_email.org")
|
306
|
+
@email_message.should have_bcc("bcc@sanitize_email.org")
|
188
307
|
end
|
189
308
|
end
|
190
|
-
context "
|
309
|
+
context "non-matching" do
|
191
310
|
before(:each) do
|
192
|
-
sanitize_spec_dryer
|
193
|
-
configure_sanitize_email({:
|
194
|
-
|
195
|
-
|
196
|
-
it "original to is not prepended" do
|
197
|
-
@email_message.should_not have_to_username("to at example.org <to@sanitize_email.org>")
|
311
|
+
sanitize_spec_dryer('production')
|
312
|
+
configure_sanitize_email({:local_environments => ['development']}) # Won't match!
|
313
|
+
SanitizeEmail[:activation_proc].call.should == false
|
314
|
+
mail_delivery
|
198
315
|
end
|
199
316
|
it "should not alter non-sanitized attributes" do
|
200
317
|
@email_message.should have_from('from@example.org')
|
201
318
|
@email_message.should have_reply_to('reply_to@example.org')
|
202
319
|
end
|
203
|
-
it "should
|
204
|
-
@email_message.
|
205
|
-
@email_message.
|
320
|
+
it "should use activation_proc for non-matching environment" do
|
321
|
+
@email_message.should have_to("to@example.org")
|
322
|
+
@email_message.should have_cc("cc@example.org")
|
323
|
+
@email_message.should have_bcc("bcc@example.org")
|
206
324
|
end
|
207
325
|
end
|
208
326
|
end
|
209
327
|
|
210
|
-
context "
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
SanitizeEmail[:activation_proc].call.should == true
|
220
|
-
mail_delivery
|
221
|
-
end
|
222
|
-
it "should not alter non-sanitized attributes" do
|
223
|
-
@email_message.should have_from('from@example.org')
|
224
|
-
@email_message.should have_reply_to('reply_to@example.org')
|
225
|
-
end
|
226
|
-
it "should use activation_proc for matching environment" do
|
227
|
-
@email_message.should have_to("to@sanitize_email.org")
|
228
|
-
@email_message.should have_cc("cc@sanitize_email.org")
|
229
|
-
@email_message.should have_bcc("bcc@sanitize_email.org")
|
230
|
-
end
|
231
|
-
end
|
232
|
-
context "non-matching" do
|
233
|
-
before(:each) do
|
234
|
-
sanitize_spec_dryer('production')
|
235
|
-
configure_sanitize_email({:local_environments => ['development']}) # Won't match!
|
236
|
-
SanitizeEmail[:activation_proc].call.should == false
|
237
|
-
mail_delivery
|
238
|
-
end
|
239
|
-
it "should not alter non-sanitized attributes" do
|
240
|
-
@email_message.should have_from('from@example.org')
|
241
|
-
@email_message.should have_reply_to('reply_to@example.org')
|
242
|
-
end
|
243
|
-
it "should use activation_proc for non-matching environment" do
|
244
|
-
@email_message.should have_to("to@example.org")
|
245
|
-
@email_message.should have_cc("cc@example.org")
|
246
|
-
@email_message.should have_bcc("bcc@example.org")
|
247
|
-
end
|
248
|
-
end
|
328
|
+
context ":sanitized_recipients" do
|
329
|
+
before(:each) do
|
330
|
+
sanitize_spec_dryer
|
331
|
+
configure_sanitize_email({:sanitized_recipients => 'barney@sanitize_email.org'})
|
332
|
+
sanitary_mail_delivery
|
333
|
+
end
|
334
|
+
it "should not alter non-sanitized attributes" do
|
335
|
+
@email_message.should have_from('from@example.org')
|
336
|
+
@email_message.should have_reply_to('reply_to@example.org')
|
249
337
|
end
|
338
|
+
it "used as sanitized_to" do
|
339
|
+
@email_message.should have_to("barney@sanitize_email.org")
|
340
|
+
end
|
341
|
+
end
|
250
342
|
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
343
|
+
context ":force_sanitize" do
|
344
|
+
before(:each) do
|
345
|
+
sanitize_spec_dryer
|
346
|
+
# Should turn off sanitization using the force_sanitize
|
347
|
+
configure_sanitize_email({:activation_proc => Proc.new {true}, :force_sanitize => false})
|
348
|
+
mail_delivery
|
349
|
+
end
|
350
|
+
it "should not alter non-sanitized attributes" do
|
351
|
+
@email_message.should have_from('from@example.org')
|
352
|
+
@email_message.should have_reply_to('reply_to@example.org')
|
353
|
+
end
|
354
|
+
it "should not alter normally sanitized attributes" do
|
355
|
+
@email_message.should have_to("to@example.org")
|
264
356
|
end
|
265
357
|
end
|
358
|
+
|
266
359
|
end
|
267
360
|
end
|
268
361
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'sanitize_email'
|
2
|
+
require 'sanitize_email/rspec_matchers'
|
2
3
|
require 'launchy'
|
3
4
|
require 'mail'
|
4
5
|
require 'rails'
|
@@ -14,6 +15,6 @@ RSpec.configure do |config|
|
|
14
15
|
config.run_all_when_everything_filtered = true
|
15
16
|
#config.filter_run :focus
|
16
17
|
|
17
|
-
config.include SanitizeEmail::
|
18
|
+
config.include SanitizeEmail::RspecMatchers
|
18
19
|
end
|
19
20
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sanitize_email
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -217,9 +217,10 @@ files:
|
|
217
217
|
- lib/sanitize_email/bleach.rb
|
218
218
|
- lib/sanitize_email/config.rb
|
219
219
|
- lib/sanitize_email/deprecation.rb
|
220
|
-
- lib/sanitize_email/email_matchers.rb
|
221
220
|
- lib/sanitize_email/engine.rb
|
222
221
|
- lib/sanitize_email/railtie.rb
|
222
|
+
- lib/sanitize_email/rspec_matchers.rb
|
223
|
+
- lib/sanitize_email/test_helpers.rb
|
223
224
|
- lib/sanitize_email/version.rb
|
224
225
|
- sanitize_email.gemspec
|
225
226
|
- spec/sanitize_email_spec.rb
|
@@ -1,51 +0,0 @@
|
|
1
|
-
module SanitizeEmail
|
2
|
-
module EmailMatchers
|
3
|
-
class UnexpectedMailType < StandardError; end
|
4
|
-
|
5
|
-
def string_matching(matcher, part, mail_or_part)
|
6
|
-
if mail_or_part.respond_to?(:=~) # Can we match a regex against it?
|
7
|
-
mail_or_part =~ Regexp.new(Regexp.escape(matcher))
|
8
|
-
else
|
9
|
-
raise UnexpectedMailType, "Cannot match #{matcher} for #{part}"
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
# Normalize arrays to strings
|
14
|
-
def array_matching(matcher, part, mail_or_part)
|
15
|
-
mail_or_part = mail_or_part.join(', ') if mail_or_part.respond_to?(:join)
|
16
|
-
string_matching(matcher, part, mail_or_part)
|
17
|
-
end
|
18
|
-
|
19
|
-
def email_matching(matcher, part, mail_or_part)
|
20
|
-
array_matching(matcher, part, mail_or_part.send(part))
|
21
|
-
end
|
22
|
-
|
23
|
-
if defined?(Rspec)
|
24
|
-
[:from, :to, :cc, :bcc, :subject, :reply_to].each do |attribute|
|
25
|
-
RSpec::Matchers.define "have_#{attribute}" do |matcher|
|
26
|
-
match do |actual|
|
27
|
-
email_matching(matcher, attribute, actual)
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
[:from, :to, :cc, :bcc, :subject, :reply_to].each do |attribute|
|
33
|
-
RSpec::Matchers.define "be_#{attribute}" do |matcher|
|
34
|
-
match do |actual|
|
35
|
-
string_matching(matcher, attribute, actual)
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
RSpec::Matchers.define "have_to_username" do |matcher|
|
41
|
-
def get_username(email_message)
|
42
|
-
email_message.header.fields[3].value
|
43
|
-
end
|
44
|
-
match do |actual|
|
45
|
-
string_matching(matcher, :to_username, get_username(actual))
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
end
|
51
|
-
end
|