File tree 3 files changed +31
-1
lines changed
3 files changed +31
-1
lines changed Original file line number Diff line number Diff line change @@ -222,7 +222,10 @@ Socket.prototype.onclose = function (reason) {
222
222
*/
223
223
224
224
Socket . prototype . onpacket = function ( packet ) {
225
- if ( packet . nsp !== this . nsp ) return ;
225
+ var sameNamespace = packet . nsp === this . nsp ;
226
+ var rootNamespaceError = packet . type === parser . ERROR && packet . nsp === '/' ;
227
+
228
+ if ( ! sameNamespace && ! rootNamespaceError ) return ;
226
229
227
230
switch ( packet . type ) {
228
231
case parser . CONNECT :
Original file line number Diff line number Diff line change @@ -158,4 +158,22 @@ describe('socket', function () {
158
158
} ) ;
159
159
} ) ;
160
160
} ) ;
161
+
162
+ it ( 'should fire an error event on middleware failure from main namespace' , function ( done ) {
163
+ var socket = io ( '/foo' , { forceNew : true , query : { 'fail' : true } } ) ;
164
+ socket . on ( 'error' , function ( err ) {
165
+ expect ( err ) . to . eql ( 'Auth failed (main namespace)' ) ;
166
+ socket . disconnect ( ) ;
167
+ done ( ) ;
168
+ } ) ;
169
+ } ) ;
170
+
171
+ it ( 'should fire an error event on middleware failure from custom namespace' , function ( done ) {
172
+ var socket = io ( '/no' , { forceNew : true } ) ;
173
+ socket . on ( 'error' , function ( err ) {
174
+ expect ( err ) . to . eql ( 'Auth failed (custom namespace)' ) ;
175
+ socket . disconnect ( ) ;
176
+ done ( ) ;
177
+ } ) ;
178
+ } ) ;
161
179
} ) ;
Original file line number Diff line number Diff line change @@ -25,6 +25,15 @@ server.of('/abc').on('connection', function (socket) {
25
25
socket . emit ( 'handshake' , socket . handshake ) ;
26
26
} ) ;
27
27
28
+ server . use ( function ( socket , next ) {
29
+ if ( socket . request . _query . fail ) return next ( new Error ( 'Auth failed (main namespace)' ) ) ;
30
+ next ( ) ;
31
+ } ) ;
32
+
33
+ server . of ( '/no' ) . use ( function ( socket , next ) {
34
+ next ( new Error ( 'Auth failed (custom namespace)' ) ) ;
35
+ } ) ;
36
+
28
37
server . on ( 'connection' , function ( socket ) {
29
38
// simple test
30
39
socket . on ( 'hi' , function ( ) {
You can’t perform that action at this time.
0 commit comments