Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

sys_controller_test.rb 4.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. # Redmine - project management software
  2. # Copyright (C) 2006-2017 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 SysControllerTest < Redmine::ControllerTest
  19. fixtures :projects, :repositories, :enabled_modules
  20. def setup
  21. Setting.sys_api_enabled = '1'
  22. Setting.enabled_scm = %w(Subversion Git)
  23. end
  24. def teardown
  25. Setting.clear_cache
  26. end
  27. def test_projects_with_repository_enabled
  28. get :projects
  29. assert_response :success
  30. assert_equal 'application/json', @response.content_type
  31. data = ActiveSupport::JSON.decode(response.body)
  32. assert_equal Project.active.has_module(:repository).count, data.size
  33. project = data.first
  34. assert project['identifier']
  35. assert project['is_public']
  36. assert_not_include 'extra-info', response.body
  37. assert_not_include 'extra_info', response.body
  38. end
  39. def test_create_project_repository
  40. assert_nil Project.find(4).repository
  41. post :create_project_repository, :params => {
  42. :id => 4,
  43. :vendor => 'Subversion',
  44. :repository => { :url => 'file:///create/project/repository/subproject2'}
  45. }
  46. assert_response :created
  47. assert_equal 'application/json', @response.content_type
  48. r = Project.find(4).repository
  49. assert r.is_a?(Repository::Subversion)
  50. assert_equal 'file:///create/project/repository/subproject2', r.url
  51. data = ActiveSupport::JSON.decode(response.body)
  52. assert data['repository-subversion']
  53. assert_equal r.id, data['repository-subversion']['id']
  54. assert_equal r.url, data['repository-subversion']['url']
  55. assert_not_include 'extra-info', response.body
  56. assert_not_include 'extra_info', response.body
  57. end
  58. def test_create_already_existing
  59. post :create_project_repository, :params => {
  60. :id => 1,
  61. :vendor => 'Subversion',
  62. :repository => { :url => 'file:///create/project/repository/subproject2'}
  63. }
  64. assert_response :conflict
  65. end
  66. def test_create_with_failure
  67. post :create_project_repository, :params => {
  68. :id => 4,
  69. :vendor => 'Subversion',
  70. :repository => { :url => 'invalid url'}
  71. }
  72. assert_response :unprocessable_entity
  73. end
  74. def test_fetch_changesets
  75. Repository::Subversion.any_instance.expects(:fetch_changesets).twice.returns(true)
  76. get :fetch_changesets
  77. assert_response :success
  78. end
  79. def test_fetch_changesets_one_project_by_identifier
  80. Repository::Subversion.any_instance.expects(:fetch_changesets).once.returns(true)
  81. get :fetch_changesets, :params => {:id => 'ecookbook'}
  82. assert_response :success
  83. end
  84. def test_fetch_changesets_one_project_by_id
  85. Repository::Subversion.any_instance.expects(:fetch_changesets).once.returns(true)
  86. get :fetch_changesets, :params => {:id => '1'}
  87. assert_response :success
  88. end
  89. def test_fetch_changesets_unknown_project
  90. get :fetch_changesets, :params => {:id => 'unknown'}
  91. assert_response 404
  92. end
  93. def test_disabled_ws_should_respond_with_403_error
  94. with_settings :sys_api_enabled => '0' do
  95. get :projects
  96. assert_response 403
  97. assert_include 'Access denied', response.body
  98. end
  99. end
  100. def test_api_key
  101. with_settings :sys_api_key => 'my_secret_key' do
  102. get :projects, :params => {:key => 'my_secret_key'}
  103. assert_response :success
  104. end
  105. end
  106. def test_wrong_key_should_respond_with_403_error
  107. with_settings :sys_api_enabled => 'my_secret_key' do
  108. get :projects, :params => {:key => 'wrong_key'}
  109. assert_response 403
  110. assert_include 'Access denied', response.body
  111. end
  112. end
  113. end