~ knotless Search/
↑↓ move↵ open⇧↵ all results
0
0

Harness: the reference's session tokens may live a second more

Merged chadtmiller.com asked to merge into main from chadtmiller.com/monolith:ref-token-life
harness/checks/lifecycle.mjs+3−1
@@ -735,7 +735,9 @@ async function takendownSession(acct, s, what) {
for (const [field, typ, scope, life] of [['access', 'at+jwt', 'com.atproto.takendown', 7200], ['refresh', 'refresh+jwt', 'com.atproto.refresh', 7776000]]) {
const jwt = decode(s[side.name][field])
const p = jwt?.payload ?? {}
const got = { typ: jwt?.header?.typ, scope: p.scope, sub: p.sub === did ? '<its DID>' : p.sub, aud: p.aud, life: p.exp - p.iat, jti: field === 'refresh' ? typeof p.jti : undefined }
// As in sessions.mjs: the reference may give a second more, the server not.
const life2 = side === ref && p.exp - p.iat === life + 1 ? life : p.exp - p.iat
const got = { typ: jwt?.header?.typ, scope: p.scope, sub: p.sub === did ? '<its DID>' : p.sub, aud: p.aud, life: life2, jti: field === 'refresh' ? typeof p.jti : undefined }
const want = { typ, scope, sub: '<its DID>', aud: 'did:web:localhost', life, jti: field === 'refresh' ? 'string' : undefined }
if (!isDeepStrictEqual(got, want)) await fail(side, `${field} token of a takendown session`, { what }, want, got)
}
harness/checks/sessions.mjs+4−1
@@ -85,7 +85,10 @@ async function checkTokens(side, acct, body, scope, window, request) {
aud,
...(field === 'refreshJwt' ? { jti: typeof id === 'string' && id ? '<jti>' : id } : id === undefined ? {} : { jti: id }),
iat: timely ? '<iat>' : iat,
life: Number.isInteger(exp) && Number.isInteger(iat) ? exp - iat : exp,
// The reference reads the clock for `iat` and again for `exp`, so it
// gives a second more when the two reads fall either side of one; the
// server is held to the life exactly.
life: !Number.isInteger(exp) || !Number.isInteger(iat) ? exp : side === ref && exp - iat === life + 1 ? life : exp - iat,
...rest,
}
const want = { typ, scope: wantScope, sub: `<did:${acct.n}>`, aud: 'did:web:localhost', ...(field === 'refreshJwt' ? { jti: '<jti>' } : {}), iat: '<iat>', life }