Skip to content

Commit

Permalink
fix: Add fallback for legacy socket authenticate event (#1356)
Browse files Browse the repository at this point in the history
  • Loading branch information
daffl authored May 14, 2019
1 parent 85afcca commit 61b1056
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
7 changes: 7 additions & 0 deletions packages/transport-commons/src/socket/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,13 @@ export function socket ({ done, emit, socketKey, getParams }: SocketOptions) {
runMethod(app, getParams(connection), path, method, args);
});
}

connection.on('authenticate', (...args: any[]) => {
if (app.get('defaultAuthentication')) {
debug('Got legacy authenticate event');
runMethod(app, getParams(connection), app.get('defaultAuthentication'), 'create', args);
}
});
}));

// Legacy `socket.emit('serviceName::methodName', ...args)` handlers
Expand Down
26 changes: 26 additions & 0 deletions packages/transport-commons/test/socket/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,32 @@ describe('@feathersjs/transport-commons', () => {
});

describe('legacy method socket event format', () => {
it('legacy `authenticate`', done => {
const socket = new EventEmitter();
const data = {
test: 'data'
};

app.set('defaultAuthentication', 'myservice');
provider.emit('connection', socket);

socket.emit('authenticate', data, (error: any, result: any) => {
try {
const params = Object.assign({
query: {},
route: {},
connection
}, connection);

assert.ok(!error);
assert.deepStrictEqual(result, Object.assign({ params }, data));
done();
} catch (e) {
done(e);
}
});
});

it('.get without params', done => {
const socket = new EventEmitter();

Expand Down

0 comments on commit 61b1056

Please # to comment.