From a1fe1b73e197fcee92a684af0a62608067456159 Mon Sep 17 00:00:00 2001 From: Tom Hughes Date: Sun, 1 Mar 2020 16:40:07 +0000 Subject: [PATCH] Add test for mail role --- .github/workflows/test-kitchen.yml | 1 + .kitchen.yml | 3 +++ cookbooks/exim/recipes/default.rb | 4 +++- roles/mail.rb | 1 + test/data_bags/exim/aliases.json | 6 +++++ test/data_bags/exim/dkim.json | 7 ++++++ .../mail/serverspec/clamav_spec.rb | 22 +++++++++++++++++++ test/integration/mail/serverspec/exim_spec.rb | 17 ++++++++++++++ .../mail/serverspec/spamassassin_spec.rb | 17 ++++++++++++++ 9 files changed, 77 insertions(+), 1 deletion(-) create mode 100644 test/data_bags/exim/aliases.json create mode 100644 test/data_bags/exim/dkim.json create mode 100644 test/integration/mail/serverspec/clamav_spec.rb create mode 100644 test/integration/mail/serverspec/exim_spec.rb create mode 100644 test/integration/mail/serverspec/spamassassin_spec.rb diff --git a/.github/workflows/test-kitchen.yml b/.github/workflows/test-kitchen.yml index e15ed4eac..613addabd 100644 --- a/.github/workflows/test-kitchen.yml +++ b/.github/workflows/test-kitchen.yml @@ -44,6 +44,7 @@ jobs: - letsencrypt - logstash - logstash-forwarder + - mail - mailman - memcached - munin diff --git a/.kitchen.yml b/.kitchen.yml index e63b8b855..c116e2411 100644 --- a/.kitchen.yml +++ b/.kitchen.yml @@ -165,6 +165,9 @@ suites: paths: - /var/log/apache2/access.log type: apache + - name: mail + run_list: + - role[mail] - name: mailman run_list: - recipe[mailman::default] diff --git a/cookbooks/exim/recipes/default.rb b/cookbooks/exim/recipes/default.rb index 6af07c8e1..9266425e3 100644 --- a/cookbooks/exim/recipes/default.rb +++ b/cookbooks/exim/recipes/default.rb @@ -26,7 +26,9 @@ package %w[ ssl-cert ] -package "exim4-daemon-heavy" if File.exist?("/var/run/clamav/clamd.ctl") +package "exim4-daemon-heavy" do + only_if { ::File.exist?("/var/run/clamav/clamd.ctl") } +end group "ssl-cert" do action :modify diff --git a/roles/mail.rb b/roles/mail.rb index 99fcf1a08..c1c7d307c 100644 --- a/roles/mail.rb +++ b/roles/mail.rb @@ -91,5 +91,6 @@ default_attributes( run_list( "recipe[clamav]", + "recipe[exim]", "recipe[spamassassin]" ) diff --git a/test/data_bags/exim/aliases.json b/test/data_bags/exim/aliases.json new file mode 100644 index 000000000..7003ab2d4 --- /dev/null +++ b/test/data_bags/exim/aliases.json @@ -0,0 +1,6 @@ +{ + "id": "aliases", + "mail": { + "test": "test@example.com" + } +} diff --git a/test/data_bags/exim/dkim.json b/test/data_bags/exim/dkim.json new file mode 100644 index 000000000..0a20d504f --- /dev/null +++ b/test/data_bags/exim/dkim.json @@ -0,0 +1,7 @@ +{ + "id": "dkim", + "openstreetmap.org": [ + "-----BEGIN RSA PRIVATE KEY-----", + "-----END RSA PRIVATE KEY-----" + ] +} diff --git a/test/integration/mail/serverspec/clamav_spec.rb b/test/integration/mail/serverspec/clamav_spec.rb new file mode 100644 index 000000000..ce8687e5b --- /dev/null +++ b/test/integration/mail/serverspec/clamav_spec.rb @@ -0,0 +1,22 @@ +require "serverspec" + +# Required by serverspec +set :backend, :exec + +describe package("clamav-daemon") do + it { should be_installed } +end + +describe service("clamav-daemon") do + it { should be_enabled } + it { should be_running } +end + +describe package("clamav-freshclam") do + it { should be_installed } +end + +describe service("clamav-freshclam") do + it { should be_enabled } + it { should be_running } +end diff --git a/test/integration/mail/serverspec/exim_spec.rb b/test/integration/mail/serverspec/exim_spec.rb new file mode 100644 index 000000000..2a6f6b2a9 --- /dev/null +++ b/test/integration/mail/serverspec/exim_spec.rb @@ -0,0 +1,17 @@ +require "serverspec" + +# Required by serverspec +set :backend, :exec + +describe package("exim4") do + it { should be_installed } +end + +describe service("exim4") do + it { should be_enabled } + it { should be_running } +end + +describe port(25) do + it { should be_listening.with("tcp") } +end diff --git a/test/integration/mail/serverspec/spamassassin_spec.rb b/test/integration/mail/serverspec/spamassassin_spec.rb new file mode 100644 index 000000000..1276f140c --- /dev/null +++ b/test/integration/mail/serverspec/spamassassin_spec.rb @@ -0,0 +1,17 @@ +require "serverspec" + +# Required by serverspec +set :backend, :exec + +describe package("spamassassin") do + it { should be_installed } +end + +describe service("spamassassin") do + it { should be_enabled } + it { should be_running } +end + +describe port(783) do + it { should be_listening.with("tcp") } +end -- 2.39.5