diff options
author | Tom Duffield <tom@chef.io> | 2016-10-19 16:32:52 -0500 |
---|---|---|
committer | Tom Duffield <tom@chef.io> | 2016-10-20 15:13:40 -0500 |
commit | f1920088085648f74225c6fdda4efdd95afa35ff (patch) | |
tree | d99d97931f4c1f331a0f46a7998edfc23f7a5c3d /spec | |
parent | 20cc4626599063e7a8f284fd6dc89e127d360d15 (diff) | |
download | chef-f1920088085648f74225c6fdda4efdd95afa35ff.tar.gz |
Raise error if suse group manager adds non-existent userCOOL-597/address-suse-test-failures
The expected behavior of chef, as defined by our tests, is that if a
user specified in a group resource does not exist than chef should raise
an error. On suse, we use groupmod which will not raise an error if you
attempt to add a non-existent user to a group. This change adds in a
simple check that will raise an error if the specified does not exist.
Signed-off-by: Tom Duffield <tom@chef.io>
Diffstat (limited to 'spec')
-rw-r--r-- | spec/unit/provider/group/suse_spec.rb | 90 |
1 files changed, 90 insertions, 0 deletions
diff --git a/spec/unit/provider/group/suse_spec.rb b/spec/unit/provider/group/suse_spec.rb new file mode 100644 index 0000000000..da4e8e9155 --- /dev/null +++ b/spec/unit/provider/group/suse_spec.rb @@ -0,0 +1,90 @@ +# +# Author:: Tom Duffield (<tom@chef.io>) +# Copyright:: Copyright 2016 Chef Software, Inc. +# License:: Apache License, Version 2.0 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +require "spec_helper" + +describe Chef::Provider::Group::Suse do + let(:node) { Chef::Node.new } + let(:events) { Chef::EventDispatch::Dispatcher.new } + let(:run_context) { Chef::RunContext.new(node, {}, events) } + let(:new_members) { %w{root new_user} } + let(:new_resource) do + Chef::Resource::Group.new("new_group").tap do |r| + r.gid 50 + r.members new_members + r.system false + r.non_unique false + end + end + let(:current_resource) do + Chef::Resource::Group.new("new_group").tap do |r| + r.gid 50 + r.members %w{root} + r.system false + r.non_unique false + end + end + let(:provider) do + described_class.new(new_resource, run_context).tap do |p| + p.current_resource = current_resource + end + end + + describe "when determining the current group state" do + before(:each) do + allow(File).to receive(:exists?).and_return(true) + provider.action = :create + provider.define_resource_requirements + end + + # Checking for required binaries is already done in the spec + # for Chef::Provider::Group - no need to repeat it here. We'll + # include only what's specific to this provider. + it "should raise an error if the required binary /usr/sbin/groupmod doesn't exist" do + expect(File).to receive(:exists?).with("/usr/sbin/groupmod").and_return(false) + expect { provider.process_resource_requirements }.to raise_error(Chef::Exceptions::Group) + end + + it "should raise error if one of the member users does not exist" do + expect(Etc).to receive(:getpwnam).with("new_user").and_raise ArgumentError + expect { provider.process_resource_requirements }.to raise_error(Chef::Exceptions::Group) + end + end + + describe "#set_members" do + it "should add missing members and remove deleted members" do + expect(provider).not_to receive(:remove_member) + expect(provider).to receive(:add_member).with("new_user") + provider.set_members(new_members) + end + end + + describe "#add_member" do + it "should call out to groupmod to add user" do + expect(provider).to receive(:shell_out!).with("groupmod -A new_user new_group") + provider.add_member("new_user") + end + end + + describe "#remove_member" do + it "should call out to groupmod to remove user" do + expect(provider).to receive(:shell_out!).with("groupmod -R new_user new_group") + provider.remove_member("new_user") + end + end +end |