developer.rb 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. class Auth
  3. class Backend
  4. class Developer < Auth::Backend::Base
  5. private
  6. # Special development/test password validation.
  7. # * For the developer mode the password 'test' is allowed for every User.
  8. # * For the test environment the password can be blank if also the user password is currently blank.
  9. #
  10. # @returns [Boolean] true if the validation works, otherwise false.
  11. def authenticated?
  12. if valid_for_developer_mode? || valid_for_test_environment?
  13. Rails.logger.info "System in test/developer mode, authentication for user #{user.login} ok."
  14. return true
  15. end
  16. false
  17. end
  18. # No password required for developer mode and test environment.
  19. #
  20. # @returns [Boolean] false
  21. def password_required?
  22. false
  23. end
  24. # Overwrites the default behaviour to check for a allowed environment.
  25. #
  26. # @returns [Boolean] true if the environment is development or test.
  27. def perform?
  28. allowed_environment?
  29. end
  30. # Check for allowed environments.
  31. #
  32. # @returns [Boolean] true if one allowed environment is active.
  33. def allowed_environment?
  34. Setting.get('developer_mode') == true || Rails.env.test?
  35. end
  36. # Validate password for test environment.
  37. #
  38. # @returns [Boolean] true if password and user password is blank, otherwise false.
  39. def valid_for_test_environment?
  40. Rails.env.test? && password.blank? && user.password.blank?
  41. end
  42. # Validate password for test environment.
  43. #
  44. # @returns [Boolean] true if the given password is 'test', otherwise false.
  45. def valid_for_developer_mode?
  46. Setting.get('developer_mode') == true && password == 'test'
  47. end
  48. end
  49. end
  50. end