summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLamont Granquist <lamont@scriptkiddie.org>2018-02-21 12:45:12 -0800
committerTim Smith <tsmith@chef.io>2018-02-22 09:24:43 -0800
commit963264299935403c0ad4aff76f148cda9c00e401 (patch)
tree186f4457055f3dfd49e1276b28fe5d1349488e97
parent1a1b1002b1852c7a74094011a24da5e69eef6e58 (diff)
downloadchef-963264299935403c0ad4aff76f148cda9c00e401.tar.gz
mock specs to very fake user+groupfix_chef_13_builds
travis tests were sporadially failing based on the presence or absence of an "aj:aj" user+group on the travis testing boxes. Signed-off-by: Lamont Granquist <lamont@scriptkiddie.org>
-rw-r--r--spec/unit/daemon_spec.rb25
1 files changed, 14 insertions, 11 deletions
diff --git a/spec/unit/daemon_spec.rb b/spec/unit/daemon_spec.rb
index 9448380c91..02736a1daf 100644
--- a/spec/unit/daemon_spec.rb
+++ b/spec/unit/daemon_spec.rb
@@ -19,6 +19,9 @@ require "spec_helper"
require "ostruct"
describe Chef::Daemon do
+ let(:testuser) { "thisisausernamewhichshouldnotexist" }
+ let(:testgroup) { "thisisagroupnamewhichshouldnotexist" }
+
before do
if windows?
mock_struct = #Struct::Passwd.new(nil, nil, 111, 111)
@@ -75,7 +78,7 @@ describe Chef::Daemon do
before do
allow(Chef::Daemon).to receive(:_change_privilege)
allow(Chef::Application).to receive(:fatal!).and_return(true)
- Chef::Config[:user] = "aj"
+ Chef::Config[:user] = testuser
allow(Dir).to receive(:chdir)
end
@@ -87,28 +90,28 @@ describe Chef::Daemon do
describe "when the user and group options are supplied" do
before do
- Chef::Config[:group] = "staff"
+ Chef::Config[:group] = testgroup
end
it "should log an appropriate info message" do
- expect(Chef::Log).to receive(:info).with("About to change privilege to aj:staff")
+ expect(Chef::Log).to receive(:info).with("About to change privilege to #{testuser}:#{testgroup}")
Chef::Daemon.change_privilege
end
it "should call _change_privilege with the user and group" do
- expect(Chef::Daemon).to receive(:_change_privilege).with("aj", "staff")
+ expect(Chef::Daemon).to receive(:_change_privilege).with(testuser, testgroup)
Chef::Daemon.change_privilege
end
end
describe "when just the user option is supplied" do
it "should log an appropriate info message" do
- expect(Chef::Log).to receive(:info).with("About to change privilege to aj")
+ expect(Chef::Log).to receive(:info).with("About to change privilege to #{testuser}")
Chef::Daemon.change_privilege
end
it "should call _change_privilege with just the user" do
- expect(Chef::Daemon).to receive(:_change_privilege).with("aj")
+ expect(Chef::Daemon).to receive(:_change_privilege).with(testuser)
Chef::Daemon.change_privilege
end
end
@@ -139,18 +142,18 @@ describe Chef::Daemon do
end
it "should initialize the supplemental group list" do
- expect(Process).to receive(:initgroups).with("aj", 20)
- Chef::Daemon._change_privilege("aj")
+ expect(Process).to receive(:initgroups).with(testuser, 20)
+ Chef::Daemon._change_privilege(testuser)
end
it "should attempt to change the process GID" do
expect(Process::GID).to receive(:change_privilege).with(20).and_return(20)
- Chef::Daemon._change_privilege("aj")
+ Chef::Daemon._change_privilege(testuser)
end
it "should attempt to change the process UID" do
expect(Process::UID).to receive(:change_privilege).with(501).and_return(501)
- Chef::Daemon._change_privilege("aj")
+ Chef::Daemon._change_privilege(testuser)
end
end
@@ -172,7 +175,7 @@ describe Chef::Daemon do
error = "Not owner"
end
expect(Chef::Application).to receive(:fatal!).with("Permission denied when trying to change 999:999 to 501:20. #{error}")
- Chef::Daemon._change_privilege("aj")
+ Chef::Daemon._change_privilege(testuser)
end
end