summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBryan McLellan <btm@opscode.com>2013-11-26 07:54:02 -0800
committerBryan McLellan <btm@opscode.com>2013-11-26 09:07:05 -0800
commit8d9e96ab5fb4c8381755a252e83d445bcc8a958a (patch)
treea41671b2d699d648c1d0bcd7476d2828f158a3f9
parentad5bbfea38a1c8d2c4f0b6339ca825016f5fa4ac (diff)
downloadchef-8d9e96ab5fb4c8381755a252e83d445bcc8a958a.tar.gz
CHEF-3940: Raise an error if we cannot find the user
We need the user to find their HOME, and we don't want to guess about the HOME.
-rw-r--r--lib/chef/provider/git.rb3
-rw-r--r--spec/unit/provider/git_spec.rb4
2 files changed, 6 insertions, 1 deletions
diff --git a/lib/chef/provider/git.rb b/lib/chef/provider/git.rb
index e9d42a5d01..e77948d367 100644
--- a/lib/chef/provider/git.rb
+++ b/lib/chef/provider/git.rb
@@ -17,6 +17,7 @@
#
+require 'chef/exceptions'
require 'chef/log'
require 'chef/provider'
require 'chef/mixin/shell_out'
@@ -282,7 +283,7 @@ class Chef
require 'etc'
Etc.getpwnam(@new_resource.user).dir
rescue ArgumentError # user not found
- "/home/#{@new_resource.user}"
+ raise Chef::Exceptions::User, "Could not determine HOME for specified user '#{@new_resource.user}' for resource '#{@new_resource.name}'"
end
end
run_opts[:group] = @new_resource.group if @new_resource.group
diff --git a/spec/unit/provider/git_spec.rb b/spec/unit/provider/git_spec.rb
index a18319b469..4c54a17958 100644
--- a/spec/unit/provider/git_spec.rb
+++ b/spec/unit/provider/git_spec.rb
@@ -179,6 +179,7 @@ SHAS
before do
@resource.user deploy_user
@resource.ssh_wrapper wrapper
+ Etc.stub!(:getpwnam).and_return(double("Struct::Passwd", :name => @resource.user, :dir => "/home/deployNinja"))
end
context "without a timeout set" do
it "clones a repo with default git options" do
@@ -198,6 +199,7 @@ SHAS
it "runs a clone command with escaped destination" do
@resource.user "deployNinja"
+ Etc.stub!(:getpwnam).and_return(double("Struct::Passwd", :name => @resource.user, :dir => "/home/deployNinja"))
@resource.destination "/Application Support/with/space"
@resource.ssh_wrapper "do_it_this_way.sh"
expected_cmd = "git clone \"git://github.com/opscode/chef.git\" \"/Application Support/with/space\""
@@ -253,6 +255,7 @@ SHAS
it "runs a sync command with the user and group specified in the resource" do
@resource.user("whois")
+ Etc.stub!(:getpwnam).and_return(double("Struct::Passwd", :name => @resource.user, :dir => "/home/whois"))
@resource.group("thisis")
@provider.should_receive(:setup_remote_tracking_branches).with(@resource.remote, @resource.repository)
expected_cmd = "git fetch origin && git fetch origin --tags && git reset --hard d35af14d41ae22b19da05d7d03a0bafc321b244c"
@@ -299,6 +302,7 @@ SHAS
it "runs the config with the user and group specified in the resource" do
@resource.user("whois")
@resource.group("thisis")
+ Etc.stub!(:getpwnam).and_return(double("Struct::Passwd", :name => @resource.user, :dir => "/home/whois"))
command_response = double('shell_out')
command_response.stub(:exitstatus) { 1 }
expected_command = "git config --get remote.#{@resource.remote}.url"