mirror of
https://github.com/hexastack/hexabot
synced 2025-06-26 18:27:28 +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(
|
expect(result).toEqual(
|
||||||
new Set([
|
new Set([
|
||||||
|
'*',
|
||||||
'https://example.com',
|
'https://example.com',
|
||||||
'https://test.com',
|
'https://test.com',
|
||||||
'https://another.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([]);
|
jest.spyOn(settingService, 'find').mockResolvedValue([]);
|
||||||
|
|
||||||
const result = await settingService.getAllowedOrigins();
|
const result = await settingService.getAllowedOrigins();
|
||||||
@ -181,7 +182,7 @@ describe('SettingService', () => {
|
|||||||
expect(settingService.find).toHaveBeenCalledWith({
|
expect(settingService.find).toHaveBeenCalledWith({
|
||||||
label: 'allowed_domains',
|
label: 'allowed_domains',
|
||||||
});
|
});
|
||||||
expect(result).toEqual(new Set());
|
expect(result).toEqual(new Set(['*']));
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should handle settings with empty values', async () => {
|
it('should handle settings with empty values', async () => {
|
||||||
@ -197,7 +198,7 @@ describe('SettingService', () => {
|
|||||||
expect(settingService.find).toHaveBeenCalledWith({
|
expect(settingService.find).toHaveBeenCalledWith({
|
||||||
label: 'allowed_domains',
|
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',
|
label: 'allowed_domains',
|
||||||
})) as TextSetting[];
|
})) as TextSetting[];
|
||||||
|
|
||||||
const uniqueOrigins = new Set(
|
const allowedDomains = settings.flatMap((setting) =>
|
||||||
settings.flatMap((setting) =>
|
setting.value.split(',').filter((o) => !!o),
|
||||||
setting.value.split(',').filter((o) => !!o),
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const uniqueOrigins = new Set([
|
||||||
|
...config.security.cors.allowOrigins,
|
||||||
|
...config.sockets.onlyAllowOrigins,
|
||||||
|
...allowedDomains,
|
||||||
|
]);
|
||||||
|
|
||||||
return uniqueOrigins;
|
return uniqueOrigins;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user