diff options
| author | Tom Duffield <tom@chef.io> | 2016-10-24 15:34:12 -0500 |
|---|---|---|
| committer | Tom Duffield <tom@chef.io> | 2016-10-31 12:40:45 -0500 |
| commit | 1738bd548fe1227017f3fbd093fcf13f5c194bad (patch) | |
| tree | 2756697a9b05c31b0906adcf0e831460692d7413 /spec | |
| parent | f1ee3c3ad99a39bcecc631ce411378b60ec878f8 (diff) | |
| download | chef-1738bd548fe1227017f3fbd093fcf13f5c194bad.tar.gz | |
Properly check lock status of user on solaris2
On Solaris, the 'shadow' database does not exist within `getent`, so the
checking for the username there won't return accurate results. As the
Solaris provider assumes user management via /etc/shadow, we can very
easily parse the contents of the file directly.
Signed-off-by: Tom Duffield <tom@chef.io>
Diffstat (limited to 'spec')
| -rw-r--r-- | spec/unit/provider/user/solaris_spec.rb | 42 |
1 files changed, 34 insertions, 8 deletions
diff --git a/spec/unit/provider/user/solaris_spec.rb b/spec/unit/provider/user/solaris_spec.rb index 8a5e654a0d..ee2a744ea2 100644 --- a/spec/unit/provider/user/solaris_spec.rb +++ b/spec/unit/provider/user/solaris_spec.rb @@ -99,7 +99,27 @@ describe Chef::Provider::User::Solaris do end describe "when managing user locked status" do + let(:user_lock) { "adam:FOO:::::::" } + let(:shadow_file_contents) do + %W{ + user1:LK::::::: + #{user_lock} + user2:NP::::::: + } + end + describe "when determining if the user is locked" do + before do + allow(IO).to receive(:read).and_return(shadow_file_contents.join("\n")) + end + + context "when user does not exist" do + let(:user_lock) { "other_user:FOO:::::::" } + + it "should raise a sensible error" do + expect { provider.check_lock }.to raise_error(Chef::Exceptions::User) + end + end # locked shadow lines [ @@ -107,12 +127,15 @@ describe Chef::Provider::User::Solaris do "adam:*LK*:::::::", "adam:*LK*foobar:::::::", "adam:*LK*bahamas10:::::::", + "adam:*LK*goonawaLK:::::::", "adam:*LK*L....:::::::", ].each do |shadow| - it "should return true if user is locked with #{shadow}" do - shell_return = shellcmdresult.new(shadow + "\n", "", 0) - expect(provider).to receive(:shell_out!).with("getent", "shadow", "adam").and_return(shell_return) - expect(provider.check_lock).to eql(true) + context "for user 'adam' with entry '#{shadow}'" do + let(:user_lock) { shadow } + + it "should return true" do + expect(provider.check_lock).to eql(true) + end end end @@ -122,12 +145,15 @@ describe Chef::Provider::User::Solaris do "adam:*NP*:::::::", "adam:foobar:::::::", "adam:bahamas10:::::::", + "adam:goonawaLK:::::::", "adam:L...:::::::", ].each do |shadow| - it "should return false if user is unlocked with #{shadow}" do - shell_return = shellcmdresult.new(shadow + "\n", "", 0) - expect(provider).to receive(:shell_out!).with("getent", "shadow", "adam").and_return(shell_return) - expect(provider.check_lock).to eql(false) + context "for user 'adam' with entry '#{shadow}'" do + let(:user_lock) { shadow } + + it "should return false" do + expect(provider.check_lock).to eql(false) + end end end end |
