From 7d714b15f58af1c3e3dfd6b3d98855da79a46752 Mon Sep 17 00:00:00 2001 From: Samuel Mannehed Date: Mon, 29 Aug 2016 14:56:57 +0200 Subject: [PATCH] Remove special password state We already have a callback mechanism for this, so let's use that. Adds an optional parameter 'msg' to the callback. Fixes vnc_auto.html (#646) which was broken after 4e0c36dda708628836dc6f5d68fc40d05c7716d9 --- app/ui.js | 33 +++++++++++++++++++++++---------- core/rfb.js | 15 +++++---------- tests/test.rfb.js | 29 ++++++++++++++++++++--------- vnc_auto.html | 19 +++++++++++-------- 4 files changed, 59 insertions(+), 37 deletions(-) diff --git a/app/ui.js b/app/ui.js index ee0b6dbb..601abc28 100644 --- a/app/ui.js +++ b/app/ui.js @@ -339,6 +339,7 @@ var UI; try { UI.rfb = new RFB({'target': document.getElementById('noVNC_canvas'), 'onUpdateState': UI.updateState, + 'onPasswordRequired': UI.passwordRequired, 'onXvpInit': UI.updateXvpButton, 'onClipboard': UI.clipboardReceive, 'onFBUComplete': UI.initialResize, @@ -373,15 +374,6 @@ var UI; case 'loaded': UI.showStatus(msg, 'normal'); break; - case 'password': - document.getElementById('noVNC_password_dlg') - .classList.add('noVNC_open'); - setTimeout(function () { - document.getElementById(('noVNC_password_input').focus()); - }, 100); - - UI.showStatus(msg, 'warn'); - break; default: UI.showStatus(msg, 'warn'); break; @@ -977,6 +969,27 @@ var UI; // Don't display the connection settings until we're actually disconnected }, +/* ------^------- + * /CONNECTION + * ============== + * PASSWORD + * ------v------*/ + + passwordRequired: function(rfb, msg) { + + document.getElementById('noVNC_password_dlg') + .classList.add('noVNC_open'); + + setTimeout(function () { + document.getElementById('noVNC_password_input').focus(); + }, 100); + + if (typeof msg === 'undefined') { + msg = "Password is required"; + } + UI.updateState(null, "warning", null, msg); + }, + setPassword: function() { UI.rfb.sendPassword(document.getElementById('noVNC_password_input').value); document.getElementById('noVNC_password_dlg') @@ -985,7 +998,7 @@ var UI; }, /* ------^------- - * /CONNECTION + * /PASSWORD * ============== * FULLSCREEN * ------v------*/ diff --git a/core/rfb.js b/core/rfb.js index 0718c89d..ea49c0cf 100644 --- a/core/rfb.js +++ b/core/rfb.js @@ -158,7 +158,7 @@ // Callback functions 'onUpdateState': function () { }, // onUpdateState(rfb, state, oldstate, statusMsg): state update/change - 'onPasswordRequired': function () { }, // onPasswordRequired(rfb): VNC password is required + 'onPasswordRequired': function () { }, // onPasswordRequired(rfb, msg): VNC password is required 'onClipboard': function () { }, // onClipboard(rfb, text): RFB clipboard contents received 'onBell': function () { }, // onBell(rfb): RFB Bell message received 'onFBUReceive': function () { }, // onFBUReceive(rfb, fbu): RFB FBU received but not yet processed @@ -269,7 +269,6 @@ sendPassword: function (passwd) { this._rfb_password = passwd; - this._rfb_state = 'Authentication'; setTimeout(this._init_msg.bind(this), 0); }, @@ -433,7 +432,6 @@ * ProtocolVersion * Security * Authentication - * password - waiting for password, not part of RFB * SecurityResult * ClientInitialization - not triggered by server message * ServerInitialization (to normal) @@ -737,9 +735,9 @@ var xvp_sep = this._xvp_password_sep; var xvp_auth = this._rfb_password.split(xvp_sep); if (xvp_auth.length < 3) { - this._updateState('password', 'XVP credentials required (user' + xvp_sep + - 'target' + xvp_sep + 'password) -- got only ' + this._rfb_password); - this._onPasswordRequired(this); + var msg = 'XVP credentials required (user' + xvp_sep + + 'target' + xvp_sep + 'password) -- got only ' + this._rfb_password; + this._onPasswordRequired(this, msg); return false; } @@ -755,9 +753,6 @@ _negotiate_std_vnc_auth: function () { if (this._rfb_password.length === 0) { - // Notify via both callbacks since it's kind of - // an RFB state change and a UI interface issue - this._updateState('password', "Password Required"); this._onPasswordRequired(this); return false; } @@ -1326,7 +1321,7 @@ // Callback functions ['onUpdateState', 'rw', 'func'], // onUpdateState(rfb, state, oldstate, statusMsg): RFB state update/change - ['onPasswordRequired', 'rw', 'func'], // onPasswordRequired(rfb): VNC password is required + ['onPasswordRequired', 'rw', 'func'], // onPasswordRequired(rfb, msg): VNC password is required ['onClipboard', 'rw', 'func'], // onClipboard(rfb, text): RFB clipboard contents received ['onBell', 'rw', 'func'], // onBell(rfb): RFB Bell message received ['onFBUReceive', 'rw', 'func'], // onFBUReceive(rfb, fbu): RFB FBU received but not yet processed diff --git a/tests/test.rfb.js b/tests/test.rfb.js index 9ceda664..d5ceede5 100644 --- a/tests/test.rfb.js +++ b/tests/test.rfb.js @@ -126,10 +126,9 @@ describe('Remote Frame Buffer Protocol Client', function() { beforeEach(function () { this.clock = sinon.useFakeTimers(); }); afterEach(function () { this.clock.restore(); }); - it('should set the state to "Authentication"', function () { - client._rfb_state = "blah"; + it('should set the rfb password properly"', function () { client.sendPassword('pass'); - expect(client._rfb_state).to.equal('Authentication'); + expect(client._rfb_password).to.equal('pass'); }); it('should call init_msg "soon"', function () { @@ -728,9 +727,13 @@ describe('Remote Frame Buffer Protocol Client', function() { client._rfb_version = 3.8; }); - it('should transition to the "password" state if missing a password', function () { + it('should call the passwordRequired callback if missing a password', function () { + client.set_onPasswordRequired(sinon.spy()); send_security(2, client); - expect(client._rfb_state).to.equal('password'); + + var spy = client.get_onPasswordRequired(); + expect(client._rfb_password.length).to.equal(0); + expect(spy).to.have.been.calledOnce; }); it('should encrypt the password with DES and then send it back', function () { @@ -777,15 +780,23 @@ describe('Remote Frame Buffer Protocol Client', function() { expect(client._negotiate_std_vnc_auth).to.have.been.calledOnce; }); - it('should transition to the "password" state if the passwords is missing', function() { + it('should call the passwordRequired callback if the password is missing', function() { + client.set_onPasswordRequired(sinon.spy()); + client._rfb_password = ''; send_security(22, client); - expect(client._rfb_state).to.equal('password'); + + var spy = client.get_onPasswordRequired(); + expect(client._rfb_password.length).to.equal(0); + expect(spy).to.have.been.calledOnce; }); - it('should transition to the "password" state if the passwords is improperly formatted', function() { + it('should call the passwordRequired callback if the password is improperly formatted', function() { + client.set_onPasswordRequired(sinon.spy()); client._rfb_password = 'user@target'; send_security(22, client); - expect(client._rfb_state).to.equal('password'); + + var spy = client.get_onPasswordRequired(); + expect(spy).to.have.been.calledOnce; }); it('should split the password, send the first two parts, and pass on the last part', function () { diff --git a/vnc_auto.html b/vnc_auto.html index a4cbb236..1d9cd9e8 100644 --- a/vnc_auto.html +++ b/vnc_auto.html @@ -102,15 +102,18 @@ UIresize(); rfb.set_onFBUComplete(function() { }); } - function passwordRequired(rfb) { - var msg; - msg = '