Count the pagination gap in your own inventory script

short · 50 min · Objective 3.1

Task

Write an inventory collector that reads one page, measure how wrong it is, then fix it and add the assertion that would have caught it.

Steps

  1. Write lab/inventory.py that fetches a list WITHOUT following continuation tokens and writes the count to lab/inv-page1.txt.
  2. Obtain the true total by another route -- the console, a CLI with automatic paging, a count endpoint -- and record it in lab/inv-true.txt.
  3. Write lab/inv-gap.md stating both numbers and the percentage of the estate the first script would have placed outside every scope derived from it.
  4. Fix pagination, re-run, and confirm the counts match.
  5. Add an assertion that fails LOUDLY if the count changes by more than a defined proportion between runs, then simulate a drop by limiting the query and confirm the assertion fires.

Verify

cat lab/inv-page1.txt lab/inv-true.txt
grep -Ec '[0-9]+%' lab/inv-gap.md
python lab/inventory.py; echo "fixed exit=$?"

Two different counts recorded, the gap expressed as a percentage, and the assertion observed firing. Pagination failure is the worst possible shape for a control -- confident, wrong and reassuring -- because the report covers what was fetched and says nothing about what was not.

This is an independent study companion for CompTIA SecurityX CAS-005 and is not produced by or endorsed by CompTIA.