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
4e0c36dda7
This commit is contained in:
Samuel Mannehed 2016-08-29 14:56:57 +02:00
parent f4f4e8993d
commit f9177c92c7
3 changed files with 45 additions and 27 deletions

View File

@ -265,7 +265,6 @@ var RFB;
sendPassword: function (passwd) { sendPassword: function (passwd) {
this._rfb_password = passwd; this._rfb_password = passwd;
this._rfb_state = 'Authentication';
setTimeout(this._init_msg.bind(this), 0); setTimeout(this._init_msg.bind(this), 0);
}, },
@ -429,7 +428,6 @@ var RFB;
* ProtocolVersion * ProtocolVersion
* Security * Security
* Authentication * Authentication
* password - waiting for password, not part of RFB
* SecurityResult * SecurityResult
* ClientInitialization - not triggered by server message * ClientInitialization - not triggered by server message
* ServerInitialization (to normal) * ServerInitialization (to normal)
@ -732,7 +730,7 @@ var RFB;
var xvp_sep = this._xvp_password_sep; var xvp_sep = this._xvp_password_sep;
var xvp_auth = this._rfb_password.split(xvp_sep); var xvp_auth = this._rfb_password.split(xvp_sep);
if (xvp_auth.length < 3) { if (xvp_auth.length < 3) {
this._updateState('password', 'XVP credentials required (user' + xvp_sep + Util.Debug('XVP credentials required (user' + xvp_sep +
'target' + xvp_sep + 'password) -- got only ' + this._rfb_password); 'target' + xvp_sep + 'password) -- got only ' + this._rfb_password);
this._onPasswordRequired(this); this._onPasswordRequired(this);
return false; return false;
@ -750,9 +748,6 @@ var RFB;
_negotiate_std_vnc_auth: function () { _negotiate_std_vnc_auth: function () {
if (this._rfb_password.length === 0) { 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); this._onPasswordRequired(this);
return false; return false;
} }

View File

@ -192,6 +192,7 @@ var UI;
try { try {
UI.rfb = new RFB({'target': $D('noVNC_canvas'), UI.rfb = new RFB({'target': $D('noVNC_canvas'),
'onUpdateState': UI.updateState, 'onUpdateState': UI.updateState,
'onPasswordRequired': UI.passwordRequired,
'onXvpInit': UI.updateXvpButton, 'onXvpInit': UI.updateXvpButton,
'onClipboard': UI.clipboardReceive, 'onClipboard': UI.clipboardReceive,
'onFBUComplete': UI.initialResize, 'onFBUComplete': UI.initialResize,
@ -275,23 +276,15 @@ var UI;
case 'loaded': case 'loaded':
klass = "noVNC_status_normal"; klass = "noVNC_status_normal";
break; 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: default:
klass = "noVNC_status_warn"; klass = "noVNC_status_warn";
break; break;
} }
if (typeof(msg) !== 'undefined') {
$D('noVNC_control_bar').setAttribute("class", klass); $D('noVNC_control_bar').setAttribute("class", klass);
if (typeof(msg) !== 'undefined') {
$D('noVNC_status').innerHTML = msg; $D('noVNC_status').innerHTML = msg;
} }
UI.updateVisualState(); UI.updateVisualState();
@ -750,6 +743,25 @@ var UI;
// Don't display the connection settings until we're actually disconnected // 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() { setPassword: function() {
UI.rfb.sendPassword($D('noVNC_setting_password').value); UI.rfb.sendPassword($D('noVNC_setting_password').value);
//Reset connect button. //Reset connect button.
@ -761,7 +773,7 @@ var UI;
}, },
/* ------^------- /* ------^-------
* /CONNECTION * /PASSWORD
* ============== * ==============
* FULLSCREEN * FULLSCREEN
* ------v------*/ * ------v------*/

View File

@ -107,10 +107,9 @@ describe('Remote Frame Buffer Protocol Client', function() {
beforeEach(function () { this.clock = sinon.useFakeTimers(); }); beforeEach(function () { this.clock = sinon.useFakeTimers(); });
afterEach(function () { this.clock.restore(); }); afterEach(function () { this.clock.restore(); });
it('should set the state to "Authentication"', function () { it('should set the rfb password properly"', function () {
client._rfb_state = "blah";
client.sendPassword('pass'); client.sendPassword('pass');
expect(client._rfb_state).to.equal('Authentication'); expect(client._rfb_password).to.equal('pass');
}); });
it('should call init_msg "soon"', function () { it('should call init_msg "soon"', function () {
@ -704,9 +703,13 @@ describe('Remote Frame Buffer Protocol Client', function() {
client._rfb_version = 3.8; 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); 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 () { 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; 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); 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'; client._rfb_password = 'user@target';
send_security(22, client); 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 () { it('should split the password, send the first two parts, and pass on the last part', function () {