Improved test coverage

- Added tests for handshakes in namespaces (one roundtrip)
- Replaced misleading 'handshake' with 'authentication', where the second roundtrip is used
This commit is contained in:
Fabian Arndt
2019-10-15 12:54:02 +02:00
parent e66148fbb2
commit 8c9a31a16b
5 changed files with 65 additions and 10 deletions

View File

@ -7,6 +7,7 @@ const socketIo = require('socket.io');
const socketio_jwt = require('../../lib');
const jwt = require('jsonwebtoken');
const xtend = require('xtend');
const enableDestroy = require('server-destroy');
const bodyParser = require('body-parser');
@ -44,17 +45,26 @@ exports.start = (callback) => {
});
// Global namespace (public)
sio.on('connection', (socket) => {
socket.emit('hi');
});
// Second roundtrip
const admin_nsp = sio.of('/admin');
admin_nsp.on('connection', socketio_jwt.authorize(options))
.on('authenticated', (socket) => {
socket.emit('hi admin');
});
.on('authenticated', (socket) => {
socket.emit('hi admin');
});
// One roundtrip
const admin_nsp_hs = sio.of('/admin_hs');
admin_nsp_hs.use(socketio_jwt.authorize(xtend(options, { handshake: true })));
admin_nsp_hs.on('connection', (socket) => {
socket.emit('hi admin');
});
server.listen(9000, callback);