snapshot of https://github.com/RocketChat/Rocket.Chat.git (develop, 2026-09-16; blobs > 131072B omitted)
Some checks failed
Create issues from TODOs / todos (push) Failing after 3s
Close inactive issues / close-issues (push) Has been cancelled
Deploy GitHub Pages / deploy-preview (push) Has been cancelled
CI / ⚙️ Variables Setup (push) Has been cancelled
CI / ⚙️ Test Guard (push) Has been cancelled
CI / 🚀 Notify external services - draft (push) Has been cancelled
CI / 📦 Build Packages (push) Has been cancelled
CI / 📦 Meteor Build (coverage) (push) Has been cancelled
CI / 📦 Meteor Build (production) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [account-service presence-service omnichannel-transcript-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [account-service presence-service omnichannel-transcript-service], fips) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [authorization-service queue-worker-service ddp-streamer-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [authorization-service queue-worker-service ddp-streamer-service], fips) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], coverage) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], fips) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [account-service presence-service omnichannel-transcript-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [authorization-service queue-worker-service ddp-streamer-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [rocketchat], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [rocketchat], coverage) (push) Has been cancelled
CI / 🚢 Publish Docker Images (ghcr.io) (push) Has been cancelled
CI / 📦 Track Image Sizes (push) Has been cancelled
CI / 🔎 Code Check - Action Lint (push) Has been cancelled
CI / 🔎 Code Check (push) Has been cancelled
CI / 🔨 Test Storybook (push) Has been cancelled
CI / 🔨 Test Unit (push) Has been cancelled
CI / 🔨 Test API (CE) (push) Has been cancelled
CI / 🔨 Test API Livechat (CE) (push) Has been cancelled
CI / 🔨 Test UI (CE) (push) Has been cancelled
CI / 🔨 Test API (EE) (push) Has been cancelled
CI / 🔨 Test API Livechat (EE) (push) Has been cancelled
CI / 🔨 Test API Apps (deno-runtime - EE) (push) Has been cancelled
CI / 🔨 Test UI (EE) (push) Has been cancelled
CI / 🔨 Test API (FIPS) (push) Has been cancelled
CI / 🔨 Test API Livechat (FIPS) (push) Has been cancelled
CI / 🔨 Test UI (FIPS) (push) Has been cancelled
CI / 🔨 Test Federation Matrix (push) Has been cancelled
CI / 📊 Report Coverage (push) Has been cancelled
CI / ✅ Tests Done (push) Has been cancelled
CI / 🚀 Publish build assets (push) Has been cancelled
CI / 🚀 Publish Docker Images (DockerHub) (push) Has been cancelled
CI / 🚀 Notify external services (push) Has been cancelled
CI / Update Version Durability (push) Has been cancelled
Release / Release (push) Has been cancelled
Auto-close duplicate issues / auto-close-duplicates (push) Failing after 1s
Code scanning - action / CodeQL-Build (push) Failing after 1s
Some checks failed
Create issues from TODOs / todos (push) Failing after 3s
Close inactive issues / close-issues (push) Has been cancelled
Deploy GitHub Pages / deploy-preview (push) Has been cancelled
CI / ⚙️ Variables Setup (push) Has been cancelled
CI / ⚙️ Test Guard (push) Has been cancelled
CI / 🚀 Notify external services - draft (push) Has been cancelled
CI / 📦 Build Packages (push) Has been cancelled
CI / 📦 Meteor Build (coverage) (push) Has been cancelled
CI / 📦 Meteor Build (production) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [account-service presence-service omnichannel-transcript-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [account-service presence-service omnichannel-transcript-service], fips) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [authorization-service queue-worker-service ddp-streamer-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [authorization-service queue-worker-service ddp-streamer-service], fips) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], coverage) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], fips) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [account-service presence-service omnichannel-transcript-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [authorization-service queue-worker-service ddp-streamer-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [rocketchat], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [rocketchat], coverage) (push) Has been cancelled
CI / 🚢 Publish Docker Images (ghcr.io) (push) Has been cancelled
CI / 📦 Track Image Sizes (push) Has been cancelled
CI / 🔎 Code Check - Action Lint (push) Has been cancelled
CI / 🔎 Code Check (push) Has been cancelled
CI / 🔨 Test Storybook (push) Has been cancelled
CI / 🔨 Test Unit (push) Has been cancelled
CI / 🔨 Test API (CE) (push) Has been cancelled
CI / 🔨 Test API Livechat (CE) (push) Has been cancelled
CI / 🔨 Test UI (CE) (push) Has been cancelled
CI / 🔨 Test API (EE) (push) Has been cancelled
CI / 🔨 Test API Livechat (EE) (push) Has been cancelled
CI / 🔨 Test API Apps (deno-runtime - EE) (push) Has been cancelled
CI / 🔨 Test UI (EE) (push) Has been cancelled
CI / 🔨 Test API (FIPS) (push) Has been cancelled
CI / 🔨 Test API Livechat (FIPS) (push) Has been cancelled
CI / 🔨 Test UI (FIPS) (push) Has been cancelled
CI / 🔨 Test Federation Matrix (push) Has been cancelled
CI / 📊 Report Coverage (push) Has been cancelled
CI / ✅ Tests Done (push) Has been cancelled
CI / 🚀 Publish build assets (push) Has been cancelled
CI / 🚀 Publish Docker Images (DockerHub) (push) Has been cancelled
CI / 🚀 Notify external services (push) Has been cancelled
CI / Update Version Durability (push) Has been cancelled
Release / Release (push) Has been cancelled
Auto-close duplicate issues / auto-close-duplicates (push) Failing after 1s
Code scanning - action / CodeQL-Build (push) Failing after 1s
This commit is contained in:
226
apps/meteor/tests/unit/server/api/lib/isValidQuery.spec.ts
Normal file
226
apps/meteor/tests/unit/server/api/lib/isValidQuery.spec.ts
Normal file
@@ -0,0 +1,226 @@
|
||||
import { expect } from 'chai';
|
||||
import { describe, it } from 'mocha';
|
||||
|
||||
import { isValidQuery } from '../../../../../server/api/lib/isValidQuery';
|
||||
|
||||
describe('isValidQuery', () => {
|
||||
describe('shallow keys', () => {
|
||||
it('should return false if the query contains an operation that is not in the props array', () => {
|
||||
const props = ['_id', 'name'];
|
||||
const query = {
|
||||
$or: [
|
||||
{
|
||||
_id: '123',
|
||||
},
|
||||
{
|
||||
name: '456',
|
||||
},
|
||||
],
|
||||
};
|
||||
expect(isValidQuery(query, props, [])).to.be.false;
|
||||
expect(isValidQuery.errors.length).to.be.equals(1);
|
||||
});
|
||||
|
||||
it('should return true if the query contains operation and the attributes are set in the props array ', () => {
|
||||
const props = ['_id', 'name'];
|
||||
const query = {
|
||||
$or: [
|
||||
{
|
||||
_id: '123',
|
||||
},
|
||||
{
|
||||
name: '456',
|
||||
},
|
||||
],
|
||||
};
|
||||
expect(isValidQuery(query, props, ['$or'])).to.be.true;
|
||||
expect(isValidQuery.errors.length).to.be.equals(0);
|
||||
});
|
||||
|
||||
it('should return false if the query contains operations allowed but some attributes are not set in the props array ', () => {
|
||||
const props = ['name'];
|
||||
const query = {
|
||||
$or: [
|
||||
{
|
||||
_id: '123',
|
||||
},
|
||||
{
|
||||
name: '456',
|
||||
},
|
||||
],
|
||||
};
|
||||
expect(isValidQuery(query, props, ['$or'])).to.be.false;
|
||||
expect(isValidQuery.errors.length).to.be.equals(1);
|
||||
});
|
||||
|
||||
it('should return true if the query contains only attributes set in the props array ', () => {
|
||||
const props = ['_id', 'name'];
|
||||
const query = {
|
||||
_id: '123',
|
||||
name: '456',
|
||||
};
|
||||
expect(isValidQuery(query, props, [])).to.be.true;
|
||||
expect(isValidQuery.errors.length).to.be.equals(0);
|
||||
});
|
||||
|
||||
it('should return false if the query contains an attribute that is not in the props array ', () => {
|
||||
const props = ['_id'];
|
||||
const query = {
|
||||
_id: '123',
|
||||
name: '456',
|
||||
};
|
||||
expect(isValidQuery(query, props, [])).to.be.false;
|
||||
expect(isValidQuery.errors.length).to.be.equals(1);
|
||||
});
|
||||
});
|
||||
|
||||
describe('deep keys', () => {
|
||||
it('should return false if the query contains deep attributes that are not set on allowed keys', () => {
|
||||
const props = ['_id', 'name'];
|
||||
const query = {
|
||||
user: {
|
||||
_id: '123',
|
||||
name: '456',
|
||||
},
|
||||
};
|
||||
expect(isValidQuery(query, props, [])).to.be.false;
|
||||
expect(isValidQuery.errors.length).to.be.equals(1);
|
||||
});
|
||||
|
||||
it('should return false if the query contains deep attributes that are and are not set as allowed', () => {
|
||||
const props = ['user', '_id', 'name'];
|
||||
const query = {
|
||||
user: {
|
||||
_id: '123',
|
||||
name: '456',
|
||||
},
|
||||
};
|
||||
expect(isValidQuery(query, props, [])).to.be.false;
|
||||
expect(isValidQuery.errors.length).to.be.equals(1);
|
||||
});
|
||||
|
||||
it('should return true if the query contains deep attributes that are set on allowed keys', () => {
|
||||
const props = ['user', 'user._id', 'user.name'];
|
||||
const query = {
|
||||
user: {
|
||||
_id: '123',
|
||||
name: '456',
|
||||
},
|
||||
};
|
||||
expect(isValidQuery(query, props, [])).to.be.true;
|
||||
expect(isValidQuery.errors.length).to.be.equals(0);
|
||||
});
|
||||
|
||||
it('should return true if the query contains deep attributes that are set on allowed keys even for many layers', () => {
|
||||
const props = ['user', 'user._id', 'user.name', 'user.address', 'user.address.city'];
|
||||
const query = {
|
||||
user: {
|
||||
_id: '123',
|
||||
name: '456',
|
||||
address: {
|
||||
city: 'New York',
|
||||
},
|
||||
},
|
||||
};
|
||||
expect(isValidQuery(query, props, [])).to.be.true;
|
||||
expect(isValidQuery.errors.length).to.be.equals(0);
|
||||
});
|
||||
});
|
||||
|
||||
describe('using .* for match keys', () => {
|
||||
it('should return true if the query contains attributes and * are being used', () => {
|
||||
const props = ['user', 'user.*'];
|
||||
const query = {
|
||||
user: {
|
||||
_id: '123',
|
||||
name: '456',
|
||||
},
|
||||
};
|
||||
expect(isValidQuery(query, props, [])).to.be.true;
|
||||
expect(isValidQuery.errors.length).to.be.equals(0);
|
||||
});
|
||||
});
|
||||
|
||||
describe('using * for match keys', () => {
|
||||
it('should return true if the query contains attributes and * are being used', () => {
|
||||
const props = ['user', '*'];
|
||||
const query = {
|
||||
user: {
|
||||
_id: '123',
|
||||
name: '456',
|
||||
},
|
||||
};
|
||||
expect(isValidQuery(query, props, [])).to.be.true;
|
||||
expect(isValidQuery.errors.length).to.be.equals(0);
|
||||
});
|
||||
it('should return false if query uses * but the operation is not allowed', () => {
|
||||
const props = ['user', '*'];
|
||||
const query = {
|
||||
$or: [{ user: '123' }, { user: '456' }],
|
||||
};
|
||||
expect(isValidQuery(query, props, [])).to.be.false;
|
||||
expect(isValidQuery.errors.length).to.be.equals(1);
|
||||
});
|
||||
});
|
||||
|
||||
describe('testing $regex', () => {
|
||||
it('should return true if the query contains attributes and * are being used', () => {
|
||||
const props = ['user.*'];
|
||||
const query = {
|
||||
user: {
|
||||
_id: '123',
|
||||
name: {
|
||||
$regex: '*',
|
||||
},
|
||||
},
|
||||
};
|
||||
expect(isValidQuery(query, props, ['$or', '$regex'])).to.be.true;
|
||||
expect(isValidQuery.errors.length).to.be.equals(0);
|
||||
});
|
||||
|
||||
it('should return false for services.password.reset.token', () => {
|
||||
const query = {
|
||||
$or: [
|
||||
{ 'emails.address': { $regex: '', $options: 'i' } },
|
||||
{ username: { $regex: '', $options: 'i' } },
|
||||
{ name: { $regex: '', $options: 'i' } },
|
||||
],
|
||||
$and: [{ username: 'g1' }, { 'services.password.reset.token': { $regex: '.*' } }],
|
||||
};
|
||||
expect(
|
||||
isValidQuery(
|
||||
query,
|
||||
['name', 'username', 'emails', 'roles', 'status', 'active', 'avatarETag', 'lastLogin', 'email.address.*', 'username.*', 'name.*'],
|
||||
['$or', '$and'],
|
||||
),
|
||||
).to.be.false;
|
||||
});
|
||||
it('should return false for services.totp.secret', () => {
|
||||
const query = {
|
||||
$or: [
|
||||
{ 'emails.address': { $regex: '', $options: 'i' } },
|
||||
{ username: { $regex: '', $options: 'i' } },
|
||||
{ name: { $regex: '', $options: 'i' } },
|
||||
],
|
||||
$and: [{ username: 'g1' }, { 'services.totp.secret': { $regex: '.*' } }],
|
||||
};
|
||||
expect(
|
||||
isValidQuery(
|
||||
query,
|
||||
['name', 'username', 'emails', 'roles', 'status', 'active', 'avatarETag', 'lastLogin', 'email.address.*', 'username.*', 'name.*'],
|
||||
['$or', '$and'],
|
||||
),
|
||||
).to.be.false;
|
||||
});
|
||||
|
||||
it('should return false if the query contains nested conditions with disallowed operators', () => {
|
||||
const props = ['username'];
|
||||
const allowedOps = ['$and', '$ne'];
|
||||
const query = {
|
||||
$and: [{ username: { $exists: true } }, { username: { $ne: '1000' } }],
|
||||
};
|
||||
expect(isValidQuery(query, props, allowedOps)).to.be.false;
|
||||
expect(isValidQuery.errors.length).to.be.equals(1);
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user