Skip to content

Commit

Permalink
macro bash_ensure_ini_config: do not put space around equals sign
Browse files Browse the repository at this point in the history
This is consistent with Systemd configuration and it is allowed by respective OVAL checks.
  • Loading branch information
vojtapolasek committed Jul 4, 2024
1 parent 2bd5fba commit 893536e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
6 changes: 3 additions & 3 deletions shared/macros/10-bash.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -2094,12 +2094,12 @@ for f in $(echo -n "{{{ files }}}"); do

# find key in section and change value
if grep -qzosP "[[:space:]]*\[{{{ section }}}\]([^\n\[]*\n+)+?[[:space:]]*{{{ key }}}" "$f"; then
sed -i "s/{{{ key }}}[^(\n)]*/{{{ key }}} = {{{ value }}}/" "$f"
sed -i "s/{{{ key }}}[^(\n)]*/{{{ key }}}={{{ value }}}/" "$f"
found=true

# find section and add key = value to it
elif grep -qs "[[:space:]]*\[{{{ section }}}\]" "$f"; then
sed -i "/[[:space:]]*\[{{{ section }}}\]/a {{{ key }}} = {{{ value }}}" "$f"
sed -i "/[[:space:]]*\[{{{ section }}}\]/a {{{ key }}}={{{ value }}}" "$f"
found=true
fi
done
Expand All @@ -2108,7 +2108,7 @@ done
if ! $found ; then
file=$(echo "{{{ files }}}" | cut -f1 -d ' ')
mkdir -p "$(dirname "$file")"
echo -e "[{{{ section }}}]\n{{{ key }}} = {{{ value }}}" >> "$file"
echo -e "[{{{ section }}}]\n{{{ key }}}={{{ value }}}" >> "$file"
fi
{{%- endmacro %}}

Expand Down
18 changes: 9 additions & 9 deletions tests/unit/bash/test_bash_ensure_ini_config.bats.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ teardown() {

@test "bash_ensure_ini_config - Basic value remediation" {
printf "[pam]\npam_cert_auth = false\n" > sssd_test/sssd.conf
expected_output="[pam]\npam_cert_auth = true\n"
expected_output="[pam]\npam_cert_auth=true\n"

call_bash_ensure_ini_config "sssd_test/sssd.conf" "pam" "pam_cert_auth" "true"

Expand All @@ -57,7 +57,7 @@ teardown() {
@test "bash_ensure_ini_config - Value remediation in multiple files" {
printf "[pam]\npam_cert_auth = false\n" > sssd_test/sssd.conf
printf "[pam]\npam_cert_auth = false\n" > pam_cert_auth.conf
expected_output="[pam]\npam_cert_auth = true\n"
expected_output="[pam]\npam_cert_auth=true\n"

call_bash_ensure_ini_config "sssd_test/sssd.conf pam_cert_auth.conf" "pam" "pam_cert_auth" "true"

Expand All @@ -70,7 +70,7 @@ teardown() {

@test "bash_ensure_ini_config - No remediation happened" {
printf "[pam]\npam_cert_auth = true\n" > sssd_test/sssd.conf
expected_output="[pam]\npam_cert_auth = true\n"
expected_output="[pam]\npam_cert_auth=true\n"

call_bash_ensure_ini_config "sssd_test/sssd.conf" "pam" "pam_cert_auth" "true"

Expand All @@ -80,7 +80,7 @@ teardown() {

@test "bash_ensure_ini_config - Append section with option to empty file" {
printf "" > sssd_test/sssd.conf
expected_output="[pam]\npam_cert_auth = true\n"
expected_output="[pam]\npam_cert_auth=true\n"

call_bash_ensure_ini_config "sssd_test/sssd.conf" "pam" "pam_cert_auth" "true"

Expand All @@ -89,7 +89,7 @@ teardown() {
}

@test "bash_ensure_ini_config - Create file with section and option" {
expected_output="[pam]\npam_cert_auth = true\n"
expected_output="[pam]\npam_cert_auth=true\n"

call_bash_ensure_ini_config "sssd_test/sssd.conf" "pam" "pam_cert_auth" "true"

Expand All @@ -99,7 +99,7 @@ teardown() {

@test "bash_ensure_ini_config - Append option to section" {
printf "[pam]\n" > sssd_test/sssd.conf
expected_output="[pam]\npam_cert_auth = true\n"
expected_output="[pam]\npam_cert_auth=true\n"

call_bash_ensure_ini_config "sssd_test/sssd.conf" "pam" "pam_cert_auth" "true"

Expand All @@ -109,7 +109,7 @@ teardown() {

@test "bash_ensure_ini_config - Append option to section when section is substring of option" {
printf "[pam]\n" > sssd_test/sssd.conf
expected_output="[pam]\npam_verbosity = 1\npam_cert_auth = true\n"
expected_output="[pam]\npam_verbosity=1\npam_cert_auth=true\n"

call_bash_ensure_ini_config "sssd_test/sssd.conf" "pam" "pam_cert_auth" "true"
call_bash_ensure_ini_config "sssd_test/sssd.conf" "pam" "pam_verbosity" "1"
Expand All @@ -121,7 +121,7 @@ teardown() {
@test "bash_ensure_ini_config - Append option to section in multiple files" {
printf "[pam]\n" > sssd_test/sssd.conf
printf "[pam]\n" > pam_cert_auth.conf
expected_output="[pam]\npam_cert_auth = true\n"
expected_output="[pam]\npam_cert_auth=true\n"

call_bash_ensure_ini_config "pam_cert_auth.conf sssd_test/sssd.conf" "pam" "pam_cert_auth" "true"

Expand All @@ -134,7 +134,7 @@ teardown() {

@test "bash_ensure_ini_config - Append section with option to non-empty file" {
printf "[section]\nkey = value\n" > sssd_test/sssd.conf
expected_output="[section]\nkey = value\n[pam]\npam_cert_auth = true\n"
expected_output="[section]\nkey = value\n[pam]\npam_cert_auth=true\n"

call_bash_ensure_ini_config "sssd_test/sssd.conf" "pam" "pam_cert_auth" "true"

Expand Down

0 comments on commit 893536e

Please sign in to comment.