Skip to content

Commit a4814d3

Browse files
authored
Merge pull request #644 from SeanHood/remove-user-non-admin-db
2 parents 61c6690 + 942089d commit a4814d3

File tree

3 files changed

+25
-2
lines changed

3 files changed

+25
-2
lines changed

lib/puppet/provider/mongodb_user/mongodb.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ def create
8989
end
9090

9191
def destroy
92-
mongo_eval("db.dropUser(#{@resource[:username].to_json})")
92+
mongo_eval("db.dropUser(#{@resource[:username].to_json})", @resource[:database])
9393
end
9494

9595
def exists?

spec/acceptance/user_spec.rb

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,29 @@ class { 'mongodb::server': }
2424
expect(r.stdout.chomp).to eq('1')
2525
end
2626
end
27+
28+
it 'removes a user with no errors' do
29+
pp = <<-EOS
30+
class { 'mongodb::server': }
31+
-> class { 'mongodb::client': }
32+
-> mongodb_database { 'testdb': ensure => present }
33+
->
34+
mongodb_user {'testuser':
35+
ensure => absent,
36+
password_hash => mongodb_password('testuser', 'passw0rd'),
37+
database => 'testdb',
38+
}
39+
EOS
40+
41+
apply_manifest(pp, catch_failures: true)
42+
apply_manifest(pp, catch_changes: true)
43+
end
44+
45+
it 'auth should fail' do
46+
shell("mongo testdb --quiet --eval 'db.auth(\"testuser\",\"passw0rd\")'") do |r|
47+
expect(r.stdout.chomp).to contain('Error: Authentication failed')
48+
end
49+
end
2750
end
2851

2952
context 'with custom port' do

spec/unit/puppet/provider/mongodb_user/mongodb_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@
6969

7070
describe 'destroy' do
7171
it 'removes a user' do
72-
allow(provider).to receive(:mongo_eval).with('db.dropUser("new_user")')
72+
allow(provider).to receive(:mongo_eval).with('db.dropUser("new_user")', 'new_database')
7373
provider.destroy
7474
expect(provider).to have_received(:mongo_eval)
7575
end

0 commit comments

Comments
 (0)