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