|
@@ -64,8 +64,15 @@ RSpec.describe 'Ldap import', integration: true, required_envs: %w[IMPORT_LDAP_E
|
|
|
end
|
|
|
end
|
|
|
|
|
|
+ shared_examples 'certificate verification error' do
|
|
|
+ it 'returns certificate verify failed error' do
|
|
|
+ expect(ImportJob.last.result[:error]).to match(%r{error: certificate verify failed \(self(-|\s)signed certificate in certificate chain\)})
|
|
|
+ end
|
|
|
+ end
|
|
|
+
|
|
|
context 'when importing' do
|
|
|
before do
|
|
|
+ before_hook if defined? before_hook
|
|
|
Setting.set('ldap_integration', true)
|
|
|
TCR.turned_off do
|
|
|
ldap_source
|
|
@@ -76,15 +83,60 @@ RSpec.describe 'Ldap import', integration: true, required_envs: %w[IMPORT_LDAP_E
|
|
|
include_examples 'ldap import'
|
|
|
|
|
|
context 'with ssl' do
|
|
|
- let(:ldap_source) { create(:ldap_source, :with_ssl) }
|
|
|
+ context 'with ssl verification' do
|
|
|
+ context 'with trusted certificate' do
|
|
|
+ let(:ldap_source) { create(:ldap_source, :with_ssl_verified) }
|
|
|
+ let(:ca_certificate) { Rails.root.join('spec/fixtures/files/ldap/ca.crt').read }
|
|
|
+ let(:before_hook) do
|
|
|
+ import_ca_certificate
|
|
|
+ end
|
|
|
+
|
|
|
+ include_examples 'ldap import'
|
|
|
+ end
|
|
|
+
|
|
|
+ context 'without trusted certificate' do
|
|
|
+ let(:ldap_source) { create(:ldap_source, :with_ssl_verified) }
|
|
|
|
|
|
- include_examples 'ldap import'
|
|
|
+ include_examples 'certificate verification error'
|
|
|
+ end
|
|
|
+ end
|
|
|
+
|
|
|
+ context 'without ssl verification' do
|
|
|
+ let(:ldap_source) { create(:ldap_source, :with_ssl) }
|
|
|
+
|
|
|
+ include_examples 'ldap import'
|
|
|
+ end
|
|
|
end
|
|
|
|
|
|
context 'with starttls' do
|
|
|
- let(:ldap_source) { create(:ldap_source, :with_starttls) }
|
|
|
+ context 'with ssl verification' do
|
|
|
+ context 'with trusted certificate' do
|
|
|
+ let(:ldap_source) { create(:ldap_source, :with_starttls_verified) }
|
|
|
+ let(:ca_certificate) { Rails.root.join('spec/fixtures/files/ldap/ca.crt').read }
|
|
|
+ let(:before_hook) do
|
|
|
+ import_ca_certificate
|
|
|
+ end
|
|
|
+
|
|
|
+ include_examples 'ldap import'
|
|
|
+ end
|
|
|
+
|
|
|
+ context 'without trusted certificate' do
|
|
|
+ let(:ldap_source) { create(:ldap_source, :with_ssl_verified) }
|
|
|
+
|
|
|
+ include_examples 'certificate verification error'
|
|
|
+ end
|
|
|
+ end
|
|
|
+
|
|
|
+ context 'without ssl verification' do
|
|
|
+ let(:ldap_source) { create(:ldap_source, :with_starttls) }
|
|
|
+
|
|
|
+ include_examples 'ldap import'
|
|
|
+ end
|
|
|
+ end
|
|
|
|
|
|
- include_examples 'ldap import'
|
|
|
+ def import_ca_certificate
|
|
|
+ # Import CA certificate into the trust store.
|
|
|
+ SSLCertificate.create!(certificate: Rails.root.join('spec/fixtures/files/ldap/ca.crt').read)
|
|
|
end
|
|
|
end
|
|
|
end
|