Testing

<!-- NOTES - Notes here --> <!-- GOAL ONE-LINER --> <p>Verify whether dovecot has been correctly configured for retrieving mail.</p> <!-- RATIONALE --> <p>After configuring dovecot, the mail server should be capable of receiving e-mails. In order to verify the configuration, <a href="https://linux.die.net/man/1/swaks">swaks</a> is used to mimic an external SMTP server by sending emails. By mimicking an external SMTP server, a variety of happy flow and error flow scenarios can be explicitly tested.</p> <!-- NUANCE --> <blockquote> <p>:warning: <strong>WARNING</strong>: These tests assumes availability of the <a href="/mailserver/dovecot-storage-config/testing/Mail-server_Example-data-import">test data imported earlier</a>!</p> </blockquote> <h2>Procedure</h2> <!-- NARRATIVE FORM --> <!-- STEP BY STEP --> <ol start="0"> <li> <p>Ensure swaks is installed on the system you are executed the tests from:</p> <pre><code class="language-shell"># Clear the mail related log files apt install -y swaks</code></pre> </li> <li> <p>Clear the mail related log files to prevent possible false positive test results later:</p> <pre><code class="language-shell"># Clear the mail related log files echo " " &gt; /var/log/mail.log echo " " &gt; /var/log/mail.err echo " " &gt; /var/log/mail.info</code></pre> </li> <li> <p>Execute the following SMTP protocol tests (<code>PASSED</code> reflects correct operation):</p> <pre><code class="language-shell"># Configure the ip address being used (to avoid having to retype it every time ip=&lt;MAIL SERVER IP&gt; # Test whether e-mails to a known user / known domain combination gets accepted swaks --to john.doe@example.org --server $ip | grep "250 2.0.0 Ok: queued as" &amp;&amp; echo "PASSED" || echo "FAILED" # Test whether e-mails to a known user/unknown domain combination get rejected swaks --to john.doe@unknowndomain.org --server $ip | grep "454 4.7.1 &lt;john.doe@unknowndomain.org&gt;: Relay access denied" &amp;&amp; echo "PASSED" || echo "FAILED" # Test whether e-mails addressed to a known, specific, alias get accepted swaks --to jane.doe@example.org --server $ip | grep "250 2.0.0 Ok: queued as" &amp;&amp; echo "PASSED" || echo "FAILED" # Test whether e-mails to a known, catchall alias get accepted swaks --to catchall@example.org --server $ip | grep "250 2.0.0 Ok: queued as" &amp;&amp; echo "PASSED" || echo "FAILED"</code></pre> <p><code>&lt;MAIL SERVER IP&gt;</code> is local IP address (e.g. 192.168.1.x) of the mail server.</p> <blockquote> <p>:warning: <strong>WARNING</strong>: Don't use localhost (127.0.0.1), as this changes the server feedback!</p> </blockquote> </li> <li> <p>Check the mail.log whether the aliases correctly got processed:</p> <pre><code class="language-shell"># Test whether the known, specific, alias correctly got resolved (during step 1 execution) grep "to=&lt;john.doe@example.org&gt;, orig_to=&lt;jane.doe@example.org&gt;" /var/log/mail.log &amp;&amp; echo "PASSED" || echo "FAILED" # Test whether the known catch-all alias correctly got resolved (during step 1 execution) grep "to=&lt;jack.doe@example.org&gt;, orig_to=&lt;catchall@example.org&gt;" /var/log/mail.log &amp;&amp; echo "PASSED" || echo "FAILED"</code></pre> </li> <li> <p>Execute the SMTP protocol scenario that cannot be executed having a catch all alias active:</p> <pre><code class="language-shell"># Open mysql mysql</code></pre> <pre><code class="language-mysql">-- Remove the catch-all alias from the MySQL database DELETE FROM `mailserver`.`aliases` WHERE `source` = '@example.org'; exit;</code></pre> <pre><code class="language-shell"># Configure the ip address being used (to avoid having to retype it every time ip=&lt;MAIL SERVER IP&gt; # Test whether e-mails to an unknown user / known domain get rejected swaks --to unknownuser@example.org --server $ip | grep "550 5.1.1 &lt;unknownuser@example.org&gt;: Recipient address rejected: User unknown in virtual mailbox table" &amp;&amp; echo "PASSED" || echo "FAILED"</code></pre> <p><code>&lt;MAIL SERVER IP&gt;</code> is local IP address (e.g. 192.168.1.x) of the mail server.</p> <blockquote> <p>:warning: <strong>WARNING</strong>: Don't use localhost (127.0.0.1), as this changes the server feedback!</p> </blockquote> <pre><code class="language-shell"># Open mysql mysql</code></pre> <pre><code class="language-mysql">-- Restore the catch-all entry: INSERT INTO `mailserver`.`aliases` (`domain`, `source`, `destination`) VALUES ('example.org', '@example.org', 'jack.doe@example.org'); exit;</code></pre> </li> </ol> <!-- REFERENCES -->