| 1 |
#!/bin/bash |
| 2 |
# GDBus++ - glib2 GDBus C++ wrapper |
| 3 |
# |
| 4 |
# SPDX-License-Identifier: AGPL-3.0-only |
| 5 |
# |
| 6 |
# Copyright (C) OpenVPN Inc <[email protected]> |
| 7 |
# Copyright (C) David Sommerseth <[email protected]> |
| 8 |
# |
| 9 |
|
| 10 |
set -eu |
| 11 |
|
| 12 |
## |
| 13 |
# @file tests/scripts/test-fd-passing.sh |
| 14 |
# |
| 15 |
# @brief Runs a test using tests/fd-send-fstat.cpp and verify the result |
| 16 |
# |
| 17 |
# This test program sends a file descriptor to an opened file |
| 18 |
# where the D-Bus service is expected to perform an fstat() call |
| 19 |
# using the file descriptor and return back the UID, GID and file |
| 20 |
# size. This result is verified against running `stat` and |
| 21 |
# comparing the values. |
| 22 |
# |
| 23 |
# This tests requires the tests/simple-service.cpp test service |
| 24 |
# to be running |
| 25 |
# |
| 26 |
|
| 27 |
FAIL=0 |
| 28 |
|
| 29 |
run_fd_fstat() |
| 30 |
{ |
| 31 |
rm -f fd_stat.results |
| 32 |
echo ">> Running fd-send-fstat command: ${BUILD_DIR:-.}/test_fd-send-fstat $@" |
| 33 |
${BUILD_DIR:-.}/test_fd-send-fstat -q "$@" > fd_stat.results |
| 34 |
if [ $? -ne 0 ]; then |
| 35 |
echo ">> ## FAIL: sending file descriptor" |
| 36 |
FAIL=1 |
| 37 |
else |
| 38 |
echo ">> Success: file descriptor send, result retrieved" |
| 39 |
fi |
| 40 |
} |
| 41 |
|
| 42 |
run_fd_fstat -f ${BUILD_DIR:-.}/test_fd-send-fstat |
| 43 |
if [ $FAIL -eq 1 ]; then |
| 44 |
echo "** ERROR ** Could not receive a file descriptor to read from D-Bus service" |
| 45 |
exit 1 |
| 46 |
fi |
| 47 |
|
| 48 |
# Verify the results |
| 49 |
eval $(cat ./fd_stat.results) |
| 50 |
eval $(stat --print "export verify_result_size=%s\nexport verify_result_uid=%u\nexport verify_result_gid=%g\n" ${BUILD_DIR:-.}/test_fd-send-fstat) |
| 51 |
|
| 52 |
if [ $verify_result_uid != $testresult_uid ]; then |
| 53 |
echo "FAIL: UID values do not match ... expected ${verify_result_uid}, received ${testresult_uid}" |
| 54 |
FAIL=1 |
| 55 |
fi |
| 56 |
|
| 57 |
if [ $verify_result_gid != $testresult_gid ]; then |
| 58 |
echo "FAIL: GID values do not match ... expected ${verify_result_gid}, received ${testresult_gid}" |
| 59 |
FAIL=1 |
| 60 |
fi |
| 61 |
|
| 62 |
if [ $verify_result_size != $testresult_size ]; then |
| 63 |
echo "FAIL: File size values do not match ... expected ${verify_result_size}, received ${testresult_size}" |
| 64 |
FAIL=1 |
| 65 |
fi |
| 66 |
|
| 67 |
|
| 68 |
if [ $FAIL -gt 0 ]; then |
| 69 |
echo "Test result: ** FAILED **" |
| 70 |
exit 1 |
| 71 |
fi |
| 72 |
echo "Verifying UID, GID and file size - all matched" |
| 73 |
echo "Test result: -- SUCCESS --" |
| 74 |
exit 0 |