You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

mail_handler_controller_test.rb 2.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. # Redmine - project management software
  2. # Copyright (C) 2006-2013 Jean-Philippe Lang
  3. #
  4. # This program is free software; you can redistribute it and/or
  5. # modify it under the terms of the GNU General Public License
  6. # as published by the Free Software Foundation; either version 2
  7. # of the License, or (at your option) any later version.
  8. #
  9. # This program is distributed in the hope that it will be useful,
  10. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. # GNU General Public License for more details.
  13. #
  14. # You should have received a copy of the GNU General Public License
  15. # along with this program; if not, write to the Free Software
  16. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  17. require File.expand_path('../../test_helper', __FILE__)
  18. class MailHandlerControllerTest < ActionController::TestCase
  19. fixtures :users, :projects, :enabled_modules, :roles, :members, :member_roles, :issues, :issue_statuses,
  20. :trackers, :projects_trackers, :enumerations
  21. FIXTURES_PATH = File.dirname(__FILE__) + '/../fixtures/mail_handler'
  22. def setup
  23. User.current = nil
  24. end
  25. def test_should_create_issue
  26. # Enable API and set a key
  27. Setting.mail_handler_api_enabled = 1
  28. Setting.mail_handler_api_key = 'secret'
  29. assert_difference 'Issue.count' do
  30. post :index, :key => 'secret', :email => IO.read(File.join(FIXTURES_PATH, 'ticket_on_given_project.eml'))
  31. end
  32. assert_response 201
  33. end
  34. def test_should_respond_with_422_if_not_created
  35. Project.find('onlinestore').destroy
  36. Setting.mail_handler_api_enabled = 1
  37. Setting.mail_handler_api_key = 'secret'
  38. assert_no_difference 'Issue.count' do
  39. post :index, :key => 'secret', :email => IO.read(File.join(FIXTURES_PATH, 'ticket_on_given_project.eml'))
  40. end
  41. assert_response 422
  42. end
  43. def test_should_not_allow_with_api_disabled
  44. # Disable API
  45. Setting.mail_handler_api_enabled = 0
  46. Setting.mail_handler_api_key = 'secret'
  47. assert_no_difference 'Issue.count' do
  48. post :index, :key => 'secret', :email => IO.read(File.join(FIXTURES_PATH, 'ticket_on_given_project.eml'))
  49. end
  50. assert_response 403
  51. end
  52. def test_should_not_allow_with_wrong_key
  53. # Disable API
  54. Setting.mail_handler_api_enabled = 1
  55. Setting.mail_handler_api_key = 'secret'
  56. assert_no_difference 'Issue.count' do
  57. post :index, :key => 'wrong', :email => IO.read(File.join(FIXTURES_PATH, 'ticket_on_given_project.eml'))
  58. end
  59. assert_response 403
  60. end
  61. end