wireshark/Sanity/basic-lua-script/runtest.sh
2024-09-02 15:07:14 +02:00

73 lines
2.8 KiB
Bash
Executable file

#!/bin/bash
# vim: dict+=/usr/share/beakerlib/dictionary.vim cpt=.,w,b,u,t,i,k
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#
# runtest.sh of /CoreOS/wireshark/Sanity/basic-lua-script
# Description: Checking if lua is enabled and running basic hello.lua script.
# Author: František Hrdina <fhrdina@redhat.com>
#
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#
# Copyright (c) 2022 Red Hat, Inc.
#
# This program is free software: you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation, either version 2 of
# the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be
# useful, but WITHOUT ANY WARRANTY; without even the implied
# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
# PURPOSE. See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see http://www.gnu.org/licenses/.
#
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Include Beaker environment
. /usr/share/beakerlib/beakerlib.sh || exit 1
PACKAGE="wireshark"
LOG="/tmp/tshark.log"
rlJournalStart
rlPhaseStartSetup
TestDir=$(pwd)
rlAssertRpm $PACKAGE
rlRun "TmpDir=\$(mktemp -d)" 0 "Creating tmp directory"
rlRun "pushd $TmpDir"
rlPhaseEnd
rlPhaseStartTest "Testing if lua is enabled"
rlRun "rlFetchSrcForInstalled wireshark" 0 "Downloading wireshark source rpm "
SRPM=`rpm -q --qf %{nvr} wireshark`.src.rpm
rlRun "touch build-requires"
rlAssertExists $SRPM
rlAssertExists build-requires
rlRun "rpm -qpR $SRPM > build-requires"
if rlIsFedora '>=41'; then
rlAssertGrep lua-devel build-requires -i
else
rlAssertGrep compat-lua-devel build-requires -i
fi
rlPhaseEnd
#lua scripts will not run under root for safety reasons, we need to create a regular user to run
rlPhaseStartTest "Running basic hello.lua script"
rlRun "useradd test" 0 "Adding a regular user"
rlRun "usermod -aG wireshark test" 0 "Adding user to the wireshark group"
rlRun "su -c 'tshark -c 10 -X lua_script:$TestDir/hello.lua &> $LOG' test" 0 "Running hello.lua script"
rlAssertExists $LOG
rlAssertGrep "10 packets captured" $LOG
rlAssertGrep "Hello world, from Lua" $LOG
rlAssertNotGrep "This version of TShark was not built with support for Lua scripting" $LOG
rlPhaseEnd
rlPhaseStartCleanup
rlRun "popd"
rlRun "rm -r $TmpDir" 0 "Removing tmp directory"
rlPhaseEnd
rlJournalPrintText
rlJournalEnd