fix: report config write failures instead of exiting 0

`config:set`, `config:unset` and `config:clear` discarded the result of writing the app's environment, so a write that never landed still printed `Setting config vars`, still fired the `post-config-update` trigger, still restarted the app and still exited 0. The `config-set` and `config-unset` plugin triggers behaved the same way, which meant an `app.json` `env` block that could not be persisted deployed anyway with the variables missing. The environment is now staged in a temporary file and renamed into place, so a write that fails partway leaves the previous environment intact, and that file is created at `0600` rather than being created at `0644` and chmodded afterwards. `apps:clone` and `apps:rename` never applied that chmod at all and left the new app's environment world-readable.
This commit is contained in:
Jose Diaz-Gonzalez committed 2026-09-18 00:36:38 -04:00
1 parent 4fc19fe1bc
commit 0c3ae47299
11 files changed
+369 -43

No files matched your search

+103
View File
@@ -11,6 +11,7 @@ setup() {
}
teardown() {
restore_app_config_dir
destroy_app
if [[ -f ${DOKKU_LIB_ROOT}/config/--global/ENV.bak ]]; then
mv -f ${DOKKU_LIB_ROOT}/config/--global/ENV.bak ${DOKKU_LIB_ROOT}/config/--global/ENV
@@ -704,6 +705,108 @@ teardown() {
assert_success
}
@test "(config:set) fails when the config file cannot be written" {
run /bin/bash -c "dokku config:set --no-restart $TEST_APP first_key=first_value"
echo "output: $output"
echo "status: $status"
assert_success
block_app_config_dir
run /bin/bash -c "dokku config:set --no-restart $TEST_APP second_key=second_value"
echo "output: $output"
echo "status: $status"
assert_failure
assert_output_contains "Unable to write config vars"
restore_app_config_dir
run /bin/bash -c "dokku config:get $TEST_APP first_key"
echo "output: $output"
echo "status: $status"
assert_success
assert_output "first_value"
run /bin/bash -c "dokku config:get $TEST_APP second_key"
echo "output: $output"
echo "status: $status"
assert_failure
}
@test "(config:unset) fails when the config file cannot be written" {
run /bin/bash -c "dokku config:set --no-restart $TEST_APP first_key=first_value"
echo "output: $output"
echo "status: $status"
assert_success
block_app_config_dir
run /bin/bash -c "dokku config:unset --no-restart $TEST_APP first_key"
echo "output: $output"
echo "status: $status"
assert_failure
assert_output_contains "Unable to write config vars"
restore_app_config_dir
run /bin/bash -c "dokku config:get $TEST_APP first_key"
echo "output: $output"
echo "status: $status"
assert_success
assert_output "first_value"
}
@test "(config:clear) fails when the config file cannot be written" {
run /bin/bash -c "dokku config:set --no-restart $TEST_APP first_key=first_value"
echo "output: $output"
echo "status: $status"
assert_success
block_app_config_dir
run /bin/bash -c "dokku config:clear --no-restart $TEST_APP"
echo "output: $output"
echo "status: $status"
assert_failure
assert_output_contains "Unable to write config vars"
restore_app_config_dir
run /bin/bash -c "dokku config:get $TEST_APP first_key"
echo "output: $output"
echo "status: $status"
assert_success
assert_output "first_value"
}
@test "(config) config-unset plugin trigger reports a failure" {
run_plugn_trigger config-unset "$TEST_APP" invalid-key false
echo "output: $output"
echo "status: $status"
assert_failure
assert_output_contains "Invalid key name"
}
block_app_config_dir() {
declare desc="makes the app config directory unwritable for the dokku user"
run /bin/bash -c "sudo chown root:root ${DOKKU_LIB_ROOT}/config/$TEST_APP && sudo chmod 0555 ${DOKKU_LIB_ROOT}/config/$TEST_APP"
echo "output: $output"
echo "status: $status"
assert_success
}
restore_app_config_dir() {
declare desc="hands the app config directory back to the dokku user"
if [[ ! -d "${DOKKU_LIB_ROOT}/config/$TEST_APP" ]]; then
return 0
fi
sudo chmod 0755 "${DOKKU_LIB_ROOT}/config/$TEST_APP"
sudo chown -R dokku:dokku "${DOKKU_LIB_ROOT}/config/$TEST_APP"
}
stage_stale_env() {
declare desc="writes a legacy ENV file at the pre-0.38 path for the test app"