end
end
+ # States should always be sorted. This ensures that the output from
+ # iptables-save and user supplied resources is consistent.
+ hash[:state] = hash[:state].sort unless hash[:state].nil?
+
# This forces all existing, commentless rules to be moved to the bottom of the stack.
# Puppet-firewall requires that all rules have comments (resource names) and will fail if
# a rule in iptables does not have a comment. We get around this by appending a high level
newvalues(:INVALID,:ESTABLISHED,:NEW,:RELATED)
+ # States should always be sorted. This normalizes the resource states to
+ # keep it consistent with the sorted result from iptables-save.
+ def should=(values)
+ @should = super(values).sort
+ end
+
def should_to_s(value)
value = [value] unless value.is_a?(Array)
value.join(',')
:sport => ["15","512-1024"],
},
},
+ 'state_returns_sorted_values' => {
+ :line => '-A INPUT -m state --state INVALID,RELATED,ESTABLISHED',
+ :table => 'filter',
+ :params => {
+ :state => ['ESTABLISHED', 'INVALID', 'RELATED'],
+ :action => nil,
+ },
+ },
}
# This hash is for testing converting a hash to an argument line.
},
:args => ["-t", :filter, "-p", :tcp, "-m", "multiport", "--dports", "15,512:1024", "-m", "comment", "--comment", "100 sport range"],
},
+ 'states_set_from_array' => {
+ :params => {
+ :name => "100 states_set_from_array",
+ :table => "filter",
+ :state => ['ESTABLISHED', 'INVALID']
+ },
+ :args => ["-t", :filter, "-p", :tcp, "-m", "comment", "--comment", "100 states_set_from_array",
+ "-m", "state", "--state", "ESTABLISHED,INVALID"],
+ },
}
@resource[:state] = [:INVALID, :NEW]
@resource[:state].should == [:INVALID, :NEW]
end
+
+ it 'should sort values alphabetically' do
+ @resource[:state] = [:NEW, :ESTABLISHED]
+ @resource[:state].should == [:ESTABLISHED, :NEW]
+ end
end
describe ':burst' do