diff options
author | Tim Smith <tsmith@chef.io> | 2018-01-05 11:59:57 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-01-05 11:59:57 -0800 |
commit | 90b263b605387f056e0754888e44475114823102 (patch) | |
tree | d35aaa663165805957120b07959156b8751fd3b9 | |
parent | aaf0aa51823346d81b6baa4e5770d769f5412a4e (diff) | |
parent | 3f54ed4ddfc6f394906cc160ebff2e41448fbd4e (diff) | |
download | chef-90b263b605387f056e0754888e44475114823102.tar.gz |
Merge pull request #6735 from get9/fix-dscl-home-exists
Check for set home property before file existence (fixes #5777)
-rw-r--r-- | lib/chef/provider/user/dscl.rb | 2 | ||||
-rw-r--r-- | spec/unit/provider/user/dscl_spec.rb | 26 |
2 files changed, 27 insertions, 1 deletions
diff --git a/lib/chef/provider/user/dscl.rb b/lib/chef/provider/user/dscl.rb index 60167856d1..bc865b17c5 100644 --- a/lib/chef/provider/user/dscl.rb +++ b/lib/chef/provider/user/dscl.rb @@ -318,7 +318,7 @@ user password using shadow hash.") end def current_home_exists? - ::File.exist?(current_resource.home) + !!current_resource.home && ::File.exist?(current_resource.home) end def new_home_exists? diff --git a/spec/unit/provider/user/dscl_spec.rb b/spec/unit/provider/user/dscl_spec.rb index f59709e717..956c32664d 100644 --- a/spec/unit/provider/user/dscl_spec.rb +++ b/spec/unit/provider/user/dscl_spec.rb @@ -213,6 +213,32 @@ ea18e18b720e358e7fbe3cfbeaa561456f6ba008937a30" end end + describe "current_home_exists?" do + let(:current_resource) do + new_resource.dup + end + + before do + provider.current_resource = current_resource + end + + it "returns false for nil home dir" do + current_resource.home nil + expect(provider.current_home_exists?).to be_falsey + end + + it "is false for empty string" do + current_resource.home "" + expect(provider.current_home_exists?).to be_falsey + end + + it "is true for existing directory" do + current_resource.home "/Users/blah" + allow(::File).to receive(:exist?).with("/Users/blah").and_return(true) + expect(provider.current_home_exists?).to be_truthy + end + end + describe "when modifying the home directory" do let(:current_resource) do new_resource.dup |