mirror of
https://github.com/hexastack/hexabot
synced 2025-04-10 07:45:57 +00:00
fix: add config allowed origins
This commit is contained in:
parent
395b033f74
commit
97cff8acff
@ -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']));
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user