Commit f379dfa
committed
fix(oauth): preserve TTL on refresh, age via updated_at, reject fractional floats
Addresses Oracle second-pass review findings on dd3c25f9:
- _refresh_access_token: when the refresh response omits expires_in,
preserve the prior TTL by computing (expires_at - updated_at) from the
existing record instead of clearing expires_at to NULL. Clearing it
caused proactive refresh to stop after the first such response, since
_is_token_expired returns False for NULL. Falls back to NULL only when
the token had no prior expiry (genuine no-expiry providers like GitHub
OAuth Apps). New _preserve_prior_ttl() module-level helper handles
timezone-naive timestamps and non-positive deltas.
- cleanup_expired_tokens: NULL-expiry rows now age via updated_at, not
created_at. store_tokens advances updated_at on re-authorization, so
using created_at would delete tokens that were re-authorized recently
but originally created more than max_age_days ago.
- parse_expires_in: tighten validation against int() truncation. Previously
expires_in=-0.5 would silently pass as 0 because int(-0.5) == 0 (Python
truncates toward zero). Now: sign-check the original numeric before
conversion, and reject non-integer floats (RFC 6749 §5.1 specifies
integer seconds). Order matters - sign check fires first since 'negative'
is the more fundamental violation.
Tests:
- test_refresh_without_expires_in_clears_expiry replaced by:
test_refresh_without_expires_in_preserves_prior_ttl (asserts new TTL
~= prior TTL after refresh) and
test_refresh_without_expires_in_no_prior_ttl_stays_none.
- test_cleanup_expired_tokens_targets_null_expires_at now asserts the
query uses updated_at AND does NOT use created_at.
- test_parse_expires_in_negative_raises extended with -0.5 and -3600.7.
- New test_parse_expires_in_non_integer_float_raises covers 3600.5, 0.5,
3600.7.
Signed-off-by: Jonathan Springer <jps@s390x.com>1 parent e8176da commit f379dfa
4 files changed
Lines changed: 122 additions & 14 deletions
File tree
- mcpgateway/services
- tests/unit/mcpgateway/services
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1711 | 1711 | | |
1712 | 1712 | | |
1713 | 1713 | | |
| 1714 | + | |
| 1715 | + | |
| 1716 | + | |
| 1717 | + | |
| 1718 | + | |
| 1719 | + | |
| 1720 | + | |
1714 | 1721 | | |
1715 | 1722 | | |
1716 | 1723 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
29 | 29 | | |
30 | 30 | | |
31 | 31 | | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
32 | 74 | | |
33 | 75 | | |
34 | 76 | | |
| |||
330 | 372 | | |
331 | 373 | | |
332 | 374 | | |
| 375 | + | |
333 | 376 | | |
334 | | - | |
| 377 | + | |
335 | 378 | | |
336 | | - | |
337 | | - | |
338 | | - | |
339 | | - | |
340 | | - | |
341 | | - | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
342 | 399 | | |
343 | 400 | | |
344 | 401 | | |
| |||
500 | 557 | | |
501 | 558 | | |
502 | 559 | | |
503 | | - | |
| 560 | + | |
504 | 561 | | |
505 | | - | |
| 562 | + | |
| 563 | + | |
| 564 | + | |
| 565 | + | |
| 566 | + | |
506 | 567 | | |
507 | 568 | | |
508 | 569 | | |
509 | 570 | | |
510 | | - | |
| 571 | + | |
511 | 572 | | |
512 | 573 | | |
513 | 574 | | |
| |||
526 | 587 | | |
527 | 588 | | |
528 | 589 | | |
529 | | - | |
| 590 | + | |
530 | 591 | | |
531 | 592 | | |
532 | 593 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
69 | 69 | | |
70 | 70 | | |
71 | 71 | | |
72 | | - | |
| 72 | + | |
73 | 73 | | |
| 74 | + | |
74 | 75 | | |
75 | 76 | | |
76 | 77 | | |
| |||
81 | 82 | | |
82 | 83 | | |
83 | 84 | | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
84 | 92 | | |
85 | 93 | | |
86 | 94 | | |
| |||
Lines changed: 34 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
339 | 339 | | |
340 | 340 | | |
341 | 341 | | |
342 | | - | |
| 342 | + | |
| 343 | + | |
343 | 344 | | |
344 | 345 | | |
345 | 346 | | |
346 | 347 | | |
| 348 | + | |
| 349 | + | |
347 | 350 | | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
348 | 360 | | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
349 | 377 | | |
350 | 378 | | |
| 379 | + | |
351 | 380 | | |
352 | 381 | | |
353 | 382 | | |
| |||
568 | 597 | | |
569 | 598 | | |
570 | 599 | | |
571 | | - | |
| 600 | + | |
| 601 | + | |
| 602 | + | |
| 603 | + | |
572 | 604 | | |
573 | 605 | | |
574 | 606 | | |
| |||
0 commit comments