diff options
author | Thom May <thom@may.lt> | 2016-05-18 10:55:29 +0100 |
---|---|---|
committer | Thom May <thom@may.lt> | 2016-05-18 10:55:29 +0100 |
commit | 2f19f54b60a5c05fea0ec75ce20af25940f545d9 (patch) | |
tree | e2e44e47d21b3c2110178e6a47777d07ef369359 | |
parent | 568848bd2be018e6d5f80e8bf8fea0363f3d2ccf (diff) | |
parent | 321106fbf5e92f6bcad8bba78e5ed59642777747 (diff) | |
download | chef-2f19f54b60a5c05fea0ec75ce20af25940f545d9.tar.gz |
Merge pull request #4902 from MichaelPereira/handle-user-id-git-resource
Handle numeric id for the user value in the git resource
-rw-r--r-- | lib/chef/provider/git.rb | 7 | ||||
-rw-r--r-- | spec/unit/provider/git_spec.rb | 36 |
2 files changed, 42 insertions, 1 deletions
diff --git a/lib/chef/provider/git.rb b/lib/chef/provider/git.rb index 004e0b550d..d051bb1d92 100644 --- a/lib/chef/provider/git.rb +++ b/lib/chef/provider/git.rb @@ -300,7 +300,12 @@ class Chef # user who is executing `git` not the user running Chef. env["HOME"] = begin require "etc" - Etc.getpwnam(@new_resource.user).dir + case @new_resource.user + when Integer + Etc.getpwuid(@new_resource.user).dir + else + Etc.getpwnam(@new_resource.user.to_s).dir + end rescue ArgumentError # user not found raise Chef::Exceptions::User, "Could not determine HOME for specified user '#{@new_resource.user}' for resource '#{@new_resource.name}'" end diff --git a/spec/unit/provider/git_spec.rb b/spec/unit/provider/git_spec.rb index 36c33d313c..a60c1b44c3 100644 --- a/spec/unit/provider/git_spec.rb +++ b/spec/unit/provider/git_spec.rb @@ -267,6 +267,42 @@ SHAS end end + context "with a user id" do + let(:deploy_user) { 123 } + let(:expected_cmd) { 'git clone "git://github.com/opscode/chef.git" "/my/deploy/dir"' } + let(:default_options) do + { + :user => 123, + :environment => { "HOME" => "/home/deployNinja" }, + :log_tag => "git[web2.0 app]", + } + end + before do + @resource.user deploy_user + allow(Etc).to receive(:getpwuid).and_return(double("Struct::Passwd", :name => @resource.user, :dir => "/home/deployNinja")) + end + context "with a specific home" do + let (:override_home) do + { "HOME" => "/home/masterNinja" } + end + let(:overrided_options) do + { + :user => 123, + :environment => { "HOME" => "/home/masterNinja" }, + :log_tag => "git[web2.0 app]", + } + end + before do + @resource.environment(override_home) + end + before { @resource.environment(override_home) } + it "clones a repo with amended git options with specific home" do + expect(@provider).to receive(:shell_out!).with(expected_cmd, hash_including(overrided_options)) + @provider.clone + end + end + end + it "runs a clone command with escaped destination" do @resource.user "deployNinja" allow(Etc).to receive(:getpwnam).and_return(double("Struct::Passwd", :name => @resource.user, :dir => "/home/deployNinja")) |