From fe7e68bfcb680cfa81d4a8bcba4eff4a71da0c76 Mon Sep 17 00:00:00 2001 From: Sloane Hertel <19572925+s-hertel@users.noreply.github.com> Date: Tue, 13 Aug 2024 17:20:39 -0400 Subject: [PATCH] Fix ansible-vault integration test for missing vault ids (#83777) * Fix broken, circumvented test for missing vault ids * verify the command returns a non-zero exit code Co-authored-by: Matt Clay --- .../targets/ansible-vault/runme.sh | 23 ++++++++++--------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/test/integration/targets/ansible-vault/runme.sh b/test/integration/targets/ansible-vault/runme.sh index 4165762668e..0bcd3c3c67e 100755 --- a/test/integration/targets/ansible-vault/runme.sh +++ b/test/integration/targets/ansible-vault/runme.sh @@ -552,21 +552,22 @@ sudo chmod 000 "${MYTMPDIR}/unreadable" ansible-vault encrypt_string content ansible-vault encrypt_string content --encrypt-vault-id id3 -set +e - # Try to use a missing vault password file -ansible-vault encrypt_string content --encrypt-vault-id id1 2>&1 | tee out.txt -test $? -ne 0 -grep out.txt -e '[WARNING]: Error getting vault password file (id1)' -grep out.txt -e "ERROR! Did not find a match for --encrypt-vault-id=id2 in the known vault-ids ['id3']" +if ansible-vault encrypt_string content --encrypt-vault-id id1 > out.txt 2>&1; then + echo "command did not fail" + exit 1 +fi +grep out.txt -e '\[WARNING\]: Error getting vault password file (id1)' +grep out.txt -e "ERROR! Did not find a match for --encrypt-vault-id=id1 in the known vault-ids \['id3'\]" # Try to use an inaccessible vault password file -ansible-vault encrypt_string content --encrypt-vault-id id2 2>&1 | tee out.txt -test $? -ne 0 -grep out.txt -e "[WARNING]: Error in vault password file loading (id2)" -grep out.txt -e "ERROR! Did not find a match for --encrypt-vault-id=id2 in the known vault-ids ['id3']" +if ansible-vault encrypt_string content --encrypt-vault-id id2 > out.txt 2>&1; then + echo "command did not fail" + exit 1 +fi +grep out.txt -e "\[WARNING\]: Error in vault password file loading (id2)" +grep out.txt -e "ERROR! Did not find a match for --encrypt-vault-id=id2 in the known vault-ids \['id3'\]" -set -e unset ANSIBLE_VAULT_IDENTITY_LIST # 'real script'