Files
MyIP/tests
jason5ng32andClaude Opus 4.7 4ae07831f6 refactor(backend): mount requireValidIP; strip per-handler IP checks
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>
2026-04-18 17:53:00 +08:00
..