summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhil Dibowitz <phil@ipom.com>2015-10-20 18:31:09 -0700
committerPhil Dibowitz <phil@ipom.com>2015-10-20 18:31:09 -0700
commit00b6873865ded8d1e560c3b77dee8da6c9eb1b09 (patch)
tree3dd030414cda55fa00ebd6832d9dd64d8560119c
parenta16d253bec53b8209a092d990c58bcb3e10bd3bd (diff)
parent5b2326a93c1c926ee0c302f57e46edabf8638fc7 (diff)
downloadchef-00b6873865ded8d1e560c3b77dee8da6c9eb1b09.tar.gz
Merge pull request #3119 from cmluciano/cml/bug1586
Fix condition of removing a group before user error.
-rw-r--r--lib/chef/provider/user.rb2
-rw-r--r--spec/unit/http_spec.rb2
-rw-r--r--spec/unit/provider/user_spec.rb9
3 files changed, 11 insertions, 2 deletions
diff --git a/lib/chef/provider/user.rb b/lib/chef/provider/user.rb
index 244b11db98..76aefbf1c8 100644
--- a/lib/chef/provider/user.rb
+++ b/lib/chef/provider/user.rb
@@ -89,7 +89,7 @@ class Chef
end
def define_resource_requirements
- requirements.assert(:all_actions) do |a|
+ requirements.assert(:create, :modify, :manage, :lock, :unlock) do |a|
a.assertion { @group_name_resolved }
a.failure_message Chef::Exceptions::User, "Couldn't lookup integer GID for group name #{@new_resource.gid}"
a.whyrun "group name #{@new_resource.gid} does not exist. This will cause group assignment to fail. Assuming this group will have been created previously."
diff --git a/spec/unit/http_spec.rb b/spec/unit/http_spec.rb
index 4d851df951..a654d14aa2 100644
--- a/spec/unit/http_spec.rb
+++ b/spec/unit/http_spec.rb
@@ -89,4 +89,4 @@ describe Chef::HTTP do
end # head
-end
+end \ No newline at end of file
diff --git a/spec/unit/provider/user_spec.rb b/spec/unit/provider/user_spec.rb
index 2345ce18fb..bd24a6a01e 100644
--- a/spec/unit/provider/user_spec.rb
+++ b/spec/unit/provider/user_spec.rb
@@ -452,11 +452,20 @@ describe Chef::Provider::User do
it "should raise an error if we can't translate the group name during resource assertions" do
expect(Etc).to receive(:getgrnam).and_raise(ArgumentError)
+ @provider.action = :create
@provider.define_resource_requirements
@provider.convert_group_name
expect { @provider.process_resource_requirements }.to raise_error(Chef::Exceptions::User)
end
+ it "does not raise an error if we can't translate the group name during resource assertions if we are removing the user" do
+ expect(Etc).to receive(:getgrnam).and_raise(ArgumentError)
+ @provider.action = :remove
+ @provider.define_resource_requirements
+ @provider.convert_group_name
+ expect { @provider.process_resource_requirements }.not_to raise_error
+ end
+
it "should set the new resources gid to the integerized version if available" do
expect(Etc).to receive(:getgrnam).with("999").and_return(@group)
@provider.convert_group_name