From f9177c92c776328be1879dc486ff179a61da1c53 Mon Sep 17 00:00:00 2001 From: Samuel Mannehed Date: Mon, 29 Aug 2016 14:56:57 +0200 Subject: Remove special password state We already have a callback mechanism for this, so let's use that. Fixes vnc_auto.html (#646) which was broken after 4e0c36dda708628836dc6f5d68fc40d05c7716d9 --- include/rfb.js | 9 ++------- include/ui.js | 34 +++++++++++++++++++++++----------- tests/test.rfb.js | 29 ++++++++++++++++++++--------- 3 files changed, 45 insertions(+), 27 deletions(-) diff --git a/include/rfb.js b/include/rfb.js index 9935962..e84c8a7 100644 --- a/include/rfb.js +++ b/include/rfb.js @@ -265,7 +265,6 @@ var RFB; sendPassword: function (passwd) { this._rfb_password = passwd; - this._rfb_state = 'Authentication'; setTimeout(this._init_msg.bind(this), 0); }, @@ -429,7 +428,6 @@ var RFB; * ProtocolVersion * Security * Authentication - * password - waiting for password, not part of RFB * SecurityResult * ClientInitialization - not triggered by server message * ServerInitialization (to normal) @@ -732,8 +730,8 @@ var RFB; 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); + Util.Debug('XVP credentials required (user' + xvp_sep + + 'target' + xvp_sep + 'password) -- got only ' + this._rfb_password); this._onPasswordRequired(this); return false; } @@ -750,9 +748,6 @@ var RFB; _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; } diff --git a/include/ui.js b/include/ui.js index d69a4f6..66608d1 100644 --- a/include/ui.js +++ b/include/ui.js @@ -192,6 +192,7 @@ var UI; try { UI.rfb = new RFB({'target': $D('noVNC_canvas'), 'onUpdateState': UI.updateState, + 'onPasswordRequired': UI.passwordRequired, 'onXvpInit': UI.updateXvpButton, 'onClipboard': UI.clipboardReceive, 'onFBUComplete': UI.initialResize, @@ -275,23 +276,15 @@ var UI; case 'loaded': klass = "noVNC_status_normal"; break; - case 'password': - UI.toggleConnectPanel(); - - $D('noVNC_connect_button').value = "Send Password"; - $D('noVNC_connect_button').onclick = UI.setPassword; - $D('noVNC_setting_password').focus(); - - klass = "noVNC_status_warn"; - break; default: klass = "noVNC_status_warn"; break; } + $D('noVNC_control_bar').setAttribute("class", klass); if (typeof(msg) !== 'undefined') { - $D('noVNC_control_bar').setAttribute("class", klass); $D('noVNC_status').innerHTML = msg; + } UI.updateVisualState(); @@ -750,6 +743,25 @@ var UI; // Don't display the connection settings until we're actually disconnected }, +/* ------^------- + * /CONNECTION + * ============== + * PASSWORD + * ------v------*/ + + passwordRequired: function(rfb) { + UI.connSettingsOpen = false; + UI.toggleConnectPanel(); + + $D('noVNC_connect_button').value = "Send Password"; + $D('noVNC_connect_button').onclick = UI.setPassword; + $D('noVNC_setting_password').focus(); + + var msg = "Password is required"; + UI.popupStatus(msg); + UI.updateState(null, "warning", null, msg); + }, + setPassword: function() { UI.rfb.sendPassword($D('noVNC_setting_password').value); //Reset connect button. @@ -761,7 +773,7 @@ var UI; }, /* ------^------- - * /CONNECTION + * /PASSWORD * ============== * FULLSCREEN * ------v------*/ diff --git a/tests/test.rfb.js b/tests/test.rfb.js index 06eeebe..22059f3 100644 --- a/tests/test.rfb.js +++ b/tests/test.rfb.js @@ -107,10 +107,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 () { @@ -704,9 +703,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 () { @@ -753,15 +756,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 () { -- cgit v1.2.1