Skip to content

Commit

Permalink
Fix tests in sshd_lineinfile template
Browse files Browse the repository at this point in the history
In some cases the testing environment had existing non compliant
configurations which made some test fail when they were expected to
pass. This ensures that doesn't happen

Signed-off-by: Edgar Aguilar <[email protected]>
  • Loading branch information
Xeicker committed May 19, 2023
1 parent 2e5d857 commit d01898c
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 17 deletions.
12 changes: 1 addition & 11 deletions shared/templates/sshd_lineinfile/tests/comment.fail.sh
Original file line number Diff line number Diff line change
@@ -1,13 +1,3 @@
#!/bin/bash

SSHD_PARAM={{{ PARAMETER }}}
SSHD_VAL={{{ VALUE }}}

mkdir -p /etc/ssh/sshd_config.d
touch /etc/ssh/sshd_config.d/nothing

if grep -q "^\s*${SSHD_PARAM}" /etc/ssh/sshd_config /etc/ssh/sshd_config.d/* ; then
sed -i "s/^${SSHD_PARAM}.*/# ${SSHD_PARAM} ${SSHD_VAL}/g" /etc/ssh/sshd_config /etc/ssh/sshd_config.d/*
else
echo "# ${SSHD_PARAM} ${SSHD_VAL}" >> /etc/ssh/sshd_config
fi
source common.sh
13 changes: 13 additions & 0 deletions shared/templates/sshd_lineinfile/tests/common.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/bash

SSHD_PARAM={{{ PARAMETER }}}
SSHD_VAL={{{ VALUE }}}

mkdir -p /etc/ssh/sshd_config.d
touch /etc/ssh/sshd_config.d/nothing

if grep -q "^\s*${SSHD_PARAM}" /etc/ssh/sshd_config /etc/ssh/sshd_config.d/* ; then
sed -i "s/^${SSHD_PARAM}.*/# ${SSHD_PARAM} ${SSHD_VAL}/g" /etc/ssh/sshd_config /etc/ssh/sshd_config.d/*
else
echo "# ${SSHD_PARAM} ${SSHD_VAL}" >> /etc/ssh/sshd_config
fi
2 changes: 2 additions & 0 deletions shared/templates/sshd_lineinfile/tests/correct_value.pass.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/bin/bash

source common.sh

{{{ bash_sshd_remediation(parameter=PARAMETER, value=VALUE, config_is_distributed=sshd_distributed_config) -}}}
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@

# platform = multi_platform_fedora,Oracle Linux 8,Oracle Linux 9,Red Hat Enterprise Linux 9

mkdir -p /etc/ssh/sshd_config.d
touch /etc/ssh/sshd_config.d/nothing
source common.sh

{{% if product in ["ol8", "ol9"] %}}
{{{ bash_replace_or_append("/etc/ssh/sshd_config", "Include", "/etc/ssh/sshd_config.d/*.conf", "%s %s") }}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@

# platform = Oracle Linux 8,Oracle Linux 9

mkdir -p /etc/ssh/sshd_config.d
touch /etc/ssh/sshd_config.d/nothing
source common.sh

{{{ bash_replace_or_append("/etc/ssh/sshd_config", "Include", "sshd_config.d/*.conf", "%s %s") }}}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@

# platform = Oracle Linux 8,Oracle Linux 9

mkdir -p /etc/ssh/sshd_config.d
touch /etc/ssh/sshd_config.d/nothing
source common.sh

{{{ bash_replace_or_append("/etc/ssh/sshd_config", "Include", "sshd_config.d/*.conf", "%s %s") }}}
echo "Include /etc/dummy" >> "/etc/ssh/sshd_config"
Expand Down

0 comments on commit d01898c

Please sign in to comment.