commit fe450fa8a4b5c3a38bd1d7a520baaa8bfb4c3469
parent 053acc4ef8a515ceab2be9b6539e8ecf383dfa00
Author: Gaute Hope <eg@gaute.vetsj.com>
Date: Wed, 15 Jan 2014 09:49:26 +0100
test: bad or binary content transfer encodings
Diffstat:
3 files changed, 141 insertions(+), 0 deletions(-)
diff --git a/test/messages/bad-content-transfer-encoding-1.eml b/test/messages/bad-content-transfer-encoding-1.eml
@@ -0,0 +1,8 @@
+From: foo@example.org
+MIME-Version: 1.0
+Subject: Content-Transfer-Encoding:-bug in sup
+Content-Type: message/rfc822
+Content-Transfer-Encoding: nosuchcontenttransferencoding
+
+foo
+
diff --git a/test/messages/binary-content-transfer-encoding-2.eml b/test/messages/binary-content-transfer-encoding-2.eml
@@ -0,0 +1,21 @@
+From: foo@example.org
+MIME-Version: 1.0
+Content-type: multipart/report; boundary="======11647==82899======"; report-type="spam-notification"
+Subject: Important
+
+This is a multi-part message in MIME format...
+
+--======11647==82899======
+Content-Type: text/plain; charset="ISO-8859-1"
+Content-Disposition: inline
+Content-Transfer-Encoding: quoted-printable
+
+
+--======11647==82899======
+Content-Type: message/rfc822
+Content-Disposition: attachment
+Content-Transfer-Encoding: binary
+
+
+--======11647==82899======--
+
diff --git a/test/test_messages.rb b/test/test_messages.rb
@@ -0,0 +1,112 @@
+#!/usr/bin/ruby
+
+require 'test_helper'
+require 'sup'
+require 'stringio'
+
+require 'dummy_source'
+
+# override File.exists? to make it work with StringIO for testing.
+# FIXME: do aliasing to avoid breaking this when sup moves from
+# File.exists? to File.exist?
+
+class File
+
+ def File.exists? file
+ # puts "fake File::exists?"
+
+ if file.is_a?(StringIO)
+ return false
+ end
+ # use the different function
+ File.exist?(file)
+ end
+
+end
+
+module Redwood
+
+class TestMessage < ::Minitest::Unit::TestCase
+
+ def setup
+ @path = Dir.mktmpdir
+ Redwood::HookManager.init File.join(@path, 'hooks')
+ end
+
+ def teardown
+ Redwood::HookManager.deinstantiate!
+ FileUtils.rm_r @path
+ end
+
+ def test_binary_content_transfer_encoding
+ message = ''
+ File.open 'test/messages/binary-content-transfer-encoding-2.eml' do |f|
+ message = f.read
+ end
+
+ source = DummySource.new("sup-test://test_messages")
+ source.messages = [ message ]
+ source_info = 0
+
+ sup_message = Message.build_from_source(source, source_info)
+ sup_message.load_from_source!
+
+ from = sup_message.from
+ # "from" is just a simple person item
+
+ assert_equal("foo@example.org", from.email)
+ #assert_equal("Fake Sender", from.name)
+
+ subj = sup_message.subj
+ assert_equal("Important", subj)
+
+ chunks = sup_message.load_from_source!
+ indexable_chunks = sup_message.indexable_chunks
+
+ # there should be only one chunk
+ #assert_equal(1, chunks.length)
+
+ lines = chunks[0].lines
+
+ # lines should contain an error message
+ assert (lines.join.include? "An error occurred while loading this message."), "This message should not load successfully"
+ end
+
+ def test_bad_content_transfer_encoding
+ message = ''
+ File.open 'test/messages/bad-content-transfer-encoding-1.eml' do |f|
+ message = f.read
+ end
+
+ source = DummySource.new("sup-test://test_messages")
+ source.messages = [ message ]
+ source_info = 0
+
+ sup_message = Message.build_from_source(source, source_info)
+ sup_message.load_from_source!
+
+ from = sup_message.from
+ # "from" is just a simple person item
+
+ assert_equal("foo@example.org", from.email)
+ #assert_equal("Fake Sender", from.name)
+
+ subj = sup_message.subj
+ assert_equal("Content-Transfer-Encoding:-bug in sup", subj)
+
+ chunks = sup_message.load_from_source!
+ indexable_chunks = sup_message.indexable_chunks
+
+ # there should be only one chunk
+ #assert_equal(1, chunks.length)
+
+ lines = chunks[0].lines
+
+ # lines should contain an error message
+ assert (lines.join.include? "An error occurred while loading this message."), "This message should not load successfully"
+ end
+end
+
+end
+
+# vim:noai:ts=2:sw=2: