-
-
Notifications
You must be signed in to change notification settings - Fork 368
fix: fall back to AdminPassword from PalWorldSettings.ini when ADMIN_PASSWORD is unset #931
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Cabecinha84
wants to merge
2
commits into
thijsvanloef:main
Choose a base branch
from
Cabecinha84:fix/admin-password-from-ini
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+195
−2
Open
Changes from 1 commit
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,90 @@ | ||
| #!/bin/bash | ||
|
|
||
| set -eo pipefail | ||
|
|
||
| repo_root="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" | ||
| # shellcheck source=scripts/helper_functions.sh | ||
| source "${repo_root}/scripts/helper_functions.sh" | ||
|
|
||
| settings_file="$(mktemp)" | ||
| trap 'rm -f "${settings_file}"' EXIT | ||
|
|
||
| fail() { | ||
| echo "test failure: $*" >&2 | ||
| exit 1 | ||
| } | ||
|
|
||
| # Writes a single line settings file, the same shape compile-settings.sh produces | ||
| write_settings() { | ||
| printf '[/Script/Pal.PalGameWorldSettings]\nOptionSettings=(Difficulty=None,ServerPassword="%s",AdminPassword=%s,PublicPort=8211)\n' "$1" "$2" > "${settings_file}" | ||
| } | ||
|
|
||
| assert_password_from_settings() { | ||
| write_settings "serverPass" '"adminPass"' | ||
| local password | ||
| password="$(get_admin_password_from_settings "${settings_file}")" || fail "no password read from the settings file" | ||
| [ "${password}" = "adminPass" ] || fail "expected adminPass, got ${password}" | ||
| } | ||
|
|
||
| assert_special_characters_are_kept() { | ||
| write_settings "serverPass" '"p@ss w0rd$&=,"' | ||
| local password | ||
| password="$(get_admin_password_from_settings "${settings_file}")" || fail "no password read from the settings file" | ||
| [ "${password}" = 'p@ss w0rd$&=,' ] || fail "expected p@ss w0rd\$&=, got ${password}" | ||
| } | ||
|
|
||
| assert_carriage_returns_are_stripped() { | ||
| printf 'OptionSettings=(AdminPassword="adminPass")\r\n' > "${settings_file}" | ||
| local password | ||
| password="$(get_admin_password_from_settings "${settings_file}")" || fail "no password read from the settings file" | ||
| [ "${password}" = "adminPass" ] || fail "carriage return was not stripped from ${password}" | ||
| } | ||
|
|
||
| assert_empty_password_is_rejected() { | ||
| write_settings "serverPass" '""' | ||
| if get_admin_password_from_settings "${settings_file}"; then | ||
| fail "an empty AdminPassword was accepted" | ||
| fi | ||
| } | ||
|
|
||
| assert_missing_file_is_rejected() { | ||
| if get_admin_password_from_settings "${settings_file}.missing"; then | ||
| fail "a missing settings file was accepted" | ||
| fi | ||
| } | ||
|
|
||
| assert_environment_variable_wins() { | ||
| write_settings "serverPass" '"adminPass"' | ||
| ADMIN_PASSWORD="fromEnvironment" | ||
| local password | ||
| password="$(get_admin_password "${settings_file}")" || fail "no password returned" | ||
| [ "${password}" = "fromEnvironment" ] || fail "expected fromEnvironment, got ${password}" | ||
| unset ADMIN_PASSWORD | ||
| } | ||
|
|
||
| assert_settings_are_used_when_environment_variable_is_empty() { | ||
| write_settings "serverPass" '"adminPass"' | ||
| ADMIN_PASSWORD="" | ||
| local password | ||
| password="$(get_admin_password "${settings_file}")" || fail "no password returned" | ||
| [ "${password}" = "adminPass" ] || fail "expected adminPass, got ${password}" | ||
| unset ADMIN_PASSWORD | ||
| } | ||
|
|
||
| assert_unset_environment_variable_is_tolerated() { | ||
| unset ADMIN_PASSWORD | ||
| if get_admin_password "${settings_file}.missing" > /dev/null; then | ||
| fail "a password was returned without ADMIN_PASSWORD and without a settings file" | ||
| fi | ||
| } | ||
|
|
||
| assert_password_from_settings | ||
| assert_special_characters_are_kept | ||
| assert_carriage_returns_are_stripped | ||
| assert_empty_password_is_rejected | ||
| assert_missing_file_is_rejected | ||
| assert_environment_variable_wins | ||
| assert_settings_are_used_when_environment_variable_is_empty | ||
| assert_unset_environment_variable_is_tolerated | ||
|
|
||
| echo "admin password tests passed" |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Confirmed, and fixed in 52e2184.
I reproduced it against a YAML parser before changing anything: in a double quoted scalar
pa\ssw0rdfails to parse,tab\thereis silently rewritten with a real tab, and a password holding"breaks the mapping. Worth noting the same hole already existed on the${ADMIN_PASSWORD}line this PR replaces, so this is not new behaviour, but the fallback is a good moment to close it.The password is now written as a YAML single quoted scalar, which processes no escape sequences at all and only needs a literal quote doubled:
yaml_single_quoted()inhelper_functions.shdoes the doubling,start.shrenders the scalar before the heredoc, andtests/test-admin-password.shcovers backslashes, double quotes and single quotes. Round tripping the generatedrcon.yamlthrough a parser returns the password unchanged.