-
-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
It can be a string or a hash. We validate string content and hash content. +tests
- Loading branch information
Showing
5 changed files
with
109 additions
and
3 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
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,21 @@ | ||
module PuppetX | ||
module Firewalld | ||
module Property | ||
class RichRuleAction < Puppet::Property | ||
def _validate_action(value) | ||
raise Puppet::Error, "Authorized action values are `accept`, `reject`, `drop` or `mark`, got #{value}" unless %w[accept drop reject mark].include? value | ||
end | ||
validate do |value| | ||
if value.is_a?(Hash) | ||
if value.keys.sort != %i[action type] | ||
raise Puppet::Error, "Rule action hash should contain `action` and `type` keys. Use a string if you only want to declare the action to be `accept` or `reject`. Got #{value}" | ||
end | ||
_validate_action(value[:action]) | ||
elsif value.is_a?(String) | ||
_validate_action(value) | ||
end | ||
end | ||
end | ||
end | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
require 'spec_helper' | ||
|
||
provider_class = Puppet::Type.type(:firewalld_rich_rule).provider(:firewall_cmd) | ||
|
||
describe provider_class do | ||
let(:resource) do | ||
@resource = Puppet::Type.type(:firewalld_rich_rule).new( | ||
ensure: :present, | ||
name: 'Accept ssh from barny', | ||
zone: 'restricted', | ||
service: 'ssh', | ||
source: '192.168.1.2/32', | ||
action: 'accept', | ||
provider: described_class.name | ||
) | ||
end | ||
let(:provider) { resource.provider } | ||
|
||
before :each do | ||
provider.class.stubs(:execute_firewall_cmd).returns(Object.any_instance.stubs(:exitstatus => 0)) | ||
provider.class.stubs(:execute_firewall_cmd).with(['--list-interfaces']).returns(Object.any_instance.stubs(:exitstatus => 0, :chomp => "")) | ||
end | ||
|
||
describe 'when creating' do | ||
context 'with basic parameters' do | ||
it "should build the rich rule" do | ||
resource.expects(:[]).with(:source).returns('192.168.1.2/32').at_least_once | ||
resource.expects(:[]).with(:service).returns('ssh').at_least_once | ||
resource.expects(:[]).with("family").returns('ipv4').at_least_once | ||
resource.expects(:[]).with(:dest).returns(nil) | ||
resource.expects(:[]).with(:port).returns(nil) | ||
resource.expects(:[]).with(:protocol).returns(nil) | ||
resource.expects(:[]).with(:icmp_block).returns(nil) | ||
resource.expects(:[]).with(:masquerade).returns(nil) | ||
resource.expects(:[]).with(:forward_port).returns(nil) | ||
resource.expects(:[]).with(:log).returns(nil) | ||
resource.expects(:[]).with(:audit).returns(nil) | ||
resource.expects(:[]).with(:raw_rule).returns(nil) | ||
resource.expects(:[]).with(:action).returns('accept') | ||
expect(provider.build_rich_rule).to eq("rule family=\"ipv4\" source service name=\"ssh\" accept") | ||
end | ||
end | ||
context 'with reject type' do | ||
it "should build the rich rule" do | ||
resource.expects(:[]).with(:source).returns(nil).at_least_once | ||
resource.expects(:[]).with(:service).returns('ssh').at_least_once | ||
resource.expects(:[]).with("family").returns('ipv4').at_least_once | ||
resource.expects(:[]).with(:dest).returns({'address' => '192.168.0.1/32'}) | ||
resource.expects(:[]).with(:port).returns(nil) | ||
resource.expects(:[]).with(:protocol).returns(nil) | ||
resource.expects(:[]).with(:icmp_block).returns(nil) | ||
resource.expects(:[]).with(:masquerade).returns(nil) | ||
resource.expects(:[]).with(:forward_port).returns(nil) | ||
resource.expects(:[]).with(:log).returns(nil) | ||
resource.expects(:[]).with(:audit).returns(nil) | ||
resource.expects(:[]).with(:raw_rule).returns(nil) | ||
resource.expects(:[]).with(:action).returns({'action' => 'reject', 'type' => 'icmp-admin-prohibited'}) | ||
expect(provider.build_rich_rule).to eq("rule family=\"ipv4\" destination service name=\"ssh\" reject type=\"icmp-admin-prohibited\"") | ||
end | ||
end | ||
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