fix(auth): revoke captured client sessions safely on logout

This commit is contained in:
2026-10-05 17:13:46 +08:00
parent e139c5c87b
commit 3703d0a677
8 changed files with 175 additions and 28 deletions
+20
View File
@@ -1,6 +1,7 @@
import assert from 'node:assert/strict'
import test from 'node:test'
import {
accessTokenIdentity,
ACCESS_TOKEN_KEY,
REFRESH_TOKEN_KEY,
REMEMBERED_LOGIN_ID_KEY,
@@ -68,3 +69,22 @@ test('normal token rotation never removes either shared token between writes', (
assert.ok(!removed.includes(ACCESS_TOKEN_KEY))
assert.ok(!removed.includes(REFRESH_TOKEN_KEY))
})
function rawIdentity(overrides = '') {
return `test.${Buffer.from(`{"user_id":2107003446494334978,"tenant_id":2107003446494334978,"membership_id":2107003446494334978,"app_code":"MERCHANT"${overrides}}`).toString('base64url')}.test`
}
test('identity preserves low digits of numeric 19 digit user customer and membership',()=>{
const original=rawIdentity();const json=Buffer.from(original.split('.')[1],'base64url').toString();
for(const field of ['user_id','tenant_id','membership_id']){
const changed=json.replace(`"${field}":2107003446494334978`,`"${field}":2107003446494334979`)
assert.notEqual(accessTokenIdentity(original),accessTokenIdentity(`test.${Buffer.from(changed).toString('base64url')}.test`))
}
})
test('identity string and numeric integers are equivalent without changing other strings',()=>{
const a=rawIdentity();const raw=Buffer.from(a.split('.')[1],'base64url').toString();
const b=`test.${Buffer.from(raw.replaceAll(':2107003446494334978',':"2107003446494334978"')).toString('base64url')}.test`
assert.equal(accessTokenIdentity(a),accessTokenIdentity(b))
const decorated=rawIdentity(',"username":'+JSON.stringify('number 2107003446494334979 and "tenant_id":2107003446494334979')+',"note":"1234567890123456789"')
assert.equal(accessTokenIdentity(a),accessTokenIdentity(decorated))
assert.ok(accessTokenIdentity(a).includes('2107003446494334978'))
})