auth_test.rb 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. require 'test_helper'
  2. class AuthTest < ActiveSupport::TestCase
  3. test 'auth' do
  4. user = User.find_by(email: 'nicole.braun@zammad.org')
  5. user.update!(
  6. login: 'nicole.braun',
  7. firstname: 'Nicole',
  8. lastname: 'Braun',
  9. email: 'nicole.braun@zammad.org',
  10. password: 'some_pass',
  11. active: true,
  12. updated_by_id: 1,
  13. created_by_id: 1
  14. )
  15. tests = [
  16. # test 1
  17. {
  18. username: 'not_existing',
  19. password: 'password',
  20. result: nil,
  21. },
  22. # test 2
  23. {
  24. username: 'nicole.braun@zammad.org',
  25. password: 'some_pass',
  26. result: true,
  27. verify: {
  28. firstname: 'Nicole',
  29. lastname: 'Braun',
  30. email: 'nicole.braun@zammad.org',
  31. }
  32. },
  33. # test 3
  34. {
  35. username: 'nicole.bRaUn@zammad.org',
  36. password: 'some_pass',
  37. result: true,
  38. verify: {
  39. firstname: 'Nicole',
  40. lastname: 'Braun',
  41. email: 'nicole.braun@zammad.org',
  42. }
  43. },
  44. # test 4
  45. {
  46. username: 'nicole.bRaUn',
  47. password: 'some_pass',
  48. result: true,
  49. verify: {
  50. firstname: 'Nicole',
  51. lastname: 'Braun',
  52. email: 'nicole.braun@zammad.org',
  53. }
  54. },
  55. ]
  56. tests.each do |test|
  57. user = User.authenticate(test[:username], test[:password])
  58. if test[:result] == true
  59. if !user
  60. assert(false, 'auth failed')
  61. else
  62. test[:verify].each do |key, value|
  63. assert_equal(user[key], value, 'verify')
  64. end
  65. end
  66. elsif test[:result].nil?
  67. assert_nil(user, 'failed or not existing')
  68. else
  69. assert_equal(test[:result], user, 'failed or not existing')
  70. end
  71. end
  72. end
  73. end