From 253c8faef61c3544ddb006c291105b02dd8febc3 Mon Sep 17 00:00:00 2001 From: Marek Walczak <2558195+mwlczk@users.noreply.github.com> Date: Sat, 3 Mar 2018 09:20:23 +0100 Subject: [PATCH] Dkim key size - Addon (#871) * added Tests --- Makefile | 4 ++- setup.sh | 4 +-- test/tests.bats | 70 +++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 75 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index cc8aa3f0..8d18e0cc 100644 --- a/Makefile +++ b/Makefile @@ -263,9 +263,11 @@ clean: fi -sudo rm -rf test/onedir \ test/config/empty \ + test/config/keyDefault \ + test/config/key2048 \ + test/config/key1024 \ test/config/without-accounts \ test/config/without-virtual \ test/config/with-domain \ test/config/dovecot-lmtp/userdb \ test/config/postfix-*-access.cf* - diff --git a/setup.sh b/setup.sh index bc5b6569..9964d35c 100755 --- a/setup.sh +++ b/setup.sh @@ -58,7 +58,7 @@ SUBCOMMANDS: config: - $0 config dkim + $0 config dkim (default: 2048) $0 config ssl debug: @@ -186,7 +186,7 @@ case $1 in shift case $1 in dkim) - _docker_image generate-dkim-config + _docker_image generate-dkim-config $2 ;; ssl) _docker_image generate-ssl-certificate diff --git a/test/tests.bats b/test/tests.bats index a7a1ebf6..e4878406 100644 --- a/test/tests.bats +++ b/test/tests.bats @@ -527,6 +527,76 @@ load 'test_helper/bats-assert/load' assert_output 2 } + +# this set of tests is of low quality. It does not test the RSA-Key size properly via openssl or similar +# Instead it tests the file-size (here 511) - which may differ with a different domain names +# This test may be re-used as a global test to provide better test coverage. +@test "checking opendkim: generator creates default keys size" { + # Prepare default key size 2048 + rm -rf "$(pwd)/test/config/keyDefault" && mkdir -p "$(pwd)/test/config/keyDefault" + run docker run --rm \ + -v "$(pwd)/test/config/keyDefault/":/tmp/docker-mailserver/ \ + -v "$(pwd)/test/config/postfix-accounts.cf":/tmp/docker-mailserver/postfix-accounts.cf \ + -v "$(pwd)/test/config/postfix-virtual.cf":/tmp/docker-mailserver/postfix-virtual.cf \ + `docker inspect --format '{{ .Config.Image }}' mail` /bin/sh -c 'generate-dkim-config | wc -l' + assert_success + assert_output 6 + + run docker run --rm \ + -v "$(pwd)/test/config/keyDefault/opendkim":/etc/opendkim \ + `docker inspect --format '{{ .Config.Image }}' mail` \ + /bin/sh -c 'stat -c%s /etc/opendkim/keys/localhost.localdomain/mail.txt' + + assert_success + assert_output 511 +} + +# this set of tests is of low quality. It does not test the RSA-Key size properly via openssl or similar +# Instead it tests the file-size (here 511) - which may differ with a different domain names +# This test may be re-used as a global test to provide better test coverage. +@test "checking opendkim: generator creates key size 2048" { + # Prepare set key size 2048 + rm -rf "$(pwd)/test/config/key2048" && mkdir -p "$(pwd)/test/config/key2048" + run docker run --rm \ + -v "$(pwd)/test/config/key2048/":/tmp/docker-mailserver/ \ + -v "$(pwd)/test/config/postfix-accounts.cf":/tmp/docker-mailserver/postfix-accounts.cf \ + -v "$(pwd)/test/config/postfix-virtual.cf":/tmp/docker-mailserver/postfix-virtual.cf \ + `docker inspect --format '{{ .Config.Image }}' mail` /bin/sh -c 'generate-dkim-config 2048 | wc -l' + assert_success + assert_output 6 + + run docker run --rm \ + -v "$(pwd)/test/config/key2048/opendkim":/etc/opendkim \ + `docker inspect --format '{{ .Config.Image }}' mail` \ + /bin/sh -c 'stat -c%s /etc/opendkim/keys/localhost.localdomain/mail.txt' + + assert_success + assert_output 511 +} + +# this set of tests is of low quality. It does not test the RSA-Key size properly via openssl or similar +# Instead it tests the file-size (here 329) - which may differ with a different domain names +# This test may be re-used as a global test to provide better test coverage. +@test "checking opendkim: generator creates key size 1024" { + # Prepare set key size 1024 + rm -rf "$(pwd)/test/config/key1024" && mkdir -p "$(pwd)/test/config/key1024" + run docker run --rm \ + -v "$(pwd)/test/config/key1024/":/tmp/docker-mailserver/ \ + -v "$(pwd)/test/config/postfix-accounts.cf":/tmp/docker-mailserver/postfix-accounts.cf \ + -v "$(pwd)/test/config/postfix-virtual.cf":/tmp/docker-mailserver/postfix-virtual.cf \ + `docker inspect --format '{{ .Config.Image }}' mail` /bin/sh -c 'generate-dkim-config 1024 | wc -l' + assert_success + assert_output 6 + + run docker run --rm \ + -v "$(pwd)/test/config/key1024/opendkim":/etc/opendkim \ + `docker inspect --format '{{ .Config.Image }}' mail` \ + /bin/sh -c 'stat -c%s /etc/opendkim/keys/localhost.localdomain/mail.txt' + + assert_success + assert_output 329 +} + @test "checking opendkim: generator creates keys, tables and TrustedHosts" { rm -rf "$(pwd)/test/config/empty" && mkdir -p "$(pwd)/test/config/empty" run docker run --rm \