Skip to content
Snippets Groups Projects
Verified Commit e6a10982 authored by Stan Hu's avatar Stan Hu
Browse files

Fix LDAP tls_options not working

The removal of the Settingslogic gem in
!113040 created a
regression when LDAP `tls_options` were used. It resulted in
`Gitlab::config.ldap.servers.main.tls_options.cert` returning `nil`
instead of the certificate.

This occurred because `Gitlab::Auth::Ldap::Config#custom_tls_options`
attempts to duplicate the `tls_options` Hash and symbolize the keys,
but instead it altered the internal Hash representation of
`GitlabSettings::Options`. Since all the keys were transformed to
symbols but `GitlabSettings::Options` converts all keys to strings,
the values were inaccessible.

To fix this, implement a `dup` to create a copy of the internal
representation. We should also consider refactoring
`Gitlab::Auth::Ldap::Config`.

Relates to #413017

Changelog: fixed
parent 3598a40d
No related branches found
No related tags found
1 merge request!122789Fix LDAP tls_options not working
......@@ -43,6 +43,10 @@ def to_hash
end
alias_method :to_h, :to_hash
def dup
self.class.build(to_hash)
end
def merge(other)
self.class.build(to_hash.merge(other.deep_stringify_keys))
end
......
......@@ -81,6 +81,20 @@
end
end
describe '#dup' do
it 'returns a deep copy' do
new_options = options.dup
expect(options.to_hash).to eq('foo' => { 'bar' => 'baz' })
expect(new_options.to_hash).to eq(options.to_hash)
new_options['test'] = 1
new_options['foo']['bar'] = 'zzz'
expect(options.to_hash).to eq('foo' => { 'bar' => 'baz' })
expect(new_options.to_hash).to eq('test' => 1, 'foo' => { 'bar' => 'zzz' })
end
end
describe '#merge' do
it 'merges a hash to the existing options' do
expect(options.merge(more: 'configs').to_hash).to eq(
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment