mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-22 11:20:15 +01:00
fix: update appConfig usage to access allowedDomains from actions instead of registration
This commit is contained in:
parent
493f60fa54
commit
f25e4253d0
7 changed files with 23 additions and 59 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', () => {
|
||||
|
|
@ -24,21 +24,21 @@ describe('isEmailDomainAllowed', () => {
|
|||
|
||||
it('should return true if customConfig is not available', async () => {
|
||||
const email = 'test@domain1.com';
|
||||
getCustomConfig.mockResolvedValue(null);
|
||||
getAppConfig.mockResolvedValue(null);
|
||||
const result = await 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({});
|
||||
getAppConfig.mockResolvedValue({});
|
||||
const result = await 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'],
|
||||
},
|
||||
|
|
@ -49,7 +49,7 @@ describe('isEmailDomainAllowed', () => {
|
|||
|
||||
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'],
|
||||
},
|
||||
|
|
@ -80,7 +80,7 @@ describe('isActionDomainAllowed', () => {
|
|||
});
|
||||
|
||||
it('should return false for invalid domain formats', async () => {
|
||||
getCustomConfig.mockResolvedValue({
|
||||
getAppConfig.mockResolvedValue({
|
||||
actions: { allowedDomains: ['http://', 'https://'] },
|
||||
});
|
||||
expect(await isActionDomainAllowed('http://', ['http://', 'https://'])).toBe(false);
|
||||
|
|
@ -91,17 +91,17 @@ describe('isActionDomainAllowed', () => {
|
|||
// Configuration Tests
|
||||
describe('configuration handling', () => {
|
||||
it('should return true if customConfig is null', async () => {
|
||||
getCustomConfig.mockResolvedValue(null);
|
||||
getAppConfig.mockResolvedValue(null);
|
||||
expect(await isActionDomainAllowed('example.com', null)).toBe(true);
|
||||
});
|
||||
|
||||
it('should return true if actions.allowedDomains is not defined', async () => {
|
||||
getCustomConfig.mockResolvedValue({});
|
||||
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);
|
||||
|
|
@ -119,7 +119,7 @@ describe('isActionDomainAllowed', () => {
|
|||
];
|
||||
|
||||
beforeEach(() => {
|
||||
getCustomConfig.mockResolvedValue({
|
||||
getAppConfig.mockResolvedValue({
|
||||
actions: {
|
||||
allowedDomains,
|
||||
},
|
||||
|
|
@ -160,7 +160,7 @@ describe('isActionDomainAllowed', () => {
|
|||
const edgeAllowedDomains = ['example.com', '*.test.com'];
|
||||
|
||||
beforeEach(() => {
|
||||
getCustomConfig.mockResolvedValue({
|
||||
getAppConfig.mockResolvedValue({
|
||||
actions: {
|
||||
allowedDomains: edgeAllowedDomains,
|
||||
},
|
||||
|
|
@ -186,7 +186,7 @@ describe('isActionDomainAllowed', () => {
|
|||
|
||||
it('should handle invalid entries in allowedDomains', async () => {
|
||||
const invalidAllowedDomains = ['example.com', null, undefined, '', 'test.com'];
|
||||
getCustomConfig.mockResolvedValue({
|
||||
getAppConfig.mockResolvedValue({
|
||||
actions: {
|
||||
allowedDomains: invalidAllowedDomains,
|
||||
},
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue