mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-17 08:50:15 +01:00
* Allow LDAP login via username This patch adds the option to login via username instead of using an email address since the latter may not be unique or may change. For example, our organization has two main domains and users have a log and a short form of their mail address. This makes it hard for users to identify what their primary email address is and causes a lot of confusion. Using their username instead makes it much easier. Using a username will also make it easier in the future to not need a separate bind user to get user attributes. So, this is also a bit of prep work for that. * Update config.js * feat: Enable LDAP login via username This commit enables the option to login via username instead of using an email address for LDAP authentication. This change is necessary because email addresses may not be unique or may change, causing confusion for users. By using usernames, it becomes easier for users to identify their primary email address. Additionally, this change prepares for future improvements by eliminating the need for a separate bind user to retrieve user attributes. Co-authored-by: Danny Avila <danny@librechat.ai> * chore: jsdocs * chore: import order * ci: add ldap config tests --------- Co-authored-by: Lars Kiesow <lkiesow@uos.de>
55 lines
1.6 KiB
JavaScript
55 lines
1.6 KiB
JavaScript
const request = require('supertest');
|
|
const express = require('express');
|
|
const { getLdapConfig } = require('~/server/services/Config/ldap');
|
|
const { isEnabled } = require('~/server/utils');
|
|
|
|
jest.mock('~/server/services/Config/ldap');
|
|
jest.mock('~/server/utils');
|
|
|
|
const app = express();
|
|
|
|
// Mock the route handler
|
|
app.get('/api/config', (req, res) => {
|
|
const ldapConfig = getLdapConfig();
|
|
res.json({ ldap: ldapConfig });
|
|
});
|
|
|
|
describe('LDAP Config Tests', () => {
|
|
afterEach(() => {
|
|
jest.resetAllMocks();
|
|
});
|
|
|
|
it('should return LDAP config with username property when LDAP_LOGIN_USES_USERNAME is enabled', async () => {
|
|
getLdapConfig.mockReturnValue({ enabled: true, username: true });
|
|
isEnabled.mockReturnValue(true);
|
|
|
|
const response = await request(app).get('/api/config');
|
|
|
|
expect(response.statusCode).toBe(200);
|
|
expect(response.body.ldap).toEqual({
|
|
enabled: true,
|
|
username: true,
|
|
});
|
|
});
|
|
|
|
it('should return LDAP config without username property when LDAP_LOGIN_USES_USERNAME is not enabled', async () => {
|
|
getLdapConfig.mockReturnValue({ enabled: true });
|
|
isEnabled.mockReturnValue(false);
|
|
|
|
const response = await request(app).get('/api/config');
|
|
|
|
expect(response.statusCode).toBe(200);
|
|
expect(response.body.ldap).toEqual({
|
|
enabled: true,
|
|
});
|
|
});
|
|
|
|
it('should not return LDAP config when LDAP is not enabled', async () => {
|
|
getLdapConfig.mockReturnValue(undefined);
|
|
|
|
const response = await request(app).get('/api/config');
|
|
|
|
expect(response.statusCode).toBe(200);
|
|
expect(response.body.ldap).toBeUndefined();
|
|
});
|
|
});
|