:ip6tables_save => 'ip6tables-save',
})
+ confine :kernel => :linux
+
def initialize(*args)
if Facter.fact('ip6tables_version').value.match /1\.3\.\d/
raise ArgumentError, 'The ip6tables provider is not supported on version 1.3 of iptables'
})
defaultfor :kernel => :linux
+ confine :kernel => :linux
iptables_version = Facter.fact('iptables_version').value
if (iptables_version and Puppet::Util::Package.versioncmp(iptables_version, '1.4.1') < 0)
})
defaultfor :kernel => :linux
+ confine :kernel => :linux
# chain name is greedy so we anchor from the end.
# [\d+:\d+] doesn't exist on ebtables
it { expect { should contain_class('firewall::linux') }.to raise_error(Puppet::Error) }
end
+ context 'kernel => SunOS' do
+ let(:facts) {{ :kernel => 'SunOS' }}
+ it { expect { should contain_class('firewall::linux') }.to raise_error(Puppet::Error) }
+ end
+
+ context 'kernel => Darwin' do
+ let(:facts) {{ :kernel => 'Darwin' }}
+ it { expect { should contain_class('firewall::linux') }.to raise_error(Puppet::Error) }
+ end
+
context 'ensure => stopped' do
let(:facts) {{ :kernel => 'Linux' }}
let(:params) {{ :ensure => 'stopped' }}
before :each do
# Reset the default provider
Puppet::Type.type(:firewallchain).defaultprovider = nil
+
+ # Stub confine facts
+ allow(Facter.fact(:kernel)).to receive(:value).and_return('Linux')
+ allow(Facter.fact(:operatingsystem)).to receive(:value).and_return('Debian')
end
it "should default to iptables provider if /sbin/(eb|ip|ip6)tables[-save] exists" do
# Every other command should return false so we don't pick up any
# other providers
- allow(exists).to receive(:which).with() { |value|
+ allow(exists).to receive(:which) { |value|
value !~ /(eb|ip|ip6)tables(-save)?$/
}.and_return false
before :each do
# Reset the default provider
Puppet::Type.type(:firewall).defaultprovider = nil
+
+ # Stub confine facts
+ allow(Facter.fact(:kernel)).to receive(:value).and_return('Linux')
+ allow(Facter.fact(:operatingsystem)).to receive(:value).and_return('Debian')
end
it "should default to iptables provider if /sbin/iptables[-save] exists" do
# Every other command should return false so we don't pick up any
# other providers
- allow(exists).to receive(:which).with() { |value|
+ allow(exists).to receive(:which) { |value|
! ["iptables","iptables-save"].include?(value)
}.and_return false
it "the parameter '#{param_name.to_s}' should match #{param_value.inspect}" do
# booleans get cludged to string "true"
if param_value == true then
- expect(resource[param_name]).to be_true
+ expect(resource[param_name]).to be_truthy
else
expect(resource[param_name]).to eq(data[:params][param_name])
end
end
end
end
+ it 'is suitable' do
+ expect(@resource.suitable?).to be_truthy
+ end
+end
+
+describe 'firewall on unsupported platforms' do
+ it 'is not suitable' do
+ # Stub iptables version
+ allow(Facter.fact(:iptables_version)).to receive(:value).and_return(nil)
+ allow(Facter.fact(:ip6tables_version)).to receive(:value).and_return(nil)
+
+ # Stub confine facts
+ allow(Facter.fact(:kernel)).to receive(:value).and_return('Darwin')
+ allow(Facter.fact(:operatingsystem)).to receive(:value).and_return('Darwin')
+ resource = firewall.new(:name => "000 test foo", :ensure => :present)
+
+ # If our provider list is nil, then the Puppet::Transaction#evaluate will
+ # say 'Error: Could not find a suitable provider for firewall' but there
+ # isn't a unit testable way to get this.
+ expect(resource.suitable?).to be_falsey
+ end
end
expect(resource.generate.size).to eq(0)
end
end
+ it 'is suitable' do
+ expect(resource.suitable?).to be_truthy
+ end
+end
+
+describe 'firewall on unsupported platforms' do
+ it 'is not suitable' do
+ # Stub iptables version
+ allow(Facter.fact(:iptables_version)).to receive(:value).and_return(nil)
+ allow(Facter.fact(:ip6tables_version)).to receive(:value).and_return(nil)
+
+ # Stub confine facts
+ allow(Facter.fact(:kernel)).to receive(:value).and_return('Darwin')
+ allow(Facter.fact(:operatingsystem)).to receive(:value).and_return('Darwin')
+ resource = firewallchain.new(:name => "INPUT:filter:IPv4", :ensure => :present)
+
+ # If our provider list is nil, then the Puppet::Transaction#evaluate will
+ # say 'Error: Could not find a suitable provider for firewall' but there
+ # isn't a unit testable way to get this.
+ expect(resource.suitable?).to be_falsey
+ end
end