Commit 9be3ef7
committed
fix(auth): tell a replayed-and-dead token apart from a skewed clock
An elapsed claim has two causes and they want opposite answers. The previous
commit treated both as skew.
replayed the server keeps handing back one cached token and its `exp` has
finally passed. The token really is dead. Falling back to
`expires_in` gives a corpse a fresh 300s lease -- the pre-fix
behaviour -- and leaves the 401 retry to pay a round trip that a
proactive mint would have avoided.
first seen the clocks disagree. The server validates `exp` against its own
clock, so the token is fine and only this client disbelieves it.
Honouring the claim pins `_exp` in the past and runs both grants on
every request forever.
`_replayed`, set two lines above, already separates them: it is True only for a
token this manager already held, i.e. one whose claim it accepted as FUTURE on an
earlier mint -- so the clock cannot be the explanation the second time. Under skew
each mint returns a distinct token, so the fallback still applies.
The union -- skewed clock AND replaying server -- takes the honour-the-claim
branch and goes back to both grants per request. Traded knowingly: rarer than
either alone, and the 401 retry still covers it.
The elapsed-claim path had coverage only in the skew direction; the replay test
stopped at a claim 10s in the future, so nothing pinned down what happened when
that token finally elapsed. The new test drives `_mint` directly rather than
waiting out the first fallback's 300s lease, since that lease is the thing under
test and not a precondition worth sleeping for.
234 passed. Live endpoint tracks exactly (300/300 ... 290/290).1 parent 5d0c0ad commit 9be3ef7
2 files changed
Lines changed: 49 additions & 8 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
367 | 367 | | |
368 | 368 | | |
369 | 369 | | |
370 | | - | |
| 370 | + | |
371 | 371 | | |
372 | 372 | | |
373 | | - | |
374 | | - | |
375 | | - | |
376 | | - | |
377 | | - | |
378 | | - | |
379 | | - | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
380 | 397 | | |
381 | 398 | | |
382 | 399 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1213 | 1213 | | |
1214 | 1214 | | |
1215 | 1215 | | |
| 1216 | + | |
| 1217 | + | |
| 1218 | + | |
| 1219 | + | |
| 1220 | + | |
| 1221 | + | |
| 1222 | + | |
| 1223 | + | |
| 1224 | + | |
| 1225 | + | |
| 1226 | + | |
| 1227 | + | |
| 1228 | + | |
| 1229 | + | |
| 1230 | + | |
| 1231 | + | |
| 1232 | + | |
| 1233 | + | |
| 1234 | + | |
| 1235 | + | |
| 1236 | + | |
| 1237 | + | |
| 1238 | + | |
| 1239 | + | |
0 commit comments