@@ -69,6 +69,19 @@ var connectionHandler = function (socket) {
69
69
respond ( err ) ;
70
70
}
71
71
} ) ;
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
+ } ) ;
72
85
socket . on ( 'setAuthKey' , function ( newAuthKey , respond ) {
73
86
server . signatureKey = newAuthKey ;
74
87
server . verificationKey = newAuthKey ;
@@ -102,10 +115,13 @@ describe('integration tests', function () {
102
115
} ) ;
103
116
104
117
afterEach ( 'shut down client after each test' , function ( done ) {
105
- if ( client ) {
118
+ if ( client && client . state != client . CLOSED ) {
106
119
client . once ( 'disconnect' , function ( ) {
107
120
done ( ) ;
108
121
} ) ;
122
+ client . once ( 'connectAbort' , function ( ) {
123
+ done ( ) ;
124
+ } ) ;
109
125
client . disconnect ( ) ;
110
126
} else {
111
127
done ( ) ;
@@ -358,5 +374,42 @@ describe('integration tests', function () {
358
374
} ) ;
359
375
} ) ;
360
376
} ) ;
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
+ } ) ;
361
414
} ) ;
362
415
} ) ;
0 commit comments