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.

access_control_test.rb 2.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. # frozen_string_literal: true
  2. # Redmine - project management software
  3. # Copyright (C) 2006-2022 Jean-Philippe Lang
  4. #
  5. # This program is free software; you can redistribute it and/or
  6. # modify it under the terms of the GNU General Public License
  7. # as published by the Free Software Foundation; either version 2
  8. # of the License, or (at your option) any later version.
  9. #
  10. # This program is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. # GNU General Public License for more details.
  14. #
  15. # You should have received a copy of the GNU General Public License
  16. # along with this program; if not, write to the Free Software
  17. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  18. require File.expand_path('../../../../test_helper', __FILE__)
  19. class Redmine::AccessControlTest < ActiveSupport::TestCase
  20. def setup
  21. @access_module = Redmine::AccessControl
  22. end
  23. def test_permissions
  24. perms = @access_module.permissions
  25. assert perms.is_a?(Array)
  26. assert perms.first.is_a?(Redmine::AccessControl::Permission)
  27. end
  28. def test_module_permission
  29. perm = @access_module.permission(:view_issues)
  30. assert perm.is_a?(Redmine::AccessControl::Permission)
  31. assert_equal :view_issues, perm.name
  32. assert_equal :issue_tracking, perm.project_module
  33. assert perm.actions.is_a?(Array)
  34. assert perm.actions.include?('issues/index')
  35. end
  36. def test_no_module_permission
  37. perm = @access_module.permission(:edit_project)
  38. assert perm.is_a?(Redmine::AccessControl::Permission)
  39. assert_equal :edit_project, perm.name
  40. assert_nil perm.project_module
  41. assert perm.actions.is_a?(Array)
  42. assert perm.actions.include?('projects/settings')
  43. end
  44. def test_read_action_should_return_true_for_read_actions
  45. assert_equal true, @access_module.read_action?(:view_project)
  46. assert_equal true, @access_module.read_action?(:controller => 'projects', :action => 'show')
  47. end
  48. def test_read_action_should_return_false_for_update_actions
  49. assert_equal false, @access_module.read_action?(:edit_project)
  50. assert_equal false, @access_module.read_action?(:controller => 'projects', :action => 'edit')
  51. end
  52. end