test/api.sh: do not use /tmp, but $WORKDIR

Do not create files directly in `/tmp`, but use `$WORKDIR`, which is a
temporary directory for transient files, which gets cleaned up when the
test case finishes. Without this change, running `api.sh` twice fails
the second time.

Signed-off-by: Tomas Hozza <thozza@redhat.com>
This commit is contained in:
Tomas Hozza 2022-03-15 17:33:30 +01:00 committed by Tom Gundersen
parent b2d18166de
commit e8a347d1e8

View file

@ -503,7 +503,7 @@ else
fi fi
# generate a temp key for user tests # generate a temp key for user tests
ssh-keygen -t rsa-sha2-512 -f /tmp/usertest -C "usertest" -N "" ssh-keygen -t rsa-sha2-512 -f "${WORKDIR}/usertest" -C "usertest" -N ""
function createReqFileAWS() { function createReqFileAWS() {
AWS_SNAPSHOT_NAME=${TEST_ID} AWS_SNAPSHOT_NAME=${TEST_ID}
@ -531,11 +531,11 @@ function createReqFileAWS() {
{ {
"name": "user1", "name": "user1",
"groups": ["wheel"], "groups": ["wheel"],
"key": "$(cat /tmp/usertest.pub)" "key": "$(cat "${WORKDIR}/usertest.pub")"
}, },
{ {
"name": "user2", "name": "user2",
"key": "$(cat /tmp/usertest.pub)" "key": "$(cat "${WORKDIR}/usertest.pub")"
} }
] ]
}, },
@ -576,11 +576,11 @@ function createReqFileAWSS3() {
{ {
"name": "user1", "name": "user1",
"groups": ["wheel"], "groups": ["wheel"],
"key": "$(cat /tmp/usertest.pub)" "key": "$(cat "${WORKDIR}/usertest.pub")"
}, },
{ {
"name": "user2", "name": "user2",
"key": "$(cat /tmp/usertest.pub)" "key": "$(cat "${WORKDIR}/usertest.pub")"
} }
] ]
}, },
@ -977,14 +977,14 @@ function verifyInAWS() {
_instanceCheck "$_ssh" _instanceCheck "$_ssh"
# Check access to user1 and user2 # Check access to user1 and user2
check_groups=$(ssh -oStrictHostKeyChecking=no -i /tmp/usertest "user1@$HOST" -t 'groups') check_groups=$(ssh -oStrictHostKeyChecking=no -i "${WORKDIR}/usertest" "user1@$HOST" -t 'groups')
if [[ $check_groups =~ "wheel" ]]; then if [[ $check_groups =~ "wheel" ]]; then
echo "✔️ user1 has the group wheel" echo "✔️ user1 has the group wheel"
else else
echo 'user1 should have the group wheel 😢' echo 'user1 should have the group wheel 😢'
exit 1 exit 1
fi fi
check_groups=$(ssh -oStrictHostKeyChecking=no -i /tmp/usertest "user2@$HOST" -t 'groups') check_groups=$(ssh -oStrictHostKeyChecking=no -i "${WORKDIR}/usertest" "user2@$HOST" -t 'groups')
if [[ $check_groups =~ "wheel" ]]; then if [[ $check_groups =~ "wheel" ]]; then
echo 'user2 should not have group wheel 😢' echo 'user2 should not have group wheel 😢'
exit 1 exit 1