summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/fixtures/mail_handler/ticket_by_unknown_user.eml18
-rw-r--r--test/unit/mail_handler_test.rb39
2 files changed, 55 insertions, 2 deletions
diff --git a/test/fixtures/mail_handler/ticket_by_unknown_user.eml b/test/fixtures/mail_handler/ticket_by_unknown_user.eml
new file mode 100644
index 000000000..a7abb05e0
--- /dev/null
+++ b/test/fixtures/mail_handler/ticket_by_unknown_user.eml
@@ -0,0 +1,18 @@
+Return-Path: <john.doe@somenet.foo>
+Received: from osiris ([127.0.0.1])
+ by OSIRIS
+ with hMailServer ; Sun, 22 Jun 2008 12:28:07 +0200
+Message-ID: <000501c8d452$a95cd7e0$0a00a8c0@osiris>
+From: "John Doe" <john.doe@somenet.foo>
+To: <redmine@somenet.foo>
+Subject: Ticket by unknown user
+Date: Sun, 22 Jun 2008 12:28:07 +0200
+MIME-Version: 1.0
+Content-Type: text/plain;
+ format=flowed;
+ charset="iso-8859-1";
+ reply-type=original
+Content-Transfer-Encoding: 7bit
+
+This is a ticket submitted by an unknown user.
+
diff --git a/test/unit/mail_handler_test.rb b/test/unit/mail_handler_test.rb
index 295b8ae68..2d780d93d 100644
--- a/test/unit/mail_handler_test.rb
+++ b/test/unit/mail_handler_test.rb
@@ -1,5 +1,5 @@
-# redMine - project management software
-# Copyright (C) 2006-2007 Jean-Philippe Lang
+# Redmine - project management software
+# Copyright (C) 2006-2009 Jean-Philippe Lang
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
@@ -130,6 +130,41 @@ class MailHandlerTest < Test::Unit::TestCase
assert_equal 1, issue.watchers.size
end
+ def test_add_issue_by_unknown_user
+ assert_no_difference 'User.count' do
+ assert_equal false, submit_email('ticket_by_unknown_user.eml', :issue => {:project => 'ecookbook'})
+ end
+ end
+
+ def test_add_issue_by_anonymous_user
+ Role.anonymous.add_permission!(:add_issues)
+ assert_no_difference 'User.count' do
+ issue = submit_email('ticket_by_unknown_user.eml', :issue => {:project => 'ecookbook'}, :unknown_user => 'accept')
+ assert issue.is_a?(Issue)
+ assert issue.author.anonymous?
+ end
+ end
+
+ def test_add_issue_by_created_user
+ Setting.default_language = 'en'
+ assert_difference 'User.count' do
+ issue = submit_email('ticket_by_unknown_user.eml', :issue => {:project => 'ecookbook'}, :unknown_user => 'create')
+ assert issue.is_a?(Issue)
+ assert issue.author.active?
+ assert_equal 'john.doe@somenet.foo', issue.author.mail
+ assert_equal 'John', issue.author.firstname
+ assert_equal 'Doe', issue.author.lastname
+
+ # account information
+ email = ActionMailer::Base.deliveries.first
+ assert_not_nil email
+ assert email.subject.include?('account activation')
+ login = email.body.match(/\* Login: (.*)$/)[1]
+ password = email.body.match(/\* Password: (.*)$/)[1]
+ assert_equal issue.author, User.try_to_login(login, password)
+ end
+ end
+
def test_add_issue_without_from_header
Role.anonymous.add_permission!(:add_issues)
assert_equal false, submit_email('ticket_without_from_header.eml')