@ -402,6 +402,61 @@ 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_IPv6_only_link_local ( Pihole ) :
''' confirms IPv6 blocking is disabled for Link-local address '''
# mock ip -6 address to return Link-local address
mock_command_2 ( ' ip ' , { ' -6 address ' : ( ' inet6 fe80::d210:52fa:fe00:7ad7/64 scope link ' , ' 0 ' ) } , Pihole )
detectPlatform = Pihole . run ( '''
source / opt / pihole / basic - install . sh
useIPv6dialog
''' )
expected_stdout = ' Found neither IPv6 ULA nor GUA address, blocking IPv6 ads will not be enabled '
assert expected_stdout in detectPlatform . stdout
def test_IPv6_only_ULA ( Pihole ) :
''' confirms IPv6 blocking is enabled for ULA addresses '''
# mock ip -6 address to return ULA address
mock_command_2 ( ' ip ' , { ' -6 address ' : ( ' inet6 fda2:2001:5555:0:d210:52fa:fe00:7ad7/64 scope global ' , ' 0 ' ) } , Pihole )
detectPlatform = Pihole . run ( '''
source / opt / pihole / basic - install . sh
useIPv6dialog
''' )
expected_stdout = ' Found IPv6 ULA address, using it for blocking IPv6 ads '
assert expected_stdout in detectPlatform . stdout
def test_IPv6_only_GUA ( Pihole ) :
''' confirms IPv6 blocking is enabled for GUA addresses '''
# mock ip -6 address to return GUA address
mock_command_2 ( ' ip ' , { ' -6 address ' : ( ' inet6 2003:12:1e43:301:d210:52fa:fe00:7ad7/64 scope global ' , ' 0 ' ) } , Pihole )
detectPlatform = Pihole . run ( '''
source / opt / pihole / basic - install . sh
useIPv6dialog
''' )
expected_stdout = ' Found IPv6 GUA address, using it for blocking IPv6 ads '
assert expected_stdout in detectPlatform . stdout
def test_IPv6_GUA_ULA_test ( Pihole ) :
''' confirms IPv6 blocking is enabled for GUA and ULA addresses '''
# mock ip -6 address to return GUA and ULA addresses
mock_command_2 ( ' ip ' , { ' -6 address ' : ( ' inet6 2003:12:1e43:301:d210:52fa:fe00:7ad7/64 scope global \n inet6 fda2:2001:5555:0:d210:52fa:fe00:7ad7/64 scope global ' , ' 0 ' ) } , Pihole )
detectPlatform = Pihole . run ( '''
source / opt / pihole / basic - install . sh
useIPv6dialog
''' )
expected_stdout = ' Found IPv6 ULA address, using it for blocking IPv6 ads '
assert expected_stdout in detectPlatform . stdout
def test_IPv6_ULA_GUA_test ( Pihole ) :
''' confirms IPv6 blocking is enabled for GUA and ULA addresses '''
# mock ip -6 address to return ULA and GUA addresses
mock_command_2 ( ' ip ' , { ' -6 address ' : ( ' inet6 fda2:2001:5555:0:d210:52fa:fe00:7ad7/64 scope global \n inet6 2003:12:1e43:301:d210:52fa:fe00:7ad7/64 scope global ' , ' 0 ' ) } , Pihole )
detectPlatform = Pihole . run ( '''
source / opt / pihole / basic - install . sh
useIPv6dialog
''' )
expected_stdout = ' Found IPv6 ULA address, using it for blocking IPv6 ads '
assert expected_stdout in detectPlatform . stdout
# Helper functions
def mock_command ( script , args , container ) :
''' Allows for setup of commands we don ' t really want to have to run for real in unit tests '''
@ -424,6 +479,27 @@ def mock_command(script, args, container):
chmod + x { script }
rm - f / var / log / { scriptlog } ''' .format(script=full_script_path, content=mock_script, scriptlog=script))
def mock_command_2 ( script , args , container ) :
''' Allows for setup of commands we don ' t really want to have to run for real in unit tests '''
full_script_path = ' /usr/local/bin/ {} ' . format ( script )
mock_script = dedent ( ''' \
#!/bin/bash -e
echo " \ $0 \ $@ " >> / var / log / { script }
case " \ $1 \ $2 " in ''' .format(script=script))
for k , v in args . iteritems ( ) :
case = dedent ( '''
\" {arg} \" )
echo \" {res} \"
exit { retcode }
; ; ''' .format(arg=k, res=v[0], retcode=v[1]))
mock_script + = case
mock_script + = dedent ( '''
esac ''' )
container . run ( '''
cat << EOF > { script } \n { content } \nEOF
chmod + x { script }
rm - f / var / log / { scriptlog } ''' .format(script=full_script_path, content=mock_script, scriptlog=script))
def run_script ( Pihole , script ) :
result = Pihole . run ( script )
assert result . rc == 0