Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

Add LDAP env seeder

Oliver Günther5b303cd573f0
diff --git a/app/seeders/env_data/ldap_seeder.rb b/app/seeders/env_data/ldap_seeder.rb
new file mode 100644
index 00000000000..938bb8a2424
--- /dev/null
+++ b/app/seeders/env_data/ldap_seeder.rb
@@ -0,0 +1,116 @@
+#-- copyright
+
+# OpenProject is an open source project management software.
+# Copyright (C) 2012-2023 the OpenProject GmbH
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License version 3.
+#
+# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
+# Copyright (C) 2006-2013 Jean-Philippe Lang
+# Copyright (C) 2010-2013 the ChiliProject Team
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+# See COPYRIGHT and LICENSE files for more details.
+module EnvData
+ class LdapSeeder < Seeder
+ def seed_data!
+ print_status ' ↳ Creating LDAP connection' do
+ Setting.seed_ldap.each do |name, options|
+ ldap = LdapAuthSource.find_or_initialize_by(name:)
+
+ print_ldap_status(ldap)
+ upsert_settings(ldap, options)
+ update_filters(ldap, options['groupfilter'])
+ end
+ end
+
+ end
+
+ def applicable?
+ Setting.seed_ldap.any?
+ end
+
+ private
+
+ # rubocop:disable Metrics/AbcSize
+ def upsert_settings(ldap, options)
+ ldap.host = options['host']
+ ldap.port = options['port']
+
+ ldap.tls_mode = options['security']
+ ldap.verify_peer = ActiveRecord::Type::Boolean.new.deserialize options.fetch('tlsverify', true)
+ ldap.onthefly_register = ActiveRecord::Type::Boolean.new.deserialize options.fetch('sync_users', false)
+ ldap.tls_certificate_string = options['tls_certificate'].presence
+
+ ldap.filter_string = options['filter'].presence
+ ldap.base_dn = options['basedn']
+ ldap.account = options['binduser']
+ ldap.account_password = options['bindpassword']
+
+ ldap.attr_login = options['login_mapping'].presence
+ ldap.attr_firstname = options['firstname_mapping'].presence
+ ldap.attr_lastname = options['lastname_mapping'].presence
+ ldap.attr_mail = options['mail_mapping'].presence
+ ldap.attr_admin = options['admin_mapping'].presence
+
+ ldap.save!
+ end
+ # rubocop:enable Metrics/AbcSize
+
+ def update_filters(ldap, filters)
+ return if filters.blank? && !LdapGroups::SynchronizedFilter.exists?(ldap_auth_source: ldap)
+
+ upsert_existing_filters(ldap, filters) if filters.present?
+ remove_not_found_filters(ldap, filters&.keys || [])
+ end
+
+ def upsert_existing_filters(ldap, filters)
+ filters.each do |name, options|
+ filter = ::LdapGroups::SynchronizedFilter.find_or_initialize_by(auth_source: ldap, name:)
+ print_ldap_status(filter)
+
+ filter.group_name_attribute = options.fetch('group_attribute', 'dn')
+ filter.sync_users = ActiveRecord::Type::Boolean.new.deserialize options.fetch('sync_users', false)
+ filter.filter_string = options['filter']
+ filter.base_dn = options['base']
+
+ filter.save!
+ end
+ end
+
+ def remove_not_found_filters(ldap, names)
+ not_found = ::LdapGroups::SynchronizedFilter
+ .where(ldap_auth_source: ldap)
+ .where.not(name: names)
+
+ return unless not_found.exists?
+
+ not_found_names = not_found.pluck(:name).join(', ')
+ print_status " - Removing LDAP filter #{not_found_names} no longer present in ENV"
+
+ not_found.destroy_all
+ end
+
+ def print_ldap_status(object)
+ if object.new_record?
+ print_status " - Creating new #{object.model_name.human} #{object.name} from ENV"
+ else
+ print_status " - Updating existing #{object.model_name.human} #{object.name} from ENV"
+ end
+ end
+ end
+end
diff --git a/app/seeders/env_data_seeder.rb b/app/seeders/env_data_seeder.rb
new file mode 100644
index 00000000000..d4ecf0519ba
--- /dev/null
+++ b/app/seeders/env_data_seeder.rb
@@ -0,0 +1,37 @@
+#-- copyright
+# OpenProject is an open source project management software.
+# Copyright (C) 2012-2023 the OpenProject GmbH
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License version 3.
+#
+# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
+# Copyright (C) 2006-2013 Jean-Philippe Lang
+# Copyright (C) 2010-2013 the ChiliProject Team
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+# See COPYRIGHT and LICENSE files for more details.
+class EnvDataSeeder < CompositeSeeder
+ def data_seeder_classes
+ [
+ EnvData::LdapSeeder
+ ]
+ end
+
+ def namespace
+ 'EnvData'
+ end
+end
diff --git a/app/seeders/root_seeder.rb b/app/seeders/root_seeder.rb
index 10a29f855b8..d8baf468235 100644
--- a/app/seeders/root_seeder.rb
+++ b/app/seeders/root_seeder.rb
@@ -63,6 +63,7 @@ class RootSeeder < Seeder
seed_demo_data
seed_development_data if seed_development_data?
seed_plugins_data
+ seed_env_data
end
end
@@ -140,6 +141,11 @@ class RootSeeder < Seeder
DemoDataSeeder.new(seed_data).seed!
end
+ def seed_env_data
+ print_status '*** Seeding data from environment variables'
+ EnvDataSeeder.new(seed_data).seed!
+ end
+
def seed_development_data
print_status '*** Seeding development data'
require 'factory_bot'
diff --git a/config/constants/settings/definition.rb b/config/constants/settings/definition.rb
index 63e355b3fed..4dbc0c2a744 100644
--- a/config/constants/settings/definition.rb
+++ b/config/constants/settings/definition.rb
@@ -823,6 +823,12 @@ module Settings
default: true,
writable: false
},
+ seed_ldap: {
+ description: 'Provide an LDAP connection and sync settings through ENV',
+ writable: false,
+ default: nil,
+ format: :hash
+ },
self_registration: {
default: 2
},
diff --git a/modules/ldap_groups/lib/open_project/ldap_groups/patches/ldap_auth_source_patch.rb b/modules/ldap_groups/lib/open_project/ldap_groups/patches/ldap_auth_source_patch.rb
index c8effc02dd5..b5137b1e17a 100644
--- a/modules/ldap_groups/lib/open_project/ldap_groups/patches/ldap_auth_source_patch.rb
+++ b/modules/ldap_groups/lib/open_project/ldap_groups/patches/ldap_auth_source_patch.rb
@@ -6,6 +6,10 @@ module OpenProject::LdapGroups
has_many :ldap_groups_synchronized_groups,
class_name: '::LdapGroups::SynchronizedGroup',
dependent: :destroy
+
+ has_many :ldap_groups_synchronized_filters,
+ class_name: '::LdapGroups::SynchronizedFilter',
+ dependent: :destroy
end
end
end
diff --git a/spec/factories/ldap_auth_source_factory.rb b/spec/factories/ldap_auth_source_factory.rb
index 976bf01b0e8..e782d441af4 100644
--- a/spec/factories/ldap_auth_source_factory.rb
+++ b/spec/factories/ldap_auth_source_factory.rb
@@ -33,5 +33,6 @@ FactoryBot.define do
port { 225 } # a reserved port, should not be in use
attr_login { 'uid' }
tls_mode { 'plain_ldap' }
+ base_dn { 'dc=example,dc=com' }
end
end
diff --git a/spec/fixtures/files/example.com.crt b/spec/fixtures/files/example.com.crt
new file mode 100644
index 00000000000..fae66439427
--- /dev/null
+++ b/spec/fixtures/files/example.com.crt
@@ -0,0 +1,30 @@
+-----BEGIN CERTIFICATE-----
+MIIFOzCCAyOgAwIBAgIUNKLrEALGA1SQ3YvCTAyGkBKIfDwwDQYJKoZIhvcNAQEL
+BQAwFjEUMBIGA1UEAwwLZXhhbXBsZS5jb20wHhcNMjMwNzI3MTQxNzE5WhcNMzMw
+NzI0MTQxNzE5WjAWMRQwEgYDVQQDDAtleGFtcGxlLmNvbTCCAiIwDQYJKoZIhvcN
+AQEBBQADggIPADCCAgoCggIBAKuFN324z9TlT1aEyCnWRXj6SzturoQdM4B3/0AF
+RO7nlHzoE9vahFVtrD1U9oKp2g3dInCjLkPBOioK79HqW8bQ2m1hgEzZ01/VLG8W
+SKKUoGDNfeip3dnG96gdJfNIaR9ZtU7EVX3ihHOonj1aU5ScsqZqDt/aEhamAuC0
+V+k4Wnbw/YMJcIlrWBGgyE8ypmirZqJxd0LVJcCjU3rv4Y4Q/8xfjlPJQ3crJpIb
+zlIKJb+lY2H8G2jdCcg2nT2dqqNmc22R/uHI78DATZvnskM5MoHJEXHS650LBdNB
+lzxixPCWfxlLwwCmCRYUq2cfg4v//0Qs944iPklgdvv31SAnDN+4c6shNWaqeqAt
+aVljRsTcNQ6obtY9iU+vKwIhf4eKQB/L+dXNef8FE+PvutRG0jaNrVYILPQBjtWA
+mW++MA5O0LQLmUaqKsJ5d6hVG/SLqiYA5GYIP3AZ6aEfdw0O1I5kPki/ePsSA9nd
+keP+5MbkegcZWd4+GX9C6tD+DU/DaSH0tl1xEDer33ROE+CUxapGD2UrXUgBOHC5
+o0fOp27/thPffQmq1F+dn4iPiirTUOS6uXpI/7QJ7hqyPz9FuHB6gewuckPS1LRu
+THIQEcHOYgxiTzDqRgf8Td8ba73otuVXBlsmV4HMDt+5OH/LcySuyoMp8Knt5aeO
+ksRvAgMBAAGjgYAwfjAdBgNVHQ4EFgQUJtpmQh+zH3F8+4IG1q7s9WK7S60wHwYD
+VR0jBBgwFoAUJtpmQh+zH3F8+4IG1q7s9WK7S60wDwYDVR0TAQH/BAUwAwEB/zAr
+BgNVHREEJDAiggtleGFtcGxlLmNvbYINKi5leGFtcGxlLmNvbYcECgAAATANBgkq
+hkiG9w0BAQsFAAOCAgEAntYwbpIQBrg4JJV9dxKqEgQOwj6zSOkOF4RdBJT339zL
+MDMZjWGtkB6qMC2agsHZLlPHwz+vtsJndsd4UzE5QyoI2zkbekHDkKyPZ41HEchL
+Af6XQ+pngBQaQ1w9AiFCSsQqZthIbrVlX6MOVtqvvtOWRgQHPtchxI8oIT87dVPh
+Ef6Y2sekBHmv7DdedjZ4e3xkwQARSkQqzuciyJKSlxd2e3J/fUyinhssm18/9jI4
+sXew10XECPO52noVVrpPmWDYcDe5n66U09hl9gQsYgHZ+Z7Aubm2tHNaspP+YUp5
+0sCJ+hTYB0W6OHq9VPsH43RjKUmAnBAVNTL4j2BAIjPYPUREDDUlpGkRQnFjdAuF
+kP5PxbP3DDNAdsNxCL8h4QfBPCNooSBRxVMz73xjOIHABJfg8bs782ZFhzupumuo
+Iz81NWK0rDsmWbGOtbWKsw3h5T/s3c/KQSD9qwLF39TG9hJdKgAh/VrHJEZUAiOZ
+y3iFWTw/Ot2IkqJTLQgEgXxHtLTbpAjHQWo3J02LXnLH4xoOYOKvcAApGa5Kh+zT
+xvT8hm97tqa2oLd+78oVFoEQ8/dw6dQw61LTdr4VItidTOAFKECq4fLz2Mv2mFO7
+7cqSiyJncixvjxzhlBkbYXqFzVHeiMxrWmV86ga4MSuV/4oVnwc+o0CuBQihMTQ=
+-----END CERTIFICATE-----
diff --git a/spec/seeders/env_data/ldap_seeder_spec.rb b/spec/seeders/env_data/ldap_seeder_spec.rb
new file mode 100644
index 00000000000..5fc734b955b
--- /dev/null
+++ b/spec/seeders/env_data/ldap_seeder_spec.rb
@@ -0,0 +1,218 @@
+# frozen_string_literal: true
+
+#-- copyright
+# OpenProject is an open source project management software.
+# Copyright (C) 2012-2023 the OpenProject GmbH
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License version 3.
+#
+# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
+# Copyright (C) 2006-2013 Jean-Philippe Lang
+# Copyright (C) 2010-2013 the ChiliProject Team
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+# See COPYRIGHT and LICENSE files for more details.
+#++
+
+require 'spec_helper'
+
+RSpec.describe EnvData::LdapSeeder do
+ let(:seed_data) { Source::SeedData.new({}) }
+
+ subject(:seeder) { described_class.new(seed_data) }
+
+ context 'when not provided' do
+ it 'does nothing' do
+ expect { seeder.seed! }.not_to change(LdapAuthSource, :count)
+ end
+ end
+
+ context 'when providing seed variables',
+ :settings_reset,
+ with_env: {
+ OPENPROJECT_SEED_LDAP_FOO_HOST: "localhost",
+ OPENPROJECT_SEED_LDAP_FOO_PORT: "12389",
+ OPENPROJECT_SEED_LDAP_FOO_SECURITY: "plain_ldap",
+ OPENPROJECT_SEED_LDAP_FOO_TLSVERIFY: "false",
+ OPENPROJECT_SEED_LDAP_FOO_TLS__CERTIFICATE: Rails.root.join("spec/fixtures/files/example.com.crt").read,
+ OPENPROJECT_SEED_LDAP_FOO_BINDUSER: "uid=admin,ou=system",
+ OPENPROJECT_SEED_LDAP_FOO_BINDPASSWORD: "secret",
+ OPENPROJECT_SEED_LDAP_FOO_BASEDN: "dc=example,dc=com",
+ OPENPROJECT_SEED_LDAP_FOO_FILTER: "(uid=*)",
+ OPENPROJECT_SEED_LDAP_FOO_SYNC__USERS: "true",
+ OPENPROJECT_SEED_LDAP_FOO_LOGIN__MAPPING: "uid",
+ OPENPROJECT_SEED_LDAP_FOO_FIRSTNAME__MAPPING: "givenName",
+ OPENPROJECT_SEED_LDAP_FOO_LASTNAME__MAPPING: "sn",
+ OPENPROJECT_SEED_LDAP_FOO_MAIL__MAPPING: "mail",
+ OPENPROJECT_SEED_LDAP_FOO_ADMIN__MAPPING: "is_openproject_admin",
+ OPENPROJECT_SEED_LDAP_FOO_GROUPFILTER_BAR_BASE: "ou=groups,dc=example,dc=com",
+ OPENPROJECT_SEED_LDAP_FOO_GROUPFILTER_BAR_FILTER: "(cn=*)",
+ OPENPROJECT_SEED_LDAP_FOO_GROUPFILTER_BAR_SYNC__USERS: "true",
+ OPENPROJECT_SEED_LDAP_FOO_GROUPFILTER_BAR_GROUP__ATTRIBUTE: "dn"
+ } do
+ it 'uses those variables' do # rubocop:disable RSpec/MultipleExpectations, RSpec/ExampleLength
+ reset(:seed_ldap)
+
+ allow(LdapGroups::SynchronizationJob).to receive(:perform_now)
+
+ seeder.seed!
+
+ expect(LdapGroups::SynchronizationJob).to have_received(:perform_now)
+
+ ldap = LdapAuthSource.last
+ expect(ldap.name).to eq 'foo'
+ expect(ldap.host).to eq 'localhost'
+ expect(ldap.port).to eq 12389
+ expect(ldap.tls_mode).to eq 'plain_ldap'
+ expect(ldap.read_ldap_certificates.first).to be_a(OpenSSL::X509::Certificate)
+ expect(ldap.verify_peer).to be false
+ expect(ldap.account).to eq 'uid=admin,ou=system'
+ expect(ldap.account_password).to eq 'secret'
+ expect(ldap.base_dn).to eq 'dc=example,dc=com'
+ expect(ldap.filter_string).to eq '(uid=*)'
+ expect(ldap).to be_onthefly_register
+ expect(ldap.attr_login).to eq 'uid'
+ expect(ldap.attr_firstname).to eq 'givenName'
+ expect(ldap.attr_lastname).to eq 'sn'
+ expect(ldap.attr_mail).to eq 'mail'
+ expect(ldap.attr_admin).to eq 'is_openproject_admin'
+
+ expect(ldap.ldap_groups_synchronized_filters.count).to eq(1)
+ filter = ldap.ldap_groups_synchronized_filters.first
+ expect(filter.name).to eq 'bar'
+ expect(filter.base_dn).to eq 'ou=groups,dc=example,dc=com'
+ expect(filter.filter_string).to eq '(cn=*)'
+ expect(filter.sync_users).to be true
+ expect(filter.group_name_attribute).to eq 'dn'
+ end
+ end
+
+ context 'when removing a previously seeded filter',
+ :settings_reset,
+ with_env: {
+ OPENPROJECT_SEED_LDAP_FOO_HOST: "localhost",
+ OPENPROJECT_SEED_LDAP_FOO_PORT: "12389",
+ OPENPROJECT_SEED_LDAP_FOO_SECURITY: "plain_ldap",
+ OPENPROJECT_SEED_LDAP_FOO_TLSVERIFY: "false",
+ OPENPROJECT_SEED_LDAP_FOO_BINDUSER: "uid=admin,ou=system",
+ OPENPROJECT_SEED_LDAP_FOO_BINDPASSWORD: "secret",
+ OPENPROJECT_SEED_LDAP_FOO_BASEDN: "dc=example,dc=com",
+ OPENPROJECT_SEED_LDAP_FOO_FILTER: "(uid=*)",
+ OPENPROJECT_SEED_LDAP_FOO_SYNC__USERS: "true",
+ OPENPROJECT_SEED_LDAP_FOO_LOGIN__MAPPING: "uid",
+ OPENPROJECT_SEED_LDAP_FOO_FIRSTNAME__MAPPING: "givenName",
+ OPENPROJECT_SEED_LDAP_FOO_LASTNAME__MAPPING: "sn",
+ OPENPROJECT_SEED_LDAP_FOO_MAIL__MAPPING: "mail"
+ } do
+ let!(:ldap) { create(:ldap_auth_source, name: 'foo') }
+ let!(:filter) { create(:ldap_synchronized_filter, name: 'bar', ldap_auth_source: ldap) }
+
+ it 'removes the other one' do # rubocop:disable RSpec/MultipleExpectations
+ expect(ldap.ldap_groups_synchronized_filters.count).to eq(1)
+ names = ldap.ldap_groups_synchronized_filters.pluck(:name)
+ expect(names).to contain_exactly('bar')
+
+ reset(:seed_ldap)
+
+ allow(LdapGroups::SynchronizationJob).to receive(:perform_now)
+
+ seeder.seed!
+
+ expect(LdapGroups::SynchronizationJob).to have_received(:perform_now)
+
+ ldap.reload
+ expect(ldap.name).to eq 'foo'
+ expect(ldap.host).to eq 'localhost'
+ expect(ldap.port).to eq 12389
+ expect(ldap.tls_mode).to eq 'plain_ldap'
+ expect(ldap.verify_peer).to be false
+ expect(ldap.account).to eq 'uid=admin,ou=system'
+ expect(ldap.account_password).to eq 'secret'
+ expect(ldap.base_dn).to eq 'dc=example,dc=com'
+ expect(ldap.filter_string).to eq '(uid=*)'
+ expect(ldap).to be_onthefly_register
+ expect(ldap.attr_login).to eq 'uid'
+ expect(ldap.attr_firstname).to eq 'givenName'
+ expect(ldap.attr_lastname).to eq 'sn'
+ expect(ldap.attr_mail).to eq 'mail'
+ expect(ldap.attr_admin).to be_nil
+
+ expect(ldap.ldap_groups_synchronized_filters.count).to eq(0)
+ end
+ end
+
+ context 'when removing a previously seeded filter and adding one',
+ :settings_reset,
+ with_env: {
+ OPENPROJECT_SEED_LDAP_FOO_HOST: "localhost",
+ OPENPROJECT_SEED_LDAP_FOO_PORT: "12389",
+ OPENPROJECT_SEED_LDAP_FOO_SECURITY: "plain_ldap",
+ OPENPROJECT_SEED_LDAP_FOO_TLSVERIFY: "false",
+ OPENPROJECT_SEED_LDAP_FOO_BINDUSER: "uid=admin,ou=system",
+ OPENPROJECT_SEED_LDAP_FOO_BINDPASSWORD: "secret",
+ OPENPROJECT_SEED_LDAP_FOO_BASEDN: "dc=example,dc=com",
+ OPENPROJECT_SEED_LDAP_FOO_FILTER: "(uid=*)",
+ OPENPROJECT_SEED_LDAP_FOO_SYNC__USERS: "true",
+ OPENPROJECT_SEED_LDAP_FOO_LOGIN__MAPPING: "uid",
+ OPENPROJECT_SEED_LDAP_FOO_FIRSTNAME__MAPPING: "givenName",
+ OPENPROJECT_SEED_LDAP_FOO_LASTNAME__MAPPING: "sn",
+ OPENPROJECT_SEED_LDAP_FOO_MAIL__MAPPING: "mail",
+ OPENPROJECT_SEED_LDAP_FOO_ADMIN__MAPPING: "",
+ OPENPROJECT_SEED_LDAP_FOO_GROUPFILTER_ANOTHER_BASE: "ou=groups,dc=example,dc=com",
+ OPENPROJECT_SEED_LDAP_FOO_GROUPFILTER_ANOTHER_FILTER: "(cn=*)",
+ OPENPROJECT_SEED_LDAP_FOO_GROUPFILTER_ANOTHER_SYNC__USERS: "true",
+ OPENPROJECT_SEED_LDAP_FOO_GROUPFILTER_ANOTHER_GROUP__ATTRIBUTE: "dn"
+ } do
+ let!(:ldap) { create(:ldap_auth_source, name: 'foo') }
+ let!(:filter) { create(:ldap_synchronized_filter, name: 'bar', ldap_auth_source: ldap) }
+
+ it 'removes the other one' do # rubocop:disable RSpec/MultipleExpectations, RSpec/ExampleLength
+ expect(ldap.ldap_groups_synchronized_filters.count).to eq(1)
+ names = ldap.ldap_groups_synchronized_filters.pluck(:name)
+ expect(names).to contain_exactly('bar')
+
+ reset(:seed_ldap)
+
+ allow(LdapGroups::SynchronizationJob).to receive(:perform_now)
+
+ seeder.seed!
+
+ expect(LdapGroups::SynchronizationJob).to have_received(:perform_now)
+
+ ldap.reload
+ expect(ldap.name).to eq 'foo'
+ expect(ldap.host).to eq 'localhost'
+ expect(ldap.port).to eq 12389
+ expect(ldap.tls_mode).to eq 'plain_ldap'
+ expect(ldap.verify_peer).to be false
+ expect(ldap.account).to eq 'uid=admin,ou=system'
+ expect(ldap.account_password).to eq 'secret'
+ expect(ldap.base_dn).to eq 'dc=example,dc=com'
+ expect(ldap.filter_string).to eq '(uid=*)'
+ expect(ldap).to be_onthefly_register
+ expect(ldap.attr_login).to eq 'uid'
+ expect(ldap.attr_firstname).to eq 'givenName'
+ expect(ldap.attr_lastname).to eq 'sn'
+ expect(ldap.attr_mail).to eq 'mail'
+ expect(ldap.attr_admin).to be_nil
+
+ expect(ldap.ldap_groups_synchronized_filters.count).to eq(1)
+ names = ldap.ldap_groups_synchronized_filters.pluck(:name)
+ expect(names).to contain_exactly('another')
+ end
+ end
+end