Skip to content

Commit d384fb7

Browse files
committed
(PUP-10997) Add spec for empty line in /etc/group
1 parent 76ddcc8 commit d384fb7

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

spec/unit/provider/user/useradd_spec.rb

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -375,21 +375,36 @@
375375
before { described_class.has_feature :manages_local_users_and_groups }
376376

377377
let(:content) do
378-
<<~EOF
378+
StringIO.new(<<~EOF)
379379
group1:x:0:myuser
380380
group2:x:999:
381381
group3:x:998:myuser
382382
EOF
383383
end
384384

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+
385394
it "should return the local groups string when forcelocal is true" do
386395
resource[:forcelocal] = true
387-
group1, group2, group3 = content.split
388396
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)
390398
expect(provider.groups).to eq(['group1', 'group3'])
391399
end
392400

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+
393408
it "should fall back to nameservice groups when forcelocal is false" do
394409
resource[:forcelocal] = false
395410
allow(Puppet::Util::POSIX).to receive(:groups_of).with('myuser').and_return(['remote groups'])

0 commit comments

Comments
 (0)