PadMessageHandler: Improve message sanity checking

Use exceptions instead of silent drops so that the client can detect
the error and react appropriately.
This commit is contained in:
Richard Hansen 2022-02-22 23:33:03 -05:00
parent 3b76b2dd67
commit b276eb0a23
2 changed files with 97 additions and 183 deletions

View file

@ -146,8 +146,9 @@ describe(__filename, function () {
it('handleMessageSecurity can grant one-time write access', async function () {
const cs = 'Z:1>5+5$hello';
const errRegEx = /write attempt on read-only pad/;
// First try to send a change and verify that it was dropped.
await sendUserChanges(roSocket, cs);
await assert.rejects(sendUserChanges(roSocket, cs), errRegEx);
// sendUserChanges() waits for message ack, so if the message was accepted then head should
// have already incremented by the time we get here.
assert.equal(pad.head, rev); // Not incremented.
@ -162,7 +163,7 @@ describe(__filename, function () {
// The next change should be dropped.
plugins.hooks.handleMessageSecurity = [];
await sendUserChanges(roSocket, 'Z:6>6=5+6$ world');
await assert.rejects(sendUserChanges(roSocket, 'Z:6>6=5+6$ world'), errRegEx);
assert.equal(pad.head, rev); // Not incremented.
assert.equal(pad.text(), 'hello\n');
});