Skip to content

Commit 56aa480

Browse files
p-mongop
andcommitted
Fix RUBY-2347 GSSAPI service name is not defaulted when any other auth mechanism properties are set (#2042)
Co-authored-by: Oleg Pudeyev <oleg@bsdpower.com>
1 parent e0b2410 commit 56aa480

File tree

2 files changed

+49
-1
lines changed

2 files changed

+49
-1
lines changed

lib/mongo/client.rb

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -466,7 +466,18 @@ def initialize(addresses_or_uri, options = nil)
466466
# construction
467467
sdam_proc = options.delete(:sdam_proc)
468468

469-
options = default_options(options).merge(options)
469+
# For gssapi service_name, the default option is given in a hash
470+
# (one level down from the top level).
471+
merged_options = default_options(options)
472+
options.each do |k, v|
473+
default_v = merged_options[k]
474+
if Hash === default_v
475+
v = default_v.merge(v)
476+
end
477+
merged_options[k] = v
478+
end
479+
options = merged_options
480+
470481
@options = validate_new_options!(options)
471482
=begin WriteConcern object support
472483
if @options[:write_concern].is_a?(WriteConcern::Base)

spec/integration/client_authentication_options_spec.rb

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,43 @@
256256
expect(client.options[:auth_mech_properties]).to eq({ 'service_name' => 'mongodb' })
257257
end
258258
end
259+
260+
context 'when properties are given but not service name' do
261+
context 'with URI options' do
262+
let(:credentials) { "#{user}:#{pwd}@" }
263+
264+
context 'with default auth mech properties' do
265+
let(:options) { '?authMechanism=GSSAPI&authMechanismProperties=service_realm:foo' }
266+
267+
it 'sets service name to mongodb' do
268+
expect(client.options[:auth_mech_properties]).to eq(
269+
'service_name' => 'mongodb',
270+
'service_realm' => 'foo',
271+
)
272+
end
273+
end
274+
end
275+
276+
context 'with client options' do
277+
let(:client_opts) do
278+
{
279+
auth_mech: :gssapi,
280+
user: user,
281+
password: pwd,
282+
auth_mech_properties: {
283+
service_realm: 'foo',
284+
}.freeze,
285+
}.freeze
286+
end
287+
288+
it 'sets default auth mech properties' do
289+
expect(client.options[:auth_mech_properties]).to eq(
290+
'service_name' => 'mongodb',
291+
'service_realm' => 'foo',
292+
)
293+
end
294+
end
295+
end
259296
end
260297

261298
context 'with PLAIN auth mechanism' do

0 commit comments

Comments
 (0)