diff --git a/lib/puppet/provider/mongodb.rb b/lib/puppet/provider/mongodb.rb index 48093217a..396ccf791 100644 --- a/lib/puppet/provider/mongodb.rb +++ b/lib/puppet/provider/mongodb.rb @@ -183,4 +183,13 @@ def self.mongo_4? def mongo_4? self.class.mongo_4? end + + def self.mongo_5? + v = mongo_version + !v[%r{^5\.}].nil? + end + + def mongo_5? + self.class.mongo_5? + end end diff --git a/lib/puppet/provider/mongodb_user/mongodb.rb b/lib/puppet/provider/mongodb_user/mongodb.rb index 9cd24a5a0..3e4065dac 100644 --- a/lib/puppet/provider/mongodb_user/mongodb.rb +++ b/lib/puppet/provider/mongodb_user/mongodb.rb @@ -61,7 +61,7 @@ def create digestPassword: false } - if mongo_4? + if mongo_4? || mongo_5? # SCRAM-SHA-256 requires digestPassword to be true. command[:mechanisms] = ['SCRAM-SHA-1'] end diff --git a/manifests/repo.pp b/manifests/repo.pp index b06c7ae64..eb60f5ae7 100644 --- a/manifests/repo.pp +++ b/manifests/repo.pp @@ -57,6 +57,7 @@ default => undef } $key = "${mongover[0]}.${mongover[1]}" ? { + '5.0' => 'F5679A222C647C87527C2F8CB00A0BD1E2C63C11', '4.4' => '20691EEC35216C63CAF66CE1656408E390CFB1F5', '4.2' => 'E162F504A20CDF15827F718D4B7C549A058F8B6B', '4.0' => '9DA31620334BD75D9DCB49F368818C72E52529D4', diff --git a/spec/unit/puppet/provider/mongodb_spec.rb b/spec/unit/puppet/provider/mongodb_spec.rb new file mode 100644 index 000000000..0b2d96a8a --- /dev/null +++ b/spec/unit/puppet/provider/mongodb_spec.rb @@ -0,0 +1,30 @@ +require 'spec_helper' + +require 'puppet/provider/mongodb' + +provider_class = Puppet::Provider::Mongodb +describe provider_class do + before do + # Clear the cached version before each test + provider_class.remove_instance_variable(:@mongo_version) \ + if provider_class.instance_variable_defined?(:@mongo_version) + end + + describe 'mongo version detection' do + v = { + '2.6.x' => { '26' => true, '4' => false, '5' => false }, + '4.x.x' => { '26' => false, '4' => true, '5' => false }, + '5.x.x' => { '26' => false, '4' => false, '5' => true }, + 'x.x.x' => { '26' => false, '4' => false, '5' => false } + } + + v.each do |key, results| + it "version detection for [#{key}]" do + allow(provider_class).to receive(:mongo_eval).with('db.version()').and_return(key) + expect(provider_class.mongo_26?).to be results['26'] + expect(provider_class.mongo_4?).to be results['4'] + expect(provider_class.mongo_5?).to be results['5'] + end + end + end +end