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.

sudo_mode_test.rb 2.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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('../../application_system_test_case', __FILE__)
  18. class SudoModeTest < ApplicationSystemTestCase
  19. fixtures :users, :email_addresses
  20. def setup
  21. Redmine::SudoMode.stubs(:enabled?).returns(true)
  22. super
  23. end
  24. def teardown
  25. travel_back
  26. super
  27. end
  28. def test_add_user
  29. log_user('admin', 'admin')
  30. expire_sudo_mode!
  31. visit '/users/new'
  32. assert_difference 'User.count' do
  33. within('form#new_user') do
  34. fill_in 'Login', :with => 'johnpaul'
  35. fill_in 'First name', :with => 'John'
  36. fill_in 'Last name', :with => 'Paul'
  37. fill_in 'Email', :with => 'john@example.net'
  38. fill_in 'Password', :with => 'password'
  39. fill_in 'Confirmation', :with => 'password'
  40. # click_button 'Create' would match both 'Create' and 'Create and continue' buttons
  41. find('input[name=commit]').click
  42. end
  43. assert_equal '/users', current_path
  44. assert page.has_content?("Confirm your password to continue")
  45. assert page.has_css?('form#sudo-form')
  46. within('form#sudo-form') do
  47. fill_in 'Password', :with => 'admin'
  48. click_button 'Submit'
  49. end
  50. end
  51. end
  52. private
  53. # sudo mode is active after sign, let it expire by advancing the time
  54. def expire_sudo_mode!
  55. travel_to 20.minutes.from_now
  56. end
  57. end