Refuse to use already closed WebSocket objects

We can't do anything useful with them anyway.
This commit is contained in:
Pierre Ossman 2021-04-18 13:53:43 +02:00
parent b7b7e4e26b
commit 9376191fc4
2 changed files with 15 additions and 0 deletions

View File

@ -480,6 +480,10 @@ export default class RFB extends EventTargetMixin {
} catch (e) { } catch (e) {
this._fail("Error attaching channel (" + e + ")"); this._fail("Error attaching channel (" + e + ")");
} }
if (this._sock.readyState === 'closed') {
this._fail("Cannot use already closed WebSocket/RTCDataChannel");
}
} }
// Make our elements part of the page // Make our elements part of the page

View File

@ -183,6 +183,17 @@ describe('Remote Frame Buffer Protocol Client', function () {
expect(attach).to.have.been.calledOnceWithExactly(sock); expect(attach).to.have.been.calledOnceWithExactly(sock);
}); });
it('should refuse closed WebSocket/RTCDataChannel objects', function () {
let sock = new FakeWebSocket('ws://HOST:8675/PATH', []);
sock.readyState = WebSocket.CLOSED;
const client = new RFB(document.createElement('div'), sock);
let callback = sinon.spy();
client.addEventListener('disconnect', callback);
this.clock.tick();
expect(callback).to.have.been.calledOnce;
expect(callback.args[0][0].detail.clean).to.be.false;
});
it('should report attach problems via event', function () { it('should report attach problems via event', function () {
attach.restore(); attach.restore();
attach = sinon.stub(Websock.prototype, 'attach'); attach = sinon.stub(Websock.prototype, 'attach');