Skip to content

Instantly share code, notes, and snippets.

@alxyang
Created January 10, 2015 02:19
Show Gist options
  • Save alxyang/cbc84a57d24744b67a32 to your computer and use it in GitHub Desktop.
Save alxyang/cbc84a57d24744b67a32 to your computer and use it in GitHub Desktop.
Authorization fail test socketio
var http = require('http').Server;
var io = require('..');
// ...
it('should be able to set authorization and send error packet', function(done) {
var httpSrv = http();
var srv = io(httpSrv);
// srv.set('authorization', function(o, f) { f(null, false); });
// srv.set('authorization', function(handshake, f){
// setTimeout(function(){
// f(null, false);
// }, 100);
// });
// srv.use(function(socket, next){
// setTimeout(function(){
// next(new Error('Not authorized'));
// }, 100);
// });
srv.use(function(socket, next){
next(new Error('Not authorized'));
});
var socket = client(httpSrv);
socket.on('connect', function(){
expect().fail();
});
socket.on('error', function(err) {
expect(err).to.be('Not authorized');
done();
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment