mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-20 02:10:15 +01:00
🛜 refactor: Streamline App Config Usage (#9234)
* WIP: app.locals refactoring
WIP: appConfig
fix: update memory configuration retrieval to use getAppConfig based on user role
fix: update comment for AppConfig interface to clarify purpose
🏷️ refactor: Update tests to use getAppConfig for endpoint configurations
ci: Update AppService tests to initialize app config instead of app.locals
ci: Integrate getAppConfig into remaining tests
refactor: Update multer storage destination to use promise-based getAppConfig and improve error handling in tests
refactor: Rename initializeAppConfig to setAppConfig and update related tests
ci: Mock getAppConfig in various tests to provide default configurations
refactor: Update convertMCPToolsToPlugins to use mcpManager for server configuration and adjust related tests
chore: rename `Config/getAppConfig` -> `Config/app`
fix: streamline OpenAI image tools configuration by removing direct appConfig dependency and using function parameters
chore: correct parameter documentation for imageOutputType in ToolService.js
refactor: remove `getCustomConfig` dependency in config route
refactor: update domain validation to use appConfig for allowed domains
refactor: use appConfig registration property
chore: remove app parameter from AppService invocation
refactor: update AppConfig interface to correct registration and turnstile configurations
refactor: remove getCustomConfig dependency and use getAppConfig in PluginController, multer, and MCP services
refactor: replace getCustomConfig with getAppConfig in STTService, TTSService, and related files
refactor: replace getCustomConfig with getAppConfig in Conversation and Message models, update tempChatRetention functions to use AppConfig type
refactor: update getAppConfig calls in Conversation and Message models to include user role for temporary chat expiration
ci: update related tests
refactor: update getAppConfig call in getCustomConfigSpeech to include user role
fix: update appConfig usage to access allowedDomains from actions instead of registration
refactor: enhance AppConfig to include fileStrategies and update related file strategy logic
refactor: update imports to use normalizeEndpointName from @librechat/api and remove redundant definitions
chore: remove deprecated unused RunManager
refactor: get balance config primarily from appConfig
refactor: remove customConfig dependency for appConfig and streamline loadConfigModels logic
refactor: remove getCustomConfig usage and use app config in file citations
refactor: consolidate endpoint loading logic into loadEndpoints function
refactor: update appConfig access to use endpoints structure across various services
refactor: implement custom endpoints configuration and streamline endpoint loading logic
refactor: update getAppConfig call to include user role parameter
refactor: streamline endpoint configuration and enhance appConfig usage across services
refactor: replace getMCPAuthMap with getUserMCPAuthMap and remove unused getCustomConfig file
refactor: add type annotation for loadedEndpoints in loadEndpoints function
refactor: move /services/Files/images/parse to TS API
chore: add missing FILE_CITATIONS permission to IRole interface
refactor: restructure toolkits to TS API
refactor: separate manifest logic into its own module
refactor: consolidate tool loading logic into a new tools module for startup logic
refactor: move interface config logic to TS API
refactor: migrate checkEmailConfig to TypeScript and update imports
refactor: add FunctionTool interface and availableTools to AppConfig
refactor: decouple caching and DB operations from AppService, make part of consolidated `getAppConfig`
WIP: fix tests
* fix: rebase conflicts
* refactor: remove app.locals references
* refactor: replace getBalanceConfig with getAppConfig in various strategies and middleware
* refactor: replace appConfig?.balance with getBalanceConfig in various controllers and clients
* test: add balance configuration to titleConvo method in AgentClient tests
* chore: remove unused `openai-chat-tokens` package
* chore: remove unused imports in initializeMCPs.js
* refactor: update balance configuration to use getAppConfig instead of getBalanceConfig
* refactor: integrate configMiddleware for centralized configuration handling
* refactor: optimize email domain validation by removing unnecessary async calls
* refactor: simplify multer storage configuration by removing async calls
* refactor: reorder imports for better readability in user.js
* refactor: replace getAppConfig calls with req.config for improved performance
* chore: replace getAppConfig calls with req.config in tests for centralized configuration handling
* chore: remove unused override config
* refactor: add configMiddleware to endpoint route and replace getAppConfig with req.config
* chore: remove customConfig parameter from TTSService constructor
* refactor: pass appConfig from request to processFileCitations for improved configuration handling
* refactor: remove configMiddleware from endpoint route and retrieve appConfig directly in getEndpointsConfig if not in `req.config`
* test: add mockAppConfig to processFileCitations tests for improved configuration handling
* fix: pass req.config to hasCustomUserVars and call without await after synchronous refactor
* fix: type safety in useExportConversation
* refactor: retrieve appConfig using getAppConfig in PluginController and remove configMiddleware from plugins route, to avoid always retrieving when plugins are cached
* chore: change `MongoUser` typedef to `IUser`
* fix: Add `user` and `config` fields to ServerRequest and update JSDoc type annotations from Express.Request to ServerRequest
* fix: remove unused setAppConfig mock from Server configuration tests
This commit is contained in:
parent
e1ad235f17
commit
9a210971f5
210 changed files with 4102 additions and 3465 deletions
|
|
@ -1,8 +1,8 @@
|
|||
const { isEmailDomainAllowed, isActionDomainAllowed } = require('~/server/services/domains');
|
||||
const { getCustomConfig } = require('~/server/services/Config');
|
||||
const { getAppConfig } = require('~/server/services/Config');
|
||||
|
||||
jest.mock('~/server/services/Config', () => ({
|
||||
getCustomConfig: jest.fn(),
|
||||
getAppConfig: jest.fn(),
|
||||
}));
|
||||
|
||||
describe('isEmailDomainAllowed', () => {
|
||||
|
|
@ -12,49 +12,49 @@ describe('isEmailDomainAllowed', () => {
|
|||
|
||||
it('should return false if email is falsy', async () => {
|
||||
const email = '';
|
||||
const result = await isEmailDomainAllowed(email);
|
||||
const result = isEmailDomainAllowed(email);
|
||||
expect(result).toBe(false);
|
||||
});
|
||||
|
||||
it('should return false if domain is not present in the email', async () => {
|
||||
const email = 'test';
|
||||
const result = await isEmailDomainAllowed(email);
|
||||
const result = isEmailDomainAllowed(email);
|
||||
expect(result).toBe(false);
|
||||
});
|
||||
|
||||
it('should return true if customConfig is not available', async () => {
|
||||
const email = 'test@domain1.com';
|
||||
getCustomConfig.mockResolvedValue(null);
|
||||
const result = await isEmailDomainAllowed(email);
|
||||
getAppConfig.mockResolvedValue(null);
|
||||
const result = isEmailDomainAllowed(email, null);
|
||||
expect(result).toBe(true);
|
||||
});
|
||||
|
||||
it('should return true if allowedDomains is not defined in customConfig', async () => {
|
||||
const email = 'test@domain1.com';
|
||||
getCustomConfig.mockResolvedValue({});
|
||||
const result = await isEmailDomainAllowed(email);
|
||||
getAppConfig.mockResolvedValue({});
|
||||
const result = isEmailDomainAllowed(email, undefined);
|
||||
expect(result).toBe(true);
|
||||
});
|
||||
|
||||
it('should return true if domain is included in the allowedDomains', async () => {
|
||||
const email = 'user@domain1.com';
|
||||
getCustomConfig.mockResolvedValue({
|
||||
getAppConfig.mockResolvedValue({
|
||||
registration: {
|
||||
allowedDomains: ['domain1.com', 'domain2.com'],
|
||||
},
|
||||
});
|
||||
const result = await isEmailDomainAllowed(email);
|
||||
const result = isEmailDomainAllowed(email, ['domain1.com', 'domain2.com']);
|
||||
expect(result).toBe(true);
|
||||
});
|
||||
|
||||
it('should return false if domain is not included in the allowedDomains', async () => {
|
||||
const email = 'user@domain3.com';
|
||||
getCustomConfig.mockResolvedValue({
|
||||
getAppConfig.mockResolvedValue({
|
||||
registration: {
|
||||
allowedDomains: ['domain1.com', 'domain2.com'],
|
||||
},
|
||||
});
|
||||
const result = await isEmailDomainAllowed(email);
|
||||
const result = isEmailDomainAllowed(email, ['domain1.com', 'domain2.com']);
|
||||
expect(result).toBe(false);
|
||||
});
|
||||
});
|
||||
|
|
@ -80,114 +80,119 @@ describe('isActionDomainAllowed', () => {
|
|||
});
|
||||
|
||||
it('should return false for invalid domain formats', async () => {
|
||||
getCustomConfig.mockResolvedValue({
|
||||
getAppConfig.mockResolvedValue({
|
||||
actions: { allowedDomains: ['http://', 'https://'] },
|
||||
});
|
||||
expect(await isActionDomainAllowed('http://')).toBe(false);
|
||||
expect(await isActionDomainAllowed('https://')).toBe(false);
|
||||
expect(await isActionDomainAllowed('http://', ['http://', 'https://'])).toBe(false);
|
||||
expect(await isActionDomainAllowed('https://', ['http://', 'https://'])).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
// Configuration Tests
|
||||
describe('configuration handling', () => {
|
||||
it('should return true if customConfig is null', async () => {
|
||||
getCustomConfig.mockResolvedValue(null);
|
||||
expect(await isActionDomainAllowed('example.com')).toBe(true);
|
||||
getAppConfig.mockResolvedValue(null);
|
||||
expect(await isActionDomainAllowed('example.com', null)).toBe(true);
|
||||
});
|
||||
|
||||
it('should return true if actions.allowedDomains is not defined', async () => {
|
||||
getCustomConfig.mockResolvedValue({});
|
||||
expect(await isActionDomainAllowed('example.com')).toBe(true);
|
||||
getAppConfig.mockResolvedValue({});
|
||||
expect(await isActionDomainAllowed('example.com', undefined)).toBe(true);
|
||||
});
|
||||
|
||||
it('should return true if allowedDomains is empty array', async () => {
|
||||
getCustomConfig.mockResolvedValue({
|
||||
getAppConfig.mockResolvedValue({
|
||||
actions: { allowedDomains: [] },
|
||||
});
|
||||
expect(await isActionDomainAllowed('example.com')).toBe(true);
|
||||
expect(await isActionDomainAllowed('example.com', [])).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
// Domain Matching Tests
|
||||
describe('domain matching', () => {
|
||||
const allowedDomains = [
|
||||
'example.com',
|
||||
'*.subdomain.com',
|
||||
'specific.domain.com',
|
||||
'www.withprefix.com',
|
||||
'swapi.dev',
|
||||
];
|
||||
|
||||
beforeEach(() => {
|
||||
getCustomConfig.mockResolvedValue({
|
||||
getAppConfig.mockResolvedValue({
|
||||
actions: {
|
||||
allowedDomains: [
|
||||
'example.com',
|
||||
'*.subdomain.com',
|
||||
'specific.domain.com',
|
||||
'www.withprefix.com',
|
||||
'swapi.dev',
|
||||
],
|
||||
allowedDomains,
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
it('should match exact domains', async () => {
|
||||
expect(await isActionDomainAllowed('example.com')).toBe(true);
|
||||
expect(await isActionDomainAllowed('other.com')).toBe(false);
|
||||
expect(await isActionDomainAllowed('swapi.dev')).toBe(true);
|
||||
expect(await isActionDomainAllowed('example.com', allowedDomains)).toBe(true);
|
||||
expect(await isActionDomainAllowed('other.com', allowedDomains)).toBe(false);
|
||||
expect(await isActionDomainAllowed('swapi.dev', allowedDomains)).toBe(true);
|
||||
});
|
||||
|
||||
it('should handle domains with www prefix', async () => {
|
||||
expect(await isActionDomainAllowed('www.example.com')).toBe(true);
|
||||
expect(await isActionDomainAllowed('www.withprefix.com')).toBe(true);
|
||||
expect(await isActionDomainAllowed('www.example.com', allowedDomains)).toBe(true);
|
||||
expect(await isActionDomainAllowed('www.withprefix.com', allowedDomains)).toBe(true);
|
||||
});
|
||||
|
||||
it('should handle full URLs', async () => {
|
||||
expect(await isActionDomainAllowed('https://example.com')).toBe(true);
|
||||
expect(await isActionDomainAllowed('http://example.com')).toBe(true);
|
||||
expect(await isActionDomainAllowed('https://example.com/path')).toBe(true);
|
||||
expect(await isActionDomainAllowed('https://example.com', allowedDomains)).toBe(true);
|
||||
expect(await isActionDomainAllowed('http://example.com', allowedDomains)).toBe(true);
|
||||
expect(await isActionDomainAllowed('https://example.com/path', allowedDomains)).toBe(true);
|
||||
});
|
||||
|
||||
it('should handle wildcard subdomains', async () => {
|
||||
expect(await isActionDomainAllowed('test.subdomain.com')).toBe(true);
|
||||
expect(await isActionDomainAllowed('any.subdomain.com')).toBe(true);
|
||||
expect(await isActionDomainAllowed('subdomain.com')).toBe(true);
|
||||
expect(await isActionDomainAllowed('test.subdomain.com', allowedDomains)).toBe(true);
|
||||
expect(await isActionDomainAllowed('any.subdomain.com', allowedDomains)).toBe(true);
|
||||
expect(await isActionDomainAllowed('subdomain.com', allowedDomains)).toBe(true);
|
||||
});
|
||||
|
||||
it('should handle specific subdomains', async () => {
|
||||
expect(await isActionDomainAllowed('specific.domain.com')).toBe(true);
|
||||
expect(await isActionDomainAllowed('other.domain.com')).toBe(false);
|
||||
expect(await isActionDomainAllowed('specific.domain.com', allowedDomains)).toBe(true);
|
||||
expect(await isActionDomainAllowed('other.domain.com', allowedDomains)).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
// Edge Cases
|
||||
describe('edge cases', () => {
|
||||
const edgeAllowedDomains = ['example.com', '*.test.com'];
|
||||
|
||||
beforeEach(() => {
|
||||
getCustomConfig.mockResolvedValue({
|
||||
getAppConfig.mockResolvedValue({
|
||||
actions: {
|
||||
allowedDomains: ['example.com', '*.test.com'],
|
||||
allowedDomains: edgeAllowedDomains,
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
it('should handle domains with query parameters', async () => {
|
||||
expect(await isActionDomainAllowed('example.com?param=value')).toBe(true);
|
||||
expect(await isActionDomainAllowed('example.com?param=value', edgeAllowedDomains)).toBe(true);
|
||||
});
|
||||
|
||||
it('should handle domains with ports', async () => {
|
||||
expect(await isActionDomainAllowed('example.com:8080')).toBe(true);
|
||||
expect(await isActionDomainAllowed('example.com:8080', edgeAllowedDomains)).toBe(true);
|
||||
});
|
||||
|
||||
it('should handle domains with trailing slashes', async () => {
|
||||
expect(await isActionDomainAllowed('example.com/')).toBe(true);
|
||||
expect(await isActionDomainAllowed('example.com/', edgeAllowedDomains)).toBe(true);
|
||||
});
|
||||
|
||||
it('should handle case insensitivity', async () => {
|
||||
expect(await isActionDomainAllowed('EXAMPLE.COM')).toBe(true);
|
||||
expect(await isActionDomainAllowed('Example.Com')).toBe(true);
|
||||
expect(await isActionDomainAllowed('EXAMPLE.COM', edgeAllowedDomains)).toBe(true);
|
||||
expect(await isActionDomainAllowed('Example.Com', edgeAllowedDomains)).toBe(true);
|
||||
});
|
||||
|
||||
it('should handle invalid entries in allowedDomains', async () => {
|
||||
getCustomConfig.mockResolvedValue({
|
||||
const invalidAllowedDomains = ['example.com', null, undefined, '', 'test.com'];
|
||||
getAppConfig.mockResolvedValue({
|
||||
actions: {
|
||||
allowedDomains: ['example.com', null, undefined, '', 'test.com'],
|
||||
allowedDomains: invalidAllowedDomains,
|
||||
},
|
||||
});
|
||||
expect(await isActionDomainAllowed('example.com')).toBe(true);
|
||||
expect(await isActionDomainAllowed('test.com')).toBe(true);
|
||||
expect(await isActionDomainAllowed('example.com', invalidAllowedDomains)).toBe(true);
|
||||
expect(await isActionDomainAllowed('test.com', invalidAllowedDomains)).toBe(true);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue