fix: add config allowed origins

This commit is contained in:
Mohamed Marrouchi 2025-01-23 18:07:56 +01:00
parent 395b033f74
commit 97cff8acff
2 changed files with 12 additions and 7 deletions

View File

@ -166,6 +166,7 @@ describe('SettingService', () => {
});
expect(result).toEqual(
new Set([
'*',
'https://example.com',
'https://test.com',
'https://another.com',
@ -173,7 +174,7 @@ describe('SettingService', () => {
);
});
it('should return an empty set if no settings are found', async () => {
it('should return the config allowed cors only if no settings are found', async () => {
jest.spyOn(settingService, 'find').mockResolvedValue([]);
const result = await settingService.getAllowedOrigins();
@ -181,7 +182,7 @@ describe('SettingService', () => {
expect(settingService.find).toHaveBeenCalledWith({
label: 'allowed_domains',
});
expect(result).toEqual(new Set());
expect(result).toEqual(new Set(['*']));
});
it('should handle settings with empty values', async () => {
@ -197,7 +198,7 @@ describe('SettingService', () => {
expect(settingService.find).toHaveBeenCalledWith({
label: 'allowed_domains',
});
expect(result).toEqual(new Set(['https://example.com']));
expect(result).toEqual(new Set(['*', 'https://example.com']));
});
});
});

View File

@ -142,12 +142,16 @@ export class SettingService extends BaseService<Setting> {
label: 'allowed_domains',
})) as TextSetting[];
const uniqueOrigins = new Set(
settings.flatMap((setting) =>
setting.value.split(',').filter((o) => !!o),
),
const allowedDomains = settings.flatMap((setting) =>
setting.value.split(',').filter((o) => !!o),
);
const uniqueOrigins = new Set([
...config.security.cors.allowOrigins,
...config.sockets.onlyAllowOrigins,
...allowedDomains,
]);
return uniqueOrigins;
}