File tree Expand file tree Collapse file tree 3 files changed +25
-2
lines changed
lib/puppet/provider/mongodb_user
unit/puppet/provider/mongodb_user Expand file tree Collapse file tree 3 files changed +25
-2
lines changed Original file line number Diff line number Diff 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?
Original file line number Diff line number Diff 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
Original file line number Diff line number Diff line change 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
You can’t perform that action at this time.
0 commit comments