summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLamont Granquist <lamont@scriptkiddie.org>2016-08-19 15:32:19 -0700
committerLamont Granquist <lamont@scriptkiddie.org>2016-08-19 15:34:23 -0700
commitf769d7eba17b3f5aa9e0561126bd9f6801c1bac2 (patch)
tree801dcc6f208510b9b7329e2bfcbc2ccbc055e09d
parent0447477abd41488674f609cfa59c2bdf35ed6d03 (diff)
downloadchef-f769d7eba17b3f5aa9e0561126bd9f6801c1bac2.tar.gz
user provider manage_home behavior and refactor
split out the user provider into 1:1 resources. fix the behavior of the linux user provider to implement manage_home behavior correctly. Signed-off-by: Lamont Granquist <lamont@scriptkiddie.org>
-rw-r--r--lib/chef/provider/user/aix.rb5
-rw-r--r--lib/chef/provider/user/dscl.rb1
-rw-r--r--lib/chef/provider/user/linux.rb33
-rw-r--r--lib/chef/provider/user/pw.rb3
-rw-r--r--lib/chef/provider/user/solaris.rb3
-rw-r--r--lib/chef/provider/user/useradd.rb9
-rw-r--r--lib/chef/provider/user/windows.rb2
-rw-r--r--lib/chef/providers.rb5
-rw-r--r--lib/chef/resource/user.rb6
-rw-r--r--lib/chef/resource/user/aix_user.rb31
-rw-r--r--lib/chef/resource/user/dscl_user.rb31
-rw-r--r--lib/chef/resource/user/linux_user.rb52
-rw-r--r--lib/chef/resource/user/pw_user.rb31
-rw-r--r--lib/chef/resource/user/solaris_user.rb31
-rw-r--r--lib/chef/resource/user/windows_user.rb31
-rw-r--r--lib/chef/resources.rb6
-rw-r--r--spec/functional/resource/group_spec.rb8
-rw-r--r--spec/support/shared/unit/provider/useradd_based_user_provider.rb52
-rw-r--r--spec/unit/provider/user/dscl_spec.rb2
-rw-r--r--spec/unit/provider/user/linux_spec.rb (renamed from spec/unit/provider/user/useradd_spec.rb)32
-rw-r--r--spec/unit/provider/user/pw_spec.rb9
-rw-r--r--spec/unit/provider/user/solaris_spec.rb6
-rw-r--r--spec/unit/provider/user/windows_spec.rb6
-rw-r--r--spec/unit/provider_resolver_spec.rb76
-rw-r--r--spec/unit/resource/user_spec.rb2
25 files changed, 395 insertions, 78 deletions
diff --git a/lib/chef/provider/user/aix.rb b/lib/chef/provider/user/aix.rb
index befb6ac3fd..8ac229ae4d 100644
--- a/lib/chef/provider/user/aix.rb
+++ b/lib/chef/provider/user/aix.rb
@@ -14,11 +14,14 @@
# 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, platform: %w{aix}
+ provides :user, os: "aix"
+ provides :aix_user
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 e933bf9dc0..821fa8e8a7 100644
--- a/lib/chef/provider/user/dscl.rb
+++ b/lib/chef/provider/user/dscl.rb
@@ -48,6 +48,7 @@ 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
new file mode 100644
index 0000000000..ca331311f1
--- /dev/null
+++ b/lib/chef/provider/user/linux.rb
@@ -0,0 +1,33 @@
+#
+# 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 949a21790b..a1d7671c28 100644
--- a/lib/chef/provider/user/pw.rb
+++ b/lib/chef/provider/user/pw.rb
@@ -22,7 +22,8 @@ class Chef
class Provider
class User
class Pw < Chef::Provider::User
- provides :user, platform: %w{freebsd}
+ provides :pw_user
+ provides :user, os: "freebsd"
def load_current_resource
super
diff --git a/lib/chef/provider/user/solaris.rb b/lib/chef/provider/user/solaris.rb
index 83ee8346a9..8d3df9e68b 100644
--- a/lib/chef/provider/user/solaris.rb
+++ b/lib/chef/provider/user/solaris.rb
@@ -24,7 +24,8 @@ class Chef
class Provider
class User
class Solaris < Chef::Provider::User::Useradd
- provides :user, platform: %w{omnios solaris2}
+ provides :solaris_user
+ provides :user, os: %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 3fef8d3642..68b62812a7 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
- provides :user
+ # MAJOR XXX: this should become the base class of all Useradd providers instead of the linux implementation
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 << "-d" << new_resource.home << "-m"
+ opts << "-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 || new_resource.supports[:non_unique]
+ opts << "-o" if new_resource.non_unique
opts
end
end
@@ -141,6 +141,7 @@ 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 9545b1fd59..b086a1e32b 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 14c47df939..9e2a914b71 100644
--- a/lib/chef/providers.rb
+++ b/lib/chef/providers.rb
@@ -101,12 +101,13 @@ 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 012fa278f1..a07ce8b24b 100644
--- a/lib/chef/resource/user.rb
+++ b/lib/chef/resource/user.rb
@@ -21,6 +21,7 @@ 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
@@ -42,8 +43,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
@@ -154,7 +155,6 @@ 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
new file mode 100644
index 0000000000..7c07db2e25
--- /dev/null
+++ b/lib/chef/resource/user/aix_user.rb
@@ -0,0 +1,31 @@
+#
+# 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
new file mode 100644
index 0000000000..61517d8b44
--- /dev/null
+++ b/lib/chef/resource/user/dscl_user.rb
@@ -0,0 +1,31 @@
+#
+# 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
new file mode 100644
index 0000000000..3452459e39
--- /dev/null
+++ b/lib/chef/resource/user/linux_user.rb
@@ -0,0 +1,52 @@
+#
+# 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
new file mode 100644
index 0000000000..873be19d59
--- /dev/null
+++ b/lib/chef/resource/user/pw_user.rb
@@ -0,0 +1,31 @@
+#
+# 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
new file mode 100644
index 0000000000..bb897228b9
--- /dev/null
+++ b/lib/chef/resource/user/solaris_user.rb
@@ -0,0 +1,31 @@
+#
+# 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
new file mode 100644
index 0000000000..d1a249fb50
--- /dev/null
+++ b/lib/chef/resource/user/windows_user.rb
@@ -0,0 +1,31 @@
+#
+# 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 af9c918f55..0e73264832 100644
--- a/lib/chef/resources.rb
+++ b/lib/chef/resources.rb
@@ -82,6 +82,12 @@ 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 89f742a8f9..06a89a67c5 100644
--- a/spec/functional/resource/group_spec.rb
+++ b/spec/functional/resource/group_spec.rb
@@ -85,8 +85,14 @@ 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::User.new("#{username}", run_context)
+ usr = Chef::Resource.resource_for_node(:user, node).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 6677a069ea..de851c4ad4 100644
--- a/spec/support/shared/unit/provider/useradd_based_user_provider.rb
+++ b/spec/support/shared/unit/provider/useradd_based_user_provider.rb
@@ -18,13 +18,18 @@
# 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.new("adam", @run_context)
+ @new_resource = Chef::Resource::User::LinuxUser.new("adam", @run_context)
@new_resource.comment "Adam Jacob"
@new_resource.uid 1000
@new_resource.gid 1000
@@ -35,7 +40,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.new("adam", @run_context)
+ @current_resource = Chef::Resource::User::LinuxUser.new("adam", @run_context)
@current_resource.comment "Adam Jacob"
@current_resource.uid 1000
@current_resource.gid 1000
@@ -46,7 +51,6 @@ 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
@@ -102,9 +106,8 @@ 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
- allow(@new_resource).to receive(:home).and_return("/wowaweea")
- allow(@new_resource).to receive(:supports).and_return({ :manage_home => true,
- :non_unique => false })
+ @new_resource.home "/wowaweea"
+ @new_resource.manage_home true
end
it "should set -m -d /homedir" do
@@ -126,32 +129,20 @@ shared_examples_for "a useradd-based user provider" do |supported_useradd_option
end
end
- 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
+ it "when non_unique is false should not set -m" do
+ @new_resource.non_unique false
+ expect(provider.universal_options).to eql([ ])
end
- 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
+ it "when non_unique is true should set -o" do
+ @new_resource.non_unique true
+ expect(provider.universal_options).to eql([ "-o" ])
end
end
describe "when creating a user" do
before(:each) do
- @current_resource = Chef::Resource::User.new(@new_resource.name, @run_context)
+ @current_resource = Chef::Resource::User::LinuxUser.new(@new_resource.name, @run_context)
@current_resource.username(@new_resource.username)
provider.current_resource = @current_resource
provider.new_resource.manage_home true
@@ -246,15 +237,12 @@ 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.supports({ :manage_home => true,
- :non_unique => false })
+ @new_resource.manage_home true
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
@@ -420,9 +408,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.new("adam", @run_context)
- @current_resource = Chef::Resource::User.new("adam", @run_context)
- provider = Chef::Provider::User::Useradd.new(@new_resource, @run_context)
+ @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)
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 a309033161..dfaaa377d3 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.new("toor")
+ r = Chef::Resource::User::DsclUser.new("toor")
r.password(password)
r.salt(salt)
r.iterations(iterations)
diff --git a/spec/unit/provider/user/useradd_spec.rb b/spec/unit/provider/user/linux_spec.rb
index 7c67449a86..ef12cec234 100644
--- a/spec/unit/provider/user/useradd_spec.rb
+++ b/spec/unit/provider/user/linux_spec.rb
@@ -21,7 +21,7 @@
require "spec_helper"
require "chef/provider/user/useradd"
-describe Chef::Provider::User::Useradd do
+describe Chef::Provider::User::Linux do
subject(:provider) do
p = described_class.new(@new_resource, @run_context)
@@ -48,4 +48,34 @@ describe Chef::Provider::User::Useradd do
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 1e9fda9f7e..624bcfc67d 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.new("adam")
+ @new_resource = Chef::Resource::User::PwUser.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.new("adam")
+ @current_resource = Chef::Resource::User::PwUser.new("adam")
@current_resource.comment "Adam Jacob"
@current_resource.uid 1000
@current_resource.gid 1000
@@ -170,7 +170,6 @@ 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
@@ -194,7 +193,6 @@ 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
@@ -206,7 +204,6 @@ 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
@@ -236,7 +233,7 @@ describe Chef::Provider::User::Pw do
describe "when loading the current state" do
before do
- @provider.new_resource = Chef::Resource::User.new("adam")
+ @provider.new_resource = Chef::Resource::User::PwUser.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 af16a6bd80..860c9e41dd 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.new("adam", @run_context)
- @current_resource = Chef::Resource::User.new("adam", @run_context)
+ @new_resource = Chef::Resource::User::SolarisUser.new("adam", @run_context)
+ @current_resource = Chef::Resource::User::SolarisUser.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.new("dave")
+ @new_resource = Chef::Resource::User::SolarisUser.new("dave")
@current_resource = @new_resource.dup
@provider = Chef::Provider::User::Solaris.new(@new_resource, @run_context)
diff --git a/spec/unit/provider/user/windows_spec.rb b/spec/unit/provider/user/windows_spec.rb
index 4a62e6ec9d..324b5f503f 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.new("monkey")
+ @new_resource = Chef::Resource::User::WindowsUser.new("monkey")
@events = Chef::EventDispatch::Dispatcher.new
@run_context = Chef::RunContext.new(@node, {}, @events)
- @current_resource = Chef::Resource::User.new("monkey")
+ @current_resource = Chef::Resource::User::WindowsUser.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.new("adam")
+ @current_resource = Chef::Resource::User::WindowsUser.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 f1567ed86e..5ba5ddae03 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 %w{freebsd netbsd}, platform_version: "3.1.4" do
+ on_platform "freebsd", os: "freebsd", platform_version: "10.3" 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,7 +507,41 @@ describe Chef::ProviderResolver do
expect(resolved_provider).to eql(Chef::Provider::Service::Freebsd)
end
- it "foo" do
+ 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
stub_service_providers
stub_service_configs
expect(resolved_provider).to eql(Chef::Provider::Service::Freebsd)
@@ -552,7 +586,12 @@ 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 ],
- user: [ Chef::Resource::User, Chef::Provider::User::Useradd ],
+ 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 ],
whyrun_safe_ruby_block: [ Chef::Resource::WhyrunSafeRubyBlock, Chef::Provider::WhyrunSafeRubyBlock ],
# We want to check that these are unsupported:
@@ -634,15 +673,6 @@ 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" => {
@@ -704,12 +734,24 @@ 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, Chef::Provider::User::Dscl ],
+ user: [ Chef::Resource::User::DsclUser, Chef::Provider::User::Dscl ],
"mac_os_x" => {
"10.9.2" => {
@@ -727,7 +769,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, Chef::Provider::User::Windows ],
+ user: [ Chef::Resource::User::WindowsUser, Chef::Provider::User::Windows ],
windows_package: [ Chef::Resource::WindowsPackage, Chef::Provider::Package::Windows ],
windows_service: [ Chef::Resource::WindowsService, Chef::Provider::Service::Windows ],
@@ -748,7 +790,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, Chef::Provider::User::Aix ],
+ user: [ Chef::Resource::User::AixUser, Chef::Provider::User::Aix ],
# service: [ Chef::Resource::AixService, Chef::Provider::Service::Aix ],
"aix" => {
@@ -815,7 +857,7 @@ describe Chef::ProviderResolver do
},
"omnios" => {
"3.1.4" => {
- user: [ Chef::Resource::User, Chef::Provider::User::Solaris ],
+ user: [ Chef::Resource::User::SolarisUser, Chef::Provider::User::Solaris ],
},
},
"openindiana" => {
@@ -827,7 +869,7 @@ describe Chef::ProviderResolver do
},
},
"solaris2" => {
- user: [ Chef::Resource::User, Chef::Provider::User::Solaris ],
+ user: [ Chef::Resource::User::SolarisUser, 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 9648ee1305..138ffb1bfe 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)
+ expect(@resource.resource_name).to eql(:user_resource_abstract_base_class)
end
it "should set the username equal to the argument to initialize" do