From be073c4bea09649b294726716452a8a4d4c5431d Mon Sep 17 00:00:00 2001 From: Lee Garrett Date: Wed, 21 Aug 2024 15:57:32 +0200 Subject: [PATCH] Fix callback_default integration test for non-root users This test compares the test output to previously collected output. However, this previously assumed that the tests are run as root, even though needs/root in aliases is not set. So instead parameterize the output, and use sed to replace the value that diverge when running it as different users. --- .../callback_default.out.include_role_fails.stderr | 2 +- .../callback_default.out.include_role_fails.stdout | 2 +- ...efault.out.result_format_yaml_lossy_verbose.stdout | 8 ++++---- ...back_default.out.result_format_yaml_verbose.stdout | 8 ++++---- test/integration/targets/callback_default/runme.sh | 11 +++++++++++ 5 files changed, 21 insertions(+), 10 deletions(-) diff --git a/test/integration/targets/callback_default/callback_default.out.include_role_fails.stderr b/test/integration/targets/callback_default/callback_default.out.include_role_fails.stderr index 315f17bbfe4..b7e5a0ab106 100644 --- a/test/integration/targets/callback_default/callback_default.out.include_role_fails.stderr +++ b/test/integration/targets/callback_default/callback_default.out.include_role_fails.stderr @@ -1,6 +1,6 @@ + ansible-playbook -i inventory test_include_role_fails.yml ++ set +x -ERROR! the role 'does-not-exist' was not found in TEST_PATH/roles:/root/.ansible/roles:/usr/share/ansible/roles:/etc/ansible/roles:TEST_PATH +ERROR! the role 'does-not-exist' was not found in TEST_PATH/roles:/<>/.ansible/roles:/usr/share/ansible/roles:/etc/ansible/roles:TEST_PATH The error appears to be in 'TEST_PATH/test_include_role_fails.yml': line 5, column 15, but may be elsewhere in the file depending on the exact syntax problem. diff --git a/test/integration/targets/callback_default/callback_default.out.include_role_fails.stdout b/test/integration/targets/callback_default/callback_default.out.include_role_fails.stdout index adfd21b65bc..fd8affc1e4b 100644 --- a/test/integration/targets/callback_default/callback_default.out.include_role_fails.stdout +++ b/test/integration/targets/callback_default/callback_default.out.include_role_fails.stdout @@ -2,7 +2,7 @@ PLAY [testhost] **************************************************************** TASK [include_role : does-not-exist] ******************************************* -fatal: [testhost]: FAILED! => {"changed": false, "reason": "the role 'does-not-exist' was not found in TEST_PATH/roles:/root/.ansible/roles:/usr/share/ansible/roles:/etc/ansible/roles:TEST_PATH\n\nThe error appears to be in 'TEST_PATH/test_include_role_fails.yml': line 5, column 15, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n - include_role:\n name: does-not-exist\n ^ here\n"} +fatal: [testhost]: FAILED! => {"changed": false, "reason": "the role 'does-not-exist' was not found in TEST_PATH/roles:/<>/.ansible/roles:/usr/share/ansible/roles:/etc/ansible/roles:TEST_PATH\n\nThe error appears to be in 'TEST_PATH/test_include_role_fails.yml': line 5, column 15, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n - include_role:\n name: does-not-exist\n ^ here\n"} PLAY RECAP ********************************************************************* testhost : ok=0 changed=0 unreachable=0 failed=1 skipped=0 rescued=0 ignored=0 diff --git a/test/integration/targets/callback_default/callback_default.out.result_format_yaml_lossy_verbose.stdout b/test/integration/targets/callback_default/callback_default.out.result_format_yaml_lossy_verbose.stdout index 51f025162f8..10172d9ea9a 100644 --- a/test/integration/targets/callback_default/callback_default.out.result_format_yaml_lossy_verbose.stdout +++ b/test/integration/targets/callback_default/callback_default.out.result_format_yaml_lossy_verbose.stdout @@ -160,15 +160,15 @@ changed: [testhost] => changed: true checksum: 0beec7b5ea3f0fdbc95d0dd47f3c5bc275da8a33 dest: .../test_diff.txt - gid: 0 - group: root + gid: <> + group: <> md5sum: acbd18db4cc2f85cedef654fccc4a4d8 mode: '0644' - owner: root + owner: <> size: 3 src: .../.source.txt state: file - uid: 0 + uid: <> TASK [replace] ***************************************************************** --- before: .../test_diff.txt diff --git a/test/integration/targets/callback_default/callback_default.out.result_format_yaml_verbose.stdout b/test/integration/targets/callback_default/callback_default.out.result_format_yaml_verbose.stdout index 8fd5b4f0e87..69181046817 100644 --- a/test/integration/targets/callback_default/callback_default.out.result_format_yaml_verbose.stdout +++ b/test/integration/targets/callback_default/callback_default.out.result_format_yaml_verbose.stdout @@ -167,15 +167,15 @@ changed: [testhost] => changed: true checksum: 0beec7b5ea3f0fdbc95d0dd47f3c5bc275da8a33 dest: .../test_diff.txt - gid: 0 - group: root + gid: <> + group: <> md5sum: acbd18db4cc2f85cedef654fccc4a4d8 mode: '0644' - owner: root + owner: <> size: 3 src: .../.source.txt state: file - uid: 0 + uid: <> TASK [replace] ***************************************************************** --- before: .../test_diff.txt diff --git a/test/integration/targets/callback_default/runme.sh b/test/integration/targets/callback_default/runme.sh index 4dab4f40ae8..7678f9f9faf 100755 --- a/test/integration/targets/callback_default/runme.sh +++ b/test/integration/targets/callback_default/runme.sh @@ -13,6 +13,8 @@ set -eux +umask 0022 + run_test() { local testname=$1 local playbook=$2 @@ -37,6 +39,15 @@ run_test() { sed -i -e '/secontext:/d' "${OUTFILE}.${testname}.stdout" sed -i -e 's/group: wheel/group: root/g' "${OUTFILE}.${testname}.stdout" + # normalize gid/group/owner/uid/homedir so tests can run as non-root user + ESC_HOME=$(echo "${HOME}" | sed -e 's/\//\\\//g') + sed -i -e "s/${ESC_HOME}/\/<>/g" "${OUTFILE}.${testname}.stdout" + sed -i -e "s/${ESC_HOME}/\/<>/g" "${OUTFILE}.${testname}.stderr" + sed -i -e "s/gid: $(id -g)/gid: <>/g" "${OUTFILE}.${testname}.stdout" + sed -i -e "s/group: $(id -gn)/group: <>/g" "${OUTFILE}.${testname}.stdout" + sed -i -e "s/owner: $(id -un)/owner: <>/g" "${OUTFILE}.${testname}.stdout" + sed -i -e "s/uid: $(id -u)/uid: <>/g" "${OUTFILE}.${testname}.stdout" + diff -u "${ORIGFILE}.${testname}.stdout" "${OUTFILE}.${testname}.stdout" || diff_failure diff -u "${ORIGFILE}.${testname}.stderr" "${OUTFILE}.${testname}.stderr" || diff_failure }