developer_spec.rb 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. require 'lib/auth/backend/backend_examples'
  4. RSpec.describe Auth::Backend::Developer do
  5. let(:user) { create(:user) }
  6. let(:password) { 'not_used' }
  7. let(:auth) { Auth.new(user.login, password) }
  8. let(:instance) { described_class.new({ adapter: described_class.name }, auth) }
  9. describe '#valid?' do
  10. it_behaves_like 'Auth backend'
  11. context 'when Setting developer_mode is true' do
  12. before do
  13. Setting.set('developer_mode', true)
  14. end
  15. context 'when password is "test"' do
  16. let(:password) { 'test' }
  17. it 'authenticates' do
  18. expect(instance.valid?).to be true
  19. end
  20. end
  21. context 'when password matches actual User password' do
  22. let(:user) { create(:user, password: 'secure') }
  23. let(:password) { user.password_plain }
  24. it "doesn't authenticate" do
  25. expect(instance.valid?).to be false
  26. end
  27. end
  28. end
  29. context 'when Rails.env is "test"' do
  30. before do
  31. allow(Rails).to receive(:env) { 'test'.inquiry } # rubocop:disable Rails/Inquiry
  32. end
  33. context 'when password is blank' do
  34. let(:password) { '' }
  35. it 'authenticates' do
  36. expect(instance.valid?).to be true
  37. end
  38. end
  39. context 'when password matches actual User password' do
  40. let(:user) { create(:user, password: 'secure') }
  41. let(:password) { user.password_plain }
  42. it "doesn't authenticate" do
  43. expect(instance.valid?).to be false
  44. end
  45. end
  46. end
  47. context 'when Rails.env is "production"' do
  48. before do
  49. allow(Rails).to receive(:env) { 'production'.inquiry } # rubocop:disable Rails/Inquiry
  50. end
  51. context 'when password is blank' do
  52. let(:password) { '' }
  53. it "doesn't authenticate" do
  54. expect(instance.valid?).to be false
  55. end
  56. end
  57. context 'when password matches actual User password' do
  58. let(:user) { create(:user, password: 'secure') }
  59. let(:password) { user.password_plain }
  60. it "doesn't authenticate" do
  61. expect(instance.valid?).to be false
  62. end
  63. end
  64. end
  65. end
  66. end