Skip to content

Commit

Permalink
silence warning
Browse files Browse the repository at this point in the history
  • Loading branch information
grosser committed Jul 22, 2014
1 parent 08cd8f5 commit 8ad1b8d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 14 deletions.
26 changes: 13 additions & 13 deletions spec/mail/network/delivery_methods/file_delivery_spec.rb
Expand Up @@ -15,47 +15,47 @@
:enable_starttls_auto => true }
end
end

after(:each) do
files = Dir.glob(File.join(Mail.delivery_method.settings[:location], '*'))
files.each do |file|
File.delete(file)
end
end

describe "general usage" do
tmpdir = File.expand_path('../../../../tmp/mail', __FILE__)

it "should send an email to a file" do
Mail.defaults do
delivery_method :file, :location => tmpdir
end

mail = Mail.deliver do
from 'roger@moore.com'
to 'marcel@amont.com'
subject 'invalid RFC2822'
end

delivery = File.join(Mail.delivery_method.settings[:location], 'marcel@amont.com')

expect(File.read(delivery)).to eq mail.encoded
end

it "should send multiple emails to multiple files" do
Mail.defaults do
delivery_method :file, :location => tmpdir
end

mail = Mail.deliver do
from 'roger@moore.com'
to 'marcel@amont.com, bob@me.com'
subject 'invalid RFC2822'
end

delivery_one = File.join(Mail.delivery_method.settings[:location], 'marcel@amont.com')
delivery_two = File.join(Mail.delivery_method.settings[:location], 'bob@me.com')

expect(File.read(delivery_one)).to eq mail.encoded
expect(File.read(delivery_two)).to eq mail.encoded
end
Expand All @@ -64,29 +64,29 @@
Mail.defaults do
delivery_method :file, :location => tmpdir
end

Mail.deliver do
from 'roger@moore.com'
to '"Long, stupid email address" <mikel@test.lindsaar.net>'
subject 'invalid RFC2822'
end
delivery = File.join(Mail.delivery_method.settings[:location], 'mikel@test.lindsaar.net')
expect(File.exists?(delivery)).to be_truthy
expect(File.exist?(delivery)).to be_truthy
end

it "should use the base name of the file name to prevent file system traversal" do
Mail.defaults do
delivery_method :file, :location => tmpdir
end

Mail.deliver do
from 'roger@moore.com'
to '../../../../../../../../../../../tmp/pwn'
subject 'evil hacker'
end

delivery = File.join(Mail.delivery_method.settings[:location], 'pwn')
expect(File.exists?(delivery)).to be_truthy
expect(File.exist?(delivery)).to be_truthy
end

it "should raise an error if no sender is defined" do
Expand Down Expand Up @@ -118,5 +118,5 @@
end

end

end
10 changes: 9 additions & 1 deletion spec/spec_helper.rb
Expand Up @@ -30,7 +30,15 @@
# NOTE: We set the KCODE manually here in 1.8.X because upgrading to rspec-2.8.0 caused it
# to default to "NONE" (Why!?).
$KCODE='UTF8' if RUBY_VERSION < '1.9'
Encoding.default_external = 'utf-8' if defined?(Encoding) && Encoding.respond_to?(:default_external=)
if defined?(Encoding) && Encoding.respond_to?(:default_external=)
begin
old, $VERBOSE = $VERBOSE, nil
Encoding.default_external = 'utf-8'
ensure
$VERBOSE = old
end
end


def fixture(*name)
File.join(SPEC_ROOT, 'fixtures', name)
Expand Down

0 comments on commit 8ad1b8d

Please sign in to comment.