summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSamuel Mannehed <samuel@cendio.se>2016-08-29 14:56:57 +0200
committerSamuel Mannehed <samuel@cendio.se>2016-10-01 00:02:47 +0200
commit7d714b15f58af1c3e3dfd6b3d98855da79a46752 (patch)
tree69a4bf1c06d46fff3f83b2ac94cb5269fcdbb66c
parent1c1cc1d0e99f881b0dc5727bf32ff892156e56cf (diff)
downloadnovnc-7d714b15f58af1c3e3dfd6b3d98855da79a46752.tar.gz
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
-rw-r--r--app/ui.js33
-rw-r--r--core/rfb.js15
-rw-r--r--tests/test.rfb.js29
-rw-r--r--vnc_auto.html19
4 files changed, 59 insertions, 37 deletions
diff --git a/app/ui.js b/app/ui.js
index ee0b6db..601abc2 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 0718c89..ea49c0c 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 9ceda66..d5ceede 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 a4cbb23..1d9cd9e 100644
--- a/vnc_auto.html
+++ b/vnc_auto.html
@@ -102,15 +102,18 @@
UIresize();
rfb.set_onFBUComplete(function() { });
}
- function passwordRequired(rfb) {
- var msg;
- msg = '<form onsubmit="return setPassword();"';
- msg += ' style="margin-bottom: 0px">';
- msg += 'Password Required: ';
- msg += '<input type=password size=10 id="password_input" class="noVNC_status">';
- msg += '<\/form>';
+ function passwordRequired(rfb, msg) {
+ if (typeof msg === 'undefined') {
+ msg = 'Password Required: ';
+ }
+ var html;
+ html = '<form onsubmit="return setPassword();"';
+ html += ' style="margin-bottom: 0px">';
+ html += msg;
+ html += '<input type=password size=10 id="password_input" class="noVNC_status">';
+ html += '<\/form>';
document.getElementById('noVNC_status_bar').setAttribute("class", "noVNC_status_warn");
- document.getElementById('noVNC_status').innerHTML = msg;
+ document.getElementById('noVNC_status').innerHTML = html;
}
function setPassword() {
rfb.sendPassword(document.getElementById('password_input').value);