ci: update related tests

This commit is contained in:
Danny Avila 2025-08-18 01:57:57 -04:00
parent 8f89fdc802
commit 1168a7d82e
No known key found for this signature in database
GPG key ID: BF31EEB2C5CA0956
10 changed files with 169 additions and 157 deletions

View file

@ -134,49 +134,53 @@ describe('AppService', () => {
expect(process.env.CDN_PROVIDER).toEqual('testStrategy');
expect(setAppConfig).toHaveBeenCalledWith({
config: expect.objectContaining({
expect(setAppConfig).toHaveBeenCalledWith(
expect.objectContaining({
config: expect.objectContaining({
fileStrategy: 'testStrategy',
}),
registration: expect.objectContaining({
socialLogins: ['testLogin'],
}),
fileStrategy: 'testStrategy',
interfaceConfig: expect.objectContaining({
endpointsMenu: true,
modelSelect: true,
parameters: true,
sidePanel: true,
presets: true,
}),
mcpConfig: null,
turnstileConfig: mockedTurnstileConfig,
modelSpecs: undefined,
paths: expect.anything(),
ocr: expect.anything(),
imageOutputType: expect.any(String),
fileConfig: undefined,
secureImageLinks: undefined,
balance: { enabled: true },
filteredTools: undefined,
includedTools: undefined,
webSearch: expect.objectContaining({
safeSearch: 1,
jinaApiKey: '${JINA_API_KEY}',
cohereApiKey: '${COHERE_API_KEY}',
serperApiKey: '${SERPER_API_KEY}',
searxngApiKey: '${SEARXNG_API_KEY}',
firecrawlApiKey: '${FIRECRAWL_API_KEY}',
firecrawlApiUrl: '${FIRECRAWL_API_URL}',
searxngInstanceUrl: '${SEARXNG_INSTANCE_URL}',
}),
memory: undefined,
agents: expect.objectContaining({
disableBuilder: false,
capabilities: expect.arrayContaining([...defaultAgentCapabilities]),
maxCitations: 30,
maxCitationsPerFile: 7,
minRelevanceScore: 0.45,
}),
}),
socialLogins: ['testLogin'],
fileStrategy: 'testStrategy',
interfaceConfig: expect.objectContaining({
endpointsMenu: true,
modelSelect: true,
parameters: true,
sidePanel: true,
presets: true,
}),
mcpConfig: null,
turnstileConfig: mockedTurnstileConfig,
modelSpecs: undefined,
paths: expect.anything(),
ocr: expect.anything(),
imageOutputType: expect.any(String),
fileConfig: undefined,
secureImageLinks: undefined,
balance: { enabled: true },
filteredTools: undefined,
includedTools: undefined,
webSearch: {
safeSearch: 1,
jinaApiKey: '${JINA_API_KEY}',
cohereApiKey: '${COHERE_API_KEY}',
serperApiKey: '${SERPER_API_KEY}',
searxngApiKey: '${SEARXNG_API_KEY}',
firecrawlApiKey: '${FIRECRAWL_API_KEY}',
firecrawlApiUrl: '${FIRECRAWL_API_URL}',
searxngInstanceUrl: '${SEARXNG_INSTANCE_URL}',
},
memory: undefined,
agents: {
disableBuilder: false,
capabilities: expect.arrayContaining([...defaultAgentCapabilities]),
maxCitations: 30,
maxCitationsPerFile: 7,
minRelevanceScore: 0.45,
},
});
);
});
it('should log a warning if the config version is outdated', async () => {
@ -261,6 +265,8 @@ describe('AppService', () => {
adminFilter: undefined,
adminIncluded: undefined,
directory: expect.anything(),
imageOutputType: expect.any(String),
fileStrategy: expect.any(String),
});
// Verify setCachedTools was called with the tools
@ -818,7 +824,9 @@ describe('AppService updating app config and issuing warnings', () => {
paths: expect.anything(),
config: {},
fileStrategy: FileSources.local,
socialLogins: defaultSocialLogins,
registration: expect.objectContaining({
socialLogins: defaultSocialLogins,
}),
balance: expect.objectContaining({
enabled: false,
startBalance: undefined,
@ -850,7 +858,9 @@ describe('AppService updating app config and issuing warnings', () => {
paths: expect.anything(),
config: customConfig,
fileStrategy: customConfig.fileStrategy,
socialLogins: customConfig.registration.socialLogins,
registration: expect.objectContaining({
socialLogins: customConfig.registration.socialLogins,
}),
balance: customConfig.balance,
}),
);

View file

@ -5,7 +5,7 @@ const { getAppConfig } = require('./app');
jest.mock('~/server/services/ModelService');
jest.mock('./getCustomConfig');
jest.mock('./getAppConfig');
jest.mock('./app');
const exampleConfig = {
endpoints: {

View file

@ -25,6 +25,7 @@ jest.mock('librechat-data-provider', () => ({
jest.mock('./Config', () => ({
loadCustomConfig: jest.fn(),
getAppConfig: jest.fn(),
}));
jest.mock('~/config', () => ({
@ -65,8 +66,10 @@ describe('tests for the new helper functions used by the MCP connection status e
server2: { type: 'http' },
},
};
let mockGetAppConfig;
beforeEach(() => {
mockGetAppConfig = require('./Config').getAppConfig;
mockGetMCPManager.mockReturnValue({
getAllConnections: jest.fn(() => new Map()),
getUserConnections: jest.fn(() => new Map()),
@ -75,7 +78,7 @@ describe('tests for the new helper functions used by the MCP connection status e
});
it('should successfully return MCP setup data', async () => {
mockLoadCustomConfig.mockResolvedValue(mockConfig);
mockGetAppConfig.mockResolvedValue({ mcpConfig: mockConfig.mcpServers });
const mockAppConnections = new Map([['server1', { status: 'connected' }]]);
const mockUserConnections = new Map([['server2', { status: 'disconnected' }]]);
@ -90,7 +93,7 @@ describe('tests for the new helper functions used by the MCP connection status e
const result = await getMCPSetupData(mockUserId);
expect(mockLoadCustomConfig).toHaveBeenCalledWith(false);
expect(mockGetAppConfig).toHaveBeenCalled();
expect(mockGetMCPManager).toHaveBeenCalledWith(mockUserId);
expect(mockMCPManager.getAllConnections).toHaveBeenCalled();
expect(mockMCPManager.getUserConnections).toHaveBeenCalledWith(mockUserId);
@ -105,12 +108,12 @@ describe('tests for the new helper functions used by the MCP connection status e
});
it('should throw error when MCP config not found', async () => {
mockLoadCustomConfig.mockResolvedValue({});
mockGetAppConfig.mockResolvedValue({});
await expect(getMCPSetupData(mockUserId)).rejects.toThrow('MCP config not found');
});
it('should handle null values from MCP manager gracefully', async () => {
mockLoadCustomConfig.mockResolvedValue(mockConfig);
mockGetAppConfig.mockResolvedValue({ mcpConfig: mockConfig.mcpServers });
const mockMCPManager = {
getAllConnections: jest.fn(() => null),

View file

@ -25,14 +25,14 @@ describe('isEmailDomainAllowed', () => {
it('should return true if customConfig is not available', async () => {
const email = 'test@domain1.com';
getCustomConfig.mockResolvedValue(null);
const result = await isEmailDomainAllowed(email);
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({});
const result = await isEmailDomainAllowed(email);
const result = await isEmailDomainAllowed(email, undefined);
expect(result).toBe(true);
});
@ -43,7 +43,7 @@ describe('isEmailDomainAllowed', () => {
allowedDomains: ['domain1.com', 'domain2.com'],
},
});
const result = await isEmailDomainAllowed(email);
const result = await isEmailDomainAllowed(email, ['domain1.com', 'domain2.com']);
expect(result).toBe(true);
});
@ -54,7 +54,7 @@ describe('isEmailDomainAllowed', () => {
allowedDomains: ['domain1.com', 'domain2.com'],
},
});
const result = await isEmailDomainAllowed(email);
const result = await isEmailDomainAllowed(email, ['domain1.com', 'domain2.com']);
expect(result).toBe(false);
});
});
@ -83,8 +83,8 @@ describe('isActionDomainAllowed', () => {
getCustomConfig.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);
});
});
@ -92,102 +92,107 @@ describe('isActionDomainAllowed', () => {
describe('configuration handling', () => {
it('should return true if customConfig is null', async () => {
getCustomConfig.mockResolvedValue(null);
expect(await isActionDomainAllowed('example.com')).toBe(true);
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);
expect(await isActionDomainAllowed('example.com', undefined)).toBe(true);
});
it('should return true if allowedDomains is empty array', async () => {
getCustomConfig.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({
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({
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 () => {
const invalidAllowedDomains = ['example.com', null, undefined, '', 'test.com'];
getCustomConfig.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);
});
});
});