Dominik bb89fbfe7b test: add comprehensive API endpoint tests, fix double-free in printFTLenv
Add pytest tests for all previously untested GET API endpoints:
dns/blocking, domains (all type/kind combinations and single lookup),
groups, stats/summary, stats/top_domains, stats/top_clients,
stats/upstreams, stats/query_types, stats/recent_blocked,
stats/database (error handling), dhcp/leases, endpoints, info/ftl,
info/login, info/version, info/messages, info/client, info/database,
info/system, network/devices, network/interfaces, logs (dnsmasq, ftl,
webserver), and padd.

All assertions use exact expected values derived from the deterministic
BATS DNS query seeding (137 total queries, 49 blocked, 47 forwarded,
41 cached, 11 active clients, 8 gravity domains).  On failure, the
full JSON response is dumped to /tmp/ftl_test_*.json for easy
inspection.

Fix double-free bug in printFTLenv() (src/config/env.c): when
printFTLenv() was called more than once (e.g. after config reload
triggered by the CLI password test), it would free item->error a
second time because neither the pointer nor the error_allocated flag
were reset after the first free.  This produced "Trying to free NULL
pointer in printFTLenv()" warnings.  Fix: set item->error = NULL and
item->error_allocated = false after freeing.

Files modified:
  src/config/env.c      — reset error/error_allocated after free
  test/api/test_api.py  — add 34 new endpoint tests (22 -> 56 total)

Signed-off-by: Dominik <dl6er@dl6er.de>
2026-03-25 13:29:17 +01:00
2019-06-08 18:35:10 +02:00
2017-06-03 15:05:41 +02:00
2025-03-06 15:04:02 +02:00

Pi-hole logo
Network-wide ad blocking via your own Linux hardware

FTLDNS logo

FTLDNS (pihole-FTL) provides an interactive API and also generates statistics for Pi-hole®'s Web interface.

  • Fast: stats are read directly from memory by coupling our codebase closely with dnsmasq
  • Versatile: upstream changes to dnsmasq can quickly be merged in without much conflict
  • Lightweight: runs smoothly with minimal hardware and software requirements such as Raspberry Pi Zero
  • Interactive: our API can be used to interface with your projects
  • Insightful: stats normally reserved inside of dnsmasq are made available so you can see what's really happening on your network

Official documentation

The official FTLDNS documentation can be found here.

Installation

FTLDNS (pihole-FTL) is automatically installed when installing Pi-hole.

IMPORTANT

FTLDNS will disable any existing installations of dnsmasq. This is because FTLDNS is dnsmasq + Pi-hole's code, so both cannot run simultaneously.

S
Description
Languages
C 96.9%
C++ 1.1%
Python 0.9%
Shell 0.7%
CMake 0.3%