summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLamont Granquist <lamont@scriptkiddie.org>2016-08-23 18:50:58 -0700
committerLamont Granquist <lamont@scriptkiddie.org>2016-08-23 18:50:58 -0700
commitd0240480ea5f52452853633554565b6229990298 (patch)
tree0da247d29c1293e2249367a2acc5460707a54ce0
parentb6bccd672282c81c05b20d8d544e65889c60bcd5 (diff)
downloadchef-d0240480ea5f52452853633554565b6229990298.tar.gz
sort out the -m / -M mess a bit better
-M is not valid for usermod Signed-off-by: Lamont Granquist <lamont@scriptkiddie.org>
-rw-r--r--lib/chef/provider/user/linux.rb13
-rw-r--r--spec/support/shared/unit/provider/useradd_based_user_provider.rb18
2 files changed, 17 insertions, 14 deletions
diff --git a/lib/chef/provider/user/linux.rb b/lib/chef/provider/user/linux.rb
index 792e05e729..ff1bc9c4c8 100644
--- a/lib/chef/provider/user/linux.rb
+++ b/lib/chef/provider/user/linux.rb
@@ -28,7 +28,7 @@ class Chef
end
def manage_user
- shell_out!(*clean_array("usermod", universal_options, new_resource.username))
+ shell_out!(*clean_array("usermod", universal_options, usermod_options, new_resource.username))
end
def remove_user
@@ -51,15 +51,18 @@ class Chef
opts << "-p" << new_resource.password if should_set?(:password)
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 new_resource.non_unique
+ opts
+ end
+
+ def usermod_options
+ opts = []
if updating_home?
- opts << "-d" << new_resource.home
if new_resource.manage_home
opts << "-m"
- else
- opts << "-M"
end
end
- opts << "-o" if new_resource.non_unique
opts
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 007441dc6c..fc12b2d5b6 100644
--- a/spec/support/shared/unit/provider/useradd_based_user_provider.rb
+++ b/spec/support/shared/unit/provider/useradd_based_user_provider.rb
@@ -111,21 +111,21 @@ shared_examples_for "a useradd-based user provider" do |supported_useradd_option
end
it "should set -m -d /homedir" do
- expect(provider.universal_options).to eq(%w{-d /wowaweea -m})
- expect(provider.useradd_options).to eq([ "-m" ]) # FIXME: repeated -m
+ expect(provider.universal_options).to eq(%w{-d /wowaweea})
+ expect(provider.usermod_options).to eq(%w{-m})
end
end
describe "when the resource has a different home directory and supports home directory management (using real attributes)" do
before do
- allow(@new_resource).to receive(:home).and_return("/wowaweea")
- allow(@new_resource).to receive(:manage_home).and_return(true)
- allow(@new_resource).to receive(:non_unique).and_return(false)
+ @new_resource.home("/wowaweea")
+ @new_resource.manage_home true
+ @new_resource.non_unique false
end
it "should set -m -d /homedir" do
- expect(provider.universal_options).to eql(%w{-d /wowaweea -m})
- expect(provider.useradd_options).to eq([ "-m" ]) # FIXME: repeated -m
+ expect(provider.universal_options).to eq(%w{-d /wowaweea})
+ expect(provider.usermod_options).to eq(%w{-m})
end
end
@@ -158,7 +158,7 @@ shared_examples_for "a useradd-based user provider" do |supported_useradd_option
command.concat([ "-s", "/usr/bin/zsh",
"-u", "1000",
"-d", "/Users/mud",
- "-m", "-m", # FIXME: repeated -m
+ "-m",
"adam" ])
expect(provider).to receive(:shell_out!).with(*command).and_return(true)
provider.create_user
@@ -220,7 +220,7 @@ shared_examples_for "a useradd-based user provider" do |supported_useradd_option
end
it "CHEF-3429: does not set -m if we aren't changing the home directory" do
- expect(provider).to receive(:updating_home?).and_return(false)
+ expect(provider).to receive(:updating_home?).at_least(:once).and_return(false)
command = ["usermod",
"-g", "23",
"adam" ]