[Close #1077] fix: preserve config key casing
Gitea requires case-sensitive setting names and escaped punctuation to interpret configuration keys correctly. Co-authored-by: Copilot <copilot@github.com>
This commit is contained in:
2 files changed
+47
-12
No files matched your search
@@ -35,15 +35,18 @@ function env2ini::read_config_to_env() {
|
|||||||
|
|
||||||
env2ini::log " + '${setting}'"
|
env2ini::log " + '${setting}'"
|
||||||
|
|
||||||
|
local masked_setting="${setting//./_0X2E_}"
|
||||||
|
masked_setting="${masked_setting//-/_0X2D_}"
|
||||||
|
|
||||||
if [[ -z "${section}" ]]; then
|
if [[ -z "${section}" ]]; then
|
||||||
export "GITEA____${setting^^}=${value}" # '^^' makes the variable content uppercase
|
export "GITEA____${masked_setting}=${value}"
|
||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
|
|
||||||
local masked_section="${section//./_0X2E_}" # '//' instructs to replace all matches
|
local masked_section="${section//./_0X2E_}" # '//' instructs to replace all matches
|
||||||
masked_section="${masked_section//-/_0X2D_}"
|
masked_section="${masked_section//-/_0X2D_}"
|
||||||
|
|
||||||
export "GITEA__${masked_section^^}__${setting^^}=${value}" # '^^' makes the variable content uppercase
|
export "GITEA__${masked_section^^}__${masked_setting}=${value}"
|
||||||
}
|
}
|
||||||
|
|
||||||
function env2ini::reload_preset_envs() {
|
function env2ini::reload_preset_envs() {
|
||||||
@@ -75,7 +78,15 @@ function env2ini::reload_preset_envs() {
|
|||||||
|
|
||||||
env2ini::log " + '${setting}'"
|
env2ini::log " + '${setting}'"
|
||||||
|
|
||||||
export "${setting^^}=${value}" # '^^' makes the variable content uppercase
|
local section_and_key="${setting#GITEA__}"
|
||||||
|
if [[ "${section_and_key}" == *'__'* ]]; then
|
||||||
|
local section="${section_and_key%%__*}"
|
||||||
|
local key="${section_and_key#*__}"
|
||||||
|
unset "${setting}"
|
||||||
|
export "GITEA__${section^^}__${key}=${value}"
|
||||||
|
else
|
||||||
|
export "${setting}=${value}"
|
||||||
|
fi
|
||||||
done < "$TMP_EXISTING_ENVS_FILE"
|
done < "$TMP_EXISTING_ENVS_FILE"
|
||||||
|
|
||||||
rm "$TMP_EXISTING_ENVS_FILE"
|
rm "$TMP_EXISTING_ENVS_FILE"
|
||||||
|
|||||||
@@ -158,6 +158,17 @@ function write_mounted_file() {
|
|||||||
refute_line '+GITEA__OAUTH2__JWT_SECRET=mocked-jwt-secret'
|
refute_line '+GITEA__OAUTH2__JWT_SECRET=mocked-jwt-secret'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@test "ensures that preset secrets with lowercase sections override generated secrets" {
|
||||||
|
expect_gitea_config_edit_ini_call
|
||||||
|
export GITEA__oauth2__JWT_SECRET="pre-defined-jwt-secret"
|
||||||
|
|
||||||
|
run execute_test_script
|
||||||
|
|
||||||
|
assert_success
|
||||||
|
assert_line '+GITEA__OAUTH2__JWT_SECRET=pre-defined-jwt-secret'
|
||||||
|
refute_line '+GITEA__OAUTH2__JWT_SECRET=mocked-jwt-secret'
|
||||||
|
}
|
||||||
|
|
||||||
@test "ensures that preset environment variables take precedence over mounted ones" {
|
@test "ensures that preset environment variables take precedence over mounted ones" {
|
||||||
expect_gitea_config_edit_ini_call
|
expect_gitea_config_edit_ini_call
|
||||||
export GITEA__OAUTH2__JWT_SECRET="pre-defined-jwt-secret"
|
export GITEA__OAUTH2__JWT_SECRET="pre-defined-jwt-secret"
|
||||||
@@ -205,22 +216,35 @@ EOF
|
|||||||
assert_line '+GITEA__REPOSITORY_0X2E_PULL_0X2D_REQUEST__WORK_IN_PROGRESS_PREFIXES=WIP:,[WIP]'
|
assert_line '+GITEA__REPOSITORY_0X2E_PULL_0X2D_REQUEST__WORK_IN_PROGRESS_PREFIXES=WIP:,[WIP]'
|
||||||
}
|
}
|
||||||
|
|
||||||
###############################################################
|
@test "preserves the case of setting names and masks dots and dashes" {
|
||||||
##### THIS IS A BUG, BUT I WANT IT TO BE COVERED BY TESTS #####
|
|
||||||
###############################################################
|
|
||||||
@test "ensures uppercase section and setting names (🐞)" {
|
|
||||||
expect_gitea_config_edit_ini_call
|
expect_gitea_config_edit_ini_call
|
||||||
export GITEA__oauth2__JwT_Secret="pre-defined-jwt-secret"
|
write_mounted_file "inlines" "log" "$(cat << EOF
|
||||||
write_mounted_file "inlines" "repository.pull-request" "$(cat << EOF
|
logger.router.MODE=console-warn
|
||||||
WORK_IN_progress_PREFIXES=WIP:,[WIP]
|
Mixed-Case=value
|
||||||
EOF
|
EOF
|
||||||
)"
|
)"
|
||||||
|
|
||||||
run execute_test_script
|
run execute_test_script
|
||||||
|
|
||||||
assert_success
|
assert_success
|
||||||
assert_line '+GITEA__REPOSITORY_0X2E_PULL_0X2D_REQUEST__WORK_IN_PROGRESS_PREFIXES=WIP:,[WIP]'
|
assert_line '+GITEA__LOG__logger_0X2E_router_0X2E_MODE=console-warn'
|
||||||
assert_line '+GITEA__OAUTH2__JWT_SECRET=pre-defined-jwt-secret'
|
assert_line '+GITEA__LOG__Mixed_0X2D_Case=value'
|
||||||
|
}
|
||||||
|
|
||||||
|
@test "preserves preset setting case and its precedence over mounted values" {
|
||||||
|
expect_gitea_config_edit_ini_call
|
||||||
|
export GITEA__log__MixedKey="preset"
|
||||||
|
write_mounted_file "inlines" "log" "$(cat << EOF
|
||||||
|
MixedKey=inline
|
||||||
|
EOF
|
||||||
|
)"
|
||||||
|
|
||||||
|
run execute_test_script
|
||||||
|
|
||||||
|
assert_success
|
||||||
|
assert_line '-GITEA__log__MixedKey=preset'
|
||||||
|
assert_line '+GITEA__LOG__MixedKey=preset'
|
||||||
|
refute_line '+GITEA__LOG__MixedKey=inline'
|
||||||
}
|
}
|
||||||
|
|
||||||
@test "treats top-level configuration as section-less" {
|
@test "treats top-level configuration as section-less" {
|
||||||
|
|||||||
Reference in new issue
Block a user