diff --git a/lib/import/ldap.rb b/lib/import/ldap.rb index 4f0834cf9..ea643781d 100644 --- a/lib/import/ldap.rb +++ b/lib/import/ldap.rb @@ -6,8 +6,9 @@ require 'ldap/group' module Import class Ldap < Import::Base - # Checks if the integration is activated. Otherwise it won't get queued - # since it will display an error which is confusing and wrong. + # Checks if the integration is activated and configured. + # Otherwise it won't get queued since it will display + # an error which is confusing and wrong. # # @example # Import::LDAP.queueable? @@ -15,7 +16,7 @@ module Import # # return [Boolean] def self.queueable? - Setting.get('ldap_integration') + Setting.get('ldap_integration') && Setting.get('ldap_config').present? end # Starts a live or dry run LDAP import. diff --git a/spec/lib/import/ldap_spec.rb b/spec/lib/import/ldap_spec.rb index 507da9b19..ecb58fbdb 100644 --- a/spec/lib/import/ldap_spec.rb +++ b/spec/lib/import/ldap_spec.rb @@ -6,13 +6,21 @@ RSpec.describe Import::Ldap do describe '#queueable?' do - it 'is queueable if ldap integration is activated' do - expect(Setting).to receive(:get).with('ldap_integration').and_return(true) + it 'is queueable if LDAP integration is activated and configured' do + allow(Setting).to receive(:get).with('ldap_integration').and_return(true) + allow(Setting).to receive(:get).with('ldap_config').and_return({ host: 'some' }) expect(described_class.queueable?).to be true end - it "isn't queueable if ldap integration is deactivated" do - expect(Setting).to receive(:get).with('ldap_integration').and_return(false) + it "isn't queueable if LDAP integration is deactivated" do + allow(Setting).to receive(:get).with('ldap_integration').and_return(false) + allow(Setting).to receive(:get).with('ldap_config').and_return({ host: 'some' }) + expect(described_class.queueable?).to be false + end + + it "isn't queueable if LDAP configuration is missing" do + allow(Setting).to receive(:get).with('ldap_integration').and_return(true) + allow(Setting).to receive(:get).with('ldap_config').and_return({}) expect(described_class.queueable?).to be false end end @@ -20,11 +28,10 @@ RSpec.describe Import::Ldap do describe '.start' do it 'starts LDAP import resource factories' do - import_job = create(:import_job) instance = described_class.new(import_job) - expect(Setting).to receive(:get).with('ldap_integration').and_return(true) + allow(Setting).to receive(:get).with('ldap_integration').and_return(true) expect(Import::Ldap::UserFactory).to receive(:import) instance.start