Skip to content
New issue

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

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

Already on GitHub? # to your account

fix(transport-commons): Ensure socket queries are always plain objects #2597

Merged
merged 1 commit into from
Apr 13, 2022
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
145 changes: 62 additions & 83 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/transport-commons/src/socket/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ export async function runMethod (app: Application, connection: RealTimeConnectio
}

const position = paramsPositions[method] !== undefined ? paramsPositions[method] : DEFAULT_PARAMS_POSITION;
const query = methodArgs[position] || {};
const query = Object.assign({}, methodArgs[position]);
// `params` have to be re-mapped to the query and added with the route
const params = Object.assign({ query, route, connection }, connection);

Expand Down
26 changes: 23 additions & 3 deletions packages/transport-commons/test/socket/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import assert from 'assert';
import { EventEmitter } from 'events';
import { feathers, Application, Params } from '@feathersjs/feathers';
import { NotAuthenticated } from '@feathersjs/errors';
import { isPlainObject } from 'lodash';

import { routing } from '../../src/routing';
import {
Expand Down Expand Up @@ -189,11 +190,15 @@ describe('socket commons utils', () => {
beforeEach(() => {
app = feathers().configure(routing());
app.use('/myservice', {
get (id: number|string, params: Params) {
async get (id: number|string, params: Params) {
if (params.query.error) {
return Promise.reject(new NotAuthenticated('None shall pass'));
throw new NotAuthenticated('None shall pass');
}
return Promise.resolve({ id });
if (!isPlainObject(params.query)) {
throw new Error('Query is not a plain object');
}

return { id };
}
});
});
Expand All @@ -212,6 +217,21 @@ describe('socket commons utils', () => {
runMethod(app, {}, 'myservice', 'get', [ 10, {}, callback ]);
});

it('queries are always plain objects', done => {
const callback = (error: any, result: any) => {
if (error) {
return done(error);
}

assert.deepStrictEqual(result, { id: 10 });
done();
};

runMethod(app, {}, 'myservice', 'get', [ 10, {
__proto__: []
}, callback ]);
});

it('merges params with connection and passes connection', done => {
const connection = {
testing: true
Expand Down