summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorJean-Philippe Lang <jp_lang@yahoo.fr>2009-06-14 14:48:34 +0000
committerJean-Philippe Lang <jp_lang@yahoo.fr>2009-06-14 14:48:34 +0000
commitb3afde14fa6046a022eda73edee85ab48171909f (patch)
tree89dc8da3ab3f51ab9ed88fcc04e216822410aebe /test
parentc48193f8c113650c14d98b2f96279d57118df973 (diff)
downloadredmine-b3afde14fa6046a022eda73edee85ab48171909f.tar.gz
redmine-b3afde14fa6046a022eda73edee85ab48171909f.zip
Ability to accept incoming emails from unknown users (#2230, #3003).
An option lets you specify how to handle emails from unknown users: * ignore: the email is ignored (previous and default behaviour) * accept: the sender is considered as an anonymous user * create: a user account is created (username/password are sent back to the user) Permissions have to be consistent with the chosen option. Eg. if you choose 'create', the 'Non member' role must have the 'Add issues' permission so that an issue can be created by an unknown user via email. If you choose 'accept', the 'Anonymous' role must have this permission. git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@2789 e93f8b46-1217-0410-a6f0-8f06a7374b81
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')