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.

disabled_rest_api_test.rb 2.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. # Redmine - project management software
  2. # Copyright (C) 2006-2016 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 Redmine::ApiTest::DisabledRestApiTest < Redmine::ApiTest::Base
  19. fixtures :projects, :trackers, :issue_statuses, :issues,
  20. :enumerations, :users, :issue_categories,
  21. :projects_trackers,
  22. :roles,
  23. :member_roles,
  24. :members,
  25. :enabled_modules
  26. def setup
  27. Setting.rest_api_enabled = '0'
  28. Setting.login_required = '1'
  29. end
  30. def teardown
  31. Setting.rest_api_enabled = '1'
  32. Setting.login_required = '0'
  33. end
  34. def test_with_a_valid_api_token
  35. @user = User.generate!
  36. @token = Token.create!(:user => @user, :action => 'api')
  37. get "/news.xml?key=#{@token.value}"
  38. assert_response :unauthorized
  39. assert_equal User.anonymous, User.current
  40. get "/news.json?key=#{@token.value}"
  41. assert_response :unauthorized
  42. assert_equal User.anonymous, User.current
  43. end
  44. def test_with_valid_username_password_http_authentication
  45. @user = User.generate! do |user|
  46. user.password = 'my_password'
  47. end
  48. get "/news.xml", nil, credentials(@user.login, 'my_password')
  49. assert_response :unauthorized
  50. assert_equal User.anonymous, User.current
  51. get "/news.json", nil, credentials(@user.login, 'my_password')
  52. assert_response :unauthorized
  53. assert_equal User.anonymous, User.current
  54. end
  55. def test_with_valid_token_http_authentication
  56. @user = User.generate!
  57. @token = Token.create!(:user => @user, :action => 'api')
  58. get "/news.xml", nil, credentials(@token.value, 'X')
  59. assert_response :unauthorized
  60. assert_equal User.anonymous, User.current
  61. get "/news.json", nil, credentials(@token.value, 'X')
  62. assert_response :unauthorized
  63. assert_equal User.anonymous, User.current
  64. end
  65. end