Skip to content

Commit

Permalink
Correctly fix aliases quoting logic (#206)
Browse files Browse the repository at this point in the history
We were previously incorrectly adding double quotes for the alias values.
According to the man page it's not required. However, there is a requirement if
its a command being pipe.

In addition, the man page mentions this for the alias name:

  The  name  is  a  local  address (no domain part).  Use double quotes when the
  name contains any special characters such as whitespace, `#', `:', or `@'. The
  name is folded to lowercase, in order to make database lookups case
  insensitive.

This includes logic to support this automatically.

- Add new tests for aliases testing all types
- Convert all serverspec tests to inspec
- Add Github actions
- Update platforms to test

Signed-off-by: Lance Albertson <lance@osuosl.org>
  • Loading branch information
ramereth authored Jan 29, 2025
1 parent 6cb80c3 commit 1cd55ab
Show file tree
Hide file tree
Showing 30 changed files with 224 additions and 250 deletions.
60 changes: 60 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
---
name: ci

"on":
pull_request:
push:
branches:
- main

jobs:
lint-unit:
uses: sous-chefs/.github/.github/workflows/lint-unit.yml@3.0.0
permissions:
actions: write
checks: write
pull-requests: write
statuses: write

integration:
needs: 'lint-unit'
runs-on: ubuntu-latest
strategy:
matrix:
os:
- almalinux-8
- almalinux-9
- amazonlinux-2023
- centos-stream-9
- debian-11
- debian-12
- opensuse-leap-15
- rockylinux-8
- rockylinux-9
- ubuntu-2004
- ubuntu-2204
- ubuntu-2404
suite:
- default
- aliases
- client
- server
- canonical
- sasl-auth-none
- sasl-auth-multiple
- sasl-auth-one
fail-fast: false

steps:
- name: Check out code
uses: actions/checkout@v4 # v4
- name: Install Chef
uses: actionshub/chef-install@2.0.4
- name: Dokken
uses: actionshub/test-kitchen@2.1.0
env:
CHEF_LICENSE: accept-no-persist
KITCHEN_LOCAL_YAML: kitchen.dokken.yml
with:
suite: ${{ matrix.suite }}
os: ${{ matrix.os }}
17 changes: 8 additions & 9 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,24 @@ This file is used to list changes made in each version of the postfix cookbook.

## Unreleased

## 6.0.29 - *2024-11-18*
- Correctly fix aliases quoting logic
- Convert all serverspec tests to inspec
- Add Github actions
- Update platforms to test

Standardise files with files in sous-chefs/repo-management
## 6.0.29 - *2024-11-18*

Standardise files with files in sous-chefs/repo-management
- Standardise files with files in sous-chefs/repo-management

## 6.0.28 - *2024-07-15*

Standardise files with files in sous-chefs/repo-management

Standardise files with files in sous-chefs/repo-management

Standardise files with files in sous-chefs/repo-management
- Standardise files with files in sous-chefs/repo-management

## 6.0.27 - *2024-05-06*

## 6.0.26 - *2023-10-03*

- add installation of postfix addon packages for RHEL 8
- Add installation of postfix addon packages for RHEL 8

## 6.0.25 - *2023-10-03*

Expand Down
23 changes: 18 additions & 5 deletions kitchen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,18 @@ verifier:

platforms:
- name: almalinux-8
- name: amazonlinux-2
- name: centos-7
- name: centos-stream-8
- name: debian-10
- name: almalinux-9
- name: amazonlinux-2023
- name: centos-stream-9
- name: debian-11
- name: debian-12
- name: fedora-latest
- name: opensuse-leap-15
- name: rockylinux-8
- name: ubuntu-18.04
- name: rockylinux-9
- name: ubuntu-20.04
- name: ubuntu-22.04
- name: ubuntu-24.04

suites:
- name: default
Expand All @@ -33,6 +35,17 @@ suites:
- name: aliases
run_list:
- recipe[postfix::aliases]
attributes:
postfix:
aliases:
foo1: bar
foo@bar: foo
foo2: "|/usr/bin/bar"
foo3: foo,bar
foo4: foo@example.com
foo5:
- foo
- bar

- name: client
run_list:
Expand Down
2 changes: 1 addition & 1 deletion templates/aliases.erb
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@
postmaster: root

<% node['postfix']['aliases'].each do |name, value| %>
<%= name %>: <%= [value].flatten.map{|x| if (x.include?("@")) then x else %Q("#{x}") end}.join(', ') %>
<%= name.match?(/[\s#:@]/) ? "\"#{name}\"" : name %>: <%= [value].flatten.map{|x| x.include?("|") ? "\"#{x}\"" : x}.join(',') %>
<% end unless node['postfix']['aliases'].nil? %>
3 changes: 3 additions & 0 deletions test/fixtures/cookbooks/test/recipes/net_setup.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# sysctl missing on SUSE
package 'procps' if platform_family?('suse')

sysctl 'net.ipv6.conf.lo.disable_ipv6' do
value 0
end
21 changes: 21 additions & 0 deletions test/integration/aliases/controls/aliases.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
control 'aliases' do
describe file '/etc/aliases' do
its('content') do
should cmp <<~EOF
#
# Auto-generated by Chef.
# Local modifications will be overwritten.
#
# See man 5 aliases for format
postmaster: root
foo1: bar
"foo@bar": foo
foo2: "|/usr/bin/bar"
foo3: foo,bar
foo4: foo@example.com
foo5: foo,bar
EOF
end
end
end
1 change: 1 addition & 0 deletions test/integration/aliases/inspec.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
name: aliases
24 changes: 0 additions & 24 deletions test/integration/aliases/serverspec/aliases_spec.rb

This file was deleted.

17 changes: 17 additions & 0 deletions test/integration/canonical/controls/canonical.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
recipient_canonical =
case os.family
when 'suse'
'/etc/postfix/recipient_canonical.lmdb'
else
'/etc/postfix/recipient_canonical.db'
end

control 'canonical' do
describe file recipient_canonical do
it { should be_file }
end

describe file '/etc/postfix/main.cf' do
its('content') { should match(%r{^\s*recipient_canonical_maps\s*=.*\/etc\/postfix\/recipient_canonical\s*$}) }
end
end
1 change: 1 addition & 0 deletions test/integration/canonical/inspec.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
name: canonical
23 changes: 0 additions & 23 deletions test/integration/canonical/serverspec/canonical_spec.rb

This file was deleted.

7 changes: 7 additions & 0 deletions test/integration/client/controls/client.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
include_controls 'default'

control 'client' do
describe file '/etc/postfix/main.cf' do
its('content') { should match /Configured as client/ }
end
end
4 changes: 4 additions & 0 deletions test/integration/client/inspec.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
name: client
depends:
- name: default
path: test/integration/default
22 changes: 0 additions & 22 deletions test/integration/client/serverspec/client_spec.rb

This file was deleted.

14 changes: 14 additions & 0 deletions test/integration/default/controls/default.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
control 'default' do
describe package 'postfix' do
it { should be_installed }
end

describe service 'postfix' do
it { should be_enabled }
it { should be_running }
end

describe file '/etc/postfix/main.cf' do
its('content') { should match(/^# Auto-generated by Chef/) }
end
end
1 change: 1 addition & 0 deletions test/integration/default/inspec.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
name: default
33 changes: 0 additions & 33 deletions test/integration/default/serverspec/default_spec.rb

This file was deleted.

19 changes: 0 additions & 19 deletions test/integration/helpers/serverspec/spec_helper.rb

This file was deleted.

19 changes: 19 additions & 0 deletions test/integration/sasl_auth_multiple/controls/sasl_auth_multiple.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
control 'sasl_auth_multiple' do
describe file '/etc/postfix/sasl_passwd' do
its('content') do
should cmp <<~EOF
# Auto-generated by Chef.
# Local modifications will be overwritten.
relayhost1 kitchenuser:not-a-real-thing
relayhost2 anotherkitchenuser:yet-not-a-real-thing
smtp_sasl_passwd :
smtp_sasl_user_name :
EOF
end
end

describe postfix_conf '/etc/postfix/main.cf' do
its('smtp_sasl_password_maps') { should eq 'hash:/etc/postfix/sasl_passwd' }
end
end
1 change: 1 addition & 0 deletions test/integration/sasl_auth_multiple/inspec.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
name: sasl_auth_multiple
Loading

0 comments on commit 1cd55ab

Please # to comment.