provider_spec.rb 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.describe Authorization::Provider, :aggregate_failures, type: :model do
  4. context "with setting 'auth_third_party_no_create_user'" do
  5. let(:uid) { SecureRandom.uuid }
  6. let(:auth_hash) do
  7. {
  8. 'info' => { 'email' => Faker::Internet.email },
  9. 'uid' => uid,
  10. }
  11. end
  12. context 'when is enabled' do
  13. before do
  14. Setting.set('auth_third_party_no_create_user', true)
  15. end
  16. it 'does not create a new user, logs and raises an error' do
  17. allow(Rails.logger).to receive(:error)
  18. expect { described_class.new(auth_hash) }.to raise_error(Authorization::Provider::AccountError)
  19. message = "User account '#{uid}' not found for authentication provider 'Provider'."
  20. expect(Rails.logger).to have_received(:error).with(no_args).once do |&block|
  21. expect(block.call).to eq(message)
  22. end
  23. expect(User.find_by(email: auth_hash['info']['email'])).to be_nil
  24. end
  25. end
  26. context 'when is disabled' do
  27. before do
  28. Setting.set('auth_third_party_no_create_user', false)
  29. end
  30. it 'creates a new user' do
  31. expect { described_class.new(auth_hash) }.to change(User, :count).by(1)
  32. end
  33. end
  34. end
  35. end