diff --git a/src/dnsmasq_interface.c b/src/dnsmasq_interface.c index 1813a2fd..df450fa4 100644 --- a/src/dnsmasq_interface.c +++ b/src/dnsmasq_interface.c @@ -222,7 +222,10 @@ char _FTL_new_query(const unsigned int flags, const char *name, const struct all if(blockingstatus != BLOCKING_DISABLED) { // We check the user blacklist first as it is typically smaller than gravity - if(in_blacklist(domainString) || in_gravity(domainString)) + // If a domain is on the exact blacklist or gravity but also on the whitelist, + // we do NOT block it. + if((in_blacklist(domainString) || in_gravity(domainString)) && + !in_whitelist(domainString)) { blockDomain = 1; } diff --git a/test/test_suite.bats b/test/test_suite.bats index d38d2d58..04186787 100644 --- a/test/test_suite.bats +++ b/test/test_suite.bats @@ -23,25 +23,12 @@ [[ ${lines[0]} == "1" ]] } -@test "Number of imported gravity domains as expected" { - run bash -c 'grep -c "Database (gravity): imported 1 domains" /var/log/pihole-FTL.log' - printf "%s\n" "${lines[@]}" - [[ ${lines[0]} == "1" ]] -} - - @test "Number of compiled regex filters as expected" { run bash -c 'grep -c "Compiled 2 whitelist and 1 blacklist regex filters" /var/log/pihole-FTL.log' printf "%s\n" "${lines[@]}" [[ ${lines[0]} == "1" ]] } -@test "Number of imported blacklist domains as expected" { - run bash -c 'grep -c "Database (blacklist): imported 1 domains" /var/log/pihole-FTL.log' - printf "%s\n" "${lines[@]}" - [[ ${lines[0]} == "1" ]] -} - @test "Blacklisted domain is blocked" { run bash -c "dig blacklisted.com @127.0.0.1 +short" printf "%s\n" "${lines[@]}" @@ -60,14 +47,12 @@ run bash -c "dig whitelisted.com @127.0.0.1 +short" printf "%s\n" "${lines[@]}" [[ ${lines[0]} != "0.0.0.0" ]] - [[ ${lines[1]} == "" ]] } @test "Gravity domain + whitelist regex match is not blocked" { run bash -c "dig 01tse443.se @127.0.0.1 +short" printf "%s\n" "${lines[@]}" [[ ${lines[0]} != "0.0.0.0" ]] - [[ ${lines[1]} == "" ]] } @test "Regex blacklist match is blocked" { @@ -81,28 +66,24 @@ run bash -c "dig regexA.com @127.0.0.1 +short" printf "%s\n" "${lines[@]}" [[ ${lines[0]} != "0.0.0.0" ]] - [[ ${lines[1]} == "" ]] } @test "Regex blacklist match + whitelist exact match is not blocked" { run bash -c "dig regex1.com @127.0.0.1 +short" printf "%s\n" "${lines[@]}" [[ ${lines[0]} != "0.0.0.0" ]] - [[ ${lines[1]} == "" ]] } @test "Regex blacklist match + whitelist regex match is not blocked" { run bash -c "dig regex2.com @127.0.0.1 +short" printf "%s\n" "${lines[@]}" [[ ${lines[0]} != "0.0.0.0" ]] - [[ ${lines[1]} == "" ]] } @test "Google.com (A) is not blocked" { run bash -c "dig A google.com @127.0.0.1 +short" printf "%s\n" "${lines[@]}" [[ ${lines[0]} != "0.0.0.0" ]] - [[ ${lines[1]} == "" ]] } @test "Google.com (AAAA) is not blocked (TCP query)" {