fix(server): tokens of deleted accounts are refused; a failing message or fight can no longer crash the server
After a database reset an old (still signed) token made economy.load insert a save for a missing user; the FOREIGN KEY error escaped the WebSocket handler and took the process down in a restart loop.
This commit is contained in:
@@ -17,6 +17,28 @@ test('socket must authenticate with hello first', async () => {
|
||||
assert.equal((await bad.closed).code, 4003);
|
||||
});
|
||||
|
||||
test('a token of a deleted account is refused - and the server keeps running', async () => {
|
||||
const a = await S.account();
|
||||
await S.json('DELETE', '/api/me', undefined, a.idToken);
|
||||
const c = await S.client(a.idToken, { expectFail: true });
|
||||
assert.equal((await c.next('error')).code, 'UNAUTH');
|
||||
assert.equal((await S.json('GET', '/api/online', undefined, a.idToken)).status, 401);
|
||||
assert.equal((await S.json('GET', '/healthz')).status, 200);
|
||||
});
|
||||
|
||||
test('a failing message handler answers with an error instead of crashing', async () => {
|
||||
const a = await S.account();
|
||||
const c = await S.client(a.idToken);
|
||||
const orig = S.lobby.handle;
|
||||
S.lobby.handle = () => { throw new Error('boom'); };
|
||||
try {
|
||||
c.send({ t: 'room', room: 'DE' });
|
||||
assert.equal((await c.next('error')).code, 'SERVER_ERROR');
|
||||
} finally { S.lobby.handle = orig; }
|
||||
assert.equal((await S.json('GET', '/healthz')).status, 200);
|
||||
c.close();
|
||||
});
|
||||
|
||||
test('old protocol version is told to reload', async () => {
|
||||
const a = await S.account();
|
||||
const c = await S.client(a.idToken, { v: 0, expectFail: true });
|
||||
|
||||
Reference in New Issue
Block a user