File tree Expand file tree Collapse file tree 2 files changed +19
-4
lines changed Expand file tree Collapse file tree 2 files changed +19
-4
lines changed Original file line number Diff line number Diff line change @@ -135,7 +135,7 @@ def localgroups
135
135
136
136
Puppet ::FileSystem . each_line ( group_file ) do |line |
137
137
data = line . chomp . split ( ':' )
138
- if data . last . split ( ',' ) . include? ( user )
138
+ if ! data . empty? && data . last . split ( ',' ) . include? ( user )
139
139
@groups_of [ user ] << data . first
140
140
end
141
141
end
Original file line number Diff line number Diff line change 375
375
before { described_class . has_feature :manages_local_users_and_groups }
376
376
377
377
let ( :content ) do
378
- <<~EOF
378
+ StringIO . new ( <<~EOF )
379
379
group1:x:0:myuser
380
380
group2:x:999:
381
381
group3:x:998:myuser
382
382
EOF
383
383
end
384
384
385
+ let ( :content_with_empty_line ) do
386
+ StringIO . new ( <<~EOF )
387
+ group1:x:0:myuser
388
+ group2:x:999:
389
+ group3:x:998:myuser
390
+
391
+ EOF
392
+ end
393
+
385
394
it "should return the local groups string when forcelocal is true" do
386
395
resource [ :forcelocal ] = true
387
- group1 , group2 , group3 = content . split
388
396
allow ( Puppet ::FileSystem ) . to receive ( :exist? ) . with ( '/etc/group' ) . and_return ( true )
389
- allow ( Puppet :: FileSystem ) . to receive ( :each_line ) . with ( '/etc/group' ) . and_yield ( group1 ) . and_yield ( group2 ) . and_yield ( group3 )
397
+ allow ( File ) . to receive ( :open ) . with ( Pathname . new ( '/etc/group' ) ) . and_yield ( content )
390
398
expect ( provider . groups ) . to eq ( [ 'group1' , 'group3' ] )
391
399
end
392
400
401
+ it "does not raise when parsing empty lines in /etc/group" do
402
+ resource [ :forcelocal ] = true
403
+ allow ( Puppet ::FileSystem ) . to receive ( :exist? ) . with ( '/etc/group' ) . and_return ( true )
404
+ allow ( File ) . to receive ( :open ) . with ( Pathname . new ( '/etc/group' ) ) . and_yield ( content_with_empty_line )
405
+ expect { provider . groups } . not_to raise_error
406
+ end
407
+
393
408
it "should fall back to nameservice groups when forcelocal is false" do
394
409
resource [ :forcelocal ] = false
395
410
allow ( Puppet ::Util ::POSIX ) . to receive ( :groups_of ) . with ( 'myuser' ) . and_return ( [ 'remote groups' ] )
You can’t perform that action at this time.
0 commit comments