2021-06-01 12:20:20 +00:00
|
|
|
# Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/
|
|
|
|
|
2017-05-05 08:58:05 +00:00
|
|
|
require 'rails_helper'
|
|
|
|
require 'lib/import/import_job_backend_examples'
|
|
|
|
|
2018-01-08 15:27:23 +00:00
|
|
|
RSpec.describe Import::Ldap, sequencer: :caller do
|
2017-05-05 08:58:05 +00:00
|
|
|
it_behaves_like 'ImportJob backend'
|
|
|
|
|
2017-05-11 15:18:03 +00:00
|
|
|
describe '.queueable?' do
|
2017-05-05 08:58:05 +00:00
|
|
|
|
2017-05-10 07:51:19 +00:00
|
|
|
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' })
|
2017-05-05 08:58:05 +00:00
|
|
|
expect(described_class.queueable?).to be true
|
|
|
|
end
|
|
|
|
|
2017-05-10 07:51:19 +00:00
|
|
|
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({})
|
2017-05-05 08:58:05 +00:00
|
|
|
expect(described_class.queueable?).to be false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-05-10 14:43:44 +00:00
|
|
|
describe '#start' do
|
2017-05-05 08:58:05 +00:00
|
|
|
it 'starts LDAP import resource factories' do
|
|
|
|
import_job = create(:import_job)
|
|
|
|
instance = described_class.new(import_job)
|
|
|
|
|
2017-05-10 07:51:19 +00:00
|
|
|
allow(Setting).to receive(:get).with('ldap_integration').and_return(true)
|
2017-05-10 14:43:44 +00:00
|
|
|
allow(Setting).to receive(:get).with('ldap_config').and_return(true)
|
2018-01-08 15:27:23 +00:00
|
|
|
|
|
|
|
expect_sequence
|
2017-05-05 08:58:05 +00:00
|
|
|
|
|
|
|
instance.start
|
|
|
|
end
|
2017-05-10 14:43:44 +00:00
|
|
|
|
|
|
|
context 'requirements' do
|
|
|
|
|
|
|
|
it 'lets dry runs always start' do
|
|
|
|
import_job = create(:import_job, dry_run: true)
|
|
|
|
instance = described_class.new(import_job)
|
|
|
|
|
2018-01-08 15:27:23 +00:00
|
|
|
expect_sequence
|
2017-05-10 14:43:44 +00:00
|
|
|
|
|
|
|
instance.start
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'informs about deactivated ldap_integration' do
|
|
|
|
import_job = create(:import_job)
|
|
|
|
instance = described_class.new(import_job)
|
|
|
|
|
|
|
|
allow(Setting).to receive(:get).with('ldap_integration').and_return(false)
|
|
|
|
|
2018-01-08 15:27:23 +00:00
|
|
|
expect_no_sequence
|
2017-05-10 14:43:44 +00:00
|
|
|
|
|
|
|
expect do
|
|
|
|
instance.start
|
|
|
|
import_job.reload
|
|
|
|
end.to change {
|
|
|
|
import_job.result
|
|
|
|
}
|
|
|
|
|
|
|
|
expect(import_job.result.key?(:info)).to be true
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'informs about blank ldap_config' do
|
|
|
|
import_job = create(:import_job)
|
|
|
|
instance = described_class.new(import_job)
|
|
|
|
|
|
|
|
allow(Setting).to receive(:get).with('ldap_integration').and_return(true)
|
|
|
|
allow(Setting).to receive(:get).with('ldap_config').and_return({})
|
|
|
|
|
2018-01-08 15:27:23 +00:00
|
|
|
expect_no_sequence
|
2017-05-10 14:43:44 +00:00
|
|
|
|
|
|
|
expect do
|
|
|
|
instance.start
|
|
|
|
import_job.reload
|
|
|
|
end.to change {
|
|
|
|
import_job.result
|
|
|
|
}
|
|
|
|
|
|
|
|
expect(import_job.result.key?(:info)).to be true
|
|
|
|
end
|
|
|
|
end
|
2017-05-05 08:58:05 +00:00
|
|
|
end
|
2017-05-11 15:18:03 +00:00
|
|
|
|
|
|
|
describe '#reschedule?' do
|
|
|
|
|
|
|
|
it 'initiates always a rescheduling' do
|
|
|
|
import_job = create(:import_job)
|
|
|
|
instance = described_class.new(import_job)
|
2021-07-16 13:29:38 +00:00
|
|
|
delayed_job = double
|
2017-05-11 15:18:03 +00:00
|
|
|
|
|
|
|
expect(instance.reschedule?(delayed_job)).to be true
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'updates the result with an info text' do
|
|
|
|
import_job = create(:import_job)
|
|
|
|
instance = described_class.new(import_job)
|
2021-07-16 13:29:38 +00:00
|
|
|
delayed_job = double
|
2017-05-11 15:18:03 +00:00
|
|
|
|
|
|
|
expect do
|
|
|
|
instance.reschedule?(delayed_job)
|
|
|
|
end.to change {
|
|
|
|
import_job.result
|
|
|
|
}
|
|
|
|
|
|
|
|
expect(import_job.result.key?(:info)).to be true
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
2017-05-05 08:58:05 +00:00
|
|
|
end
|