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:
109
apps/meteor/server/lib/ldap/Connection.spec.ts
Normal file
109
apps/meteor/server/lib/ldap/Connection.spec.ts
Normal file
@@ -0,0 +1,109 @@
|
||||
import { expect } from 'chai';
|
||||
import { beforeEach, describe, it } from 'mocha';
|
||||
import proxyquire from 'proxyquire';
|
||||
import sinon from 'sinon';
|
||||
|
||||
const loggerStub = { debug: sinon.stub(), error: sinon.stub(), info: sinon.stub(), warn: sinon.stub() };
|
||||
|
||||
const { LDAPConnection } = proxyquire.noCallThru().load('./Connection', {
|
||||
'../../settings': { settings: { get: sinon.stub() } },
|
||||
'./getLDAPConditionalSetting': { getLDAPConditionalSetting: sinon.stub().returns('') },
|
||||
'./Logger': {
|
||||
logger: loggerStub,
|
||||
connLogger: loggerStub,
|
||||
bindLogger: loggerStub,
|
||||
searchLogger: loggerStub,
|
||||
authLogger: loggerStub,
|
||||
mapLogger: loggerStub,
|
||||
},
|
||||
});
|
||||
|
||||
describe('LDAPConnection', () => {
|
||||
describe('synchronous errors from client.search (e.g. invalid filters)', () => {
|
||||
const parseError = new Error('invalid attribute name');
|
||||
let connection: any;
|
||||
|
||||
beforeEach(() => {
|
||||
connection = new LDAPConnection();
|
||||
connection.options.userSearchField = 'uid';
|
||||
connection.client = { search: sinon.stub().throws(parseError) };
|
||||
});
|
||||
|
||||
it('should reject doCustomSearch with the error', async () => {
|
||||
const error = await connection
|
||||
.doCustomSearch('dc=test', { filter: '(&(=*))' }, () => undefined)
|
||||
.then(
|
||||
() => undefined,
|
||||
(e: unknown) => e,
|
||||
);
|
||||
expect(error).to.equal(parseError);
|
||||
});
|
||||
|
||||
it('should route the error to endCallback on paged searchAllUsers instead of leaking the throw', async () => {
|
||||
const endCallback = sinon.stub();
|
||||
await connection.searchAllUsers({ endCallback });
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-expressions
|
||||
expect(endCallback.calledOnceWithExactly(parseError)).to.be.true;
|
||||
});
|
||||
|
||||
it('should route the error to endCallback on non-paged searchAllUsers instead of leaking the throw', async () => {
|
||||
connection.options.searchPageSize = 0;
|
||||
const endCallback = sinon.stub();
|
||||
await connection.searchAllUsers({ endCallback });
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-expressions
|
||||
expect(endCallback.calledOnceWithExactly(parseError)).to.be.true;
|
||||
});
|
||||
});
|
||||
|
||||
describe('getUserFilter', () => {
|
||||
let connection: any;
|
||||
|
||||
beforeEach(() => {
|
||||
connection = new LDAPConnection();
|
||||
});
|
||||
|
||||
it('should compose the filter for a single search field', () => {
|
||||
connection.options.userSearchField = 'uid';
|
||||
expect(connection.getUserFilter('john')).to.equal('(&(uid=john))');
|
||||
});
|
||||
|
||||
it('should compose an OR filter for multiple search fields', () => {
|
||||
connection.options.userSearchField = 'uid,sAMAccountName';
|
||||
expect(connection.getUserFilter('john')).to.equal('(&(|(uid=john)(sAMAccountName=john)))');
|
||||
});
|
||||
|
||||
it('should trim whitespace and ignore empty segments (e.g. trailing commas)', () => {
|
||||
connection.options.userSearchField = ' uid , sAMAccountName ,';
|
||||
expect(connection.getUserFilter('john')).to.equal('(&(|(uid=john)(sAMAccountName=john)))');
|
||||
});
|
||||
|
||||
it('should include the user search filter when configured', () => {
|
||||
connection.options.userSearchField = 'uid';
|
||||
connection.options.userSearchFilter = '(objectclass=user)';
|
||||
expect(connection.getUserFilter('*')).to.equal('(&(objectclass=user)(uid=*))');
|
||||
});
|
||||
|
||||
it('should throw a configuration error when the search field is empty', () => {
|
||||
connection.options.userSearchField = '';
|
||||
expect(() => connection.getUserFilter('*')).to.throw('LDAP User Search Field is not configured');
|
||||
});
|
||||
|
||||
it('should throw a configuration error when the search field only has empty segments', () => {
|
||||
connection.options.userSearchField = ' , ,';
|
||||
expect(() => connection.getUserFilter('*')).to.throw('LDAP User Search Field is not configured');
|
||||
});
|
||||
|
||||
it('should reject searchAllUsers with the configuration error instead of composing an invalid filter', async () => {
|
||||
connection.options.userSearchField = '';
|
||||
connection.client = { search: sinon.stub() };
|
||||
const endCallback = sinon.stub();
|
||||
const error = await connection.searchAllUsers({ endCallback }).then(
|
||||
() => undefined,
|
||||
(e: unknown) => e,
|
||||
);
|
||||
expect(error).to.be.an('error').with.property('message', 'LDAP User Search Field is not configured');
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-expressions
|
||||
expect(connection.client.search.called).to.be.false;
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user