summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortyler-ball <tyleraball@gmail.com>2014-09-30 11:16:31 -0700
committertyler-ball <tyleraball@gmail.com>2014-10-07 15:34:34 -0700
commit25104da3b9be7545ca8911cb0f11a42f524989a3 (patch)
treebd279b75a00e1b0e27cbae7a2995b372d0242e31
parentd4c52ac9722d67829e3d1393ba0b9cc59eb003ed (diff)
downloadchef-25104da3b9be7545ca8911cb0f11a42f524989a3.tar.gz
Moving documentation to a more logical place. Also no longer dis-allowing users from running brew as root.
-rw-r--r--lib/chef/exceptions.rb1
-rw-r--r--lib/chef/mixin/homebrew_user.rb12
-rw-r--r--spec/unit/mixin/homebrew_user_spec.rb20
3 files changed, 18 insertions, 15 deletions
diff --git a/lib/chef/exceptions.rb b/lib/chef/exceptions.rb
index f08cc5eb96..67429ac5a2 100644
--- a/lib/chef/exceptions.rb
+++ b/lib/chef/exceptions.rb
@@ -121,7 +121,6 @@ class Chef
class PowershellCmdletException < RuntimeError; end
class CannotDetermineHomebrewOwner < Package; end
- class HomebrewOwnerIsRoot < ArgumentError; end
# A different version of a cookbook was added to a
# VersionedRecipeList than the one already there.
diff --git a/lib/chef/mixin/homebrew_user.rb b/lib/chef/mixin/homebrew_user.rb
index 6e86e3824f..854a954a90 100644
--- a/lib/chef/mixin/homebrew_user.rb
+++ b/lib/chef/mixin/homebrew_user.rb
@@ -42,11 +42,6 @@ class Chef
end
@homebrew_owner ||= calculate_owner
- if @homebrew_owner == 0
- raise Chef::Exceptions::HomebrewOwnerIsRoot,
- 'The homebrew owner is currently "root". This is not suggested by the' +
- 'homebrew maintainers.'
- end
@homebrew_owner
end
@@ -56,13 +51,16 @@ class Chef
default_brew_path = '/usr/local/bin/brew'
if ::File.exist?(default_brew_path)
# By default, this follows symlinks which is what we want
- ::File.stat(default_brew_path).uid
+ owner = ::File.stat(default_brew_path).uid
elsif (brew_path = shell_out("which brew").stdout.strip) && !brew_path.empty?
- ::File.stat(brew_path).uid
+ owner = ::File.stat(brew_path).uid
else
raise Chef::Exceptions::CannotDetermineHomebrewOwner,
'Could not find the "brew" executable in /usr/local/bin or anywhere on the path.'
end
+
+ Chef::Log.debug "Found Homebrew owner #{Etc.getpwuid(owner).name}; executing `brew` commands as them"
+ owner
end
end
diff --git a/spec/unit/mixin/homebrew_user_spec.rb b/spec/unit/mixin/homebrew_user_spec.rb
index a27a6a0460..7af04f0958 100644
--- a/spec/unit/mixin/homebrew_user_spec.rb
+++ b/spec/unit/mixin/homebrew_user_spec.rb
@@ -47,7 +47,7 @@ describe Chef::Mixin::HomebrewUser do
end
- describe 'when the homebrew user is not provided' do
+ shared_examples "successfully find executable" do
let(:user) { nil }
let(:brew_owner) { 2001 }
let(:default_brew_path) { '/usr/local/bin/brew' }
@@ -57,6 +57,10 @@ describe Chef::Mixin::HomebrewUser do
d
}
+ before do
+ expect(Etc).to receive(:getpwuid).with(brew_owner).and_return(OpenStruct.new(:name => "name"))
+ end
+
it 'returns the owner of the brew executable when it is at a default location' do
expect(File).to receive(:exist?).with(default_brew_path).and_return(true)
expect(File).to receive(:stat).with(default_brew_path).and_return(stat_double)
@@ -69,6 +73,11 @@ describe Chef::Mixin::HomebrewUser do
expect(File).to receive(:stat).with("/foo").and_return(stat_double)
expect(homebrew_user.find_homebrew_uid(user)).to eq(brew_owner)
end
+ end
+
+ describe 'when the homebrew user is not provided' do
+
+ include_examples "successfully find executable"
it 'raises an error if no executable is found' do
expect(File).to receive(:exist?).with(default_brew_path).and_return(false)
@@ -76,13 +85,10 @@ describe Chef::Mixin::HomebrewUser do
expect { homebrew_user.find_homebrew_uid(user) }.to raise_error(Chef::Exceptions::CannotDetermineHomebrewOwner)
end
- describe "the executable is owned by root" do
+ context "the executable is owned by root" do
let(:brew_owner) { 0 }
-
- it 'raises an error' do
- expect(File).to receive(:exist?).with(default_brew_path).and_return(true)
- expect(File).to receive(:stat).with(default_brew_path).and_return(stat_double)
- expect { homebrew_user.find_homebrew_uid(user) }.to raise_error(Chef::Exceptions::HomebrewOwnerIsRoot)
+ include_examples "successfully find executable" do
+ let(:brew_owner) { 0 }
end
end