Skip to content

Commit 64c0535

Browse files
committed
Added test around issuer logic when using setAuthToken
1 parent 0d06284 commit 64c0535

File tree

1 file changed

+54
-1
lines changed

1 file changed

+54
-1
lines changed

test/integration.js

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,19 @@ var connectionHandler = function (socket) {
6969
respond(err);
7070
}
7171
});
72+
socket.on('loginWithIssAndIssuer', function (userDetails, respond) {
73+
if (allowedUsers[userDetails.username]) {
74+
userDetails.iss = 'foo';
75+
socket.setAuthToken(userDetails, {
76+
issuer: 'bar'
77+
});
78+
respond();
79+
} else {
80+
var err = new Error('Failed to login');
81+
err.name = 'FailedLoginError';
82+
respond(err);
83+
}
84+
});
7285
socket.on('setAuthKey', function (newAuthKey, respond) {
7386
server.signatureKey = newAuthKey;
7487
server.verificationKey = newAuthKey;
@@ -102,10 +115,13 @@ describe('integration tests', function () {
102115
});
103116

104117
afterEach('shut down client after each test', function (done) {
105-
if (client) {
118+
if (client && client.state != client.CLOSED) {
106119
client.once('disconnect', function () {
107120
done();
108121
});
122+
client.once('connectAbort', function () {
123+
done();
124+
});
109125
client.disconnect();
110126
} else {
111127
done();
@@ -358,5 +374,42 @@ describe('integration tests', function () {
358374
});
359375
});
360376
});
377+
378+
it('Should send back error if socket.setAuthToken tries to set both iss claim and issuer option', function (done) {
379+
var port = 8015;
380+
server = socketClusterServer.listen(port, {
381+
authKey: serverOptions.authKey,
382+
authVerifyAsync: false
383+
});
384+
var warningMap = {};
385+
386+
server.on('connection', connectionHandler);
387+
server.on('ready', function () {
388+
client = socketCluster.connect({
389+
hostname: clientOptions.hostname,
390+
port: port,
391+
multiplex: false
392+
});
393+
client.once('connect', function (statusA) {
394+
client.once('authenticate', function (newSignedToken) {
395+
throw new Error('Should not pass authentication because the signature should fail');
396+
});
397+
server.on('warning', function (warning) {
398+
assert.notEqual(warning, null);
399+
warningMap[warning.name] = warning;
400+
});
401+
client.once('error', function (err) {
402+
assert.notEqual(err, null);
403+
assert.equal(err.name, 'SocketProtocolError');
404+
});
405+
client.emit('loginWithIssAndIssuer', {username: 'bob'});
406+
setTimeout(function () {
407+
server.removeAllListeners('warning');
408+
assert.notEqual(warningMap['SocketProtocolError'], null);
409+
done();
410+
}, 1000);
411+
});
412+
});
413+
});
361414
});
362415
});

0 commit comments

Comments
 (0)