summaryrefslogtreecommitdiffstats
path: root/webapp
diff options
context:
space:
mode:
authorJoram Wilander <jwawilander@gmail.com>2016-10-31 08:59:23 -0400
committerChristopher Speller <crspeller@gmail.com>2016-10-31 08:59:23 -0400
commit316b155a42a4d00fb835438ce7e0401a64e59add (patch)
tree6a64f05e948323ae7595971608d84a4420a08290 /webapp
parentef363fd88ebb731dbb0470ad7cb5f50de0f3845c (diff)
downloadchat-316b155a42a4d00fb835438ce7e0401a64e59add.tar.gz
chat-316b155a42a4d00fb835438ce7e0401a64e59add.tar.bz2
chat-316b155a42a4d00fb835438ce7e0401a64e59add.zip
PLT-3562 Switch websocket over to post-connect authentication (#4327)
* Switch websocket over to post-connect authentication * Add ability to specify token in websocket js driver, add unit tests * Temporarily disable client websocket tests until issues are resolved * Minor refactoring and fix status test * Add isAuthenticated method to WebConn and minor status updates
Diffstat (limited to 'webapp')
-rw-r--r--webapp/client/websocket_client.jsx12
-rw-r--r--webapp/tests/client_websocket.test.jsx49
-rw-r--r--webapp/tests/test_helper.jsx20
3 files changed, 75 insertions, 6 deletions
diff --git a/webapp/client/websocket_client.jsx b/webapp/client/websocket_client.jsx
index 035e30be5..760c62b59 100644
--- a/webapp/client/websocket_client.jsx
+++ b/webapp/client/websocket_client.jsx
@@ -18,7 +18,7 @@ export default class WebSocketClient {
this.closeCallback = null;
}
- initialize(connectionUrl) {
+ initialize(connectionUrl, token) {
if (this.conn) {
return;
}
@@ -30,6 +30,10 @@ export default class WebSocketClient {
this.conn = new WebSocket(connectionUrl);
this.conn.onopen = () => {
+ if (token) {
+ this.sendMessage('authentication_challenge', {token});
+ }
+
if (this.connectFailCount > 0) {
console.log('websocket re-established connection'); //eslint-disable-line no-console
if (this.reconnectCallback) {
@@ -68,7 +72,7 @@ export default class WebSocketClient {
setTimeout(
() => {
- this.initialize(connectionUrl);
+ this.initialize(connectionUrl, token);
},
retryTime
);
@@ -152,12 +156,12 @@ export default class WebSocketClient {
}
}
- userTyping(channelId, parentId) {
+ userTyping(channelId, parentId, callback) {
const data = {};
data.channel_id = channelId;
data.parent_id = parentId;
- this.sendMessage('user_typing', data);
+ this.sendMessage('user_typing', data, callback);
}
getStatuses(callback) {
diff --git a/webapp/tests/client_websocket.test.jsx b/webapp/tests/client_websocket.test.jsx
new file mode 100644
index 000000000..6535610e3
--- /dev/null
+++ b/webapp/tests/client_websocket.test.jsx
@@ -0,0 +1,49 @@
+// Copyright (c) 2016 Mattermost, Inc. All Rights Reserved.
+// See License.txt for license information.
+/*
+var assert = require('assert');
+import TestHelper from './test_helper.jsx';
+
+describe('Client.WebSocket', function() {
+ this.timeout(10000);
+
+ it('WebSocket.getStatusesByIds', function(done) {
+ TestHelper.initBasic(() => {
+ TestHelper.basicWebSocketClient().getStatusesByIds(
+ [TestHelper.basicUser().id],
+ function(resp) {
+ TestHelper.basicWebSocketClient().close();
+ assert.equal(resp.data[TestHelper.basicUser().id], 'online');
+ done();
+ }
+ );
+ }, true);
+ });
+
+ it('WebSocket.getStatuses', function(done) {
+ TestHelper.initBasic(() => {
+ TestHelper.basicWebSocketClient().getStatuses(
+ function(resp) {
+ TestHelper.basicWebSocketClient().close();
+ assert.equal(resp.data != null, true);
+ done();
+ }
+ );
+ }, true);
+ });
+
+ it('WebSocket.userTyping', function(done) {
+ TestHelper.initBasic(() => {
+ TestHelper.basicWebSocketClient().userTyping(
+ TestHelper.basicChannel().id,
+ '',
+ function(resp) {
+ TestHelper.basicWebSocketClient().close();
+ assert.equal(resp.status, 'OK');
+ done();
+ }
+ );
+ }, true);
+ });
+});*/
+
diff --git a/webapp/tests/test_helper.jsx b/webapp/tests/test_helper.jsx
index 41d0c15ba..310714e30 100644
--- a/webapp/tests/test_helper.jsx
+++ b/webapp/tests/test_helper.jsx
@@ -2,13 +2,20 @@
// See License.txt for license information.
import Client from 'client/client.jsx';
+import WebSocketClient from 'client/websocket_client.jsx';
import jqd from 'jquery-deferred';
+var HEADER_TOKEN = 'token';
+
class TestHelperClass {
basicClient = () => {
return this.basicc;
}
+ basicWebSocketClient = () => {
+ return this.basicwsc;
+ }
+
basicTeam = () => {
return this.basict;
}
@@ -53,6 +60,12 @@ class TestHelperClass {
return c;
}
+ createWebSocketClient(token) {
+ var ws = new WebSocketClient();
+ ws.initialize('http://localhost:8065/api/v3/users/websocket', token);
+ return ws;
+ }
+
fakeEmail = () => {
return 'success' + this.generateId() + '@simulator.amazonses.com';
}
@@ -90,7 +103,7 @@ class TestHelperClass {
return post;
}
- initBasic = (callback) => {
+ initBasic = (callback, connectWS) => {
this.basicc = this.createClient();
var d1 = jqd.Deferred();
@@ -122,7 +135,10 @@ class TestHelperClass {
rteamSignup.user.email,
password,
null,
- function() {
+ function(data, res) {
+ if (connectWS) {
+ outer.basicwsc = outer.createWebSocketClient(res.header[HEADER_TOKEN]);
+ }
outer.basicClient().useHeaderToken();
var channel = outer.fakeChannel();
channel.team_id = outer.basicTeam().id;