Commit 0172879
committed
fix(cache-middleware): align config schema, reject bool/non-finite thresholds
Per CodeRabbit on NVIDIA#1879:
1. cache_middleware_config.py was out of sync with the new constructor
semantics — schema allowed similarity_threshold in [0, 1] and had no
max_entries field at all, so config-driven instantiation could pass
values the constructor now rejects. Re-export
_MIN_FUZZY_THRESHOLD and _DEFAULT_MAX_CACHE_ENTRIES from the module
and wire both constants into the schema:
similarity_threshold: ge=_MIN_FUZZY_THRESHOLD, le=1.0
max_entries: ge=1, default=_DEFAULT_MAX_CACHE_ENTRIES
Docstrings mirror the constructor's rationale (cache-poisoning for
threshold, DoS for max_entries).
2. Constructor validation did not reject `bool` (since isinstance(True, int)
is True in Python) or non-finite floats (NaN / +inf / -inf). Both are
classic config-bug foot-guns: a boolean silently becoming 0 or 1.0,
or a parser that hands back NaN from an upstream source, would slip
past the range comparison. Add explicit:
- bool rejection on similarity_threshold (before the number check)
- math.isfinite() check on similarity_threshold
- bool rejection on max_entries
New tests:
- test_threshold_bool_is_rejected (parametrized True / False)
- test_threshold_non_finite_is_rejected (parametrized NaN / +inf / -inf)
- test_bool_max_entries_is_rejected (parametrized True / False)
Signed-off-by: ColinM-sys <cmcdonough@50words.com>1 parent d8047c3 commit 0172879
3 files changed
Lines changed: 64 additions & 8 deletions
File tree
- packages/nvidia_nat_core
- src/nat/middleware/cache
- tests/nat/middleware
Lines changed: 13 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
30 | 30 | | |
31 | 31 | | |
32 | 32 | | |
| 33 | + | |
33 | 34 | | |
34 | 35 | | |
35 | 36 | | |
| |||
108 | 109 | | |
109 | 110 | | |
110 | 111 | | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
111 | 119 | | |
112 | 120 | | |
113 | 121 | | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
114 | 125 | | |
115 | 126 | | |
116 | 127 | | |
117 | 128 | | |
118 | 129 | | |
119 | 130 | | |
120 | 131 | | |
121 | | - | |
| 132 | + | |
| 133 | + | |
122 | 134 | | |
123 | 135 | | |
124 | 136 | | |
| |||
Lines changed: 28 additions & 7 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
| 22 | + | |
| 23 | + | |
22 | 24 | | |
23 | 25 | | |
24 | 26 | | |
| |||
31 | 33 | | |
32 | 34 | | |
33 | 35 | | |
34 | | - | |
35 | | - | |
36 | | - | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
37 | 46 | | |
38 | 47 | | |
39 | 48 | | |
40 | 49 | | |
41 | | - | |
42 | | - | |
43 | | - | |
44 | | - | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
Lines changed: 23 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
346 | 346 | | |
347 | 347 | | |
348 | 348 | | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
349 | 362 | | |
350 | 363 | | |
351 | 364 | | |
| |||
367 | 380 | | |
368 | 381 | | |
369 | 382 | | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
370 | 393 | | |
371 | 394 | | |
372 | 395 | | |
| |||
0 commit comments