From 809f08511f129d126c884bcd18a2c827a005e95e Mon Sep 17 00:00:00 2001 From: John Keiser Date: Tue, 23 Aug 2016 08:39:05 -0700 Subject: Revert "Merge pull request #5122 from chef/lcg/chef-2205" This reverts commit d61608487432281865d3648cf4b30d531a54f091, reversing changes made to 0447477abd41488674f609cfa59c2bdf35ed6d03. --- Gemfile | 2 +- Gemfile.lock | 46 ++++++------ lib/chef/provider/user/aix.rb | 5 +- lib/chef/provider/user/dscl.rb | 1 - lib/chef/provider/user/linux.rb | 33 --------- lib/chef/provider/user/pw.rb | 3 +- lib/chef/provider/user/solaris.rb | 3 +- lib/chef/provider/user/useradd.rb | 9 ++- lib/chef/provider/user/windows.rb | 2 +- lib/chef/providers.rb | 5 +- lib/chef/resource/user.rb | 6 +- lib/chef/resource/user/aix_user.rb | 31 --------- lib/chef/resource/user/dscl_user.rb | 31 --------- lib/chef/resource/user/linux_user.rb | 52 -------------- lib/chef/resource/user/pw_user.rb | 31 --------- lib/chef/resource/user/solaris_user.rb | 31 --------- lib/chef/resource/user/windows_user.rb | 31 --------- lib/chef/resources.rb | 6 -- spec/functional/resource/group_spec.rb | 8 +-- .../unit/provider/useradd_based_user_provider.rb | 52 ++++++++------ spec/unit/provider/user/dscl_spec.rb | 2 +- spec/unit/provider/user/linux_spec.rb | 81 ---------------------- spec/unit/provider/user/pw_spec.rb | 9 ++- spec/unit/provider/user/solaris_spec.rb | 6 +- spec/unit/provider/user/useradd_spec.rb | 51 ++++++++++++++ spec/unit/provider/user/windows_spec.rb | 6 +- spec/unit/provider_resolver_spec.rb | 76 +++++--------------- spec/unit/resource/user_spec.rb | 2 +- 28 files changed, 149 insertions(+), 472 deletions(-) delete mode 100644 lib/chef/provider/user/linux.rb delete mode 100644 lib/chef/resource/user/aix_user.rb delete mode 100644 lib/chef/resource/user/dscl_user.rb delete mode 100644 lib/chef/resource/user/linux_user.rb delete mode 100644 lib/chef/resource/user/pw_user.rb delete mode 100644 lib/chef/resource/user/solaris_user.rb delete mode 100644 lib/chef/resource/user/windows_user.rb delete mode 100644 spec/unit/provider/user/linux_spec.rb create mode 100644 spec/unit/provider/user/useradd_spec.rb diff --git a/Gemfile b/Gemfile index e06ab4ed44..a2a2bfe088 100644 --- a/Gemfile +++ b/Gemfile @@ -35,7 +35,7 @@ group(:integration) do gem "chef-provisioning-aws" gem "chef-rewind" gem "chef-sugar" - gem "chefspec", git: "https://github.com/sethvargo/chefspec", branch: "master" + gem "chefspec" gem "halite" gem "poise" gem "knife-windows" diff --git a/Gemfile.lock b/Gemfile.lock index daace58001..592504628b 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,10 +1,10 @@ GIT remote: https://github.com/chef/chefstyle.git - revision: c36dcbd6c2c21d2e19db77d9fbdf2402d0bacccf + revision: 0f9d895058964f3a14b439bd3216c0785219459f branch: master specs: - chefstyle (0.4.0) - rubocop (= 0.42.0) + chefstyle (0.3.1) + rubocop (= 0.39.0) GIT remote: https://github.com/rubysec/bundler-audit.git @@ -14,16 +14,6 @@ GIT bundler (~> 1.2) thor (~> 0.18) -GIT - remote: https://github.com/sethvargo/chefspec - revision: b8754bdbdffc26e2744dcb5d18fd5ee5e82a703a - branch: master - specs: - chefspec (4.7.0) - chef (>= 12.0) - fauxhai (~> 3.6) - rspec (~> 3.0) - PATH remote: . specs: @@ -114,12 +104,12 @@ GEM mixlib-cli (~> 1.4) artifactory (2.3.3) ast (2.3.0) - aws-sdk (2.5.5) - aws-sdk-resources (= 2.5.5) - aws-sdk-core (2.5.5) + aws-sdk (2.5.3) + aws-sdk-resources (= 2.5.3) + aws-sdk-core (2.5.3) jmespath (~> 1.0) - aws-sdk-resources (2.5.5) - aws-sdk-core (= 2.5.5) + aws-sdk-resources (2.5.3) + aws-sdk-core (= 2.5.3) aws-sdk-v1 (1.66.0) json (~> 1.4) nokogiri (>= 1.4.4) @@ -156,6 +146,10 @@ GEM cheffish (3.0.0) chef-zero (~> 4.3) net-ssh + chefspec (4.7.0) + chef (>= 11.14) + fauxhai (~> 3.2) + rspec (~> 3.0) coderay (1.1.1) colorize (0.8.1) cucumber-core (1.5.0) @@ -180,7 +174,7 @@ GEM ffi ffi-yajl (2.3.0) libyajl2 (~> 1.2) - foodcritic (7.1.0) + foodcritic (7.0.1) cucumber-core (>= 1.3) erubis nokogiri (>= 1.5, < 2.0) @@ -218,7 +212,7 @@ GEM thor hashie (3.4.4) highline (1.7.8) - httpclient (2.8.2.2) + httpclient (2.8.1) inifile (3.0.0) iniparse (1.4.2) ipaddress (0.8.3) @@ -288,14 +282,14 @@ GEM rack (>= 1.2, < 3) octokit (4.3.0) sawyer (~> 0.7.0, >= 0.5.3) - ohai (8.19.2) + ohai (8.19.1) chef-config (>= 12.5.0.alpha.1, < 13) ffi (~> 1.9) ffi-yajl (~> 2.2) ipaddress mixlib-cli mixlib-config (~> 2.0) - mixlib-log (>= 1.7.1, < 2.0) + mixlib-log mixlib-shellout (~> 2.0) plist (~> 3.1) systemu (~> 2.6.4) @@ -349,8 +343,8 @@ GEM rspec_junit_formatter (0.2.3) builder (< 4) rspec-core (>= 2, < 4, != 2.12.0) - rubocop (0.42.0) - parser (>= 2.3.1.1, < 3.0) + rubocop (0.39.0) + parser (>= 2.3.0.7, < 3.0) powerpack (~> 0.1) rainbow (>= 1.99.1, < 3.0) ruby-progressbar (~> 1.7) @@ -375,7 +369,7 @@ GEM simplecov-html (~> 0.10.0) simplecov-html (0.10.0) slop (3.6.0) - specinfra (2.61.1) + specinfra (2.60.4) net-scp net-ssh (>= 2.7, < 4.0) net-telnet @@ -452,7 +446,7 @@ DEPENDENCIES chef-rewind chef-sugar cheffish - chefspec! + chefspec chefstyle! foodcritic github_changelog_generator diff --git a/lib/chef/provider/user/aix.rb b/lib/chef/provider/user/aix.rb index 8ac229ae4d..befb6ac3fd 100644 --- a/lib/chef/provider/user/aix.rb +++ b/lib/chef/provider/user/aix.rb @@ -14,14 +14,11 @@ # See the License for the specific language governing permissions and # limitations under the License. -require "chef/provider/user/useradd" - class Chef class Provider class User class Aix < Chef::Provider::User::Useradd - provides :user, os: "aix" - provides :aix_user + provides :user, platform: %w{aix} UNIVERSAL_OPTIONS = [[:comment, "-c"], [:gid, "-g"], [:shell, "-s"], [:uid, "-u"]] diff --git a/lib/chef/provider/user/dscl.rb b/lib/chef/provider/user/dscl.rb index 821fa8e8a7..e933bf9dc0 100644 --- a/lib/chef/provider/user/dscl.rb +++ b/lib/chef/provider/user/dscl.rb @@ -48,7 +48,6 @@ class Chef attr_accessor :authentication_authority attr_accessor :password_shadow_conversion_algorithm - provides :dscl_user provides :user, os: "darwin" def define_resource_requirements diff --git a/lib/chef/provider/user/linux.rb b/lib/chef/provider/user/linux.rb deleted file mode 100644 index ca331311f1..0000000000 --- a/lib/chef/provider/user/linux.rb +++ /dev/null @@ -1,33 +0,0 @@ -# -# 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 "chef/provider/user/useradd" - -class Chef - class Provider - class User - class Linux < Chef::Provider::User::Useradd - # MAJOR XXX: the implementation of "linux" is the base class and all needs to be moved here - provides :linux_user - provides :user, os: "linux" - - def managing_home_dir? - new_resource.manage_home # linux always 'supports' manage_home - end - end - end - end -end diff --git a/lib/chef/provider/user/pw.rb b/lib/chef/provider/user/pw.rb index a1d7671c28..949a21790b 100644 --- a/lib/chef/provider/user/pw.rb +++ b/lib/chef/provider/user/pw.rb @@ -22,8 +22,7 @@ class Chef class Provider class User class Pw < Chef::Provider::User - provides :pw_user - provides :user, os: "freebsd" + provides :user, platform: %w{freebsd} def load_current_resource super diff --git a/lib/chef/provider/user/solaris.rb b/lib/chef/provider/user/solaris.rb index 8d3df9e68b..83ee8346a9 100644 --- a/lib/chef/provider/user/solaris.rb +++ b/lib/chef/provider/user/solaris.rb @@ -24,8 +24,7 @@ class Chef class Provider class User class Solaris < Chef::Provider::User::Useradd - provides :solaris_user - provides :user, os: %w{omnios solaris2} + provides :user, platform: %w{omnios solaris2} UNIVERSAL_OPTIONS = [[:comment, "-c"], [:gid, "-g"], [:shell, "-s"], [:uid, "-u"]] attr_writer :password_file diff --git a/lib/chef/provider/user/useradd.rb b/lib/chef/provider/user/useradd.rb index 68b62812a7..3fef8d3642 100644 --- a/lib/chef/provider/user/useradd.rb +++ b/lib/chef/provider/user/useradd.rb @@ -23,7 +23,7 @@ class Chef class Provider class User class Useradd < Chef::Provider::User - # MAJOR XXX: this should become the base class of all Useradd providers instead of the linux implementation + provides :user UNIVERSAL_OPTIONS = [[:comment, "-c"], [:gid, "-g"], [:password, "-p"], [:shell, "-s"], [:uid, "-u"]] @@ -116,15 +116,15 @@ class Chef update_options(field, option, opts) end if updating_home? - opts << "-d" << new_resource.home if managing_home_dir? Chef::Log.debug("#{new_resource} managing the users home directory") - opts << "-m" + opts << "-d" << new_resource.home << "-m" else Chef::Log.debug("#{new_resource} setting home to #{new_resource.home}") + opts << "-d" << new_resource.home end end - opts << "-o" if new_resource.non_unique + opts << "-o" if new_resource.non_unique || new_resource.supports[:non_unique] opts end end @@ -141,7 +141,6 @@ class Chef def useradd_options opts = [] opts << "-r" if new_resource.system - opts << "-M" unless managing_home_dir? opts end diff --git a/lib/chef/provider/user/windows.rb b/lib/chef/provider/user/windows.rb index b086a1e32b..9545b1fd59 100644 --- a/lib/chef/provider/user/windows.rb +++ b/lib/chef/provider/user/windows.rb @@ -26,7 +26,7 @@ class Chef class Provider class User class Windows < Chef::Provider::User - provides :windows_user + provides :user, os: "windows" def initialize(new_resource, run_context) diff --git a/lib/chef/providers.rb b/lib/chef/providers.rb index 9e2a914b71..14c47df939 100644 --- a/lib/chef/providers.rb +++ b/lib/chef/providers.rb @@ -101,13 +101,12 @@ require "chef/provider/service/macosx" require "chef/provider/service/aixinit" require "chef/provider/service/aix" -require "chef/provider/user/aix" require "chef/provider/user/dscl" -require "chef/provider/user/linux" require "chef/provider/user/pw" -require "chef/provider/user/solaris" require "chef/provider/user/useradd" require "chef/provider/user/windows" +require "chef/provider/user/solaris" +require "chef/provider/user/aix" require "chef/provider/group/aix" require "chef/provider/group/dscl" diff --git a/lib/chef/resource/user.rb b/lib/chef/resource/user.rb index a07ce8b24b..012fa278f1 100644 --- a/lib/chef/resource/user.rb +++ b/lib/chef/resource/user.rb @@ -21,7 +21,6 @@ require "chef/resource" class Chef class Resource class User < Chef::Resource - resource_name :user_resource_abstract_base_class # this prevents magickal class name DSL wiring identity_attr :username state_attrs :uid, :gid, :home @@ -43,8 +42,8 @@ class Chef @force = false @non_unique = false @supports = { - manage_home: false, - non_unique: false, + :manage_home => false, + :non_unique => false, } @iterations = 27855 @salt = nil @@ -155,6 +154,7 @@ class Chef :kind_of => [ TrueClass, FalseClass ] ) end + end end end diff --git a/lib/chef/resource/user/aix_user.rb b/lib/chef/resource/user/aix_user.rb deleted file mode 100644 index 7c07db2e25..0000000000 --- a/lib/chef/resource/user/aix_user.rb +++ /dev/null @@ -1,31 +0,0 @@ -# -# 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 "chef/resource/user" - -class Chef - class Resource - class User - class AixUser < Chef::Resource::User - resource_name :aix_user - - provides :aix_user - provides :user, os: "aix" - end - end - end -end diff --git a/lib/chef/resource/user/dscl_user.rb b/lib/chef/resource/user/dscl_user.rb deleted file mode 100644 index 61517d8b44..0000000000 --- a/lib/chef/resource/user/dscl_user.rb +++ /dev/null @@ -1,31 +0,0 @@ -# -# 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 "chef/resource/user" - -class Chef - class Resource - class User - class DsclUser < Chef::Resource::User - resource_name :dscl_user - - provides :dscl_user - provides :user, os: "darwin" - end - end - end -end diff --git a/lib/chef/resource/user/linux_user.rb b/lib/chef/resource/user/linux_user.rb deleted file mode 100644 index 3452459e39..0000000000 --- a/lib/chef/resource/user/linux_user.rb +++ /dev/null @@ -1,52 +0,0 @@ -# -# 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 "chef/resource/user" - -class Chef - class Resource - class User - class LinuxUser < Chef::Resource::User - resource_name :linux_user - - provides :linux_user - provides :user, os: "linux" - - def initialize(name, run_context = nil) - super - @supports = { - manage_home: true, - non_unique: true, - } - @manage_home = true - end - - def supports(args = {}) - Chef.log_deprecation "setting supports on the linux_user resource is deprecated" - # setting is deliberately disabled - super({}) - end - - def supports=(args) - Chef.log_deprecation "setting supports on the linux_user resource is deprecated" - # setting is deliberately disabled - supports({}) - end - end - end - end -end diff --git a/lib/chef/resource/user/pw_user.rb b/lib/chef/resource/user/pw_user.rb deleted file mode 100644 index 873be19d59..0000000000 --- a/lib/chef/resource/user/pw_user.rb +++ /dev/null @@ -1,31 +0,0 @@ -# -# 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 "chef/resource/user" - -class Chef - class Resource - class User - class PwUser < Chef::Resource::User - resource_name :pw_user - - provides :pw_user - provides :user, os: "freebsd" - end - end - end -end diff --git a/lib/chef/resource/user/solaris_user.rb b/lib/chef/resource/user/solaris_user.rb deleted file mode 100644 index bb897228b9..0000000000 --- a/lib/chef/resource/user/solaris_user.rb +++ /dev/null @@ -1,31 +0,0 @@ -# -# 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 "chef/resource/user" - -class Chef - class Resource - class User - class SolarisUser < Chef::Resource::User - resource_name :solaris_user - - provides :solaris_user - provides :user, os: %w{omnios solaris2} - end - end - end -end diff --git a/lib/chef/resource/user/windows_user.rb b/lib/chef/resource/user/windows_user.rb deleted file mode 100644 index d1a249fb50..0000000000 --- a/lib/chef/resource/user/windows_user.rb +++ /dev/null @@ -1,31 +0,0 @@ -# -# 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 "chef/resource/user" - -class Chef - class Resource - class User - class WindowsUser < Chef::Resource::User - resource_name :windows_user - - provides :windows_user - provides :user, os: "windows" - end - end - end -end diff --git a/lib/chef/resources.rb b/lib/chef/resources.rb index 0e73264832..af9c918f55 100644 --- a/lib/chef/resources.rb +++ b/lib/chef/resources.rb @@ -82,12 +82,6 @@ require "chef/resource/smartos_package" require "chef/resource/template" require "chef/resource/timestamped_deploy" require "chef/resource/user" -require "chef/resource/user/aix_user" -require "chef/resource/user/dscl_user" -require "chef/resource/user/linux_user" -require "chef/resource/user/pw_user" -require "chef/resource/user/solaris_user" -require "chef/resource/user/windows_user" require "chef/resource/whyrun_safe_ruby_block" require "chef/resource/windows_package" require "chef/resource/yum_package" diff --git a/spec/functional/resource/group_spec.rb b/spec/functional/resource/group_spec.rb index 06a89a67c5..89f742a8f9 100644 --- a/spec/functional/resource/group_spec.rb +++ b/spec/functional/resource/group_spec.rb @@ -85,14 +85,8 @@ describe Chef::Resource::Group, :requires_root_or_running_windows, :not_supporte end end - def node - node = Chef::Node.new - node.consume_external_attrs(ohai.data, {}) - node - end - def user(username) - usr = Chef::Resource.resource_for_node(:user, node).new(username, run_context) + usr = Chef::Resource::User.new("#{username}", run_context) if ohai[:platform_family] == "windows" usr.password("ComplexPass11!") end diff --git a/spec/support/shared/unit/provider/useradd_based_user_provider.rb b/spec/support/shared/unit/provider/useradd_based_user_provider.rb index de851c4ad4..6677a069ea 100644 --- a/spec/support/shared/unit/provider/useradd_based_user_provider.rb +++ b/spec/support/shared/unit/provider/useradd_based_user_provider.rb @@ -18,18 +18,13 @@ # limitations under the License. # -# XXX: this used to be shared by solaris and linux classes, but at some -# point became linux-specific. it is now a misnomer to call these 'shared' -# examples and they should either realy get turned into shared examples or -# should be copypasta'd back directly into the linux tests. - shared_examples_for "a useradd-based user provider" do |supported_useradd_options| before(:each) do @node = Chef::Node.new @events = Chef::EventDispatch::Dispatcher.new @run_context = Chef::RunContext.new(@node, {}, @events) - @new_resource = Chef::Resource::User::LinuxUser.new("adam", @run_context) + @new_resource = Chef::Resource::User.new("adam", @run_context) @new_resource.comment "Adam Jacob" @new_resource.uid 1000 @new_resource.gid 1000 @@ -40,7 +35,7 @@ shared_examples_for "a useradd-based user provider" do |supported_useradd_option @new_resource.manage_home false @new_resource.force false @new_resource.non_unique false - @current_resource = Chef::Resource::User::LinuxUser.new("adam", @run_context) + @current_resource = Chef::Resource::User.new("adam", @run_context) @current_resource.comment "Adam Jacob" @current_resource.uid 1000 @current_resource.gid 1000 @@ -51,6 +46,7 @@ shared_examples_for "a useradd-based user provider" do |supported_useradd_option @current_resource.manage_home false @current_resource.force false @current_resource.non_unique false + @current_resource.supports({ :manage_home => false, :non_unique => false }) end describe "when setting option" do @@ -106,8 +102,9 @@ shared_examples_for "a useradd-based user provider" do |supported_useradd_option describe "when the resource has a different home directory and supports home directory management" do before do - @new_resource.home "/wowaweea" - @new_resource.manage_home true + allow(@new_resource).to receive(:home).and_return("/wowaweea") + allow(@new_resource).to receive(:supports).and_return({ :manage_home => true, + :non_unique => false }) end it "should set -m -d /homedir" do @@ -129,20 +126,32 @@ shared_examples_for "a useradd-based user provider" do |supported_useradd_option end end - it "when non_unique is false should not set -m" do - @new_resource.non_unique false - expect(provider.universal_options).to eql([ ]) + describe "when the resource supports non_unique ids" do + before do + allow(@new_resource).to receive(:supports).and_return({ :manage_home => false, + :non_unique => true }) + end + + it "should set -m -o" do + expect(provider.universal_options).to eql([ "-o" ]) + end end - it "when non_unique is true should set -o" do - @new_resource.non_unique true - expect(provider.universal_options).to eql([ "-o" ]) + describe "when the resource supports non_unique ids (using real attributes)" do + before do + allow(@new_resource).to receive(:manage_home).and_return(false) + allow(@new_resource).to receive(:non_unique).and_return(true) + end + + it "should set -m -o" do + expect(provider.universal_options).to eql([ "-o" ]) + end end end describe "when creating a user" do before(:each) do - @current_resource = Chef::Resource::User::LinuxUser.new(@new_resource.name, @run_context) + @current_resource = Chef::Resource::User.new(@new_resource.name, @run_context) @current_resource.username(@new_resource.username) provider.current_resource = @current_resource provider.new_resource.manage_home true @@ -237,12 +246,15 @@ shared_examples_for "a useradd-based user provider" do |supported_useradd_option end it "should run userdel with the new resources user name and -r if manage_home is true" do - @new_resource.manage_home true + @new_resource.supports({ :manage_home => true, + :non_unique => false }) expect(provider).to receive(:shell_out!).with("userdel", "-r", @new_resource.username).and_return(true) provider.remove_user end it "should run userdel with the new resources user name if non_unique is true" do + @new_resource.supports({ :manage_home => false, + :non_unique => true }) expect(provider).to receive(:shell_out!).with("userdel", @new_resource.username).and_return(true) provider.remove_user end @@ -408,9 +420,9 @@ shared_examples_for "a useradd-based user provider" do |supported_useradd_option end end it "should return true if the current home does not exist but a home is specified by the new resource" do - @new_resource = Chef::Resource::User::LinuxUser.new("adam", @run_context) - @current_resource = Chef::Resource::User::LinuxUser.new("adam", @run_context) - provider = Chef::Provider::User::Linux.new(@new_resource, @run_context) + @new_resource = Chef::Resource::User.new("adam", @run_context) + @current_resource = Chef::Resource::User.new("adam", @run_context) + provider = Chef::Provider::User::Useradd.new(@new_resource, @run_context) provider.current_resource = @current_resource @current_resource.home nil @new_resource.home "/home/kitten" diff --git a/spec/unit/provider/user/dscl_spec.rb b/spec/unit/provider/user/dscl_spec.rb index dfaaa377d3..a309033161 100644 --- a/spec/unit/provider/user/dscl_spec.rb +++ b/spec/unit/provider/user/dscl_spec.rb @@ -43,7 +43,7 @@ describe Chef::Provider::User::Dscl do end let(:new_resource) do - r = Chef::Resource::User::DsclUser.new("toor") + r = Chef::Resource::User.new("toor") r.password(password) r.salt(salt) r.iterations(iterations) diff --git a/spec/unit/provider/user/linux_spec.rb b/spec/unit/provider/user/linux_spec.rb deleted file mode 100644 index ef12cec234..0000000000 --- a/spec/unit/provider/user/linux_spec.rb +++ /dev/null @@ -1,81 +0,0 @@ -# -# Author:: Adam Jacob () -# Author:: Daniel DeLeo () -# Copyright:: Copyright 2008-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" -require "chef/provider/user/useradd" - -describe Chef::Provider::User::Linux do - - subject(:provider) do - p = described_class.new(@new_resource, @run_context) - p.current_resource = @current_resource - p - end - - supported_useradd_options = { - "comment" => "-c", - "gid" => "-g", - "uid" => "-u", - "shell" => "-s", - "password" => "-p", - } - - include_examples "a useradd-based user provider", supported_useradd_options - - describe "manage_user" do - # CHEF-5247: Chef::Provider::User::Solaris subclasses Chef::Provider::User::Useradd, but does not use usermod to change passwords. - # Thus, a call to Solaris#manage_user calls Solaris#manage_password and Useradd#manage_user, but the latter should be a no-op. - it "should not run the command if universal_options is an empty array" do - allow(provider).to receive(:universal_options).and_return([]) - expect(provider).not_to receive(:shell_out!) - provider.manage_user - end - end - - describe "manage_home behavior" do - before(:each) do - @new_resource = Chef::Resource::User::LinuxUser.new("adam", @run_context) - @current_resource = Chef::Resource::User::LinuxUser.new("adam", @run_context) - end - - it "sets supports manage_home to true" do - Chef::Config[:treat_deprecation_warnings_as_errors] = false - expect( @new_resource.supports[:manage_home] ).to be true - end - - it "sets supports non-unique to true" do - Chef::Config[:treat_deprecation_warnings_as_errors] = false - expect( @new_resource.supports[:non_unique] ).to be true - end - - it "defaults manage_home to true" do - expect( @new_resource.manage_home ).to be true - end - - it "by default manage_home is true and we do not -M" do - expect( provider.useradd_options ).to eql([]) - end - - it "setting manage_home to false includes -M" do - @new_resource.manage_home false - expect( provider.useradd_options ).to eql(["-M"]) - end - end -end diff --git a/spec/unit/provider/user/pw_spec.rb b/spec/unit/provider/user/pw_spec.rb index 624bcfc67d..1e9fda9f7e 100644 --- a/spec/unit/provider/user/pw_spec.rb +++ b/spec/unit/provider/user/pw_spec.rb @@ -24,7 +24,7 @@ describe Chef::Provider::User::Pw do @events = Chef::EventDispatch::Dispatcher.new @run_context = Chef::RunContext.new(@node, {}, @events) - @new_resource = Chef::Resource::User::PwUser.new("adam") + @new_resource = Chef::Resource::User.new("adam") @new_resource.comment "Adam Jacob" @new_resource.uid 1000 @new_resource.gid 1000 @@ -34,7 +34,7 @@ describe Chef::Provider::User::Pw do @new_resource.supports :manage_home => true - @current_resource = Chef::Resource::User::PwUser.new("adam") + @current_resource = Chef::Resource::User.new("adam") @current_resource.comment "Adam Jacob" @current_resource.uid 1000 @current_resource.gid 1000 @@ -170,6 +170,7 @@ describe Chef::Provider::User::Pw do end it "logs an appropriate message" do + expect(Chef::Log).to receive(:debug).with("user[adam] no change needed to password") @provider.modify_password end end @@ -193,6 +194,7 @@ describe Chef::Provider::User::Pw do end it "logs an appropriate message" do + expect(Chef::Log).to receive(:debug).with("user[adam] no change needed to password") @provider.modify_password end end @@ -204,6 +206,7 @@ describe Chef::Provider::User::Pw do end it "should log an appropriate message" do + expect(Chef::Log).to receive(:debug).with("user[adam] updating password") @provider.modify_password end @@ -233,7 +236,7 @@ describe Chef::Provider::User::Pw do describe "when loading the current state" do before do - @provider.new_resource = Chef::Resource::User::PwUser.new("adam") + @provider.new_resource = Chef::Resource::User.new("adam") end it "should raise an error if the required binary /usr/sbin/pw doesn't exist" do diff --git a/spec/unit/provider/user/solaris_spec.rb b/spec/unit/provider/user/solaris_spec.rb index 860c9e41dd..af16a6bd80 100644 --- a/spec/unit/provider/user/solaris_spec.rb +++ b/spec/unit/provider/user/solaris_spec.rb @@ -44,8 +44,8 @@ describe Chef::Provider::User::Solaris do @events = Chef::EventDispatch::Dispatcher.new @run_context = Chef::RunContext.new(@node, {}, @events) - @new_resource = Chef::Resource::User::SolarisUser.new("adam", @run_context) - @current_resource = Chef::Resource::User::SolarisUser.new("adam", @run_context) + @new_resource = Chef::Resource::User.new("adam", @run_context) + @current_resource = Chef::Resource::User.new("adam", @run_context) @new_resource.password "hocus-pocus" @@ -81,7 +81,7 @@ describe Chef::Provider::User::Solaris do @events = Chef::EventDispatch::Dispatcher.new @run_context = Chef::RunContext.new(@node, {}, @events) - @new_resource = Chef::Resource::User::SolarisUser.new("dave") + @new_resource = Chef::Resource::User.new("dave") @current_resource = @new_resource.dup @provider = Chef::Provider::User::Solaris.new(@new_resource, @run_context) diff --git a/spec/unit/provider/user/useradd_spec.rb b/spec/unit/provider/user/useradd_spec.rb new file mode 100644 index 0000000000..7c67449a86 --- /dev/null +++ b/spec/unit/provider/user/useradd_spec.rb @@ -0,0 +1,51 @@ +# +# Author:: Adam Jacob () +# Author:: Daniel DeLeo () +# Copyright:: Copyright 2008-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" +require "chef/provider/user/useradd" + +describe Chef::Provider::User::Useradd do + + subject(:provider) do + p = described_class.new(@new_resource, @run_context) + p.current_resource = @current_resource + p + end + + supported_useradd_options = { + "comment" => "-c", + "gid" => "-g", + "uid" => "-u", + "shell" => "-s", + "password" => "-p", + } + + include_examples "a useradd-based user provider", supported_useradd_options + + describe "manage_user" do + # CHEF-5247: Chef::Provider::User::Solaris subclasses Chef::Provider::User::Useradd, but does not use usermod to change passwords. + # Thus, a call to Solaris#manage_user calls Solaris#manage_password and Useradd#manage_user, but the latter should be a no-op. + it "should not run the command if universal_options is an empty array" do + allow(provider).to receive(:universal_options).and_return([]) + expect(provider).not_to receive(:shell_out!) + provider.manage_user + end + end +end diff --git a/spec/unit/provider/user/windows_spec.rb b/spec/unit/provider/user/windows_spec.rb index 324b5f503f..4a62e6ec9d 100644 --- a/spec/unit/provider/user/windows_spec.rb +++ b/spec/unit/provider/user/windows_spec.rb @@ -30,10 +30,10 @@ end describe Chef::Provider::User::Windows do before(:each) do @node = Chef::Node.new - @new_resource = Chef::Resource::User::WindowsUser.new("monkey") + @new_resource = Chef::Resource::User.new("monkey") @events = Chef::EventDispatch::Dispatcher.new @run_context = Chef::RunContext.new(@node, {}, @events) - @current_resource = Chef::Resource::User::WindowsUser.new("monkey") + @current_resource = Chef::Resource::User.new("monkey") @net_user = double("Chef::Util::Windows::NetUser") allow(Chef::Util::Windows::NetUser).to receive(:new).and_return(@net_user) @@ -89,7 +89,7 @@ describe Chef::Provider::User::Windows do describe "and the attributes do not match" do before do - @current_resource = Chef::Resource::User::WindowsUser.new("adam") + @current_resource = Chef::Resource::User.new("adam") @current_resource.comment "Adam Jacob-foo" @current_resource.uid 1111 @current_resource.gid 1111 diff --git a/spec/unit/provider_resolver_spec.rb b/spec/unit/provider_resolver_spec.rb index 5ba5ddae03..f1567ed86e 100644 --- a/spec/unit/provider_resolver_spec.rb +++ b/spec/unit/provider_resolver_spec.rb @@ -480,7 +480,7 @@ describe Chef::ProviderResolver do end end - on_platform "freebsd", os: "freebsd", platform_version: "10.3" do + on_platform %w{freebsd netbsd}, platform_version: "3.1.4" do it "returns a Freebsd provider if it finds the /usr/local/etc/rc.d initscript" do stub_service_providers stub_service_configs(:usr_local_etc_rcd) @@ -507,41 +507,7 @@ describe Chef::ProviderResolver do expect(resolved_provider).to eql(Chef::Provider::Service::Freebsd) end - it "always returns a freebsd provider by default?" do - stub_service_providers - stub_service_configs - expect(resolved_provider).to eql(Chef::Provider::Service::Freebsd) - end - end - - on_platform "netbsd", os: "netbsd", platform_version: "7.0.1" do - it "returns a Freebsd provider if it finds the /usr/local/etc/rc.d initscript" do - stub_service_providers - stub_service_configs(:usr_local_etc_rcd) - expect(resolved_provider).to eql(Chef::Provider::Service::Freebsd) - end - - it "returns a Freebsd provider if it finds the /etc/rc.d initscript" do - stub_service_providers - stub_service_configs(:etc_rcd) - expect(resolved_provider).to eql(Chef::Provider::Service::Freebsd) - end - - it "always returns a Freebsd provider if it finds the /usr/local/etc/rc.d initscript" do - # should only care about :usr_local_etc_rcd stub in the service configs - stub_service_providers(:debian, :invokercd, :insserv, :upstart, :redhat, :systemd) - stub_service_configs(:usr_local_etc_rcd, :initd, :upstart, :xinetd, :systemd) - expect(resolved_provider).to eql(Chef::Provider::Service::Freebsd) - end - - it "always returns a Freebsd provider if it finds the /usr/local/etc/rc.d initscript" do - # should only care about :etc_rcd stub in the service configs - stub_service_providers(:debian, :invokercd, :insserv, :upstart, :redhat, :systemd) - stub_service_configs(:etc_rcd, :initd, :upstart, :xinetd, :systemd) - expect(resolved_provider).to eql(Chef::Provider::Service::Freebsd) - end - - it "always returns a freebsd provider by default?" do + it "foo" do stub_service_providers stub_service_configs expect(resolved_provider).to eql(Chef::Provider::Service::Freebsd) @@ -586,12 +552,7 @@ describe Chef::ProviderResolver do subversion: [ Chef::Resource::Subversion, Chef::Provider::Subversion ], template: [ Chef::Resource::Template, Chef::Provider::Template ], timestamped_deploy: [ Chef::Resource::TimestampedDeploy, Chef::Provider::Deploy::Timestamped ], - aix_user: [ Chef::Resource::User::AixUser, Chef::Provider::User::Aix ], - dscl_user: [ Chef::Resource::User::DsclUser, Chef::Provider::User::Dscl ], - linux_user: [ Chef::Resource::User::LinuxUser, Chef::Provider::User::Linux ], - pw_user: [ Chef::Resource::User::PwUser, Chef::Provider::User::Pw ], - solaris_user: [ Chef::Resource::User::SolarisUser, Chef::Provider::User::Solaris ], - windows_user: [ Chef::Resource::User::WindowsUser, Chef::Provider::User::Windows ], + user: [ Chef::Resource::User, Chef::Provider::User::Useradd ], whyrun_safe_ruby_block: [ Chef::Resource::WhyrunSafeRubyBlock, Chef::Provider::WhyrunSafeRubyBlock ], # We want to check that these are unsupported: @@ -673,6 +634,15 @@ describe Chef::ProviderResolver do }, }, + "freebsd" => { + group: [ Chef::Resource::Group, Chef::Provider::Group::Pw ], + user: [ Chef::Resource::User, Chef::Provider::User::Pw ], + + "freebsd" => { + "3.1.4" => { + }, + }, + }, "suse" => { group: [ Chef::Resource::Group, Chef::Provider::Group::Gpasswd ], "suse" => { @@ -734,24 +704,12 @@ describe Chef::ProviderResolver do }, - "freebsd" => { - "freebsd" => { - group: [ Chef::Resource::Group, Chef::Provider::Group::Pw ], - user: [ Chef::Resource::User::PwUser, Chef::Provider::User::Pw ], - - "freebsd" => { - "10.3" => { - }, - }, - }, - }, - "darwin" => { %w{mac_os_x mac_os_x_server} => { group: [ Chef::Resource::Group, Chef::Provider::Group::Dscl ], package: [ Chef::Resource::HomebrewPackage, Chef::Provider::Package::Homebrew ], osx_profile: [ Chef::Resource::OsxProfile, Chef::Provider::OsxProfile], - user: [ Chef::Resource::User::DsclUser, Chef::Provider::User::Dscl ], + user: [ Chef::Resource::User, Chef::Provider::User::Dscl ], "mac_os_x" => { "10.9.2" => { @@ -769,7 +727,7 @@ describe Chef::ProviderResolver do package: [ Chef::Resource::WindowsPackage, Chef::Provider::Package::Windows ], powershell_script: [ Chef::Resource::PowershellScript, Chef::Provider::PowershellScript ], service: [ Chef::Resource::WindowsService, Chef::Provider::Service::Windows ], - user: [ Chef::Resource::User::WindowsUser, Chef::Provider::User::Windows ], + user: [ Chef::Resource::User, Chef::Provider::User::Windows ], windows_package: [ Chef::Resource::WindowsPackage, Chef::Provider::Package::Windows ], windows_service: [ Chef::Resource::WindowsService, Chef::Provider::Service::Windows ], @@ -790,7 +748,7 @@ describe Chef::ProviderResolver do # TODO should be Chef::Resource::BffPackage package: [ Chef::Resource::Package, Chef::Provider::Package::Aix ], rpm_package: [ Chef::Resource::RpmPackage, Chef::Provider::Package::Rpm ], - user: [ Chef::Resource::User::AixUser, Chef::Provider::User::Aix ], + user: [ Chef::Resource::User, Chef::Provider::User::Aix ], # service: [ Chef::Resource::AixService, Chef::Provider::Service::Aix ], "aix" => { @@ -857,7 +815,7 @@ describe Chef::ProviderResolver do }, "omnios" => { "3.1.4" => { - user: [ Chef::Resource::User::SolarisUser, Chef::Provider::User::Solaris ], + user: [ Chef::Resource::User, Chef::Provider::User::Solaris ], }, }, "openindiana" => { @@ -869,7 +827,7 @@ describe Chef::ProviderResolver do }, }, "solaris2" => { - user: [ Chef::Resource::User::SolarisUser, Chef::Provider::User::Solaris ], + user: [ Chef::Resource::User, Chef::Provider::User::Solaris ], "5.11" => { package: [ Chef::Resource::IpsPackage, Chef::Provider::Package::Ips ], }, diff --git a/spec/unit/resource/user_spec.rb b/spec/unit/resource/user_spec.rb index 138ffb1bfe..9648ee1305 100644 --- a/spec/unit/resource/user_spec.rb +++ b/spec/unit/resource/user_spec.rb @@ -29,7 +29,7 @@ describe Chef::Resource::User, "initialize" do end it "should set the resource_name to :user" do - expect(@resource.resource_name).to eql(:user_resource_abstract_base_class) + expect(@resource.resource_name).to eql(:user) end it "should set the username equal to the argument to initialize" do -- cgit v1.2.1