Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add null check for connection.headers #2200

Merged
merged 2 commits into from Aug 20, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/servers/SockJSServer.js
Expand Up @@ -64,7 +64,7 @@ module.exports = class SockJSServer extends BaseServer {
// f should be passed the resulting connection and the connection headers
onConnection(f) {
this.socket.on('connection', (connection) => {
f(connection, connection.headers);
f(connection, connection ? connection.headers : null);
});
}

Expand Down
15 changes: 13 additions & 2 deletions test/server/servers/SockJSServer.test.js
Expand Up @@ -10,7 +10,7 @@ describe('SockJSServer', () => {
let socketServer;
let listeningApp;

beforeAll((done) => {
beforeEach((done) => {
wood1986 marked this conversation as resolved.
Show resolved Hide resolved
// eslint-disable-next-line new-cap
const app = new express();

Expand Down Expand Up @@ -84,9 +84,20 @@ describe('SockJSServer', () => {
done();
}, 3000);
});

it('should not throw an exception when connection is null', () => {
const cb = jest.fn();

socketServer.onConnection(cb);

expect(() => {
socketServer.socket.emit('connection', null);
}).not.toThrow();
expect(cb.mock.calls[0]).toEqual([null, null]);
});
});

afterAll((done) => {
afterEach((done) => {
listeningApp.close(done);
});
});