auth_test.rb 1.7 KB

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