From d705192a412b4cc4b33a8e84bbc2e380671990f5 Mon Sep 17 00:00:00 2001 From: Graham Clark Date: Sat, 27 Jun 2020 00:03:05 -0400 Subject: [PATCH] More CLI and UI tests for termshark. These are intended to be "black-box" tests - running termshark itself, checking CLI options and - for now in a very simple fashion - some TUI behavior. --- scripts/pcaps/telnet-cooked.pcap | Bin 0 -> 9244 bytes scripts/simple-tests.sh | 41 +++++++++++++++++++++++++++---- 2 files changed, 36 insertions(+), 5 deletions(-) create mode 100644 scripts/pcaps/telnet-cooked.pcap diff --git a/scripts/pcaps/telnet-cooked.pcap b/scripts/pcaps/telnet-cooked.pcap new file mode 100644 index 0000000000000000000000000000000000000000..34515d415da7a543efe73bde6e50a22c4e43d1e5 GIT binary patch literal 9244 zcmb7}4OCQR8pmH|fX1Oguna129@^wV8@E=dCDJ@*}Z5+8B{*8l>oqz0XBc1z;-|o?o+mgsw z``A)a8ZQppxru0C#Kb3(l=gj{r|`3#nib968wk&__chX%aoqw&9#>d1VM zi6bJ-J8UK-zMT@4m|E8T!H3~QxmPRuQ)U0nvY*QS;j({(+%qC3K|YI*`rUXPxgVZ_ zBce+r`*=*mcZ5qM0WzM~3W=PTxkP$yCgp_6XWiZLDT+93fX#4by322Tiy^ zulY@aX6Rr|a+2nnWI~1z0w0Fn0!4!Zica398t0EJ&bvAD^B~Tt5NBsbM!0$OICip* zRDe4i5pmkBN0GRzJ}NP_taIm{aH8zbkbC1~|46xalALAUD7oSQ>w10Vm%LfmA>s2S0Ycj-tQ$i@*7^h5TENc6qS1sxzl(EHbh6G1yEvY1R`@C!3RsvPyk zU%NcDMz62dW-_wxLQ_qgGP``*__;CBew<30CBavp?ex06zJT!+3ssC?u}qBeiLQ{f zi(h7}1+dwb#_zp`E7}9l2Ag4t?M|-@E1FsM#~?KBr4T4zAFKT~R-aTZ&CO7s)!4Qt zw<~E{us-rd23@u_#5=FlTnjsGY5Zdnr*t(a?Sh8=a@5=~r52P~d0a=JE7^!>*iz3< zBtHCjR3dn{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ts/simple-tests.sh +++ b/scripts/simple-tests.sh @@ -40,19 +40,50 @@ a82c7bc0a82cd5f9 7400 EOF -echo Running termshark. +echo Running termshark cli tests. -$GOPATH/bin/termshark -r /tmp/test.pcap | grep 192.168.44.123 +# if timeout is invoked because termshark is stuck, the exit code will be non-zero +export TS="timeout 10s $GOPATH/bin/termshark" -echo Running basic UI tests. +# stdout is not a tty, so falls back to tshark +$TS -r /tmp/test.pcap | grep '192.168.44.213 TFTP 77' + +[[ $($TS -r /tmp/test.pcap -T psml -n | grep '' | wc -l) == 2 ]] + +# only display the second line via tshark +[[ $($TS -r /tmp/test.pcap 'frame.number == 2' | wc -l) == 1 ]] + +[[ $($TS -r /tmp/test.pcap --pass-thru | wc -l) == 2 ]] + +[[ $($TS -r /tmp/test.pcap --pass-thru=true | wc -l) == 2 ]] + +# run in script so termshark thinks it's in a tty +cat version.go | grep -o -E "v[0-9]+\.[0-9]+(\.[0-9]+)?" | \ + xargs -i bash -c "script -q -e -c \"$TS -v\" | grep {}" + +echo Running termshark UI tests. # Load a pcap, quit { sleep 5s ; echo q ; echo ; } | \ - socat - EXEC:"sh -c \\\"stty rows 50 cols 80 && TERM=xterm $GOPATH/bin/termshark -r /tmp/test.pcap\\\"",pty,setsid,ctty + socat - EXEC:"sh -c \\\"stty rows 50 cols 80 && TERM=xterm $TS -r /tmp/test.pcap\\\"",pty,setsid,ctty + +# Run with stdout not a tty, but disable the pass-thru to tshark +{ sleep 5s ; echo q ; echo ; } | \ + socat - EXEC:"sh -c \\\"stty rows 50 cols 80 && TERM=xterm $TS -r /tmp/test.pcap --pass-thru=false | cat\\\"",pty,setsid,ctty # Load a pcap, very rudimentary scrape for an IP, quit { sleep 5s ; echo q ; echo ; } | \ - socat - EXEC:"sh -c \\\"stty rows 50 cols 80 && TERM=xterm $GOPATH/bin/termshark -r /tmp/test.pcap\\\"",pty,setsid,ctty | \ + socat - EXEC:"sh -c \\\"stty rows 50 cols 80 && TERM=xterm $TS -r /tmp/test.pcap\\\"",pty,setsid,ctty | \ + grep -a 192.168.44.123 > /dev/null + +# Load a pcap from stdin +{ sleep 5s ; echo q ; echo ; } | \ + socat - EXEC:"sh -c \\\"stty rows 50 cols 80 && cat /tmp/test.pcap | TERM=xterm $TS -i -\\\"",pty,setsid,ctty | \ grep -a 192.168.44.123 > /dev/null +# Display filter at end of command line +{ sleep 5s ; echo q ; echo ; } | \ + socat - EXEC:"sh -c \\\"stty rows 50 cols 80 && TERM=xterm $TS -r scripts/pcaps/telnet-cooked.pcap \'frame.number == 2\'\\\"",pty,setsid,ctty | \ + grep -a "Frame 2: 74 bytes" > /dev/null + echo Tests were successful.