File tree 2 files changed +21
-26
lines changed
lib/puppet/provider/mongodb_user
spec/unit/puppet/provider/mongodb_user
2 files changed +21
-26
lines changed Original file line number Diff line number Diff line change 9
9
def self . instances
10
10
require 'json'
11
11
12
- if db_ismaster
13
- script = 'EJSON.stringify(db.system.users.find().toArray())'
14
- # A hack to prevent prefetching failures until admin user is created
15
- script = "try {#{ script } } catch (e) { if (e.message.match(/requires authentication/) || e.message.match(/not authorized on admin/)) { 'not authorized on admin' } else {throw e}}" if auth_enabled
16
-
17
- out = mongo_eval ( script )
18
- return [ ] if auth_enabled && ( out . include? ( 'requires authentication' ) || out . include? ( 'not authorized on admin' ) )
19
-
20
- users = JSON . parse out
21
-
22
- users . map do |user |
23
- new ( name : user [ '_id' ] ,
24
- ensure : :present ,
25
- username : user [ 'user' ] ,
26
- database : user [ 'db' ] ,
27
- roles : from_roles ( user [ 'roles' ] , user [ 'db' ] ) ,
28
- password_hash : user [ 'credentials' ] [ 'MONGODB-CR' ] ,
29
- scram_credentials : user [ 'credentials' ] [ 'SCRAM-SHA-1' ] )
30
- end
31
- else
32
- Puppet . warning 'User info is available only from master host'
33
- [ ]
12
+ script = 'EJSON.stringify(db.system.users.find().toArray())'
13
+ # A hack to prevent prefetching failures until admin user is created
14
+ script = "try {#{ script } } catch (e) { if (e.message.match(/requires authentication/) || e.message.match(/not authorized on admin/)) { 'not authorized on admin' } else {throw e}}" if auth_enabled
15
+
16
+ out = mongo_eval ( script )
17
+ return [ ] if auth_enabled && ( out . include? ( 'requires authentication' ) || out . include? ( 'not authorized on admin' ) )
18
+
19
+ users = JSON . parse out
20
+
21
+ users . map do |user |
22
+ new ( name : user [ '_id' ] ,
23
+ ensure : :present ,
24
+ username : user [ 'user' ] ,
25
+ database : user [ 'db' ] ,
26
+ roles : from_roles ( user [ 'roles' ] , user [ 'db' ] ) ,
27
+ password_hash : user [ 'credentials' ] [ 'MONGODB-CR' ] ,
28
+ scram_credentials : user [ 'credentials' ] [ 'SCRAM-SHA-1' ] )
34
29
end
35
30
end
36
31
Original file line number Diff line number Diff line change 71
71
end
72
72
end
73
73
74
- describe 'empty self.instances from slave' do
75
- it 'doesn`t retrun array of users' do
76
- allow ( provider . class ) . to receive ( :db_ismaster ) . and_return ( false )
77
- expect ( provider . class . instances ) . to be_empty
74
+ describe 'same self.instances from slave' do
75
+ it 'returns an array of users' do
76
+ usernames = provider . class . instances . map ( & :username )
77
+ expect ( parsed_users ) . to match_array ( usernames )
78
78
end
79
79
end
80
80
You can’t perform that action at this time.
0 commit comments