mirror of
https://github.com/jason5ng32/MyIP.git
synced 2026-11-04 08:55:47 +00:00
7 handlers that take ?ip (ipinfo, ipapicom, ipchecking, ipsb, ipapiis,
ip2location, maxmind) each opened with the same 8-line block:
const ipAddress = req.query.ip;
if (!ipAddress) return res.status(400).json({ error: 'No IP...' });
if (!isValidIP(ipAddress)) return res.status(400).json({ ... });
Replace by attaching requireValidIP() to the matching routes in
backend-server.js. The handler bodies now assume ?ip has been validated
upstream and just read it:
const ipAddress = req.query.ip;
Handlers that accept other param shapes (ASN, MAC, domain, user ID) or
no params are untouched — they retain whatever handler-specific
validation they need.
Tests updated:
- tests/api-handlers.test.js: drop the 2×3 = 6 "rejects missing/malformed
ip" cases for ip-sb / ipapi-com / ipinfo-io, the 2×2 = 4 for
ipapi-is / ip2location-io, and the 2 for ipcheck-ing. Each set was
testing what the middleware now owns; tests/guards.test.js covers it.
The "reports missing API key after IP passes validation" case for
ipcheck-ing stays — that exercises handler logic beyond the middleware.
- tests/api-smoke.test.js: drop the maxmind "rejects missing and invalid
IP parameters" case (moved to middleware).
Net -13 tests vs pre-commit; 195 still pass.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>