Skip to content

Commit

Permalink
Evaluate target correctly when firewall-cmd --get-target doesn't use %%
Browse files Browse the repository at this point in the history
Closes #111

#111
  • Loading branch information
crayfishx committed Feb 28, 2017
1 parent bb509a1 commit a0b6294
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lib/puppet/provider/firewalld_zone/firewall_cmd.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,12 @@ def destroy
end

def target
execute_firewall_cmd(['--get-target']).chomp
zone_target=execute_firewall_cmd(['--get-target']).chomp
# The firewall-cmd may or may not return the target surrounded by
# %% depending on the version. See:
# https://github.com/crayfishx/puppet-firewalld/issues/111
return @resource[:target] if @resource[:target].delete('%') == zone_target
zone_target
end

def target=(t)
Expand Down
10 changes: 10 additions & 0 deletions spec/unit/puppet/type/firewalld_zone_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,16 @@
expect(provider.exists?).to be_falsey
end

it "should evalulate target" do
provider.expects(:execute_firewall_cmd).with(['--get-target']).returns('%%REJECT%%')
expect(provider.target).to eq('%%REJECT%%')
end

it "should evalulate target correctly when not surrounded with %%" do
provider.expects(:execute_firewall_cmd).with(['--get-target']).returns('REJECT')
expect(provider.target).to eq('%%REJECT%%')
end

it "should create" do
provider.expects(:execute_firewall_cmd).with(['--new-zone', 'restricted'], nil)
provider.expects(:execute_firewall_cmd).with(['--set-target', '%%REJECT%%'])
Expand Down

0 comments on commit a0b6294

Please sign in to comment.