Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #338 from pcarlisle/ticket/2.7.x/freebsd-user-pass…
…words (#11046) improve freebsd user and group providers
- Loading branch information
Showing
4 changed files
with
344 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,48 @@ | ||
require 'puppet/provider/nameservice/pw' | ||
|
||
Puppet::Type.type(:group).provide :pw, :parent => Puppet::Provider::NameService::PW do | ||
desc "Group management via `pw`. | ||
desc "Group management via `pw` on FreeBSD." | ||
|
||
Only works on FreeBSD. | ||
commands :pw => "pw" | ||
has_features :manages_members | ||
|
||
" | ||
|
||
commands :pw => "/usr/sbin/pw" | ||
defaultfor :operatingsystem => :freebsd | ||
|
||
options :members, :flag => "-M", :method => :mem | ||
|
||
verify :gid, "GID must be an integer" do |value| | ||
value.is_a? Integer | ||
end | ||
|
||
def addcmd | ||
cmd = [command(:pw), "groupadd", @resource[:name]] | ||
|
||
if gid = @resource.should(:gid) | ||
unless gid == :absent | ||
cmd << flag(:gid) << gid | ||
end | ||
end | ||
|
||
# Apparently, contrary to the man page, groupadd does | ||
# not accept -o. | ||
#if @parent[:allowdupe] == :true | ||
# cmd << "-o" | ||
#end | ||
if members = @resource.should(:members) | ||
unless members == :absent | ||
if members.is_a?(Array) | ||
members = members.join(",") | ||
end | ||
cmd << "-M" << members | ||
end | ||
end | ||
|
||
cmd << "-o" if @resource.allowdupe? | ||
|
||
cmd | ||
end | ||
|
||
def modifycmd(param, value) | ||
# members may be an array, need a comma separated list | ||
if param == :members and value.is_a?(Array) | ||
value = value.join(",") | ||
end | ||
super(param, value) | ||
end | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
#!/usr/bin/env rspec | ||
require 'spec_helper' | ||
|
||
provider_class = Puppet::Type.type(:group).provider(:pw) | ||
|
||
describe provider_class do | ||
let :resource do | ||
Puppet::Type.type(:group).new(:name => "testgroup", :provider => :pw) | ||
end | ||
|
||
let :provider do | ||
resource.provider | ||
end | ||
|
||
describe "when creating groups" do | ||
let :provider do | ||
prov = resource.provider | ||
prov.expects(:exists?).returns nil | ||
prov | ||
end | ||
|
||
it "should run pw with no additional flags when no properties are given" do | ||
provider.addcmd.must == [provider_class.command(:pw), "groupadd", "testgroup"] | ||
provider.expects(:execute).with([provider_class.command(:pw), "groupadd", "testgroup"]) | ||
provider.create | ||
end | ||
|
||
it "should use -o when allowdupe is enabled" do | ||
resource[:allowdupe] = true | ||
provider.expects(:execute).with(includes("-o")) | ||
provider.create | ||
end | ||
|
||
it "should use -g with the correct argument when the gid property is set" do | ||
resource[:gid] = 12345 | ||
provider.expects(:execute).with(all_of(includes("-g"), includes(12345))) | ||
provider.create | ||
end | ||
|
||
it "should use -M with the correct argument when the members property is set" do | ||
resource[:members] = "user1" | ||
provider.expects(:execute).with(all_of(includes("-M"), includes("user1"))) | ||
provider.create | ||
end | ||
|
||
it "should use -M with all the given users when the members property is set to an array" do | ||
resource[:members] = ["user1", "user2"] | ||
provider.expects(:execute).with(all_of(includes("-M"), includes("user1,user2"))) | ||
provider.create | ||
end | ||
end | ||
|
||
describe "when deleting groups" do | ||
it "should run pw with no additional flags" do | ||
provider.expects(:exists?).returns true | ||
provider.deletecmd.must == [provider_class.command(:pw), "groupdel", "testgroup"] | ||
provider.expects(:execute).with([provider_class.command(:pw), "groupdel", "testgroup"]) | ||
provider.delete | ||
end | ||
end | ||
|
||
describe "when modifying groups" do | ||
it "should run pw with the correct arguments" do | ||
provider.modifycmd("gid", 12345).must == [provider_class.command(:pw), "groupmod", "testgroup", "-g", 12345] | ||
provider.expects(:execute).with([provider_class.command(:pw), "groupmod", "testgroup", "-g", 12345]) | ||
provider.gid = 12345 | ||
end | ||
|
||
it "should use -M with the correct argument when the members property is changed" do | ||
resource[:members] = "user1" | ||
provider.expects(:execute).with(all_of(includes("-M"), includes("user2"))) | ||
provider.members = "user2" | ||
end | ||
|
||
it "should use -M with all the given users when the members property is changed with an array" do | ||
resource[:members] = ["user1", "user2"] | ||
provider.expects(:execute).with(all_of(includes("-M"), includes("user3,user4"))) | ||
provider.members = ["user3", "user4"] | ||
end | ||
end | ||
end |
Oops, something went wrong.