Automate clearing of broken LDAP configurations (fixes #2140)
This commit is contained in:
parent
4f6503593e
commit
e07f41ed16
3 changed files with 51 additions and 1 deletions
|
@ -51,7 +51,7 @@ get config setting
|
||||||
|
|
||||||
def self.get(name)
|
def self.get(name)
|
||||||
load
|
load
|
||||||
@@current[name]
|
@@current[name].deep_dup # prevents accidental modification of settings in console
|
||||||
end
|
end
|
||||||
|
|
||||||
=begin
|
=begin
|
||||||
|
|
15
db/migrate/20180911064647_issue_2140_reset_ldap_config.rb
Normal file
15
db/migrate/20180911064647_issue_2140_reset_ldap_config.rb
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
class Issue2140ResetLdapConfig < ActiveRecord::Migration[5.1]
|
||||||
|
def up
|
||||||
|
# return if it's a new setup
|
||||||
|
return if !Setting.find_by(name: 'system_init_done')
|
||||||
|
|
||||||
|
ldap_config = Setting.get('ldap_config')
|
||||||
|
|
||||||
|
# finish if LDAP config isn't broken
|
||||||
|
ldap_config.to_json
|
||||||
|
rescue Encoding::UndefinedConversionError
|
||||||
|
ldap_config[:wizardData].delete(:backend_user_attributes)
|
||||||
|
|
||||||
|
Setting.set('ldap_config', ldap_config)
|
||||||
|
end
|
||||||
|
end
|
35
spec/db/migrate/issue_2140_reset_ldap_config_spec.rb
Normal file
35
spec/db/migrate/issue_2140_reset_ldap_config_spec.rb
Normal file
|
@ -0,0 +1,35 @@
|
||||||
|
require 'rails_helper'
|
||||||
|
|
||||||
|
RSpec.describe Issue2140ResetLdapConfig, type: :db_migration do
|
||||||
|
before { Setting.set('ldap_config', config) }
|
||||||
|
|
||||||
|
context 'when LDAP config isn’t broken' do
|
||||||
|
let(:config) do
|
||||||
|
{ 'wizardData' =>
|
||||||
|
{ 'backend_user_attributes' =>
|
||||||
|
{ 'foo' => 'bar' },
|
||||||
|
'user_attributes' =>
|
||||||
|
{ 'baz' => 'qux' } } }.with_indifferent_access
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'makes no changes' do
|
||||||
|
expect { migrate }.not_to change { Setting.get('ldap_config') }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'when LDAP config is broken' do
|
||||||
|
let(:config) do
|
||||||
|
{ 'wizardData' =>
|
||||||
|
{ 'backend_user_attributes' =>
|
||||||
|
{ 'foo' => "\u0001\u0001\u0004€" },
|
||||||
|
'user_attributes' =>
|
||||||
|
{ 'baz' => 'qux' } } }.with_indifferent_access
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'removes the offending backend_user_attributes sub-hash' do
|
||||||
|
expect { migrate }
|
||||||
|
.to change { Setting.get('ldap_config') }
|
||||||
|
.to(config.tap { |c| c[:wizardData].delete(:backend_user_attributes) })
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in a new issue