Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix port sorting in generated firewall rules file #291

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ This file is used to list changes made in each version of the firewall cookbook.

## Unreleased

fix port sorting in generated firewall rules file

## 6.3.6 - *2024-05-06*

## 6.3.5 - *2024-05-06*
Expand Down
2 changes: 1 addition & 1 deletion libraries/helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def port_to_s(p)
p.to_s
elsif p && p.is_a?(Array)
p_strings = p.map { |o| port_to_s(o) }
p_strings.sort.join(',')
p_strings.sort_by { |s| s.scan(/\d+/).first.to_i }.join(',')
elsif p && p.is_a?(Range)
if platform_family?('windows')
"#{p.first}-#{p.last}"
Expand Down
5 changes: 5 additions & 0 deletions test/fixtures/cookbooks/firewall-test/recipes/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -107,4 +107,9 @@
command :allow
end

firewall_rule 'FreeIPA ports' do
port %w(80 88 389 443 464 636)
source '10.10.10.10'
end

include_recipe 'firewall-test::windows' if windows?
10 changes: 10 additions & 0 deletions test/integration/ufw/inspec/ufw_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
%r{ 1000:1100/tcp + ALLOW IN +Anywhere},
%r{ 1234,5000:5100,5678/tcp + ALLOW IN +Anywhere},
%r{ 23/tcp + LIMIT IN +Anywhere},
%r{ 80,88,389,443,464,636/tcp + ALLOW IN +10\.10\.10\.10},
/# ssh22/,
]

Expand All @@ -28,3 +29,12 @@
its(:stdout) { should match(/Status: active/) }
end
end

describe file('/etc/default/ufw-chef.rules') do
it { should exist }
its(:size) { should > 0 }
its(:mode) { should cmp '0644' }
it { should be_owned_by 'root' }
it { should be_grouped_into 'root' }
its(:content) { should match /ufw allow in proto tcp to any port 80,88,389,443,464,636 from 10.10.10.10 comment "FreeIPA ports"/ }
end
Loading