Standardize on camelCase for functions in RFB

This commit is contained in:
Samuel Mannehed 2020-05-21 01:41:02 +02:00 committed by Lauri Kasanen
parent eff38d47f9
commit 5a81223d96
2 changed files with 186 additions and 186 deletions

View File

@ -227,7 +227,7 @@ export default class RFB extends EventTargetMixin {
this._sock = new Websock();
this._sock.on('message', () => {
this._handle_message();
this._handleMessage();
});
this._sock.on('open', () => {
if ((this._rfbConnectionState === 'connecting') &&
@ -416,7 +416,7 @@ export default class RFB extends EventTargetMixin {
sendCredentials(creds) {
this._rfbCredentials = creds;
setTimeout(this._init_msg.bind(this), 0);
setTimeout(this._initMsg.bind(this), 0);
}
sendCtrlAltDel() {
@ -846,9 +846,9 @@ export default class RFB extends EventTargetMixin {
{ detail: { capabilities: this._capabilities } }));
}
_handle_message() {
_handleMessage() {
if (this._sock.rQlen === 0) {
Log.Warn("handle_message called on an empty receive queue");
Log.Warn("handleMessage called on an empty receive queue");
return;
}
@ -861,7 +861,7 @@ export default class RFB extends EventTargetMixin {
if (this._flushing) {
break;
}
if (!this._normal_msg()) {
if (!this._normalMsg()) {
break;
}
if (this._sock.rQlen === 0) {
@ -870,7 +870,7 @@ export default class RFB extends EventTargetMixin {
}
break;
default:
this._init_msg();
this._initMsg();
break;
}
}
@ -946,7 +946,7 @@ export default class RFB extends EventTargetMixin {
// Message Handlers
_negotiate_protocol_version() {
_negotiateProtocolVersion() {
if (this._sock.rQwait("version", 12)) {
return false;
}
@ -997,7 +997,7 @@ export default class RFB extends EventTargetMixin {
this._rfbInitState = 'Security';
}
_negotiate_security() {
_negotiateSecurity() {
// Polyfill since IE and PhantomJS doesn't have
// TypedArray.includes()
function includes(item, array) {
@ -1018,7 +1018,7 @@ export default class RFB extends EventTargetMixin {
this._rfbInitState = "SecurityReason";
this._securityContext = "no security types";
this._securityStatus = 1;
return this._init_msg();
return this._initMsg();
}
const types = this._sock.rQshiftBytes(numTypes);
@ -1049,17 +1049,17 @@ export default class RFB extends EventTargetMixin {
this._rfbInitState = "SecurityReason";
this._securityContext = "authentication scheme";
this._securityStatus = 1;
return this._init_msg();
return this._initMsg();
}
}
this._rfbInitState = 'Authentication';
Log.Debug('Authenticating using scheme: ' + this._rfbAuthScheme);
return this._init_msg(); // jump to authentication
return this._initMsg(); // jump to authentication
}
_handle_security_reason() {
_handleSecurityReason() {
if (this._sock.rQwait("reason length", 4)) {
return false;
}
@ -1091,7 +1091,7 @@ export default class RFB extends EventTargetMixin {
}
// authentication
_negotiate_xvp_auth() {
_negotiateXvpAuth() {
if (!this._rfbCredentials.username ||
!this._rfbCredentials.password ||
!this._rfbCredentials.target) {
@ -1107,11 +1107,11 @@ export default class RFB extends EventTargetMixin {
this._rfbCredentials.target;
this._sock.send_string(xvpAuthStr);
this._rfbAuthScheme = 2;
return this._negotiate_authentication();
return this._negotiateAuthentication();
}
// VeNCrypt authentication, currently only supports version 0.2 and only Plain subtype
_negotiate_vencrypt_auth() {
_negotiateVeNCryptAuth() {
// waiting for VeNCrypt version
if (this._rfbVeNCryptState == 0) {
@ -1198,7 +1198,7 @@ export default class RFB extends EventTargetMixin {
}
}
_negotiate_std_vnc_auth() {
_negotiateStdVNCAuth() {
if (this._sock.rQwait("auth challenge", 16)) { return false; }
// KasmVNC uses basic Auth, clear the VNC password, which is not used
@ -1212,7 +1212,7 @@ export default class RFB extends EventTargetMixin {
return true;
}
_negotiate_tight_unix_auth() {
_negotiateTightUnixAuth() {
if (this._rfbCredentials.username === undefined ||
this._rfbCredentials.password === undefined) {
this.dispatchEvent(new CustomEvent(
@ -1229,7 +1229,7 @@ export default class RFB extends EventTargetMixin {
return true;
}
_negotiate_tight_tunnels(numTunnels) {
_negotiateTightTunnels(numTunnels) {
const clientSupportedTunnelTypes = {
0: { vendor: 'TGHT', signature: 'NOTUNNEL' }
};
@ -1270,7 +1270,7 @@ export default class RFB extends EventTargetMixin {
}
}
_negotiate_tight_auth() {
_negotiateTightAuth() {
if (!this._rfbTightVNC) { // first pass, do the tunnel negotiation
if (this._sock.rQwait("num tunnels", 4)) { return false; }
const numTunnels = this._sock.rQshift32();
@ -1279,7 +1279,7 @@ export default class RFB extends EventTargetMixin {
this._rfbTightVNC = true;
if (numTunnels > 0) {
this._negotiate_tight_tunnels(numTunnels);
this._negotiateTightTunnels(numTunnels);
return false; // wait until we receive the sub auth to continue
}
}
@ -1321,10 +1321,10 @@ export default class RFB extends EventTargetMixin {
return true;
case 'STDVVNCAUTH_': // VNC auth
this._rfbAuthScheme = 2;
return this._init_msg();
return this._initMsg();
case 'TGHTULGNAUTH': // UNIX auth
this._rfbAuthScheme = 129;
return this._init_msg();
return this._initMsg();
default:
return this._fail("Unsupported tiny auth scheme " +
"(scheme: " + authType + ")");
@ -1335,7 +1335,7 @@ export default class RFB extends EventTargetMixin {
return this._fail("No supported sub-auth types!");
}
_negotiate_authentication() {
_negotiateAuthentication() {
switch (this._rfbAuthScheme) {
case 1: // no auth
if (this._rfbVersion >= 3.8) {
@ -1343,22 +1343,22 @@ export default class RFB extends EventTargetMixin {
return true;
}
this._rfbInitState = 'ClientInitialisation';
return this._init_msg();
return this._initMsg();
case 22: // XVP auth
return this._negotiate_xvp_auth();
return this._negotiateXvpAuth();
case 2: // VNC authentication
return this._negotiate_std_vnc_auth();
return this._negotiateStdVNCAuth();
case 16: // TightVNC Security Type
return this._negotiate_tight_auth();
return this._negotiateTightAuth();
case 19: // VeNCrypt Security Type
return this._negotiate_vencrypt_auth();
return this._negotiateVeNCryptAuth();
case 129: // TightVNC UNIX Security Type
return this._negotiate_tight_unix_auth();
return this._negotiateTightUnixAuth();
default:
return this._fail("Unsupported auth scheme (scheme: " +
@ -1366,7 +1366,7 @@ export default class RFB extends EventTargetMixin {
}
}
_handle_security_result() {
_handleSecurityResult() {
if (this._sock.rQwait('VNC auth response ', 4)) { return false; }
const status = this._sock.rQshift32();
@ -1374,13 +1374,13 @@ export default class RFB extends EventTargetMixin {
if (status === 0) { // OK
this._rfbInitState = 'ClientInitialisation';
Log.Debug('Authentication OK');
return this._init_msg();
return this._initMsg();
} else {
if (this._rfbVersion >= 3.8) {
this._rfbInitState = "SecurityReason";
this._securityContext = "security result";
this._securityStatus = status;
return this._init_msg();
return this._initMsg();
} else {
this.dispatchEvent(new CustomEvent(
"securityfailure",
@ -1391,7 +1391,7 @@ export default class RFB extends EventTargetMixin {
}
}
_negotiate_server_init() {
_negotiateServerInit() {
if (this._sock.rQwait("server initialization", 24)) { return false; }
/* Screen size */
@ -1586,22 +1586,22 @@ export default class RFB extends EventTargetMixin {
* ClientInitialization - not triggered by server message
* ServerInitialization
*/
_init_msg() {
_initMsg() {
switch (this._rfbInitState) {
case 'ProtocolVersion':
return this._negotiate_protocol_version();
return this._negotiateProtocolVersion();
case 'Security':
return this._negotiate_security();
return this._negotiateSecurity();
case 'Authentication':
return this._negotiate_authentication();
return this._negotiateAuthentication();
case 'SecurityResult':
return this._handle_security_result();
return this._handleSecurityResult();
case 'SecurityReason':
return this._handle_security_reason();
return this._handleSecurityReason();
case 'ClientInitialisation':
this._sock.send([this._shared ? 1 : 0]); // ClientInitialisation
@ -1609,7 +1609,7 @@ export default class RFB extends EventTargetMixin {
return true;
case 'ServerInitialisation':
return this._negotiate_server_init();
return this._negotiateServerInit();
default:
return this._fail("Unknown init state (state: " +
@ -1617,13 +1617,13 @@ export default class RFB extends EventTargetMixin {
}
}
_handle_set_colour_map_msg() {
_handleSetColourMapMsg() {
Log.Debug("SetColorMapEntries");
return this._fail("Unexpected SetColorMapEntries message");
}
_handle_server_cut_text() {
_handleServerCutText() {
Log.Debug("ServerCutText");
if (this._sock.rQwait("ServerCutText header", 7, 1)) { return false; }
@ -1807,7 +1807,7 @@ export default class RFB extends EventTargetMixin {
return true;
}
_handle_server_fence_msg() {
_handleServerFenceMsg() {
if (this._sock.rQwait("ServerFence header", 8, 1)) { return false; }
this._sock.rQskipBytes(3); // Padding
let flags = this._sock.rQshift32();
@ -1849,7 +1849,7 @@ export default class RFB extends EventTargetMixin {
return true;
}
_handle_xvp_msg() {
_handleXvpMsg() {
if (this._sock.rQwait("XVP version and message", 3, 1)) { return false; }
this._sock.rQskipBytes(1); // Padding
const xvpVer = this._sock.rQshift8();
@ -1872,7 +1872,7 @@ export default class RFB extends EventTargetMixin {
return true;
}
_normal_msg() {
_normalMsg() {
let msgType;
if (this._FBU.rects > 0) {
msgType = 0;
@ -1891,7 +1891,7 @@ export default class RFB extends EventTargetMixin {
return ret;
case 1: // SetColorMapEntries
return this._handle_set_colour_map_msg();
return this._handleSetColourMapMsg();
case 2: // Bell
Log.Debug("Bell");
@ -1901,7 +1901,7 @@ export default class RFB extends EventTargetMixin {
return true;
case 3: // ServerCutText
return this._handle_server_cut_text();
return this._handleServerCutText();
case 150: // EndOfContinuousUpdates
first = !this._supportsContinuousUpdates;
@ -1921,10 +1921,10 @@ export default class RFB extends EventTargetMixin {
return this._handle_server_stats_msg();
case 248: // ServerFence
return this._handle_server_fence_msg();
return this._handleServerFenceMsg();
case 250: // XVP
return this._handle_xvp_msg();
return this._handleXvpMsg();
default:
this._fail("Unexpected server message (type " + msgType + ")");
@ -1937,7 +1937,7 @@ export default class RFB extends EventTargetMixin {
this._flushing = false;
// Resume processing
if (this._sock.rQlen > 0) {
this._handle_message();
this._handleMessage();
}
}

View File

@ -139,7 +139,7 @@ describe('Remote Frame Buffer Protocol Client', function () {
container = null;
});
function make_rfb(url, options) {
function makeRFB(url, options) {
url = url || 'wss://host:8675';
const rfb = new RFB(container, url, options);
clock.tick();
@ -171,7 +171,7 @@ describe('Remote Frame Buffer Protocol Client', function () {
describe('#disconnect', function () {
let client;
beforeEach(function () {
client = make_rfb();
client = makeRFB();
});
it('should go to state "disconnecting" before "disconnected"', function () {
@ -207,7 +207,7 @@ describe('Remote Frame Buffer Protocol Client', function () {
describe('#sendCredentials', function () {
let client;
beforeEach(function () {
client = make_rfb();
client = makeRFB();
client._rfbConnectionState = 'connecting';
});
@ -216,11 +216,11 @@ describe('Remote Frame Buffer Protocol Client', function () {
expect(client._rfbCredentials).to.deep.equal({ password: 'pass' });
});
it('should call init_msg "soon"', function () {
client._init_msg = sinon.spy();
it('should call initMsg "soon"', function () {
client._initMsg = sinon.spy();
client.sendCredentials({ password: 'pass' });
this.clock.tick(5);
expect(client._init_msg).to.have.been.calledOnce;
expect(client._initMsg).to.have.been.calledOnce;
});
});
});
@ -228,7 +228,7 @@ describe('Remote Frame Buffer Protocol Client', function () {
describe('Public API Basic Behavior', function () {
let client;
beforeEach(function () {
client = make_rfb();
client = makeRFB();
});
describe('#sendCtrlAlDel', function () {
@ -408,7 +408,7 @@ describe('Remote Frame Buffer Protocol Client', function () {
describe('Clipping', function () {
let client;
beforeEach(function () {
client = make_rfb();
client = makeRFB();
container.style.width = '70px';
container.style.height = '80px';
client.clipViewport = true;
@ -581,7 +581,7 @@ describe('Remote Frame Buffer Protocol Client', function () {
describe('Scaling', function () {
let client;
beforeEach(function () {
client = make_rfb();
client = makeRFB();
container.style.width = '70px';
container.style.height = '80px';
client.scaleViewport = true;
@ -664,7 +664,7 @@ describe('Remote Frame Buffer Protocol Client', function () {
describe('Remote resize', function () {
let client;
beforeEach(function () {
client = make_rfb();
client = makeRFB();
client._supportsSetDesktopSize = true;
client.resizeSession = true;
container.style.width = '70px';
@ -797,7 +797,7 @@ describe('Remote Frame Buffer Protocol Client', function () {
describe('#_updateConnectionState', function () {
let client;
beforeEach(function () {
client = make_rfb();
client = makeRFB();
});
it('should clear the disconnect timer if the state is not "disconnecting"', function () {
@ -853,7 +853,7 @@ describe('Remote Frame Buffer Protocol Client', function () {
describe('#_fail', function () {
let client;
beforeEach(function () {
client = make_rfb();
client = makeRFB();
});
it('should close the WebSocket connection', function () {
@ -904,7 +904,7 @@ describe('Remote Frame Buffer Protocol Client', function () {
describe('connected', function () {
let client;
beforeEach(function () {
client = make_rfb();
client = makeRFB();
});
it('should result in a connect event if state becomes connected', function () {
@ -927,7 +927,7 @@ describe('Remote Frame Buffer Protocol Client', function () {
describe('disconnecting', function () {
let client;
beforeEach(function () {
client = make_rfb();
client = makeRFB();
});
it('should force disconnect if we do not call Websock.onclose within the disconnection timeout', function () {
@ -993,12 +993,12 @@ describe('Remote Frame Buffer Protocol Client', function () {
describe('Protocol Initialization States', function () {
let client;
beforeEach(function () {
client = make_rfb();
client = makeRFB();
client._rfbConnectionState = 'connecting';
});
describe('ProtocolVersion', function () {
function send_ver(ver, client) {
function sendVer(ver, client) {
const arr = new Uint8Array(12);
for (let i = 0; i < ver.length; i++) {
arr[i+4] = ver.charCodeAt(i);
@ -1010,54 +1010,54 @@ describe('Remote Frame Buffer Protocol Client', function () {
describe('version parsing', function () {
it('should interpret version 003.003 as version 3.3', function () {
send_ver('003.003', client);
sendVer('003.003', client);
expect(client._rfbVersion).to.equal(3.3);
});
it('should interpret version 003.006 as version 3.3', function () {
send_ver('003.006', client);
sendVer('003.006', client);
expect(client._rfbVersion).to.equal(3.3);
});
it('should interpret version 003.889 as version 3.3', function () {
send_ver('003.889', client);
sendVer('003.889', client);
expect(client._rfbVersion).to.equal(3.3);
});
it('should interpret version 003.007 as version 3.7', function () {
send_ver('003.007', client);
sendVer('003.007', client);
expect(client._rfbVersion).to.equal(3.7);
});
it('should interpret version 003.008 as version 3.8', function () {
send_ver('003.008', client);
sendVer('003.008', client);
expect(client._rfbVersion).to.equal(3.8);
});
it('should interpret version 004.000 as version 3.8', function () {
send_ver('004.000', client);
sendVer('004.000', client);
expect(client._rfbVersion).to.equal(3.8);
});
it('should interpret version 004.001 as version 3.8', function () {
send_ver('004.001', client);
sendVer('004.001', client);
expect(client._rfbVersion).to.equal(3.8);
});
it('should interpret version 005.000 as version 3.8', function () {
send_ver('005.000', client);
sendVer('005.000', client);
expect(client._rfbVersion).to.equal(3.8);
});
it('should fail on an invalid version', function () {
sinon.spy(client, "_fail");
send_ver('002.000', client);
sendVer('002.000', client);
expect(client._fail).to.have.been.calledOnce;
});
});
it('should send back the interpreted version', function () {
send_ver('004.000', client);
sendVer('004.000', client);
const expectedStr = 'RFB 003.008\n';
const expected = [];
@ -1069,18 +1069,18 @@ describe('Remote Frame Buffer Protocol Client', function () {
});
it('should transition to the Security state on successful negotiation', function () {
send_ver('003.008', client);
sendVer('003.008', client);
expect(client._rfbInitState).to.equal('Security');
});
describe('Repeater', function () {
beforeEach(function () {
client = make_rfb('wss://host:8675', { repeaterID: "12345" });
client = makeRFB('wss://host:8675', { repeaterID: "12345" });
client._rfbConnectionState = 'connecting';
});
it('should interpret version 000.000 as a repeater', function () {
send_ver('000.000', client);
sendVer('000.000', client);
expect(client._rfbVersion).to.equal(0);
const sentData = client._sock._websocket._get_sent_data();
@ -1089,8 +1089,8 @@ describe('Remote Frame Buffer Protocol Client', function () {
});
it('should handle two step repeater negotiation', function () {
send_ver('000.000', client);
send_ver('003.008', client);
sendVer('000.000', client);
sendVer('003.008', client);
expect(client._rfbVersion).to.equal(3.8);
});
});
@ -1148,10 +1148,10 @@ describe('Remote Frame Buffer Protocol Client', function () {
it('should transition to the Authentication state and continue on successful negotiation', function () {
client._rfbVersion = 3.7;
const authSchemes = [1, 1];
client._negotiate_authentication = sinon.spy();
client._negotiateAuthentication = sinon.spy();
client._sock._websocket._receive_data(new Uint8Array(authSchemes));
expect(client._rfbInitState).to.equal('Authentication');
expect(client._negotiate_authentication).to.have.been.calledOnce;
expect(client._negotiateAuthentication).to.have.been.calledOnce;
});
});
@ -1160,7 +1160,7 @@ describe('Remote Frame Buffer Protocol Client', function () {
client._rfbInitState = 'Security';
});
function send_security(type, cl) {
function sendSecurity(type, cl) {
cl._sock._websocket._receive_data(new Uint8Array([1, type]));
}
@ -1182,20 +1182,20 @@ describe('Remote Frame Buffer Protocol Client', function () {
it('should transition straight to SecurityResult on "no auth" (1) for versions >= 3.8', function () {
client._rfbVersion = 3.8;
send_security(1, client);
sendSecurity(1, client);
expect(client._rfbInitState).to.equal('SecurityResult');
});
it('should transition straight to ServerInitialisation on "no auth" for versions < 3.8', function () {
client._rfbVersion = 3.7;
send_security(1, client);
sendSecurity(1, client);
expect(client._rfbInitState).to.equal('ServerInitialisation');
});
it('should fail on an unknown auth scheme', function () {
sinon.spy(client, "_fail");
client._rfbVersion = 3.8;
send_security(57, client);
sendSecurity(57, client);
expect(client._fail).to.have.been.calledOnce;
});
@ -1208,7 +1208,7 @@ describe('Remote Frame Buffer Protocol Client', function () {
it('should fire the credentialsrequired event if missing a password', function () {
const spy = sinon.spy();
client.addEventListener("credentialsrequired", spy);
send_security(2, client);
sendSecurity(2, client);
const challenge = [];
for (let i = 0; i < 16; i++) { challenge[i] = i; }
@ -1221,7 +1221,7 @@ describe('Remote Frame Buffer Protocol Client', function () {
it('should encrypt the password with DES and then send it back', function () {
client._rfbCredentials = { password: 'passwd' };
send_security(2, client);
sendSecurity(2, client);
client._sock._websocket._get_sent_data(); // skip the choice of auth reply
const challenge = [];
@ -1234,7 +1234,7 @@ describe('Remote Frame Buffer Protocol Client', function () {
it('should transition to SecurityResult immediately after sending the password', function () {
client._rfbCredentials = { password: 'passwd' };
send_security(2, client);
sendSecurity(2, client);
const challenge = [];
for (let i = 0; i < 16; i++) { challenge[i] = i; }
@ -1254,16 +1254,16 @@ describe('Remote Frame Buffer Protocol Client', function () {
client._rfbCredentials = { username: 'user',
target: 'target',
password: 'password' };
client._negotiate_std_vnc_auth = sinon.spy();
send_security(22, client);
expect(client._negotiate_std_vnc_auth).to.have.been.calledOnce;
client._negotiateStdVNCAuth = sinon.spy();
sendSecurity(22, client);
expect(client._negotiateStdVNCAuth).to.have.been.calledOnce;
});
it('should fire the credentialsrequired event if all credentials are missing', function () {
const spy = sinon.spy();
client.addEventListener("credentialsrequired", spy);
client._rfbCredentials = {};
send_security(22, client);
sendSecurity(22, client);
expect(client._rfbCredentials).to.be.empty;
expect(spy).to.have.been.calledOnce;
@ -1275,7 +1275,7 @@ describe('Remote Frame Buffer Protocol Client', function () {
client.addEventListener("credentialsrequired", spy);
client._rfbCredentials = { username: 'user',
target: 'target' };
send_security(22, client);
sendSecurity(22, client);
expect(spy).to.have.been.calledOnce;
expect(spy.args[0][0].detail.types).to.have.members(["username", "password", "target"]);
@ -1285,9 +1285,9 @@ describe('Remote Frame Buffer Protocol Client', function () {
client._rfbCredentials = { username: 'user',
target: 'target',
password: 'password' };
client._negotiate_std_vnc_auth = sinon.spy();
client._negotiateStdVNCAuth = sinon.spy();
send_security(22, client);
sendSecurity(22, client);
const expected = [22, 4, 6]; // auth selection, len user, len target
for (let i = 0; i < 10; i++) { expected[i+3] = 'usertarget'.charCodeAt(i); }
@ -1300,11 +1300,11 @@ describe('Remote Frame Buffer Protocol Client', function () {
beforeEach(function () {
client._rfbInitState = 'Security';
client._rfbVersion = 3.8;
send_security(16, client);
sendSecurity(16, client);
client._sock._websocket._get_sent_data(); // skip the security reply
});
function send_num_str_pairs(pairs, client) {
function sendNumStrPairs(pairs, client) {
const data = [];
push32(data, pairs.length);
@ -1328,57 +1328,57 @@ describe('Remote Frame Buffer Protocol Client', function () {
it('should fail if no supported tunnels are listed', function () {
sinon.spy(client, "_fail");
send_num_str_pairs([[123, 'OTHR', 'SOMETHNG']], client);
sendNumStrPairs([[123, 'OTHR', 'SOMETHNG']], client);
expect(client._fail).to.have.been.calledOnce;
});
it('should choose the notunnel tunnel type', function () {
send_num_str_pairs([[0, 'TGHT', 'NOTUNNEL'], [123, 'OTHR', 'SOMETHNG']], client);
sendNumStrPairs([[0, 'TGHT', 'NOTUNNEL'], [123, 'OTHR', 'SOMETHNG']], client);
expect(client._sock).to.have.sent(new Uint8Array([0, 0, 0, 0]));
});
it('should choose the notunnel tunnel type for Siemens devices', function () {
send_num_str_pairs([[1, 'SICR', 'SCHANNEL'], [2, 'SICR', 'SCHANLPW']], client);
sendNumStrPairs([[1, 'SICR', 'SCHANNEL'], [2, 'SICR', 'SCHANLPW']], client);
expect(client._sock).to.have.sent(new Uint8Array([0, 0, 0, 0]));
});
it('should continue to sub-auth negotiation after tunnel negotiation', function () {
send_num_str_pairs([[0, 'TGHT', 'NOTUNNEL']], client);
sendNumStrPairs([[0, 'TGHT', 'NOTUNNEL']], client);
client._sock._websocket._get_sent_data(); // skip the tunnel choice here
send_num_str_pairs([[1, 'STDV', 'NOAUTH__']], client);
sendNumStrPairs([[1, 'STDV', 'NOAUTH__']], client);
expect(client._sock).to.have.sent(new Uint8Array([0, 0, 0, 1]));
expect(client._rfbInitState).to.equal('SecurityResult');
});
/*it('should attempt to use VNC auth over no auth when possible', function () {
client._rfbTightVNC = true;
client._negotiate_std_vnc_auth = sinon.spy();
send_num_str_pairs([[1, 'STDV', 'NOAUTH__'], [2, 'STDV', 'VNCAUTH_']], client);
client._negotiateStdVNCAuth = sinon.spy();
sendNumStrPairs([[1, 'STDV', 'NOAUTH__'], [2, 'STDV', 'VNCAUTH_']], client);
expect(client._sock).to.have.sent([0, 0, 0, 1]);
expect(client._negotiate_std_vnc_auth).to.have.been.calledOnce;
expect(client._negotiateStdVNCAuth).to.have.been.calledOnce;
expect(client._rfbAuthScheme).to.equal(2);
});*/ // while this would make sense, the original code doesn't actually do this
it('should accept the "no auth" auth type and transition to SecurityResult', function () {
client._rfbTightVNC = true;
send_num_str_pairs([[1, 'STDV', 'NOAUTH__']], client);
sendNumStrPairs([[1, 'STDV', 'NOAUTH__']], client);
expect(client._sock).to.have.sent(new Uint8Array([0, 0, 0, 1]));
expect(client._rfbInitState).to.equal('SecurityResult');
});
it('should accept VNC authentication and transition to that', function () {
client._rfbTightVNC = true;
client._negotiate_std_vnc_auth = sinon.spy();
send_num_str_pairs([[2, 'STDV', 'VNCAUTH__']], client);
client._negotiateStdVNCAuth = sinon.spy();
sendNumStrPairs([[2, 'STDV', 'VNCAUTH__']], client);
expect(client._sock).to.have.sent(new Uint8Array([0, 0, 0, 2]));
expect(client._negotiate_std_vnc_auth).to.have.been.calledOnce;
expect(client._negotiateStdVNCAuth).to.have.been.calledOnce;
expect(client._rfbAuthScheme).to.equal(2);
});
it('should fail if there are no supported auth types', function () {
sinon.spy(client, "_fail");
client._rfbTightVNC = true;
send_num_str_pairs([[23, 'stdv', 'badval__']], client);
sendNumStrPairs([[23, 'stdv', 'badval__']], client);
expect(client._fail).to.have.been.calledOnce;
});
});
@ -1452,7 +1452,7 @@ describe('Remote Frame Buffer Protocol Client', function () {
describe('ClientInitialisation', function () {
it('should transition to the ServerInitialisation state', function () {
const client = make_rfb();
const client = makeRFB();
client._rfbConnectionState = 'connecting';
client._rfbInitState = 'SecurityResult';
client._sock._websocket._receive_data(new Uint8Array([0, 0, 0, 0]));
@ -1460,7 +1460,7 @@ describe('Remote Frame Buffer Protocol Client', function () {
});
it('should send 1 if we are in shared mode', function () {
const client = make_rfb('wss://host:8675', { shared: true });
const client = makeRFB('wss://host:8675', { shared: true });
client._rfbConnectionState = 'connecting';
client._rfbInitState = 'SecurityResult';
client._sock._websocket._receive_data(new Uint8Array([0, 0, 0, 0]));
@ -1468,7 +1468,7 @@ describe('Remote Frame Buffer Protocol Client', function () {
});
it('should send 0 if we are not in shared mode', function () {
const client = make_rfb('wss://host:8675', { shared: false });
const client = makeRFB('wss://host:8675', { shared: false });
client._rfbConnectionState = 'connecting';
client._rfbInitState = 'SecurityResult';
client._sock._websocket._receive_data(new Uint8Array([0, 0, 0, 0]));
@ -1481,7 +1481,7 @@ describe('Remote Frame Buffer Protocol Client', function () {
client._rfbInitState = 'ServerInitialisation';
});
function send_server_init(opts, client) {
function sendServerInit(opts, client) {
const fullOpts = { width: 10, height: 12, bpp: 24, depth: 24, big_endian: 0,
true_color: 1, redMax: 255, greenMax: 255, blueMax: 255,
redShift: 16, greenShift: 8, blueShift: 0, name: 'a name' };
@ -1522,7 +1522,7 @@ describe('Remote Frame Buffer Protocol Client', function () {
}
it('should set the framebuffer width and height', function () {
send_server_init({ width: 32, height: 84 }, client);
sendServerInit({ width: 32, height: 84 }, client);
expect(client._fbWidth).to.equal(32);
expect(client._fbHeight).to.equal(84);
});
@ -1532,7 +1532,7 @@ describe('Remote Frame Buffer Protocol Client', function () {
it('should set the framebuffer name and call the callback', function () {
const spy = sinon.spy();
client.addEventListener("desktopname", spy);
send_server_init({ name: 'som€ nam€' }, client);
sendServerInit({ name: 'som€ nam€' }, client);
expect(client._fbName).to.equal('som€ nam€');
expect(spy).to.have.been.calledOnce;
@ -1543,7 +1543,7 @@ describe('Remote Frame Buffer Protocol Client', function () {
// NB(sross): we don't actually do anything with it, so just test that we can
// read it w/o throwing an error
client._rfbTightVNC = true;
send_server_init({}, client);
sendServerInit({}, client);
const tightData = [];
push16(tightData, 1);
@ -1560,7 +1560,7 @@ describe('Remote Frame Buffer Protocol Client', function () {
it('should resize the display', function () {
sinon.spy(client._display, 'resize');
send_server_init({ width: 27, height: 32 }, client);
sendServerInit({ width: 27, height: 32 }, client);
expect(client._display.resize).to.have.been.calledOnce;
expect(client._display.resize).to.have.been.calledWith(27, 32);
@ -1569,7 +1569,7 @@ describe('Remote Frame Buffer Protocol Client', function () {
it('should grab the mouse and keyboard', function () {
sinon.spy(client._keyboard, 'grab');
sinon.spy(client._mouse, 'grab');
send_server_init({}, client);
sendServerInit({}, client);
expect(client._keyboard.grab).to.have.been.calledOnce;
expect(client._mouse.grab).to.have.been.calledOnce;
});
@ -1589,7 +1589,7 @@ describe('Remote Frame Buffer Protocol Client', function () {
// TODO(directxman12): test the various options in this configuration matrix
it('should reply with the pixel format, client encodings, and initial update request', function () {
send_server_init({ width: 27, height: 32 }, client);
sendServerInit({ width: 27, height: 32 }, client);
expect(RFB.messages.pixelFormat).to.have.been.calledOnce;
expect(RFB.messages.pixelFormat).to.have.been.calledWith(client._sock, 24, true);
@ -1602,7 +1602,7 @@ describe('Remote Frame Buffer Protocol Client', function () {
});
it('should reply with restricted settings for Intel AMT servers', function () {
send_server_init({ width: 27, height: 32, name: "Intel(r) AMT KVM"}, client);
sendServerInit({ width: 27, height: 32, name: "Intel(r) AMT KVM"}, client);
expect(RFB.messages.pixelFormat).to.have.been.calledOnce;
expect(RFB.messages.pixelFormat).to.have.been.calledWith(client._sock, 8, true);
@ -1617,7 +1617,7 @@ describe('Remote Frame Buffer Protocol Client', function () {
});
it('should transition to the "connected" state', function () {
send_server_init({}, client);
sendServerInit({}, client);
expect(client._rfbConnectionState).to.equal('connected');
});
});
@ -1627,7 +1627,7 @@ describe('Remote Frame Buffer Protocol Client', function () {
let client;
beforeEach(function () {
client = make_rfb();
client = makeRFB();
client._fbName = 'some device';
client._fbWidth = 640;
client._fbHeight = 20;
@ -1656,7 +1656,7 @@ describe('Remote Frame Buffer Protocol Client', function () {
targetDataCheck = new Uint8Array(targetDataCheckArr);
});
function send_fbu_msg(rectInfo, rectData, client, rectCnt) {
function sendFbuMsg(rectInfo, rectData, client, rectCnt) {
let data = [];
if (!rectCnt || rectCnt > -1) {
@ -1720,7 +1720,7 @@ describe('Remote Frame Buffer Protocol Client', function () {
it('should fail on an unsupported encoding', function () {
sinon.spy(client, "_fail");
const rectInfo = { x: 8, y: 11, width: 27, height: 32, encoding: 234 };
send_fbu_msg([rectInfo], [[]], client);
sendFbuMsg([rectInfo], [[]], client);
expect(client._fail).to.have.been.calledOnce;
});
@ -1735,8 +1735,8 @@ describe('Remote Frame Buffer Protocol Client', function () {
{ x: 2, y: 2, width: 2, height: 2, encoding: 0x01}];
// data says [{ old_x: 2, old_y: 0 }, { old_x: 0, old_y: 0 }]
const rects = [[0, 2, 0, 0], [0, 0, 0, 0]];
send_fbu_msg([info[0]], [rects[0]], client, 2);
send_fbu_msg([info[1]], [rects[1]], client, -1);
sendFbuMsg([info[0]], [rects[0]], client, 2);
sendFbuMsg([info[1]], [rects[1]], client, -1);
expect(client._display).to.have.displayed(targetDataCheck);
});
@ -1760,7 +1760,7 @@ describe('Remote Frame Buffer Protocol Client', function () {
[0xff, 0x00, 0x00, 0, 0xff, 0x00, 0x00, 0, 0xff, 0x00, 0x00, 0, 0xff, 0x00, 0x00, 0],
[0xff, 0x00, 0xee, 0, 0xff, 0xee, 0x00, 0, 0xff, 0xee, 0xaa, 0, 0xff, 0xee, 0xab, 0],
[0xff, 0x00, 0xee, 0, 0xff, 0xee, 0x00, 0, 0xff, 0xee, 0xaa, 0, 0xff, 0xee, 0xab, 0]];
send_fbu_msg(info, rects, client);
sendFbuMsg(info, rects, client);
expect(client._display).to.have.displayed(targetData);
});
@ -1775,7 +1775,7 @@ describe('Remote Frame Buffer Protocol Client', function () {
[0x0c, 0x0c, 0x03, 0x03],
[0x0c, 0x0c, 0x03, 0x03]];
client._fbDepth = 8;
send_fbu_msg(info, rects, client);
sendFbuMsg(info, rects, client);
expect(client._display).to.have.displayed(targetDataCheck);
});
@ -1787,7 +1787,7 @@ describe('Remote Frame Buffer Protocol Client', function () {
{ x: 2, y: 2, width: 2, height: 2, encoding: 0x01}];
// data says [{ old_x: 0, old_y: 0 }, { old_x: 0, old_y: 0 }]
const rects = [[0, 2, 0, 0], [0, 0, 0, 0]];
send_fbu_msg(info, rects, client);
sendFbuMsg(info, rects, client);
expect(client._display).to.have.displayed(targetDataCheck);
});
@ -1815,7 +1815,7 @@ describe('Remote Frame Buffer Protocol Client', function () {
push16(rect, 2); // y: 2
push16(rect, 2); // width: 2
push16(rect, 2); // height: 2
send_fbu_msg(info, [rect], client);
sendFbuMsg(info, [rect], client);
expect(client._display).to.have.displayed(targetDataCheck);
});
@ -1834,7 +1834,7 @@ describe('Remote Frame Buffer Protocol Client', function () {
rect.push(1 | (1 << 4)); // width: 2, height: 2
rect.push(2 | (2 << 4)); // x: 2, y: 2
rect.push(1 | (1 << 4)); // width: 2, height: 2
send_fbu_msg(info, [rect], client);
sendFbuMsg(info, [rect], client);
expect(client._display).to.have.displayed(targetDataCheck);
});
@ -1848,7 +1848,7 @@ describe('Remote Frame Buffer Protocol Client', function () {
rect.push(targetData[i]);
rect.push(targetData[i + 3]);
}
send_fbu_msg(info, [rect], client);
sendFbuMsg(info, [rect], client);
expect(client._display).to.have.displayed(targetData);
});
@ -1857,7 +1857,7 @@ describe('Remote Frame Buffer Protocol Client', function () {
const rect = [];
rect.push(0x02);
push32(rect, 0xff00ff); // becomes 00ff00ff --> #00FF00 bg color
send_fbu_msg(info, [rect], client);
sendFbuMsg(info, [rect], client);
const expected = [];
for (let i = 0; i < 16; i++) { push32(expected, 0xff00ff); }
@ -1880,7 +1880,7 @@ describe('Remote Frame Buffer Protocol Client', function () {
// send an empty frame
rect.push(0x00);
send_fbu_msg(info, [rect], client);
sendFbuMsg(info, [rect], client);
const expected = [];
for (let i = 0; i < 16; i++) { push32(expected, 0xff00ff); } // rect 1: solid
@ -1906,7 +1906,7 @@ describe('Remote Frame Buffer Protocol Client', function () {
rect.push(0xff);
rect.push(2 | (2 << 4)); // x: 2, y: 2
rect.push(1 | (1 << 4)); // width: 2, height: 2
send_fbu_msg(info, [rect], client);
sendFbuMsg(info, [rect], client);
expect(client._display).to.have.displayed(targetDataCheck);
});
@ -1934,7 +1934,7 @@ describe('Remote Frame Buffer Protocol Client', function () {
rect.push(1); // 1 subrect
rect.push(0); // x: 0, y: 0
rect.push(1 | (1 << 4)); // width: 2, height: 2
send_fbu_msg(info, [rect], client);
sendFbuMsg(info, [rect], client);
let expected = [];
for (let i = 0; i < 4; i++) { expected = expected.concat(targetDataCheckArr); }
@ -1946,7 +1946,7 @@ describe('Remote Frame Buffer Protocol Client', function () {
sinon.spy(client, "_fail");
const info = [{ x: 0, y: 0, width: 4, height: 4, encoding: 0x05 }];
const rects = [[45]]; // an invalid subencoding
send_fbu_msg(info, rects, client);
sendFbuMsg(info, rects, client);
expect(client._fail).to.have.been.calledOnce;
});
});
@ -1961,7 +1961,7 @@ describe('Remote Frame Buffer Protocol Client', function () {
it('should handle the DesktopSize pseduo-encoding', function () {
sinon.spy(client._display, 'resize');
send_fbu_msg([{ x: 0, y: 0, width: 20, height: 50, encoding: -223 }], [[]], client);
sendFbuMsg([{ x: 0, y: 0, width: 20, height: 50, encoding: -223 }], [[]], client);
expect(client._fbWidth).to.equal(20);
expect(client._fbHeight).to.equal(50);
@ -1979,7 +1979,7 @@ describe('Remote Frame Buffer Protocol Client', function () {
sinon.spy(client._display, 'resize');
});
function make_screen_data(nrOfScreens) {
function makeScreenData(nrOfScreens) {
const data = [];
push8(data, nrOfScreens); // number-of-screens
push8(data, 0); // padding
@ -1999,9 +1999,9 @@ describe('Remote Frame Buffer Protocol Client', function () {
const reasonForChange = 1; // requested by this client
const statusCode = 0; // No error
send_fbu_msg([{ x: reasonForChange, y: statusCode,
width: 20, height: 50, encoding: -308 }],
make_screen_data(1), client);
sendFbuMsg([{ x: reasonForChange, y: statusCode,
width: 20, height: 50, encoding: -308 }],
makeScreenData(1), client);
expect(client._fbWidth).to.equal(20);
expect(client._fbHeight).to.equal(50);
@ -2014,9 +2014,9 @@ describe('Remote Frame Buffer Protocol Client', function () {
const reasonForChange = 2; // requested by another client
const statusCode = 0; // No error
send_fbu_msg([{ x: reasonForChange, y: statusCode,
width: 20, height: 50, encoding: -308 }],
make_screen_data(1), client);
sendFbuMsg([{ x: reasonForChange, y: statusCode,
width: 20, height: 50, encoding: -308 }],
makeScreenData(1), client);
expect(client._fbWidth).to.equal(20);
expect(client._fbHeight).to.equal(50);
@ -2029,9 +2029,9 @@ describe('Remote Frame Buffer Protocol Client', function () {
const reasonForChange = 2; // requested by another client
const statusCode = 0; // No error
send_fbu_msg([{ x: reasonForChange, y: statusCode,
width: 60, height: 50, encoding: -308 }],
make_screen_data(3), client);
sendFbuMsg([{ x: reasonForChange, y: statusCode,
width: 60, height: 50, encoding: -308 }],
makeScreenData(3), client);
expect(client._fbWidth).to.equal(60);
expect(client._fbHeight).to.equal(50);
@ -2044,9 +2044,9 @@ describe('Remote Frame Buffer Protocol Client', function () {
const reasonForChange = 1; // requested by this client
const statusCode = 1; // Resize is administratively prohibited
send_fbu_msg([{ x: reasonForChange, y: statusCode,
width: 20, height: 50, encoding: -308 }],
make_screen_data(1), client);
sendFbuMsg([{ x: reasonForChange, y: statusCode,
width: 20, height: 50, encoding: -308 }],
makeScreenData(1), client);
expect(client._fbWidth).to.equal(4);
expect(client._fbHeight).to.equal(4);
@ -2078,7 +2078,7 @@ describe('Remote Frame Buffer Protocol Client', function () {
}
expected = new Uint8Array(expected);
send_fbu_msg([info], [rect], client);
sendFbuMsg([info], [rect], client);
expect(client._cursor.change).to.have.been.calledOnce;
expect(client._cursor.change).to.have.been.calledWith(expected, 5, 7, 4, 4);
@ -2090,7 +2090,7 @@ describe('Remote Frame Buffer Protocol Client', function () {
encoding: -239};
const rect = [];
send_fbu_msg([info], [rect], client);
sendFbuMsg([info], [rect], client);
expect(client._cursor.change).to.have.been.calledOnce;
expect(client._cursor.change).to.have.been.calledWith(new Uint8Array, 0, 0, 0, 0);
@ -2113,7 +2113,7 @@ describe('Remote Frame Buffer Protocol Client', function () {
}
expected = new Uint8Array(expected);
send_fbu_msg([info], [rect], client);
sendFbuMsg([info], [rect], client);
expect(client._cursor.change).to.have.been.calledOnce;
expect(client._cursor.change).to.have.been.calledWith(expected, 5, 7, 4, 4);
@ -2144,7 +2144,7 @@ describe('Remote Frame Buffer Protocol Client', function () {
}
expected = new Uint8Array(expected);
send_fbu_msg([info], [rect], client);
sendFbuMsg([info], [rect], client);
expect(client._cursor.change).to.have.been.calledOnce;
expect(client._cursor.change).to.have.been.calledWith(expected, 5, 7, 4, 4);
@ -2157,7 +2157,7 @@ describe('Remote Frame Buffer Protocol Client', function () {
const rect = [];
const dot = RFB.cursors.dot;
send_fbu_msg([info], [rect], client);
sendFbuMsg([info], [rect], client);
expect(client._cursor.change).to.have.been.calledOnce;
expect(client._cursor.change).to.have.been.calledWith(dot.rgbaPixels,
@ -2179,7 +2179,7 @@ describe('Remote Frame Buffer Protocol Client', function () {
}
push32(rect, 0x00000000);
send_fbu_msg([info], [rect], client);
sendFbuMsg([info], [rect], client);
expect(client._cursor.change).to.have.been.calledOnce;
expect(client._cursor.change).to.have.been.calledWith(dot.rgbaPixels,
@ -2217,9 +2217,9 @@ describe('Remote Frame Buffer Protocol Client', function () {
push8(rect, data[i]);
}
send_fbu_msg([{ x: 0, y: 0, width: 2, height: 2,
encoding: 0x574d5664}],
[rect], client);
sendFbuMsg([{ x: 0, y: 0, width: 2, height: 2,
encoding: 0x574d5664}],
[rect], client);
expect(client._FBU.rects).to.equal(0);
});
@ -2245,9 +2245,9 @@ describe('Remote Frame Buffer Protocol Client', function () {
push8(rect, data[i]);
}
send_fbu_msg([{ x: 0, y: 0, width: w, height: h,
encoding: 0x574d5664}],
[rect], client);
sendFbuMsg([{ x: 0, y: 0, width: w, height: h,
encoding: 0x574d5664}],
[rect], client);
// expect one FBU to remain unhandled
expect(client._FBU.rects).to.equal(1);
@ -2288,10 +2288,10 @@ describe('Remote Frame Buffer Protocol Client', function () {
0x33, 0x22, 0x11, 0xff,
0x00, 0x00, 0x00, 0xff];
send_fbu_msg([{ x: hotx, y: hoty,
width: w, height: h,
encoding: 0x574d5664}],
[rect], client);
sendFbuMsg([{ x: hotx, y: hoty,
width: w, height: h,
encoding: 0x574d5664}],
[rect], client);
expect(client._cursor.change)
.to.have.been.calledOnce;
@ -2327,10 +2327,10 @@ describe('Remote Frame Buffer Protocol Client', function () {
0x00, 0xff, 0x00, 0x22,
0x00, 0x00, 0xff, 0xee];
send_fbu_msg([{ x: hotx, y: hoty,
width: w, height: h,
encoding: 0x574d5664}],
[rect], client);
sendFbuMsg([{ x: hotx, y: hoty,
width: w, height: h,
encoding: 0x574d5664}],
[rect], client);
expect(client._cursor.change)
.to.have.been.calledOnce;
@ -2346,9 +2346,9 @@ describe('Remote Frame Buffer Protocol Client', function () {
push8(rect, 0); // padding
client._cursor.change.resetHistory();
send_fbu_msg([{ x: 0, y: 0, width: 2, height: 2,
encoding: 0x574d5664}],
[rect], client);
sendFbuMsg([{ x: 0, y: 0, width: 2, height: 2,
encoding: 0x574d5664}],
[rect], client);
expect(client._cursor.change)
.to.not.have.been.called;
@ -2356,7 +2356,7 @@ describe('Remote Frame Buffer Protocol Client', function () {
});
it('should handle the last_rect pseudo-encoding', function () {
send_fbu_msg([{ x: 0, y: 0, width: 0, height: 0, encoding: -224}], [[]], client, 100);
sendFbuMsg([{ x: 0, y: 0, width: 0, height: 0, encoding: -224}], [[]], client, 100);
expect(client._FBU.rects).to.equal(0);
});
@ -2368,7 +2368,7 @@ describe('Remote Frame Buffer Protocol Client', function () {
const spy = sinon.spy();
client.addEventListener("desktopname", spy);
send_fbu_msg([{ x: 0, y: 0, width: 0, height: 0, encoding: -307 }], [data], client);
sendFbuMsg([{ x: 0, y: 0, width: 0, height: 0, encoding: -307 }], [data], client);
expect(client._fbName).to.equal('som€ nam€');
expect(spy).to.have.been.calledOnce;
@ -2719,7 +2719,7 @@ describe('Remote Frame Buffer Protocol Client', function () {
describe('Asynchronous Events', function () {
let client;
beforeEach(function () {
client = make_rfb();
client = makeRFB();
});
describe('Mouse event handlers', function () {
@ -2795,23 +2795,23 @@ describe('Remote Frame Buffer Protocol Client', function () {
describe('WebSocket event handlers', function () {
// message events
it('should do nothing if we receive an empty message and have nothing in the queue', function () {
client._normal_msg = sinon.spy();
client._normalMsg = sinon.spy();
client._sock._websocket._receive_data(new Uint8Array([]));
expect(client._normal_msg).to.not.have.been.called;
expect(client._normalMsg).to.not.have.been.called;
});
it('should handle a message in the connected state as a normal message', function () {
client._normal_msg = sinon.spy();
client._normalMsg = sinon.spy();
client._sock._websocket._receive_data(new Uint8Array([1, 2, 3]));
expect(client._normal_msg).to.have.been.called;
expect(client._normalMsg).to.have.been.called;
});
it('should handle a message in any non-disconnected/failed state like an init message', function () {
client._rfbConnectionState = 'connecting';
client._rfbInitState = 'ProtocolVersion';
client._init_msg = sinon.spy();
client._initMsg = sinon.spy();
client._sock._websocket._receive_data(new Uint8Array([1, 2, 3]));
expect(client._init_msg).to.have.been.called;
expect(client._initMsg).to.have.been.called;
});
it('should process all normal messages directly', function () {