From b7352754dfbe96adce5b1f3417c07c4ea11af41f Mon Sep 17 00:00:00 2001 From: Brennan Kinney <5098581+polarathene@users.noreply.github.com> Date: Mon, 17 Feb 2025 17:26:58 +1300 Subject: [PATCH] tests: Adjust for change in logs --- target/bin/open-dkim | 15 ++++++++------- target/scripts/startup/setup.d/dmarc_dkim_spf.sh | 6 +++++- test/tests/serial/open_dkim.bats | 16 ++++++++-------- 3 files changed, 21 insertions(+), 16 deletions(-) diff --git a/target/bin/open-dkim b/target/bin/open-dkim index e34086d9..1cfc7532 100755 --- a/target/bin/open-dkim +++ b/target/bin/open-dkim @@ -78,7 +78,7 @@ function _parse_arguments() { ( 'keysize' ) if [[ -n ${2+set} ]]; then KEYSIZE="${2}" - _log 'debug' "Keysize set to '${KEYSIZE}'" + _log 'trace' "Keysize set to '${KEYSIZE}'" else _exit_with_error "No keysize provided after 'keysize' argument" fi @@ -87,7 +87,7 @@ function _parse_arguments() { ( 'selector' ) if [[ -n ${2+set} ]]; then SELECTOR="${2}" - _log 'debug' "Selector set to '${SELECTOR}'" + _log 'trace' "Selector set to '${SELECTOR}'" else _exit_with_error "No selector provided after 'selector' argument" fi @@ -96,7 +96,7 @@ function _parse_arguments() { ( 'domain' ) if [[ -n ${2+set} ]]; then DMS_DOMAINS="${2}" - _log 'debug' "Domain(s) set to '${DMS_DOMAINS}'" + _log 'trace' "Domain(s) set to '${DMS_DOMAINS}'" else _exit_with_error "No domain(s) provided after 'domain' argument" fi @@ -209,8 +209,6 @@ SIGNING_TABLE_FILE="${OPENDKIM_BASE_DIR}/SigningTable" TRUSTED_HOSTS_FILE="${OPENDKIM_BASE_DIR}/TrustedHosts" # Create configs if missing: function _create_opendkim_configs() { - _log 'debug' 'Creating any missing OpenDKIM configs' - mkdir -p "${OPENDKIM_BASE_DIR}" local OPENDKIM_CONFIGS=( "${KEY_TABLE_FILE}" @@ -219,8 +217,11 @@ function _create_opendkim_configs() { ) # Only create if the file doesn't exist (avoids modifying mtime): - for FILE in ${OPENDKIM_CONFIGS[@]}; do - [[ ! -f "${FILE}" ]] && touch "${FILE}" + for FILE in "${OPENDKIM_CONFIGS[@]}"; do + if [[ ! -f "${FILE}" ]]; then + _log 'debug' "Creating OpenDKIM config '${FILE}'" + touch "${FILE}" + fi done # If file exists but is empty, add default hosts to trust: diff --git a/target/scripts/startup/setup.d/dmarc_dkim_spf.sh b/target/scripts/startup/setup.d/dmarc_dkim_spf.sh index c0d731f2..7b26f86b 100644 --- a/target/scripts/startup/setup.d/dmarc_dkim_spf.sh +++ b/target/scripts/startup/setup.d/dmarc_dkim_spf.sh @@ -23,7 +23,11 @@ function _setup_opendkim() { # check if any keys are available if [[ -e /tmp/docker-mailserver/opendkim/KeyTable ]]; then cp -a /tmp/docker-mailserver/opendkim/* /etc/opendkim/ - _log 'trace' "DKIM keys added for: $(find /etc/opendkim/keys/ -maxdepth 1 -type f -printf '%f ')" + + local DKIM_DOMAINS + DKIM_DOMAINS=$(find /etc/opendkim/keys/ -maxdepth 1 -type f -printf '%f ') + _log 'trace' "DKIM keys added for: ${DKIM_DOMAINS}" + chown -R opendkim:opendkim /etc/opendkim/ chmod -R 0700 /etc/opendkim/keys/ else diff --git a/test/tests/serial/open_dkim.bats b/test/tests/serial/open_dkim.bats index e51fdedb..b43b850f 100644 --- a/test/tests/serial/open_dkim.bats +++ b/test/tests/serial/open_dkim.bats @@ -62,7 +62,7 @@ function teardown() { _default_teardown ; } __init_container_without_waiting - __should_generate_dkim_key 6 + __should_generate_dkim_key 7 __assert_outputs_common_dkim_logs __should_have_tables_trustedhosts_for_domain @@ -78,7 +78,7 @@ function teardown() { _default_teardown ; } # Only mount single config file (postfix-virtual.cf): __init_container_without_waiting "${PWD}/test/config/postfix-virtual.cf:/tmp/docker-mailserver/postfix-virtual.cf:ro" - __should_generate_dkim_key 5 + __should_generate_dkim_key 6 __assert_outputs_common_dkim_logs __should_have_tables_trustedhosts_for_domain @@ -95,7 +95,7 @@ function teardown() { _default_teardown ; } # Only mount single config file (postfix-accounts.cf): __init_container_without_waiting "${PWD}/test/config/postfix-accounts.cf:/tmp/docker-mailserver/postfix-accounts.cf:ro" - __should_generate_dkim_key 5 + __should_generate_dkim_key 6 __assert_outputs_common_dkim_logs __should_have_tables_trustedhosts_for_domain @@ -113,7 +113,7 @@ function teardown() { _default_teardown ; } __init_container_without_waiting '/tmp/docker-mailserver' # generate first key (with a custom selector) - __should_generate_dkim_key 4 '1024' 'domain1.tld' 'mailer' + __should_generate_dkim_key 5 '1024' 'domain1.tld' 'mailer' __assert_outputs_common_dkim_logs # generate two additional keys different to the previous one __should_generate_dkim_key 2 '1024' 'domain2.tld,domain3.tld' @@ -183,15 +183,15 @@ function __assert_logged_dkim_creation() { function __assert_outputs_common_dkim_logs() { refute_output --partial 'No entries found, no keys to make' - assert_output --partial 'Creating DKIM KeyTable' - assert_output --partial 'Creating DKIM SigningTable' - assert_output --partial 'Creating DKIM TrustedHosts' + assert_output --partial "Creating OpenDKIM config '/tmp/docker-mailserver/opendkim/KeyTable'" + assert_output --partial "Creating OpenDKIM config '/tmp/docker-mailserver/opendkim/SigningTable'" + assert_output --partial "Creating OpenDKIM config '/tmp/docker-mailserver/opendkim/TrustedHosts'" } function __should_support_creating_key_of_size() { local EXPECTED_KEYSIZE=${1:-} - __should_generate_dkim_key 6 "${EXPECTED_KEYSIZE}" + __should_generate_dkim_key 7 "${EXPECTED_KEYSIZE}" __assert_outputs_common_dkim_logs __assert_logged_dkim_creation 'localdomain2.com' __assert_logged_dkim_creation 'localhost.localdomain'