#!/bin/bash set -e pw_file="/etc/kea/kea-api-password" pw_secret="secret_password_${RANDOM}" service="kea-ctrl-agent.service" cleanup() { /bin/true } trap cleanup EXIT override_systemd_throttling() { mkdir -p /run/systemd/system/kea-ctrl-agent.service.d cat > /run/systemd/system/kea-ctrl-agent.service.d/override.conf < "${pw_file}" echo "## Reconfiguring" reconfigure_unconfigured echo echo "## ${pw_file} should still contain ${new_secret}" contents=$(cat "${pw_file}") if [ "${contents}" != "${new_secret}" ]; then echo "## ERROR, ${pw_file} now contains \"${contents}\"" return 1 else echo "## OK, same content" fi echo "## Removing ${pw_file} and reconfiguring, a new one should not be created, and the service must be stopped" rm -f "${pw_file}" ls -la $(dirname "${pw_file}") echo "## Reconfiguring" reconfigure_unconfigured echo "## ${pw_file} was not recreated" ls -la $(dirname "${pw_file}") test ! -f "${pw_file}" echo "## With no ${pw_file}, the service must not be running" service_status_must_be inactive } test_no_start_with_empty_password() { echo echo "## Running ${FUNCNAME[0]}" echo "## kea-ctrl-agent must not start with an empty password file" echo echo "## Truncating ${pw_file}" truncate -s 0 "${pw_file}" ls -la $(dirname "${pw_file}") test ! -s "${pw_file}" echo echo "## Restarting kea-ctrl-agent" systemctl restart "${service}" echo echo "## Service must not be started" service_status_must_be inactive } test_empty_password_via_debconf() { local service_status local contents echo echo "## Running ${FUNCNAME[0]}" echo "## Reconfiguring with password set to ${pw_secret}" reconfigure_password "${pw_secret}" echo echo "## ${pw_file} must now contain ${pw_secret}" contents=$(cat "${pw_file}") if [ "${contents}" != "${pw_secret}" ]; then echo "## ERROR, ${pw_file} now contains \"${contents}\"" return 1 else echo "## OK, same content" fi echo echo "## Service must be running" service_status_must_be active echo echo "## Reconfiguring with an empty password should not change the existing password" # set an empty password (no args) reconfigure_password ls -la $(dirname "${pw_file}") contents=$(cat "${pw_file}") if [ "${contents}" != "${pw_secret}" ]; then echo "## ERROR, ${pw_file} now contains \"${contents}\"" return 1 else echo "## OK, same content" fi echo echo "## Service must be running" service_status_must_be active } # we restart kea-ctrl-agent a lot during this test override_systemd_throttling test_fresh_install test_service_wont_start_without_pwfile test_configured_password test_configured_random_password test_unconfigured test_no_start_with_empty_password test_empty_password_via_debconf