diff --git a/test/FTL-test.sh b/test/FTL-test.sh new file mode 100755 index 00000000..7e139c8a --- /dev/null +++ b/test/FTL-test.sh @@ -0,0 +1,76 @@ +#!/bin/bash +FTL_communicate() { + # Open connection to FTL + exec 3<>"/dev/tcp/localhost/4711" + + # Test if connection is open + if { "true" >&3; } 2> /dev/null; then + # Send command to FTL + echo -e ">$1" >&3 + + # Read input + read -r -t 1 LINE <&3 + until [[ ! $? ]] || [[ "$LINE" == *"EOM"* ]]; do + echo "$LINE" >&1 + read -r -t 1 LINE <&3 + done + + # Close connection + exec 3>&- + exec 3<&- + fi +} + +FTL_get_version() { + FTL_communicate "version" +} + +FTL_get_stats() { + FTL_communicate "stats" +} + +FTL_get_top_clients() { + FTL_communicate "top-clients" +} + +FTL_get_top_domains() { + FTL_communicate "top-domains" +} + +FTL_prepare_files() { + ts=$(dnsmasq_pre) +cat <> /var/log/pihole.log +${ts} query[AAAA] raspberrypi from 127.0.0.1 +${ts} /etc/pihole/local.list raspberrypi is fda2:2001:5647:0:ba27:ebff:fe37:4205 +${ts} query[A] checkip.dyndns.org from 127.0.0.1 +${ts} forwarded checkip.dyndns.org to 2001:1608:10:25::9249:d69b +${ts} forwarded checkip.dyndns.org to 2001:1608:10:25::1c04:b12f +${ts} forwarded checkip.dyndns.org to 2620:0:ccd::2 +${ts} forwarded checkip.dyndns.org to 2620:0:ccc::2 +${ts} reply checkip.dyndns.org is +${ts} reply checkip.dyndns.com is 216.146.38.70 +${ts} reply checkip.dyndns.com is 216.146.43.71 +${ts} reply checkip.dyndns.com is 91.198.22.70 +${ts} reply checkip.dyndns.com is 216.146.43.70 +${ts} query[A] pi.hole from 10.8.0.2 +${ts} /etc/pihole/local.list pi.hole is 192.168.2.10 +${ts} query[A] play.google.com from 192.168.2.208 +${ts} forwarded play.google.com to 2001:1608:10:25::9249:d69b +${ts} forwarded play.google.com to 2001:1608:10:25::1c04:b12f +${ts} forwarded play.google.com to 2620:0:ccd::2 +${ts} forwarded play.google.com to 2620:0:ccc::2 +${ts} reply play.google.com is +${ts} reply play.l.google.com is 216.58.208.110 +${ts} reply play.l.google.com is 216.58.208.110 +${ts} reply play.l.google.com is 216.58.208.110 +${ts} reply play.google.com is +${ts} query[AAAA] play.google.com from 192.168.2.208 +${ts} forwarded play.google.com to 2620:0:ccd::2 +${ts} reply play.l.google.com is 2a00:1450:4017:802::200e +EOT +} + +dnsmasq_pre() { + echo -n $(date +"%b %e %H:%M:%S") + echo -n "dnsmasq[123]:" +} diff --git a/test/test_automated_install.py b/test/test_automated_install.py index 60772625..60a0f123 100644 --- a/test/test_automated_install.py +++ b/test/test_automated_install.py @@ -402,6 +402,70 @@ def test_FTL_binary_installed_and_responsive_no_errors(Pihole): # assert '644 /run/pihole-FTL.pid' in support_files.stdout # assert '644 /var/log/pihole-FTL.log' in support_files.stdout +def test_FTL_telnet_version(Pihole): + ''' confirms FTL binary is copied and functional in installed location and through telnet ''' + FTLtest = Pihole.run(''' + source /opt/pihole/basic-install.sh + source /etc/.pihole/test/FTL-test.sh + FTL_prepare_files + FTLdetect + pihole-FTL + sleep 1 + FTL_get_version + ''') + assert 'version' in FTLtest.stdout + assert 'tag' in FTLtest.stdout + assert 'branch' in FTLtest.stdout + assert 'date' in FTLtest.stdout + +def test_FTL_telnet_statistics(Pihole): + ''' confirms FTL binary is copied and functional in installed location and through telnet ''' + FTLtest = Pihole.run(''' + source /opt/pihole/basic-install.sh + source /etc/.pihole/test/FTL-test.sh + FTL_prepare_files + FTLdetect + pihole-FTL + sleep 1 + FTL_get_stats + ''') + assert 'domains_being_blocked' in FTLtest.stdout + assert 'dns_queries_today 5' in FTLtest.stdout + assert 'unique_domains 4' in FTLtest.stdout + assert 'queries_forwarded 3' in FTLtest.stdout + assert 'queries_cached 2' in FTLtest.stdout + +def test_FTL_telnet_top_clients(Pihole): + ''' confirms FTL binary is copied and functional in installed location and through telnet ''' + FTLtest = Pihole.run(''' + source /opt/pihole/basic-install.sh + source /etc/.pihole/test/FTL-test.sh + FTL_prepare_files + FTLdetect + pihole-FTL + sleep 1 + FTL_get_top_clients + ''') + assert '0 2 192.168.2.208' in FTLtest.stdout + assert '1 2 127.0.0.1' in FTLtest.stdout + assert '2 1 10.8.0.2' in FTLtest.stdout + +def test_FTL_telnet_top_domains(Pihole): + ''' confirms FTL binary is copied and functional in installed location and through telnet ''' + FTLtest = Pihole.run(''' + source /opt/pihole/basic-install.sh + source /etc/.pihole/test/FTL-test.sh + FTL_prepare_files + FTLdetect + pihole-FTL + sleep 1 + FTL_get_top_domains + ''') + assert '0 2 play.google.com' in FTLtest.stdout + assert '1 1 pi.hole' in FTLtest.stdout + assert '2 1 checkip.dyndns.org' in FTLtest.stdout + assert '3 1 raspberrypi' in FTLtest.stdout + def test_IPv6_only_link_local(Pihole): ''' confirms IPv6 blocking is disabled for Link-local address ''' # mock ip -6 address to return Link-local address