sanitize_email 2.0.2 → 2.0.4
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.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +3 -0
- data/CHANGELOG.md +82 -12
- data/CODE_OF_CONDUCT.md +84 -0
- data/CONTRIBUTING.md +47 -0
- data/{LICENSE → LICENSE.txt} +1 -1
- data/README.md +371 -58
- data/SECURITY.md +15 -0
- data/lib/sanitize_email/bleach.rb +13 -8
- data/lib/sanitize_email/config.rb +20 -20
- data/lib/sanitize_email/deprecation.rb +6 -6
- data/lib/sanitize_email/engine.rb +1 -1
- data/lib/sanitize_email/mail_ext.rb +2 -0
- data/lib/sanitize_email/mail_header_tools.rb +19 -15
- data/lib/sanitize_email/overridden_addresses.rb +77 -19
- data/lib/sanitize_email/railtie.rb +1 -1
- data/lib/sanitize_email/rspec_matchers.rb +55 -31
- data/lib/sanitize_email/test_helpers.rb +6 -6
- data/lib/sanitize_email/version.rb +4 -2
- data/lib/sanitize_email.rb +28 -18
- data.tar.gz.sig +0 -0
- metadata +70 -90
- metadata.gz.sig +0 -0
- data/.coveralls.yml +0 -1
- data/.gitignore +0 -12
- data/.pryrc +0 -11
- data/.reek +0 -9
- data/.rspec +0 -2
- data/.rubocop.yml +0 -73
- data/.rubocop_rspec.yml +0 -35
- data/.rubocop_todo.yml +0 -21
- data/.ruby-gemset +0 -1
- data/.ruby-version +0 -1
- data/.travis.yml +0 -71
- data/Appraisals +0 -29
- data/Gemfile +0 -22
- data/REEK +0 -2
- data/Rakefile +0 -52
- data/gemfiles/rails_4_2.gemfile +0 -17
- data/gemfiles/rails_5_0.gemfile +0 -17
- data/gemfiles/rails_5_1.gemfile +0 -17
- data/gemfiles/rails_5_2.gemfile +0 -17
- data/init.rb +0 -3
- data/sanitize_email.gemspec +0 -49
- data/spec/sanitize_email_spec.rb +0 -944
- data/spec/spec_helper.rb +0 -28
data/spec/sanitize_email_spec.rb
DELETED
@@ -1,944 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# Copyright (c) 2008-16 Peter H. Boling of RailsBling.com
|
4
|
-
# Released under the MIT license
|
5
|
-
require 'spec_helper'
|
6
|
-
|
7
|
-
describe SanitizeEmail do
|
8
|
-
DEFAULT_TEST_CONFIG = {
|
9
|
-
:sanitized_cc => 'cc@sanitize_email.org',
|
10
|
-
:sanitized_bcc => 'bcc@sanitize_email.org',
|
11
|
-
:use_actual_email_prepended_to_subject => false,
|
12
|
-
:use_actual_environment_prepended_to_subject => false,
|
13
|
-
:use_actual_email_as_sanitized_user_name => false,
|
14
|
-
}.freeze
|
15
|
-
|
16
|
-
# Cleanup, so tests don't bleed
|
17
|
-
after do
|
18
|
-
SanitizeEmail::Config.config = SanitizeEmail::Config::DEFAULTS
|
19
|
-
described_class.force_sanitize = nil
|
20
|
-
Mail.class_variable_get(:@@delivery_interceptors).pop
|
21
|
-
end
|
22
|
-
|
23
|
-
def sanitize_spec_dryer(rails_env = 'test')
|
24
|
-
logger = Logger.new($stdout).tap do |logsy|
|
25
|
-
logsy.level = 5 # Unknown (make it silent!)
|
26
|
-
end
|
27
|
-
|
28
|
-
Mail.defaults do
|
29
|
-
delivery_method :logger, :logger => logger, :severity => :info
|
30
|
-
end
|
31
|
-
SanitizeEmail::Config.instance_variable_set(
|
32
|
-
:@config,
|
33
|
-
SanitizeEmail::Config::DEFAULTS.dup
|
34
|
-
)
|
35
|
-
allow(Rails).to receive(:env).and_return(rails_env)
|
36
|
-
end
|
37
|
-
|
38
|
-
def configure_sanitize_email(sanitize_hash = {})
|
39
|
-
options = DEFAULT_TEST_CONFIG.merge(sanitize_hash).dup
|
40
|
-
unless sanitize_hash.key?(:sanitized_recipients)
|
41
|
-
options.reverse_merge!(:sanitized_to => 'to@sanitize_email.org')
|
42
|
-
end
|
43
|
-
configure_from_options(options)
|
44
|
-
Mail.register_interceptor(SanitizeEmail::Bleach)
|
45
|
-
end
|
46
|
-
|
47
|
-
def configure_from_options(options)
|
48
|
-
SanitizeEmail::Config.configure do |config|
|
49
|
-
config[:engage] = options[:engage]
|
50
|
-
config[:environment] = options[:environment]
|
51
|
-
config[:activation_proc] = options[:activation_proc]
|
52
|
-
config[:sanitized_to] = options[:sanitized_to]
|
53
|
-
config[:sanitized_cc] = options[:sanitized_cc]
|
54
|
-
config[:sanitized_bcc] = options[:sanitized_bcc]
|
55
|
-
config[:use_actual_email_prepended_to_subject] = options[:use_actual_email_prepended_to_subject]
|
56
|
-
config[:use_actual_environment_prepended_to_subject] = options[:use_actual_environment_prepended_to_subject]
|
57
|
-
config[:use_actual_email_as_sanitized_user_name] = options[:use_actual_email_as_sanitized_user_name]
|
58
|
-
|
59
|
-
# For testing *deprecated* configuration options:
|
60
|
-
config[:local_environments] = options[:local_environments] if options[:local_environments]
|
61
|
-
config[:sanitized_recipients] = options[:sanitized_recipients] if options[:sanitized_recipients]
|
62
|
-
config[:force_sanitize] = options[:force_sanitize] unless options[:force_sanitize].nil?
|
63
|
-
end
|
64
|
-
end
|
65
|
-
|
66
|
-
def funky_config
|
67
|
-
SanitizeEmail::Config.configure do |config|
|
68
|
-
config[:sanitized_to] =
|
69
|
-
%w[
|
70
|
-
funky@sanitize_email.org
|
71
|
-
yummy@sanitize_email.org
|
72
|
-
same@example.org
|
73
|
-
]
|
74
|
-
config[:sanitized_cc] = nil
|
75
|
-
config[:sanitized_bcc] = nil
|
76
|
-
# logic to turn sanitize_email on and off goes in this Proc:
|
77
|
-
config[:activation_proc] = proc { Rails.env != 'production' }
|
78
|
-
config[:use_actual_email_prepended_to_subject] = true
|
79
|
-
config[:use_actual_environment_prepended_to_subject] = true
|
80
|
-
config[:use_actual_email_as_sanitized_user_name] = false
|
81
|
-
end
|
82
|
-
Mail.register_interceptor(SanitizeEmail::Bleach)
|
83
|
-
end
|
84
|
-
|
85
|
-
def sanitary_mail_delivery(config_options = {})
|
86
|
-
SanitizeEmail.sanitary(config_options) do
|
87
|
-
mail_delivery
|
88
|
-
end
|
89
|
-
end
|
90
|
-
|
91
|
-
def sanitary_mail_delivery_multiple_recipients(config_options = {})
|
92
|
-
SanitizeEmail.sanitary(config_options) do
|
93
|
-
mail_delivery_multiple_recipients
|
94
|
-
end
|
95
|
-
end
|
96
|
-
|
97
|
-
def sanitary_mail_delivery_frozen_strings(config_options = {})
|
98
|
-
SanitizeEmail.sanitary(config_options) do
|
99
|
-
mail_delivery_frozen_strings
|
100
|
-
end
|
101
|
-
end
|
102
|
-
|
103
|
-
def unsanitary_mail_delivery
|
104
|
-
SanitizeEmail.unsanitary do
|
105
|
-
mail_delivery
|
106
|
-
end
|
107
|
-
end
|
108
|
-
|
109
|
-
def mail_delivery_frozen_strings
|
110
|
-
@email_message = Mail.deliver do
|
111
|
-
from 'from@example.org'
|
112
|
-
to 'to@example.org'
|
113
|
-
subject 'original subject'
|
114
|
-
body 'funky fresh'
|
115
|
-
end
|
116
|
-
end
|
117
|
-
|
118
|
-
def mail_delivery_hot_mess
|
119
|
-
@email_message = Mail.deliver do
|
120
|
-
from 'same@example.org'
|
121
|
-
to %w[
|
122
|
-
same@example.org
|
123
|
-
same@example.org
|
124
|
-
same@example.org
|
125
|
-
same@example.org
|
126
|
-
same@example.org
|
127
|
-
]
|
128
|
-
cc 'same@example.org'
|
129
|
-
bcc 'same@example.org'
|
130
|
-
reply_to 'same@example.org'
|
131
|
-
subject 'original subject'
|
132
|
-
body 'funky fresh'
|
133
|
-
end
|
134
|
-
end
|
135
|
-
|
136
|
-
def mail_delivery
|
137
|
-
@email_message = Mail.deliver do
|
138
|
-
from 'from@example.org'
|
139
|
-
to 'to@example.org'
|
140
|
-
cc 'cc@example.org'
|
141
|
-
bcc 'bcc@example.org'
|
142
|
-
reply_to 'reply_to@example.org'
|
143
|
-
subject 'original subject'
|
144
|
-
body 'funky fresh'
|
145
|
-
end
|
146
|
-
end
|
147
|
-
|
148
|
-
def mail_delivery_multiple_recipients
|
149
|
-
@email_message = Mail.deliver do
|
150
|
-
from 'from@example.org'
|
151
|
-
to %w[to1@example.org to2@example.org to3@example.org]
|
152
|
-
cc %w[cc1@example.org cc2@example.org cc3@example.org]
|
153
|
-
bcc %w[bcc1@example.org bcc2@example.org bcc3@example.org]
|
154
|
-
reply_to 'reply_to@example.org'
|
155
|
-
subject 'original subject'
|
156
|
-
body 'funky fresh'
|
157
|
-
end
|
158
|
-
end
|
159
|
-
|
160
|
-
before do
|
161
|
-
SanitizeEmail::Deprecation.deprecate_in_silence = true
|
162
|
-
sanitize_spec_dryer
|
163
|
-
end
|
164
|
-
|
165
|
-
context 'module methods' do
|
166
|
-
context 'unsanitary' do
|
167
|
-
before do
|
168
|
-
configure_sanitize_email
|
169
|
-
unsanitary_mail_delivery
|
170
|
-
end
|
171
|
-
it 'does not alter non-sanitized attributes' do
|
172
|
-
expect(@email_message).to have_from('from@example.org')
|
173
|
-
expect(@email_message).to have_reply_to('reply_to@example.org')
|
174
|
-
expect(@email_message).to have_body_text('funky fresh')
|
175
|
-
end
|
176
|
-
it 'does not prepend overrides' do
|
177
|
-
expect(@email_message).not_to have_to_username(
|
178
|
-
'to at sanitize_email.org'
|
179
|
-
)
|
180
|
-
expect(@email_message).not_to have_subject(
|
181
|
-
'(to at sanitize_email.org)'
|
182
|
-
)
|
183
|
-
end
|
184
|
-
it 'alters nothing' do
|
185
|
-
expect(@email_message).to have_from('from@example.org')
|
186
|
-
expect(@email_message).to have_reply_to('reply_to@example.org')
|
187
|
-
expect(@email_message).to have_from('from@example.org')
|
188
|
-
expect(@email_message).to have_to('to@example.org')
|
189
|
-
expect(@email_message).not_to have_to_username('to at')
|
190
|
-
expect(@email_message).to have_cc('cc@example.org')
|
191
|
-
expect(@email_message).to have_bcc('bcc@example.org')
|
192
|
-
expect(@email_message).to have_subject('original subject')
|
193
|
-
expect(@email_message).to have_body_text('funky fresh')
|
194
|
-
end
|
195
|
-
end
|
196
|
-
|
197
|
-
context 'sanitary' do
|
198
|
-
before do
|
199
|
-
configure_sanitize_email
|
200
|
-
sanitary_mail_delivery
|
201
|
-
end
|
202
|
-
it 'does not alter non-sanitized attributes' do
|
203
|
-
expect(@email_message).to have_from('from@example.org')
|
204
|
-
expect(@email_message).to have_reply_to('reply_to@example.org')
|
205
|
-
expect(@email_message).to have_body_text('funky fresh')
|
206
|
-
end
|
207
|
-
it 'does not prepend overrides' do
|
208
|
-
expect(@email_message).not_to have_to_username(
|
209
|
-
'to at sanitize_email.org'
|
210
|
-
)
|
211
|
-
expect(@email_message).not_to have_subject(
|
212
|
-
'(to at sanitize_email.org)'
|
213
|
-
)
|
214
|
-
end
|
215
|
-
it 'overrides' do
|
216
|
-
expect(@email_message).to have_to('to@sanitize_email.org')
|
217
|
-
expect(@email_message).to have_cc('cc@sanitize_email.org')
|
218
|
-
expect(@email_message).to have_bcc('bcc@sanitize_email.org')
|
219
|
-
end
|
220
|
-
it 'sets headers' do
|
221
|
-
expect(@email_message).to have_header(
|
222
|
-
'X-Sanitize-Email-To',
|
223
|
-
'to@example.org'
|
224
|
-
)
|
225
|
-
expect(@email_message).to have_header(
|
226
|
-
'X-Sanitize-Email-Cc',
|
227
|
-
'cc@example.org'
|
228
|
-
)
|
229
|
-
expect(@email_message).not_to have_header(
|
230
|
-
'X-Sanitize-Email-Bcc',
|
231
|
-
'bcc@sanitize_email.org'
|
232
|
-
)
|
233
|
-
end
|
234
|
-
it 'does not prepend originals by default' do
|
235
|
-
expect(@email_message).not_to have_to_username(
|
236
|
-
'to at example.org <to@sanitize_email.org>'
|
237
|
-
)
|
238
|
-
expect(@email_message).not_to have_subject(
|
239
|
-
'(to at example.org) original subject'
|
240
|
-
)
|
241
|
-
end
|
242
|
-
end
|
243
|
-
|
244
|
-
context 'sanitary with multiple recipients' do
|
245
|
-
before do
|
246
|
-
configure_sanitize_email
|
247
|
-
sanitary_mail_delivery_multiple_recipients
|
248
|
-
end
|
249
|
-
it 'does not alter non-sanitized attributes' do
|
250
|
-
expect(@email_message).to have_from('from@example.org')
|
251
|
-
expect(@email_message).to have_reply_to('reply_to@example.org')
|
252
|
-
expect(@email_message).to have_body_text('funky fresh')
|
253
|
-
end
|
254
|
-
it 'does not prepend overrides' do
|
255
|
-
expect(@email_message).not_to have_to_username(
|
256
|
-
'to at sanitize_email.org'
|
257
|
-
)
|
258
|
-
expect(@email_message).not_to have_subject('(to at sanitize_email.org)')
|
259
|
-
end
|
260
|
-
it 'overrides' do
|
261
|
-
expect(@email_message).to have_to('to@sanitize_email.org')
|
262
|
-
expect(@email_message).to have_cc('cc@sanitize_email.org')
|
263
|
-
expect(@email_message).to have_bcc('bcc@sanitize_email.org')
|
264
|
-
end
|
265
|
-
it 'sets headers for sanitized :to recipients' do
|
266
|
-
expect(@email_message).to have_header(
|
267
|
-
'X-Sanitize-Email-To',
|
268
|
-
'to1@example.org'
|
269
|
-
)
|
270
|
-
expect(@email_message).not_to have_header(
|
271
|
-
'X-Sanitize-Email-To-0',
|
272
|
-
'to1@example.org'
|
273
|
-
)
|
274
|
-
expect(@email_message).not_to have_header(
|
275
|
-
'X-Sanitize-Email-To-1',
|
276
|
-
'to1@example.org'
|
277
|
-
)
|
278
|
-
expect(@email_message).to have_header(
|
279
|
-
'X-Sanitize-Email-To-2',
|
280
|
-
'to2@example.org'
|
281
|
-
)
|
282
|
-
expect(@email_message).to have_header(
|
283
|
-
'X-Sanitize-Email-To-3',
|
284
|
-
'to3@example.org'
|
285
|
-
)
|
286
|
-
end
|
287
|
-
it 'sets headers for sanitized :cc recipients' do
|
288
|
-
expect(@email_message).to have_header(
|
289
|
-
'X-Sanitize-Email-Cc',
|
290
|
-
'cc1@example.org'
|
291
|
-
)
|
292
|
-
expect(@email_message).not_to have_header(
|
293
|
-
'X-Sanitize-Email-Cc-0',
|
294
|
-
'cc1@example.org'
|
295
|
-
)
|
296
|
-
expect(@email_message).not_to have_header(
|
297
|
-
'X-Sanitize-Email-Cc-1',
|
298
|
-
'cc1@example.org'
|
299
|
-
)
|
300
|
-
expect(@email_message).to have_header(
|
301
|
-
'X-Sanitize-Email-Cc-2',
|
302
|
-
'cc2@example.org'
|
303
|
-
)
|
304
|
-
expect(@email_message).to have_header(
|
305
|
-
'X-Sanitize-Email-Cc-3',
|
306
|
-
'cc3@example.org'
|
307
|
-
)
|
308
|
-
end
|
309
|
-
it 'does not set headers for sanitized :bcc recipients' do
|
310
|
-
expect(@email_message).not_to have_header(
|
311
|
-
'X-Sanitize-Email-Bcc',
|
312
|
-
'bcc1@sanitize_email.org'
|
313
|
-
)
|
314
|
-
expect(@email_message).not_to have_header(
|
315
|
-
'X-Sanitize-Email-Bcc-0',
|
316
|
-
'bcc1@sanitize_email.org'
|
317
|
-
)
|
318
|
-
expect(@email_message).not_to have_header(
|
319
|
-
'X-Sanitize-Email-Bcc-1',
|
320
|
-
'bcc1@sanitize_email.org'
|
321
|
-
)
|
322
|
-
expect(@email_message).not_to have_header(
|
323
|
-
'X-Sanitize-Email-Bcc-2',
|
324
|
-
'bcc2@sanitize_email.org'
|
325
|
-
)
|
326
|
-
expect(@email_message).not_to have_header(
|
327
|
-
'X-Sanitize-Email-Bcc-3',
|
328
|
-
'bcc3@sanitize_email.org'
|
329
|
-
)
|
330
|
-
end
|
331
|
-
it 'does not prepend originals by default' do
|
332
|
-
expect(@email_message).not_to have_to_username(
|
333
|
-
'to at example.org <to@sanitize_email.org>'
|
334
|
-
)
|
335
|
-
expect(@email_message).not_to have_subject(
|
336
|
-
'(to at example.org) original subject'
|
337
|
-
)
|
338
|
-
end
|
339
|
-
end
|
340
|
-
|
341
|
-
context 'sanitary with funky config' do
|
342
|
-
before do
|
343
|
-
funky_config
|
344
|
-
described_class.force_sanitize = true
|
345
|
-
mail_delivery
|
346
|
-
end
|
347
|
-
it 'original to is prepended to subject' do
|
348
|
-
regex = /\(to at example.org\).*original subject/
|
349
|
-
expect(@email_message).to have_subject(regex)
|
350
|
-
end
|
351
|
-
it 'original to is only prepended once to subject' do
|
352
|
-
regex = /\(to at example.org\).*\(to at example.org\).*original subject/
|
353
|
-
expect(@email_message).not_to have_subject(regex)
|
354
|
-
end
|
355
|
-
it 'does not alter non-sanitized attributes' do
|
356
|
-
expect(@email_message).to have_from('from@example.org')
|
357
|
-
expect(@email_message).to have_reply_to('reply_to@example.org')
|
358
|
-
expect(@email_message).to have_body_text('funky fresh')
|
359
|
-
end
|
360
|
-
it 'does not prepend overrides' do
|
361
|
-
expect(@email_message).not_to have_to_username(
|
362
|
-
'to at sanitize_email.org'
|
363
|
-
)
|
364
|
-
regex = /.*\(to at sanitize_email.org\).*/
|
365
|
-
expect(@email_message).not_to have_subject(regex)
|
366
|
-
end
|
367
|
-
it 'overrides where original recipients were not nil' do
|
368
|
-
expect(@email_message).to have_to('funky@sanitize_email.org')
|
369
|
-
end
|
370
|
-
it 'does not override where original recipients were nil' do
|
371
|
-
expect(@email_message).not_to have_cc('cc@sanitize_email.org')
|
372
|
-
expect(@email_message).not_to have_bcc('bcc@sanitize_email.org')
|
373
|
-
end
|
374
|
-
it 'sets headers of originals' do
|
375
|
-
expect(@email_message).to have_header(
|
376
|
-
'X-Sanitize-Email-To',
|
377
|
-
'to@example.org'
|
378
|
-
)
|
379
|
-
expect(@email_message).to have_header(
|
380
|
-
'X-Sanitize-Email-Cc',
|
381
|
-
'cc@example.org'
|
382
|
-
)
|
383
|
-
end
|
384
|
-
it 'does not set headers of bcc' do
|
385
|
-
expect(@email_message).not_to have_header(
|
386
|
-
'X-Sanitize-Email-Bcc',
|
387
|
-
'bcc@sanitize_email.org'
|
388
|
-
)
|
389
|
-
end
|
390
|
-
it 'does not set headers of overrides' do
|
391
|
-
expect(@email_message).not_to have_header(
|
392
|
-
'X-Sanitize-Email-To',
|
393
|
-
'funky@sanitize_email.org'
|
394
|
-
)
|
395
|
-
expect(@email_message).not_to have_header(
|
396
|
-
'X-Sanitize-Email-Cc',
|
397
|
-
'cc@sanitize_email.org'
|
398
|
-
)
|
399
|
-
expect(@email_message).not_to have_header(
|
400
|
-
'X-Sanitize-Email-Bcc',
|
401
|
-
'bcc@sanitize_email.org'
|
402
|
-
)
|
403
|
-
# puts "email headers:\n#{@email_message.header}"
|
404
|
-
end
|
405
|
-
it 'does not prepend originals by default' do
|
406
|
-
expect(@email_message).not_to have_to_username(
|
407
|
-
'to at example.org <to@sanitize_email.org>'
|
408
|
-
)
|
409
|
-
expect(@email_message).not_to have_subject(
|
410
|
-
'(to at example.org) original subject'
|
411
|
-
)
|
412
|
-
end
|
413
|
-
end
|
414
|
-
|
415
|
-
context 'sanitary with funky config and hot mess delivery' do
|
416
|
-
before do
|
417
|
-
funky_config
|
418
|
-
described_class.force_sanitize = true
|
419
|
-
mail_delivery_hot_mess
|
420
|
-
end
|
421
|
-
it 'original to is prepended to subject' do
|
422
|
-
regex = /\(same at example.org\).*original subject/
|
423
|
-
expect(@email_message).to match_subject(regex)
|
424
|
-
end
|
425
|
-
it 'original to is only prepended once to subject' do
|
426
|
-
regex = /\(same at example.org\).*\(same at example.org\).*original subject/
|
427
|
-
expect(@email_message).not_to match_subject(regex)
|
428
|
-
end
|
429
|
-
it 'does not alter non-sanitized attributes' do
|
430
|
-
expect(@email_message).to have_from('same@example.org')
|
431
|
-
expect(@email_message).to have_reply_to('same@example.org')
|
432
|
-
expect(@email_message).to have_body_text('funky fresh')
|
433
|
-
end
|
434
|
-
it 'does not prepend overrides' do
|
435
|
-
expect(@email_message).not_to have_to_username('same at example.org')
|
436
|
-
end
|
437
|
-
it 'overrides where original recipients were not nil' do
|
438
|
-
expect(@email_message).to have_to('same@example.org')
|
439
|
-
end
|
440
|
-
it 'does not override where original recipients were nil' do
|
441
|
-
expect(@email_message).not_to have_cc('same@example.org')
|
442
|
-
expect(@email_message).not_to have_bcc('same@example.org')
|
443
|
-
end
|
444
|
-
it 'sets headers of originals' do
|
445
|
-
expect(@email_message).to have_header(
|
446
|
-
'X-Sanitize-Email-To',
|
447
|
-
'same@example.org'
|
448
|
-
)
|
449
|
-
expect(@email_message).to have_header(
|
450
|
-
'X-Sanitize-Email-Cc',
|
451
|
-
'same@example.org'
|
452
|
-
)
|
453
|
-
end
|
454
|
-
it 'does not set headers of bcc' do
|
455
|
-
expect(@email_message).not_to have_header(
|
456
|
-
'X-Sanitize-Email-Bcc',
|
457
|
-
'same@example.org'
|
458
|
-
)
|
459
|
-
end
|
460
|
-
it 'does not set headers of overrides' do
|
461
|
-
expect(@email_message).not_to have_header(
|
462
|
-
'X-Sanitize-Email-Bcc',
|
463
|
-
'same@example.org'
|
464
|
-
)
|
465
|
-
# puts "email headers:\n#{@email_message.header}"
|
466
|
-
end
|
467
|
-
it 'does not prepend originals by default' do
|
468
|
-
expect(@email_message).not_to have_to_username(
|
469
|
-
'same at example.org <same@example.org>'
|
470
|
-
)
|
471
|
-
expect(@email_message).not_to have_subject(
|
472
|
-
'(same at example.org) original subject'
|
473
|
-
)
|
474
|
-
end
|
475
|
-
end
|
476
|
-
|
477
|
-
context 'with frozen string (literals)' do
|
478
|
-
it 'prepends strings without exception' do
|
479
|
-
configure_sanitize_email(
|
480
|
-
:environment => '{{serverABC}}',
|
481
|
-
:use_actual_environment_prepended_to_subject => true
|
482
|
-
)
|
483
|
-
expect { sanitary_mail_delivery_frozen_strings }.not_to raise_exception
|
484
|
-
end
|
485
|
-
end
|
486
|
-
|
487
|
-
context 'force_sanitize' do
|
488
|
-
context 'true' do
|
489
|
-
before do
|
490
|
-
# Should turn off sanitization using the force_sanitize
|
491
|
-
configure_sanitize_email(:activation_proc => proc { true })
|
492
|
-
described_class.force_sanitize = true
|
493
|
-
mail_delivery
|
494
|
-
end
|
495
|
-
it 'does not alter non-sanitized attributes' do
|
496
|
-
expect(@email_message).to have_from('from@example.org')
|
497
|
-
expect(@email_message).to have_reply_to('reply_to@example.org')
|
498
|
-
expect(@email_message).to have_body_text('funky fresh')
|
499
|
-
end
|
500
|
-
it 'overrides' do
|
501
|
-
expect(@email_message).to have_to('to@sanitize_email.org')
|
502
|
-
expect(@email_message).to have_cc('cc@sanitize_email.org')
|
503
|
-
expect(@email_message).to have_bcc('bcc@sanitize_email.org')
|
504
|
-
end
|
505
|
-
it 'sets headers' do
|
506
|
-
expect(@email_message).to have_header(
|
507
|
-
'X-Sanitize-Email-To',
|
508
|
-
'to@example.org'
|
509
|
-
)
|
510
|
-
expect(@email_message).to have_header(
|
511
|
-
'X-Sanitize-Email-Cc',
|
512
|
-
'cc@example.org'
|
513
|
-
)
|
514
|
-
expect(@email_message).not_to have_header(
|
515
|
-
'X-Sanitize-Email-Bcc',
|
516
|
-
'bcc@sanitize_email.org'
|
517
|
-
)
|
518
|
-
end
|
519
|
-
end
|
520
|
-
context 'false' do
|
521
|
-
before do
|
522
|
-
# Should turn off sanitization using the force_sanitize
|
523
|
-
configure_sanitize_email(:activation_proc => proc { true })
|
524
|
-
described_class.force_sanitize = false
|
525
|
-
mail_delivery
|
526
|
-
end
|
527
|
-
it 'does not alter non-sanitized attributes' do
|
528
|
-
expect(@email_message).to have_from('from@example.org')
|
529
|
-
expect(@email_message).to have_reply_to('reply_to@example.org')
|
530
|
-
expect(@email_message).to have_body_text('funky fresh')
|
531
|
-
end
|
532
|
-
it 'does not alter normally sanitized attributes' do
|
533
|
-
expect(@email_message).to have_to('to@example.org')
|
534
|
-
expect(@email_message).to have_cc('cc@example.org')
|
535
|
-
expect(@email_message).to have_bcc('bcc@example.org')
|
536
|
-
expect(@email_message).not_to have_header(
|
537
|
-
'X-Sanitize-Email-To',
|
538
|
-
'to@example.org'
|
539
|
-
)
|
540
|
-
expect(@email_message).not_to have_header(
|
541
|
-
'X-Sanitize-Email-Cc',
|
542
|
-
'cc@example.org'
|
543
|
-
)
|
544
|
-
expect(@email_message).not_to have_header(
|
545
|
-
'X-Sanitize-Email-Bcc',
|
546
|
-
'bcc@example.org'
|
547
|
-
)
|
548
|
-
end
|
549
|
-
end
|
550
|
-
context 'nil' do
|
551
|
-
context 'activation proc enables' do
|
552
|
-
before do
|
553
|
-
# Should ignore force_sanitize setting
|
554
|
-
configure_sanitize_email(:activation_proc => proc { true })
|
555
|
-
described_class.force_sanitize = nil
|
556
|
-
mail_delivery
|
557
|
-
end
|
558
|
-
it 'does not alter non-sanitized attributes' do
|
559
|
-
expect(@email_message).to have_from('from@example.org')
|
560
|
-
expect(@email_message).to have_reply_to('reply_to@example.org')
|
561
|
-
expect(@email_message).to have_body_text('funky fresh')
|
562
|
-
end
|
563
|
-
it 'overrides' do
|
564
|
-
expect(@email_message).to have_to('to@sanitize_email.org')
|
565
|
-
expect(@email_message).to have_cc('cc@sanitize_email.org')
|
566
|
-
expect(@email_message).to have_bcc('bcc@sanitize_email.org')
|
567
|
-
expect(@email_message).to have_header(
|
568
|
-
'X-Sanitize-Email-To',
|
569
|
-
'to@example.org'
|
570
|
-
)
|
571
|
-
expect(@email_message).to have_header(
|
572
|
-
'X-Sanitize-Email-Cc',
|
573
|
-
'cc@example.org'
|
574
|
-
)
|
575
|
-
expect(@email_message).not_to have_header(
|
576
|
-
'X-Sanitize-Email-Bcc',
|
577
|
-
'bcc@sanitize_email.org'
|
578
|
-
)
|
579
|
-
end
|
580
|
-
end
|
581
|
-
context 'activation proc disables' do
|
582
|
-
before do
|
583
|
-
# Should ignore force_sanitize setting
|
584
|
-
configure_sanitize_email(:activation_proc => proc { false })
|
585
|
-
described_class.force_sanitize = nil
|
586
|
-
mail_delivery
|
587
|
-
end
|
588
|
-
it 'does not alter non-sanitized attributes' do
|
589
|
-
expect(@email_message).to have_from('from@example.org')
|
590
|
-
expect(@email_message).to have_reply_to('reply_to@example.org')
|
591
|
-
expect(@email_message).to have_body_text('funky fresh')
|
592
|
-
end
|
593
|
-
it 'does not alter normally sanitized attributes' do
|
594
|
-
expect(@email_message).to have_to('to@example.org')
|
595
|
-
expect(@email_message).to have_cc('cc@example.org')
|
596
|
-
expect(@email_message).to have_bcc('bcc@example.org')
|
597
|
-
expect(@email_message).not_to have_header(
|
598
|
-
'X-Sanitize-Email-To',
|
599
|
-
'to@example.org'
|
600
|
-
)
|
601
|
-
expect(@email_message).not_to have_header(
|
602
|
-
'X-Sanitize-Email-Cc',
|
603
|
-
'cc@example.org'
|
604
|
-
)
|
605
|
-
expect(@email_message).not_to have_header(
|
606
|
-
'X-Sanitize-Email-Bcc',
|
607
|
-
'bcc@example.org'
|
608
|
-
)
|
609
|
-
end
|
610
|
-
end
|
611
|
-
end
|
612
|
-
end
|
613
|
-
end
|
614
|
-
|
615
|
-
context 'config options' do
|
616
|
-
context ':use_actual_environment_prepended_to_subject' do
|
617
|
-
context 'true' do
|
618
|
-
before do
|
619
|
-
configure_sanitize_email(
|
620
|
-
:environment => '{{serverABC}}',
|
621
|
-
:use_actual_environment_prepended_to_subject => true
|
622
|
-
)
|
623
|
-
sanitary_mail_delivery
|
624
|
-
end
|
625
|
-
it 'original to is prepended' do
|
626
|
-
expect(@email_message).to have_subject(
|
627
|
-
'{{serverABC}} original subject'
|
628
|
-
)
|
629
|
-
end
|
630
|
-
it 'does not alter non-sanitized attributes' do
|
631
|
-
expect(@email_message).to have_from('from@example.org')
|
632
|
-
expect(@email_message).to have_reply_to('reply_to@example.org')
|
633
|
-
expect(@email_message).to have_body_text('funky fresh')
|
634
|
-
end
|
635
|
-
it 'does not prepend overrides' do
|
636
|
-
expect(@email_message).not_to have_to_username(
|
637
|
-
'to at sanitize_email.org'
|
638
|
-
)
|
639
|
-
expect(@email_message).not_to have_subject(
|
640
|
-
'(to at sanitize_email.org)'
|
641
|
-
)
|
642
|
-
end
|
643
|
-
end
|
644
|
-
context 'false' do
|
645
|
-
before do
|
646
|
-
configure_sanitize_email(
|
647
|
-
:environment => '{{serverABC}}',
|
648
|
-
:use_actual_environment_prepended_to_subject => false
|
649
|
-
)
|
650
|
-
sanitary_mail_delivery
|
651
|
-
end
|
652
|
-
it 'original to is not prepended' do
|
653
|
-
expect(@email_message).not_to have_subject(
|
654
|
-
'{{serverABC}} original subject'
|
655
|
-
)
|
656
|
-
expect(@email_message.subject).to eq('original subject')
|
657
|
-
end
|
658
|
-
it 'does not alter non-sanitized attributes' do
|
659
|
-
expect(@email_message).to have_from('from@example.org')
|
660
|
-
expect(@email_message).to have_reply_to('reply_to@example.org')
|
661
|
-
expect(@email_message).to have_body_text('funky fresh')
|
662
|
-
end
|
663
|
-
it 'does not prepend overrides' do
|
664
|
-
expect(@email_message).not_to have_to_username(
|
665
|
-
'to at sanitize_email.org'
|
666
|
-
)
|
667
|
-
expect(@email_message).not_to have_subject(
|
668
|
-
'(to at sanitize_email.org)'
|
669
|
-
)
|
670
|
-
end
|
671
|
-
end
|
672
|
-
end
|
673
|
-
|
674
|
-
context ':use_actual_email_prepended_to_subject' do
|
675
|
-
context 'true' do
|
676
|
-
before do
|
677
|
-
configure_sanitize_email(:use_actual_email_prepended_to_subject => true)
|
678
|
-
end
|
679
|
-
context 'to address is an array' do
|
680
|
-
before do
|
681
|
-
sanitary_mail_delivery_multiple_recipients
|
682
|
-
end
|
683
|
-
it 'original to is prepended' do
|
684
|
-
expect(@email_message).to have_subject(
|
685
|
-
'(to1 at example.org,to2 at example.org,to3 at example.org) original subject'
|
686
|
-
)
|
687
|
-
end
|
688
|
-
it 'does not alter non-sanitized attributes' do
|
689
|
-
expect(@email_message).to have_from('from@example.org')
|
690
|
-
expect(@email_message).to have_reply_to('reply_to@example.org')
|
691
|
-
expect(@email_message).to have_body_text('funky fresh')
|
692
|
-
end
|
693
|
-
it 'does not prepend overrides' do
|
694
|
-
expect(@email_message).not_to have_to_username(
|
695
|
-
'to at sanitize_email.org'
|
696
|
-
)
|
697
|
-
expect(@email_message).not_to have_subject(
|
698
|
-
'(to at sanitize_email.org)'
|
699
|
-
)
|
700
|
-
end
|
701
|
-
end
|
702
|
-
context 'to address is not an array' do
|
703
|
-
before do
|
704
|
-
sanitary_mail_delivery
|
705
|
-
end
|
706
|
-
it 'original to is prepended' do
|
707
|
-
expect(@email_message).to have_subject(
|
708
|
-
'(to at example.org) original subject'
|
709
|
-
)
|
710
|
-
end
|
711
|
-
it 'does not alter non-sanitized attributes' do
|
712
|
-
expect(@email_message).to have_from('from@example.org')
|
713
|
-
expect(@email_message).to have_reply_to('reply_to@example.org')
|
714
|
-
expect(@email_message).to have_body_text('funky fresh')
|
715
|
-
end
|
716
|
-
it 'does not prepend overrides' do
|
717
|
-
expect(@email_message).not_to have_to_username(
|
718
|
-
'to at sanitize_email.org'
|
719
|
-
)
|
720
|
-
expect(@email_message).not_to have_subject(
|
721
|
-
'(to at sanitize_email.org)'
|
722
|
-
)
|
723
|
-
end
|
724
|
-
end
|
725
|
-
end
|
726
|
-
context 'false' do
|
727
|
-
before do
|
728
|
-
configure_sanitize_email(:use_actual_email_prepended_to_subject => false)
|
729
|
-
sanitary_mail_delivery
|
730
|
-
end
|
731
|
-
it 'original to is not prepended' do
|
732
|
-
expect(@email_message).not_to have_subject(
|
733
|
-
'(to at example.org) original subject'
|
734
|
-
)
|
735
|
-
end
|
736
|
-
it 'does not alter non-sanitized attributes' do
|
737
|
-
expect(@email_message).to have_from('from@example.org')
|
738
|
-
expect(@email_message).to have_reply_to('reply_to@example.org')
|
739
|
-
expect(@email_message).to have_body_text('funky fresh')
|
740
|
-
end
|
741
|
-
it 'does not prepend overrides' do
|
742
|
-
expect(@email_message).not_to have_to_username(
|
743
|
-
'to at sanitize_email.org'
|
744
|
-
)
|
745
|
-
expect(@email_message).not_to have_subject(
|
746
|
-
'(to at sanitize_email.org)'
|
747
|
-
)
|
748
|
-
end
|
749
|
-
end
|
750
|
-
end
|
751
|
-
|
752
|
-
context ':use_actual_email_as_sanitized_user_name' do
|
753
|
-
context 'true' do
|
754
|
-
before do
|
755
|
-
configure_sanitize_email(
|
756
|
-
:use_actual_email_as_sanitized_user_name => true
|
757
|
-
)
|
758
|
-
sanitary_mail_delivery
|
759
|
-
end
|
760
|
-
it 'original to is munged and prepended' do
|
761
|
-
expect(@email_message).to have_to_username(
|
762
|
-
'to at example.org <to@sanitize_email.org>'
|
763
|
-
)
|
764
|
-
end
|
765
|
-
it 'does not alter non-sanitized attributes' do
|
766
|
-
expect(@email_message).to have_from('from@example.org')
|
767
|
-
expect(@email_message).to have_reply_to('reply_to@example.org')
|
768
|
-
expect(@email_message).to have_body_text('funky fresh')
|
769
|
-
end
|
770
|
-
it 'does not prepend overrides' do
|
771
|
-
expect(@email_message).not_to have_to_username(
|
772
|
-
'to at sanitize_email.org'
|
773
|
-
)
|
774
|
-
expect(@email_message).not_to have_subject(
|
775
|
-
'(to at sanitize_email.org)'
|
776
|
-
)
|
777
|
-
end
|
778
|
-
end
|
779
|
-
context 'false' do
|
780
|
-
before do
|
781
|
-
configure_sanitize_email(
|
782
|
-
:use_actual_email_as_sanitized_user_name => false
|
783
|
-
)
|
784
|
-
sanitary_mail_delivery
|
785
|
-
end
|
786
|
-
it 'original to is not prepended' do
|
787
|
-
expect(@email_message).not_to have_to_username(
|
788
|
-
'to at example.org <to@sanitize_email.org>'
|
789
|
-
)
|
790
|
-
end
|
791
|
-
it 'does not alter non-sanitized attributes' do
|
792
|
-
expect(@email_message).to have_from('from@example.org')
|
793
|
-
expect(@email_message).to have_reply_to('reply_to@example.org')
|
794
|
-
expect(@email_message).to have_body_text('funky fresh')
|
795
|
-
end
|
796
|
-
it 'does not prepend overrides' do
|
797
|
-
expect(@email_message).not_to have_to_username(
|
798
|
-
'to at sanitize_email.org'
|
799
|
-
)
|
800
|
-
expect(@email_message).not_to have_subject(
|
801
|
-
'(to at sanitize_email.org)'
|
802
|
-
)
|
803
|
-
end
|
804
|
-
end
|
805
|
-
end
|
806
|
-
|
807
|
-
context ':engage' do
|
808
|
-
context 'is true' do
|
809
|
-
before do
|
810
|
-
# Should turn off sanitization using the force_sanitize
|
811
|
-
configure_sanitize_email(
|
812
|
-
:engage => true,
|
813
|
-
:sanitized_recipients => 'marv@example.org',
|
814
|
-
:use_actual_email_prepended_to_subject => true,
|
815
|
-
:use_actual_email_as_sanitized_user_name => true
|
816
|
-
)
|
817
|
-
mail_delivery
|
818
|
-
end
|
819
|
-
it 'does not alter non-sanitized attributes' do
|
820
|
-
expect(@email_message).to have_from('from@example.org')
|
821
|
-
expect(@email_message).to have_reply_to('reply_to@example.org')
|
822
|
-
expect(@email_message).to have_body_text('funky fresh')
|
823
|
-
end
|
824
|
-
it 'prepends overrides' do
|
825
|
-
expect(@email_message).to have_to_username('to at example.org')
|
826
|
-
expect(@email_message).to have_subject('(to at example.org)')
|
827
|
-
end
|
828
|
-
it 'alters normally sanitized attributes' do
|
829
|
-
expect(@email_message).not_to have_to('to@example.org')
|
830
|
-
expect(@email_message).to have_to('marv@example.org')
|
831
|
-
end
|
832
|
-
end
|
833
|
-
context 'is false' do
|
834
|
-
before do
|
835
|
-
# Should turn off sanitization using the force_sanitize
|
836
|
-
configure_sanitize_email(
|
837
|
-
:engage => false,
|
838
|
-
:sanitized_recipients => 'marv@example.org',
|
839
|
-
:use_actual_email_prepended_to_subject => true,
|
840
|
-
:use_actual_email_as_sanitized_user_name => true
|
841
|
-
)
|
842
|
-
mail_delivery
|
843
|
-
end
|
844
|
-
it 'does not alter non-sanitized attributes' do
|
845
|
-
expect(@email_message).to have_from('from@example.org')
|
846
|
-
expect(@email_message).to have_reply_to('reply_to@example.org')
|
847
|
-
expect(@email_message).to have_body_text('funky fresh')
|
848
|
-
end
|
849
|
-
it 'does not prepend overrides' do
|
850
|
-
expect(@email_message).not_to have_to_username('to at example.org')
|
851
|
-
expect(@email_message).not_to have_subject('(to at example.org)')
|
852
|
-
end
|
853
|
-
it 'does not alter normally sanitized attributes' do
|
854
|
-
expect(@email_message).to have_to('to@example.org')
|
855
|
-
expect(@email_message).not_to have_to('marv@example.org')
|
856
|
-
end
|
857
|
-
end
|
858
|
-
end
|
859
|
-
|
860
|
-
context 'deprecated' do
|
861
|
-
# before(:each) do
|
862
|
-
# SanitizeEmail::Deprecation.deprecate_in_silence = false
|
863
|
-
# end
|
864
|
-
context ':local_environments' do
|
865
|
-
context 'matching' do
|
866
|
-
before do
|
867
|
-
configure_sanitize_email(:local_environments => ['test'])
|
868
|
-
mail_delivery
|
869
|
-
end
|
870
|
-
it 'does not alter non-sanitized attributes' do
|
871
|
-
expect(described_class[:activation_proc].call).to eq(true)
|
872
|
-
expect(@email_message).to have_from('from@example.org')
|
873
|
-
expect(@email_message).to have_reply_to('reply_to@example.org')
|
874
|
-
expect(@email_message).to have_body_text('funky fresh')
|
875
|
-
end
|
876
|
-
it 'uses activation_proc for matching environment' do
|
877
|
-
expect(described_class[:activation_proc].call).to eq(true)
|
878
|
-
expect(@email_message).to match_to('to@sanitize_email.org')
|
879
|
-
expect(@email_message).to match_cc('cc@sanitize_email.org')
|
880
|
-
expect(@email_message).to match_bcc('bcc@sanitize_email.org')
|
881
|
-
end
|
882
|
-
end
|
883
|
-
context 'non-matching' do
|
884
|
-
before do
|
885
|
-
sanitize_spec_dryer('production')
|
886
|
-
# Won't match!
|
887
|
-
configure_sanitize_email(:local_environments => ['development'])
|
888
|
-
mail_delivery
|
889
|
-
end
|
890
|
-
it 'does not alter non-sanitized attributes' do
|
891
|
-
expect(described_class[:activation_proc].call).to eq(false)
|
892
|
-
expect(@email_message).to have_from('from@example.org')
|
893
|
-
expect(@email_message).to have_reply_to('reply_to@example.org')
|
894
|
-
expect(@email_message).to have_body_text('funky fresh')
|
895
|
-
end
|
896
|
-
it 'uses activation_proc for non-matching environment' do
|
897
|
-
expect(described_class[:activation_proc].call).to eq(false)
|
898
|
-
expect(@email_message).to have_to('to@example.org')
|
899
|
-
expect(@email_message).to have_cc('cc@example.org')
|
900
|
-
expect(@email_message).to have_bcc('bcc@example.org')
|
901
|
-
end
|
902
|
-
end
|
903
|
-
end
|
904
|
-
|
905
|
-
context ':sanitized_recipients' do
|
906
|
-
before do
|
907
|
-
configure_sanitize_email(
|
908
|
-
:sanitized_recipients => 'barney@sanitize_email.org'
|
909
|
-
)
|
910
|
-
sanitary_mail_delivery
|
911
|
-
end
|
912
|
-
it 'does not alter non-sanitized attributes' do
|
913
|
-
expect(@email_message).to have_from('from@example.org')
|
914
|
-
expect(@email_message).to have_reply_to('reply_to@example.org')
|
915
|
-
expect(@email_message).to have_body_text('funky fresh')
|
916
|
-
end
|
917
|
-
it 'used as sanitized_to' do
|
918
|
-
expect(@email_message).to have_to('barney@sanitize_email.org')
|
919
|
-
end
|
920
|
-
end
|
921
|
-
|
922
|
-
context ':force_sanitize' do
|
923
|
-
before do
|
924
|
-
# Should turn off sanitization using the force_sanitize
|
925
|
-
configure_sanitize_email(
|
926
|
-
:activation_proc => proc { true },
|
927
|
-
:force_sanitize => false
|
928
|
-
)
|
929
|
-
mail_delivery
|
930
|
-
end
|
931
|
-
it 'does not alter non-sanitized attributes' do
|
932
|
-
expect(@email_message).to have_from('from@example.org')
|
933
|
-
expect(@email_message).to have_reply_to('reply_to@example.org')
|
934
|
-
expect(@email_message).to have_body_text('funky fresh')
|
935
|
-
end
|
936
|
-
it 'does not alter normally sanitized attributes' do
|
937
|
-
expect(@email_message).to have_to('to@example.org')
|
938
|
-
end
|
939
|
-
end
|
940
|
-
end
|
941
|
-
end
|
942
|
-
end
|
943
|
-
|
944
|
-
# TODO: test good_list
|