Correctly fix aliases quoting logic (#206)
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>
This commit is contained in:
21
test/integration/aliases/controls/aliases.rb
Normal file
21
test/integration/aliases/controls/aliases.rb
Normal file
@@ -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
test/integration/aliases/inspec.yml
Normal file
1
test/integration/aliases/inspec.yml
Normal file
@@ -0,0 +1 @@
|
||||
name: aliases
|
||||
@@ -1,24 +0,0 @@
|
||||
# Copyright:: 2012-2019, Chef Software, Inc.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
require_relative './spec_helper'
|
||||
|
||||
describe 'postfix::aliases' do
|
||||
context 'configures' do
|
||||
describe file('/etc/aliases') do
|
||||
its(:content) { should match(/^# Auto-generated by Chef/) }
|
||||
end
|
||||
end
|
||||
end
|
||||
17
test/integration/canonical/controls/canonical.rb
Normal file
17
test/integration/canonical/controls/canonical.rb
Normal file
@@ -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
test/integration/canonical/inspec.yml
Normal file
1
test/integration/canonical/inspec.yml
Normal file
@@ -0,0 +1 @@
|
||||
name: canonical
|
||||
@@ -1,23 +0,0 @@
|
||||
# Copyright:: 2012-2019, Chef Software, Inc.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
require_relative './spec_helper'
|
||||
|
||||
describe file('/etc/postfix/recipient_canonical.db') 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
|
||||
7
test/integration/client/controls/client.rb
Normal file
7
test/integration/client/controls/client.rb
Normal file
@@ -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
test/integration/client/inspec.yml
Normal file
4
test/integration/client/inspec.yml
Normal file
@@ -0,0 +1,4 @@
|
||||
name: client
|
||||
depends:
|
||||
- name: default
|
||||
path: test/integration/default
|
||||
@@ -1,22 +0,0 @@
|
||||
# Copyright:: 2012-2019, Chef Software, Inc.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
require_relative './spec_helper'
|
||||
|
||||
describe 'postfix::client' do
|
||||
it 'doesnt configure postfix because solo is unsupported' do
|
||||
pending 'Postfix may be set up by default on the system, but not configured by Chef because this test assumes it is run under Chef Solo'
|
||||
end
|
||||
end
|
||||
14
test/integration/default/controls/default.rb
Normal file
14
test/integration/default/controls/default.rb
Normal file
@@ -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
test/integration/default/inspec.yml
Normal file
1
test/integration/default/inspec.yml
Normal file
@@ -0,0 +1 @@
|
||||
name: default
|
||||
@@ -1,33 +0,0 @@
|
||||
# Copyright:: 2012-2019, Chef Software, Inc.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
require_relative './spec_helper'
|
||||
|
||||
describe 'postfix::default' do
|
||||
describe package('postfix') do
|
||||
it { should be_installed }
|
||||
end
|
||||
|
||||
describe service('postfix') do
|
||||
it { should be_enabled }
|
||||
it { should be_running }
|
||||
end
|
||||
|
||||
context 'configures' do
|
||||
describe file("#{postfix_conf_path}/main.cf") do
|
||||
its(:content) { should match(/^# Auto-generated by Chef/) }
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -1,19 +0,0 @@
|
||||
require 'serverspec'
|
||||
|
||||
set :backend, :exec
|
||||
set :path, '/sbin:/usr/local/sbin:$PATH'
|
||||
|
||||
def family
|
||||
fam = 'solaris2'
|
||||
return fam unless File.exist? '/etc/release'
|
||||
fam = 'omnios' if File.read('/etc/release') =~ /^\s*(OmniOS)/
|
||||
fam
|
||||
end
|
||||
|
||||
def postfix_conf_path
|
||||
if os[:family] == 'solaris' && family == 'omnios'
|
||||
'/opt/omni/etc/postfix/'
|
||||
else
|
||||
'/etc/postfix'
|
||||
end
|
||||
end
|
||||
@@ -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
test/integration/sasl_auth_multiple/inspec.yml
Normal file
1
test/integration/sasl_auth_multiple/inspec.yml
Normal file
@@ -0,0 +1 @@
|
||||
name: sasl_auth_multiple
|
||||
@@ -1,31 +0,0 @@
|
||||
# Copyright:: 2012-2019, Chef Software, Inc.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
require_relative './spec_helper'
|
||||
|
||||
describe 'postfix::sasl_auth' do
|
||||
let(:sasl_passwd_file) { '/etc/postfix/sasl_passwd' }
|
||||
|
||||
it 'manages postfix sasl_passwd' do
|
||||
expect(file(sasl_passwd_file).content).to match(/^# This file is generated by Chef for/)
|
||||
end
|
||||
|
||||
it 'configures postfix to use the sasl_passwd file' do
|
||||
expect(file('/etc/postfix/main.cf').content).to match(/^\s*smtp_sasl_password_maps\s*=.*#{sasl_passwd_file}\s*$/)
|
||||
end
|
||||
|
||||
it 'configures postfix sasl_passwd with multiple entries' do
|
||||
expect(file(sasl_passwd_file).content).to match(/^# This file is generated by Chef for .*\nrelayhost1 kitchenuser:not-a-real-thing\nrelayhost2 anotherkitchenuser:yet-not-a-real-thing\n/)
|
||||
end
|
||||
end
|
||||
17
test/integration/sasl_auth_none/controls/sasl_auth_none.rb
Normal file
17
test/integration/sasl_auth_none/controls/sasl_auth_none.rb
Normal file
@@ -0,0 +1,17 @@
|
||||
control 'sasl_auth_none' do
|
||||
describe file '/etc/postfix/sasl_passwd' do
|
||||
its('content') do
|
||||
should cmp <<~EOF
|
||||
# Auto-generated by Chef.
|
||||
# Local modifications will be overwritten.
|
||||
|
||||
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
test/integration/sasl_auth_none/inspec.yml
Normal file
1
test/integration/sasl_auth_none/inspec.yml
Normal file
@@ -0,0 +1 @@
|
||||
name: sasl_auth_none
|
||||
@@ -1,31 +0,0 @@
|
||||
# Copyright:: 2012-2019, Chef Software, Inc.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
require_relative './spec_helper'
|
||||
|
||||
describe 'postfix::sasl_auth' do
|
||||
let(:sasl_passwd_file) { '/etc/postfix/sasl_passwd' }
|
||||
|
||||
it 'manages postfix sasl_passwd' do
|
||||
expect(file(sasl_passwd_file).content).to match(/^# Auto-generated by Chef/)
|
||||
end
|
||||
|
||||
it 'configures postfix to use the sasl_passwd file' do
|
||||
expect(file('/etc/postfix/main.cf').content).to match(/^\s*smtp_sasl_password_maps\s*=.*#{sasl_passwd_file}\s*$/)
|
||||
end
|
||||
|
||||
it 'configures postfix sasl_passwd with nothing in it' do
|
||||
expect(file(sasl_passwd_file).content).to match(/^# This file is generated by Chef for .*\n/)
|
||||
end
|
||||
end
|
||||
18
test/integration/sasl_auth_one/controls/sasl_auth_one.rb
Normal file
18
test/integration/sasl_auth_one/controls/sasl_auth_one.rb
Normal file
@@ -0,0 +1,18 @@
|
||||
control 'sasl_auth_one' do
|
||||
describe file '/etc/postfix/sasl_passwd' do
|
||||
its('content') do
|
||||
should cmp <<~EOF
|
||||
# Auto-generated by Chef.
|
||||
# Local modifications will be overwritten.
|
||||
|
||||
relayhost kitchenuser: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
test/integration/sasl_auth_one/inspec.yml
Normal file
1
test/integration/sasl_auth_one/inspec.yml
Normal file
@@ -0,0 +1 @@
|
||||
name: sasl_auth_one
|
||||
@@ -1,31 +0,0 @@
|
||||
# Copyright:: 2012-2019, Chef Software, Inc.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
require_relative './spec_helper'
|
||||
|
||||
describe 'postfix::sasl_auth' do
|
||||
let(:sasl_passwd_file) { '/etc/postfix/sasl_passwd' }
|
||||
|
||||
it 'manages postfix sasl_passwd' do
|
||||
expect(file(sasl_passwd_file).content).to match(/^# This file is generated by Chef for/)
|
||||
end
|
||||
|
||||
it 'configures postfix to use the sasl_passwd file' do
|
||||
expect(file('/etc/postfix/main.cf').content).to match(/^\s*smtp_sasl_password_maps\s*=.*#{sasl_passwd_file}\s*$/)
|
||||
end
|
||||
|
||||
it 'configures postfix sasl_passwd with one entry' do
|
||||
expect(file(sasl_passwd_file).content).to match(/^# This file is generated by Chef for .*\nrelayhost kitchenuser:not-a-real-thing\n/)
|
||||
end
|
||||
end
|
||||
7
test/integration/server/controls/server.rb
Normal file
7
test/integration/server/controls/server.rb
Normal file
@@ -0,0 +1,7 @@
|
||||
include_controls 'default'
|
||||
|
||||
control 'server' do
|
||||
describe file '/etc/postfix/main.cf' do
|
||||
its('content') { should match /Configured as master/ }
|
||||
end
|
||||
end
|
||||
4
test/integration/server/inspec.yml
Normal file
4
test/integration/server/inspec.yml
Normal file
@@ -0,0 +1,4 @@
|
||||
name: server
|
||||
depends:
|
||||
- name: default
|
||||
path: test/integration/default
|
||||
@@ -1,21 +0,0 @@
|
||||
# Copyright:: 2012-2019, Chef Software, Inc.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
require_relative './spec_helper'
|
||||
|
||||
describe 'postfix::server' do
|
||||
it 'doesnt configure postfix because solo is unsupported' do
|
||||
pending 'Postfix may be set up by default on the system, but not configured by Chef because this test assumes it is run under Chef Solo'
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user