2019-10-13 15:52:14 +02:00
|
|
|
const fixture = require('./fixture/namespace');
|
|
|
|
const request = require('request');
|
|
|
|
const io = require('socket.io-client');
|
2015-08-31 16:04:04 +02:00
|
|
|
|
2019-10-14 01:46:30 +02:00
|
|
|
describe('authorizer with namespaces', () => {
|
2015-08-31 16:04:04 +02:00
|
|
|
|
|
|
|
//start and stop the server
|
|
|
|
before(fixture.start);
|
|
|
|
after(fixture.stop);
|
|
|
|
|
2019-10-14 01:46:30 +02:00
|
|
|
describe('when the user is not logged in', () => {
|
2015-08-31 16:04:04 +02:00
|
|
|
|
2019-10-14 01:46:30 +02:00
|
|
|
it('should be able to connect to the default namespace', (done) => {
|
2019-10-13 15:52:14 +02:00
|
|
|
io.connect('http://localhost:9000')
|
2019-10-14 01:46:30 +02:00
|
|
|
.once('hi', () => done());
|
2015-08-31 16:04:04 +02:00
|
|
|
});
|
|
|
|
|
2019-10-14 01:46:30 +02:00
|
|
|
it('should not be able to connect to the admin namespace', (done) => {
|
2019-10-13 15:52:14 +02:00
|
|
|
io.connect('http://localhost:9000/admin')
|
2019-10-14 01:46:30 +02:00
|
|
|
.once('disconnect', () => done())
|
|
|
|
.once('hi admin', () => done(new Error('unauthenticated client was able to connect to the admin namespace')));
|
2015-08-31 16:04:04 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
|
2019-10-14 01:46:30 +02:00
|
|
|
describe('when the user is logged in', () => {
|
2015-08-31 16:04:04 +02:00
|
|
|
|
2019-10-14 01:46:30 +02:00
|
|
|
beforeEach((done) => {
|
2015-08-31 16:04:04 +02:00
|
|
|
request.post({
|
|
|
|
url: 'http://localhost:9000/login',
|
|
|
|
form: { username: 'jose', password: 'Pa123' },
|
|
|
|
json: true
|
2019-10-14 01:46:30 +02:00
|
|
|
}, (err, resp, body) => {
|
2015-08-31 16:04:04 +02:00
|
|
|
this.token = body.token;
|
|
|
|
done();
|
2019-10-14 01:46:30 +02:00
|
|
|
});
|
2015-08-31 16:04:04 +02:00
|
|
|
});
|
|
|
|
|
2019-10-14 01:46:30 +02:00
|
|
|
it('should do the handshake and connect', (done) => {
|
2019-10-13 15:52:14 +02:00
|
|
|
io.connect('http://localhost:9000/admin', { forceNew: true })
|
2019-10-14 01:46:30 +02:00
|
|
|
.on('authenticated', () => done())
|
2019-10-13 15:52:14 +02:00
|
|
|
.emit('authenticate', { token: this.token });
|
2015-08-31 16:04:04 +02:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|