#!/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 -eux

##
# @file tests/scripts/test-credentials
#
# @brief Runs a few test_credentials tests
#

run_creds_test()
{
    DEFAULT_ARGS="-E -d net.openvpn.gdbuspp.test.simple"
    echo ">> Running credentials test: ${BUILD_DIR:-.}/test_credentials ${DEFAULT_ARGS} $@"
    ${BUILD_DIR:-.}/test_credentials ${DEFAULT_ARGS} "$@"
}


run_creds_test -u -x "$(id -u)"

chk=$(dbus-send --session --dest=org.freedesktop.DBus \
        --type=method_call --print-reply=literal \
        /net/freedesktop/DBus  org.freedesktop.DBus.GetNameOwner \
        string:"net.openvpn.gdbuspp.test.simple" | tr -d ' ')
run_creds_test -b -x "${chk}"

[ -n "$SERVICE_PID" ] && run_creds_test -p -x "${SERVICE_PID}"
