fix: delete login counters that drop to zero

A reserve returned after a KDF budget rejection or 503 left a zero key
in Valkey until the end of the window, so a flood with new usernames
created keys past the address limit and could evict real counters.
SETTLE_SCRIPT and LocalLoginLimiter now delete a counter at zero.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-18 10:42:25 +03:00
co-authored by Claude Opus 5.5
parent 3f4771c9d9
commit fa5ba51d6a
10 changed files with 163 additions and 30 deletions
+22
View File
@@ -190,6 +190,28 @@ postgres log: 56 lines, crash markers 0; "too many clients" 0, "administrator co
results: {'fault': 0, 'postgres': 0}; pki: removed …/mtusi-failures-pki-…
```
### 13.8: счётчик, дошедший до 0, удаляется (решение основной сессии, после `3f4771c`)
Тесты до правки кода (рабочее дерево поверх `3f4771c`, `src/` прежний):
```text
service-tests/unit/test_login_limit.py -k "leaves_no_key or at_zero_removed"
FAILED test_returned_reserve_leaves_no_key[aborted] — assert {'db:login:ua…': '0', …} == {}
FAILED test_returned_reserve_leaves_no_key[succeeded] — assert {'db:login:a:…': '0'} == {}
FAILED test_local_counter_at_zero_removed — assert 2 == 0
make failure_checks FAULT_ARGS='-k kdf_budget_login'
FAILED test_kdf_budget_login — login counters after the burst: ['0' × 14, '1', '1'], before it: ['1', '1']
```
После правки (`SETTLE_SCRIPT`: `DECR`, затем `DEL` при ≤ 0; `LocalLoginLimiter.release`;
эмуляция `FakeCache`): `test_login_limit.py` — 22 passed, `make service_test` — 428 passed,
`make service_test_db` — 89 passed; выборка S1 `make failure_checks` — 16 passed, 377
deselected (52,45 с), `results: {'fault': 0, 'postgres': 0}` — в том числе
`test_kdf_budget_login`: после всплеска 8 входов в Valkey только два ключа неудачи со значением 1.
Рабочий стенд после `make run_docker` (образ с правкой): `make test` — PASS, `make student_test` —
229 passed, 6 failed (сверка покрытия, раздел 1).
### Итоговые проверки
| Команда | Итог |