Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/puppet/provider/mongodb_user/mongodb.rb
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def create
end

def destroy
mongo_eval("db.dropUser(#{@resource[:username].to_json})")
mongo_eval("db.dropUser(#{@resource[:username].to_json})", @resource[:database])
end

def exists?
Expand Down
23 changes: 23 additions & 0 deletions spec/acceptance/user_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,29 @@ class { 'mongodb::server': }
expect(r.stdout.chomp).to eq('1')
end
end

it 'removes a user with no errors' do
pp = <<-EOS
class { 'mongodb::server': }
-> class { 'mongodb::client': }
-> mongodb_database { 'testdb': ensure => present }
->
mongodb_user {'testuser':
ensure => absent,
password_hash => mongodb_password('testuser', 'passw0rd'),
database => 'testdb',
}
EOS

apply_manifest(pp, catch_failures: true)
apply_manifest(pp, catch_changes: true)
end

it 'auth should fail' do
shell("mongo testdb --quiet --eval 'db.auth(\"testuser\",\"passw0rd\")'") do |r|
expect(r.stdout.chomp).to contain('Error: Authentication failed')
end
end
end

context 'with custom port' do
Expand Down
2 changes: 1 addition & 1 deletion spec/unit/puppet/provider/mongodb_user/mongodb_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@

describe 'destroy' do
it 'removes a user' do
allow(provider).to receive(:mongo_eval).with('db.dropUser("new_user")')
allow(provider).to receive(:mongo_eval).with('db.dropUser("new_user")', 'new_database')
provider.destroy
expect(provider).to have_received(:mongo_eval)
end
Expand Down