summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLamont Granquist <lamont@scriptkiddie.org>2017-02-26 15:53:22 -0800
committerLamont Granquist <lamont@scriptkiddie.org>2017-02-28 11:19:49 -0800
commit80547d21f52630d65a321975a6b9d19d9f2f49f4 (patch)
tree7e21d9e64025caa17325a5758b6570afa36044d6
parentf539a7f985c9c7f92b6197b883d8f6c201cf70e8 (diff)
downloadchef-80547d21f52630d65a321975a6b9d19d9f2f49f4.tar.gz
Chef-13: Remove supports API from all user providers
Signed-off-by: Lamont Granquist <lamont@scriptkiddie.org>
-rw-r--r--RELEASE_NOTES.md4
-rw-r--r--lib/chef/provider/user.rb12
-rw-r--r--lib/chef/provider/user/dscl.rb6
-rw-r--r--lib/chef/provider/user/linux.rb10
-rw-r--r--lib/chef/provider/user/pw.rb6
-rw-r--r--lib/chef/provider/user/solaris.rb4
-rw-r--r--lib/chef/provider/user/useradd.rb10
-rw-r--r--lib/chef/resource/user.rb18
-rw-r--r--lib/chef/resource/user/aix_user.rb2
-rw-r--r--lib/chef/resource/user/dscl_user.rb2
-rw-r--r--lib/chef/resource/user/linux_user.rb11
-rw-r--r--lib/chef/resource/user/pw_user.rb2
-rw-r--r--lib/chef/resource/user/solaris_user.rb2
-rw-r--r--lib/chef/resource/user/windows_user.rb2
-rw-r--r--spec/unit/provider/user/linux_spec.rb48
-rw-r--r--spec/unit/provider/user/pw_spec.rb14
-rw-r--r--spec/unit/resource/user_spec.rb10
17 files changed, 44 insertions, 119 deletions
diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md
index 973c6686ac..6dd5c6edc5 100644
--- a/RELEASE_NOTES.md
+++ b/RELEASE_NOTES.md
@@ -28,3 +28,7 @@ The `compile_time true` flag may still be used to force compile time.
In order to for community cookbooks to behave consistently across all users this optional flag has been removed.
+### The `supports[:manage_home]` and `supports[:non_unique]` API has been removed from all user providers
+
+The remediation is to set the manage_home and non_unique properties directly.
+
diff --git a/lib/chef/provider/user.rb b/lib/chef/provider/user.rb
index c44adbf818..43102e7dec 100644
--- a/lib/chef/provider/user.rb
+++ b/lib/chef/provider/user.rb
@@ -1,6 +1,6 @@
#
# Author:: Adam Jacob (<adam@chef.io>)
-# Copyright:: Copyright 2008-2016, Chef Software Inc.
+# Copyright:: Copyright 2008-2017, Chef Software Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -205,16 +205,6 @@ class Chef
def check_lock
raise NotImplementedError
end
-
- def non_unique?
- # XXX: THIS GOES AWAY IN CHEF-13 AND BECOMES JUST new_resource.non_unique
- new_resource.non_unique || new_resource.supports[:non_unique]
- end
-
- def managing_home_dir?
- # XXX: THIS GOES AWAY IN CHEF-13 AND BECOMES JUST new_resource.manage_home
- new_resource.manage_home || new_resource.supports[:manage_home]
- end
end
end
end
diff --git a/lib/chef/provider/user/dscl.rb b/lib/chef/provider/user/dscl.rb
index 2302a874e2..60167856d1 100644
--- a/lib/chef/provider/user/dscl.rb
+++ b/lib/chef/provider/user/dscl.rb
@@ -1,6 +1,6 @@
#
# Author:: Dreamcat4 (<dreamcat4@gmail.com>)
-# Copyright:: Copyright 2009-2016, Chef Software Inc.
+# Copyright:: Copyright 2009-2017, Chef Software Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -297,7 +297,7 @@ user password using shadow hash.")
return
end
- if managing_home_dir?
+ if new_resource.manage_home
validate_home_dir_specification!
if (current_resource.home == new_resource.home) && !new_home_exists?
@@ -442,7 +442,7 @@ user password using shadow hash.")
# and deleting home directory if needed.
#
def remove_user
- if managing_home_dir?
+ if new_resource.manage_home
# Remove home directory
FileUtils.rm_rf(current_resource.home)
end
diff --git a/lib/chef/provider/user/linux.rb b/lib/chef/provider/user/linux.rb
index 445421ad38..cf75bdc38b 100644
--- a/lib/chef/provider/user/linux.rb
+++ b/lib/chef/provider/user/linux.rb
@@ -1,5 +1,5 @@
#
-# Copyright:: Copyright 2016, Chef Software Inc.
+# Copyright:: Copyright 2016-2017, Chef Software Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -52,14 +52,14 @@ class Chef
opts << "-s" << new_resource.shell if should_set?(:shell)
opts << "-u" << new_resource.uid if should_set?(:uid)
opts << "-d" << new_resource.home if updating_home?
- opts << "-o" if non_unique?
+ opts << "-o" if new_resource.non_unique
opts
end
def usermod_options
opts = []
if updating_home?
- if managing_home_dir?
+ if new_resource.manage_home
opts << "-m"
end
end
@@ -69,7 +69,7 @@ class Chef
def useradd_options
opts = []
opts << "-r" if new_resource.system
- opts << if managing_home_dir?
+ opts << if new_resource.manage_home
"-m"
else
"-M"
@@ -79,7 +79,7 @@ class Chef
def userdel_options
opts = []
- opts << "-r" if managing_home_dir?
+ opts << "-r" if new_resource.manage_home
opts << "-f" if new_resource.force
opts
end
diff --git a/lib/chef/provider/user/pw.rb b/lib/chef/provider/user/pw.rb
index 42d862a983..cf47bb7fde 100644
--- a/lib/chef/provider/user/pw.rb
+++ b/lib/chef/provider/user/pw.rb
@@ -1,6 +1,6 @@
#
# Author:: Stephen Haynes (<sh@nomitor.com>)
-# Copyright:: Copyright 2009-2016, Chef Software Inc.
+# Copyright:: Copyright 2009-2017, Chef Software Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -42,7 +42,7 @@ class Chef
def remove_user
command = [ "pw", "userdel", new_resource.username ]
- command << "-r" if managing_home_dir?
+ command << "-r" if new_resource.manage_home
shell_out_compact!(command)
end
@@ -83,7 +83,7 @@ class Chef
opts << new_resource.send(field_symbol)
end
end
- if managing_home_dir?
+ if new_resource.manage_home
Chef::Log.debug("#{new_resource} is managing the users home directory")
opts << "-m"
end
diff --git a/lib/chef/provider/user/solaris.rb b/lib/chef/provider/user/solaris.rb
index 4e772312ae..25ec13fe5c 100644
--- a/lib/chef/provider/user/solaris.rb
+++ b/lib/chef/provider/user/solaris.rb
@@ -2,7 +2,7 @@
# Author:: Stephen Nelson-Smith (<sns@chef.io>)
# Author:: Jon Ramsey (<jonathon.ramsey@gmail.com>)
# Author:: Dave Eddy (<dave@daveeddy.com>)
-# Copyright:: Copyright 2012-2016, Chef Software Inc.
+# Copyright:: Copyright 2012-2017, Chef Software Inc.
# Copyright:: Copyright 2015-2016, Dave Eddy
# License:: Apache License, Version 2.0
#
@@ -77,7 +77,7 @@ class Chef
# @return [Array<String>]
def useradd_options
opts = []
- opts << "-m" if managing_home_dir?
+ opts << "-m" if new_resource.manage_home
opts
end
diff --git a/lib/chef/provider/user/useradd.rb b/lib/chef/provider/user/useradd.rb
index cf6f4e727f..0a32126903 100644
--- a/lib/chef/provider/user/useradd.rb
+++ b/lib/chef/provider/user/useradd.rb
@@ -1,6 +1,6 @@
#
# Author:: Adam Jacob (<adam@chef.io>)
-# Copyright:: Copyright 2008-2016, Chef Software Inc.
+# Copyright:: Copyright 2008-2017, Chef Software Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -46,7 +46,7 @@ class Chef
def remove_user
command = [ "userdel" ]
- command << "-r" if managing_home_dir?
+ command << "-r" if new_resource.manage_home
command << "-f" if new_resource.force
command << new_resource.username
shell_out_compact!(command)
@@ -117,14 +117,14 @@ class Chef
end
if updating_home?
opts << "-d" << new_resource.home
- if managing_home_dir?
+ if new_resource.manage_home
Chef::Log.debug("#{new_resource} managing the users home directory")
opts << "-m"
else
Chef::Log.debug("#{new_resource} setting home to #{new_resource.home}")
end
end
- opts << "-o" if non_unique?
+ opts << "-o" if new_resource.non_unique
opts
end
end
@@ -139,7 +139,7 @@ class Chef
def useradd_options
opts = []
opts << "-r" if new_resource.system
- opts << "-M" unless managing_home_dir?
+ opts << "-M" unless new_resource.manage_home
opts
end
diff --git a/lib/chef/resource/user.rb b/lib/chef/resource/user.rb
index fc7720bc25..288335a599 100644
--- a/lib/chef/resource/user.rb
+++ b/lib/chef/resource/user.rb
@@ -1,6 +1,6 @@
#
# Author:: Adam Jacob (<adam@chef.io>)
-# Copyright:: Copyright 2008-2016, Chef Software Inc.
+# Copyright:: Copyright 2008-2017, Chef Software Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -42,10 +42,6 @@ class Chef
@manage_home = false
@force = false
@non_unique = false
- @supports = {
- manage_home: false,
- non_unique: false,
- }
@iterations = 27855
@salt = nil
end
@@ -157,17 +153,7 @@ class Chef
end
def supports(args = {})
- if args.key?(:manage_home)
- Chef.deprecated(:supports_property, "supports { manage_home: #{args[:manage_home]} } on the user resource is deprecated and will be removed in Chef 13, set manage_home #{args[:manage_home]} instead")
- end
- if args.key?(:non_unique)
- Chef.deprecated(:supports_property, "supports { non_unique: #{args[:non_unique]} } on the user resource is deprecated and will be removed in Chef 13, set non_unique #{args[:non_unique]} instead")
- end
- super
- end
-
- def supports=(args)
- supports(args)
+ raise Chef::Exceptions::User, "calling supports on a user resource is no longer supported in Chef-13, you probably need to use the manage_home or non_unique properties directly"
end
end
end
diff --git a/lib/chef/resource/user/aix_user.rb b/lib/chef/resource/user/aix_user.rb
index 7c07db2e25..d5f1829b63 100644
--- a/lib/chef/resource/user/aix_user.rb
+++ b/lib/chef/resource/user/aix_user.rb
@@ -1,5 +1,5 @@
#
-# Copyright:: Copyright 2016, Chef Software Inc.
+# Copyright:: Copyright 2016-2017, Chef Software Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
diff --git a/lib/chef/resource/user/dscl_user.rb b/lib/chef/resource/user/dscl_user.rb
index 61517d8b44..6eb1c953f4 100644
--- a/lib/chef/resource/user/dscl_user.rb
+++ b/lib/chef/resource/user/dscl_user.rb
@@ -1,5 +1,5 @@
#
-# Copyright:: Copyright 2016, Chef Software Inc.
+# Copyright:: Copyright 2016-2017, Chef Software Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
diff --git a/lib/chef/resource/user/linux_user.rb b/lib/chef/resource/user/linux_user.rb
index ec60ac89bf..056a421197 100644
--- a/lib/chef/resource/user/linux_user.rb
+++ b/lib/chef/resource/user/linux_user.rb
@@ -1,5 +1,5 @@
#
-# Copyright:: Copyright 2016, Chef Software Inc.
+# Copyright:: Copyright 2016-2017, Chef Software Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -26,15 +26,6 @@ class Chef
provides :linux_user
provides :user, os: "linux"
- def initialize(name, run_context = nil)
- super
- @supports = {
- manage_home: false,
- non_unique: false,
- }
- @manage_home = false
- end
-
end
end
end
diff --git a/lib/chef/resource/user/pw_user.rb b/lib/chef/resource/user/pw_user.rb
index 873be19d59..3672943f5c 100644
--- a/lib/chef/resource/user/pw_user.rb
+++ b/lib/chef/resource/user/pw_user.rb
@@ -1,5 +1,5 @@
#
-# Copyright:: Copyright 2016, Chef Software Inc.
+# Copyright:: Copyright 2016-2017, Chef Software Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
diff --git a/lib/chef/resource/user/solaris_user.rb b/lib/chef/resource/user/solaris_user.rb
index bb897228b9..cca90e6743 100644
--- a/lib/chef/resource/user/solaris_user.rb
+++ b/lib/chef/resource/user/solaris_user.rb
@@ -1,5 +1,5 @@
#
-# Copyright:: Copyright 2016, Chef Software Inc.
+# Copyright:: Copyright 2016-2017, Chef Software Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
diff --git a/lib/chef/resource/user/windows_user.rb b/lib/chef/resource/user/windows_user.rb
index d1a249fb50..baedc14f5e 100644
--- a/lib/chef/resource/user/windows_user.rb
+++ b/lib/chef/resource/user/windows_user.rb
@@ -1,5 +1,5 @@
#
-# Copyright:: Copyright 2016, Chef Software Inc.
+# Copyright:: Copyright 2016-2017, Chef Software Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
diff --git a/spec/unit/provider/user/linux_spec.rb b/spec/unit/provider/user/linux_spec.rb
index b04ada2511..063ca934c3 100644
--- a/spec/unit/provider/user/linux_spec.rb
+++ b/spec/unit/provider/user/linux_spec.rb
@@ -1,7 +1,7 @@
#
# Author:: Adam Jacob (<adam@chef.io>)
# Author:: Daniel DeLeo (<dan@chef.io>)
-# Copyright:: Copyright 2008-2016, Chef Software Inc.
+# Copyright:: Copyright 2008-2017, Chef Software Inc.
#
# License:: Apache License, Version 2.0
#
@@ -45,56 +45,18 @@ describe Chef::Provider::User::Linux do
@current_resource = Chef::Resource::User::LinuxUser.new("adam", @run_context)
end
- it "supports manage_home does not exist", chef: ">= 13" do
- expect( @new_resource.supports.key?(:manage_home) ).to be false
+ it "throws an error when trying to set supports manage_home: true" do
+ expect { @new_resource.supports( manage_home: true ) }.to raise_error(Chef::Exceptions::User)
end
- it "supports non_unique does not exist", chef: ">= 13" do
- expect( @new_resource.supports.key?(:non_unique) ).to be false
- end
-
- # supports is a method on the superclass so can't totally be removed, but we should aggressively NOP it to decisively break it
- it "disables the supports API", chef: ">= 13" do
- @new_resource.supports( manage_home: true )
- expect( @new_resource.supports.key?(:manage_home) ).to be false
- end
-
- it "sets supports manage_home to false" do
- expect( @new_resource.supports[:manage_home] ).to be false
- end
-
- it "sets supports non-unique to false" do
- expect( @new_resource.supports[:non_unique] ).to be false
- end
-
- it "throws a deprecation warning on setting supports[:non_unique]" do
- Chef::Config[:treat_deprecation_warnings_as_errors] = false
- expect(Chef).to receive(:deprecated).with(:supports_property, "supports { non_unique: true } on the user resource is deprecated and will be removed in Chef 13, set non_unique true instead")
- @new_resource.supports( non_unique: true )
- end
-
- it "throws a deprecation warning on setting supports[:manage_home]" do
- Chef::Config[:treat_deprecation_warnings_as_errors] = false
- expect(Chef).to receive(:deprecated).with(:supports_property, "supports { manage_home: true } on the user resource is deprecated and will be removed in Chef 13, set manage_home true instead")
- @new_resource.supports( manage_home: true )
+ it "throws an error when trying to set supports non_unique: true" do
+ expect { @new_resource.supports( non_unique: true ) }.to raise_error(Chef::Exceptions::User)
end
it "defaults manage_home to false" do
expect( @new_resource.manage_home ).to be false
end
- it "supports[:manage_home] (incorectly) acts like manage_home" do
- Chef::Config[:treat_deprecation_warnings_as_errors] = false
- @new_resource.supports(manage_home: true)
- expect( provider.useradd_options ).to eql(["-m"])
- end
-
- it "supports[:manage_home] does not change behavior of manage_home: false", chef: ">= 13" do
- Chef::Config[:treat_deprecation_warnings_as_errors] = false
- @new_resource.supports(manage_home: true)
- expect( provider.useradd_options ).to eql(["-M"])
- end
-
it "by default manage_home is false and we use -M" do
expect( provider.useradd_options ).to eql(["-M"])
end
diff --git a/spec/unit/provider/user/pw_spec.rb b/spec/unit/provider/user/pw_spec.rb
index 2f44d6f3e3..3637ce0b95 100644
--- a/spec/unit/provider/user/pw_spec.rb
+++ b/spec/unit/provider/user/pw_spec.rb
@@ -1,6 +1,6 @@
#
# Author:: Stephen Haynes (<sh@nomitor.com>)
-# Copyright:: Copyright 2008-2016, Chef Software Inc.
+# Copyright:: Copyright 2008-2017, Chef Software Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -32,9 +32,7 @@ describe Chef::Provider::User::Pw do
@new_resource.shell "/usr/bin/zsh"
@new_resource.password "abracadabra"
- # XXX: rip out in Chef-13
- Chef::Config[:treat_deprecation_warnings_as_errors] = false
- @new_resource.supports manage_home: true
+ @new_resource.manage_home true
@current_resource = Chef::Resource::User::PwUser.new("adam")
@current_resource.comment "Adam Jacob"
@@ -67,12 +65,6 @@ describe Chef::Provider::User::Pw do
allow(@new_resource).to receive(attribute).and_return("hola")
expect(@provider.set_options).to eql([ @new_resource.username, option, @new_resource.send(attribute), "-m"])
end
-
- it "should set the option for #{attribute} if the new resources #{attribute} is not null, without homedir management" do
- allow(@new_resource).to receive(:supports).and_return(manage_home: false)
- allow(@new_resource).to receive(attribute).and_return("hola")
- expect(@provider.set_options).to eql([@new_resource.username, option, @new_resource.send(attribute)])
- end
end
it "should combine all the possible options" do
@@ -123,7 +115,7 @@ describe Chef::Provider::User::Pw do
describe "remove_user" do
it "should run pw userdel with the new resources user name" do
- @new_resource.supports manage_home: false
+ @new_resource.manage_home false
expect(@provider).to receive(:shell_out!).with("pw", "userdel", @new_resource.username).and_return(true)
@provider.remove_user
end
diff --git a/spec/unit/resource/user_spec.rb b/spec/unit/resource/user_spec.rb
index 138ffb1bfe..afd3969164 100644
--- a/spec/unit/resource/user_spec.rb
+++ b/spec/unit/resource/user_spec.rb
@@ -1,6 +1,6 @@
#
# Author:: Adam Jacob (<adam@chef.io>)
-# Copyright:: Copyright 2008-2016, Chef Software Inc.
+# Copyright:: Copyright 2008-2017, Chef Software Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -46,12 +46,12 @@ describe Chef::Resource::User, "initialize" do
expect(@resource.action).to eql([:create])
end
- it "should set supports[:manage_home] to false" do
- expect(@resource.supports[:manage_home]).to eql(false)
+ it "should set manage_home to false" do
+ expect(@resource.manage_home).to eql(false)
end
- it "should set supports[:non_unique] to false" do
- expect(@resource.supports[:non_unique]).to eql(false)
+ it "should set non_unique to false" do
+ expect(@resource.non_unique).to eql(false)
end
it "should set force to false" do