Skip to content
Open
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
14 changes: 9 additions & 5 deletions spec/unit/provider/user/openbsd_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

let(:shadow_entry) {
return unless Puppet.features.libshadow?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess we never executed that test in CI because the ruby-shadow gem is missing and then the return hits?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(we need to get the gem into our CI)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes I think that's correct. Installing the gem in CI would be well-advised, IMHO.

entry = Etc::PasswdEntry.new
entry = Shadow::Passwd::Entry.new

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this requried? did the API for the ruby-shadow gem change?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I mentioned in the OP, Etc::PasswdEntry doesn't exist, so the test crashes right there, but only when ruby-shadow is available in the environment, which is why it wasn't caught earlier.

If you look at dd3df54 it sounds like the intention was to change it to Etc::Passwd not Etc::PasswdEntry (which doesn't seem to have existed, ever) but that doesn't work either, and it was never caught because again, the spec never actually ran in CI...

entry[:sp_namp] = 'myuser' # login name
entry[:sp_loginclass] = 'staff' # login class
entry
Expand All @@ -47,7 +47,11 @@
allow(Facter).to receive(:value).with('os.family').and_return('OpenBSD')
allow(Facter).to receive(:value).with('os.release.major')
resource[:expiry] = "1997-06-01"
expect(provider.addcmd).to eq(['/usr/sbin/useradd', '-e', 'June 01 1997', 'myuser'])
if Puppet.features.libshadow?
expect(provider.addcmd).to eq(['/usr/sbin/useradd', '-e', 'June 01 1997', '-L', 'staff', 'myuser'])
else
expect(provider.addcmd).to eq(['/usr/sbin/useradd', '-e', 'June 01 1997', 'myuser'])
end
end
end

Expand All @@ -58,19 +62,19 @@

it "should return the loginclass if set", :if => Puppet.features.libshadow? do
expect(Shadow::Passwd).to receive(:getspnam).with('myuser').and_return(shadow_entry)
provider.send(:loginclass).should == 'staff'
expect(provider.send(:loginclass)).to eq('staff')
end

it "should return the empty string when loginclass isn't set", :if => Puppet.features.libshadow? do
shadow_entry[:sp_loginclass] = ''
expect(Shadow::Passwd).to receive(:getspnam).with('myuser').and_return(shadow_entry)
provider.send(:loginclass).should == ''
expect(provider.send(:loginclass)).to eq('')
end

it "should return nil when loginclass isn't available", :if => Puppet.features.libshadow? do
shadow_entry[:sp_loginclass] = nil
expect(Shadow::Passwd).to receive(:getspnam).with('myuser').and_return(shadow_entry)
provider.send(:loginclass).should be_nil
expect(provider.send(:loginclass)).to be_nil
end
end
end
4 changes: 2 additions & 2 deletions spec/unit/provider/user/useradd_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

let(:shadow_entry) {
return unless Puppet.features.libshadow?
entry = Etc::PasswdEntry.new
entry = Shadow::Passwd::Entry.new
entry[:sp_namp] = 'myuser' # login name
entry[:sp_pwdp] = '$6$FvW8Ib8h$qQMI/CR9m.QzIicZKutLpBgCBBdrch1IX0rTnxuI32K1pD9.RXZrmeKQlaC.RzODNuoUtPPIyQDufunvLOQWF0' # encrypted password
entry[:sp_lstchg] = 15573 # date of last password change
Expand Down Expand Up @@ -675,7 +675,7 @@
{
:password_min_age => 10,
:password_max_age => 20,
:password_warn_days => 30,
:password_warn_days => 7,
:password => '$6$FvW8Ib8h$qQMI/CR9m.QzIicZKutLpBgCBBdrch1IX0rTnxuI32K1pD9.RXZrmeKQlaC.RzODNuoUtPPIyQDufunvLOQWF0'
}.each_pair do |property, expected_value|
describe "##{property}" do
Expand Down