MM-41042: Allow trusted plugin routes (#1956)

* Allow trusted plugin routes

The only allowed plugin route is, for now, the export endpoint for the
channel export plugin.

* Keep it simple
This commit is contained in:
Alejandro García Montoro
2022-01-20 21:19:48 +01:00
committed by GitHub
parent e446b13b34
commit c43dfe6002
3 changed files with 16 additions and 0 deletions

View File

@@ -55,6 +55,7 @@ jest.mock('common/utils/url', () => ({
isValidURI: jest.fn(),
isPluginUrl: jest.fn(),
isManagedResource: jest.fn(),
isChannelExportUrl: jest.fn(),
}));
jest.mock('../../../electron-builder.json', () => ({
@@ -124,6 +125,12 @@ describe('main/views/webContentsEvents', () => {
expect(event.preventDefault).not.toBeCalled();
});
it('should allow navigation when it isChannelExportUrl', () => {
urlUtils.isChannelExportUrl.mockImplementation((serverURL, parsedURL) => parsedURL.toString().includes('/plugins/com.mattermost.plugin-channel-export/api/v1/export'));
willNavigate(event, 'http://server-1.com/plugins/com.mattermost.plugin-channel-export/api/v1/export');
expect(event.preventDefault).not.toBeCalled();
});
it('should not allow navigation under any other circumstances', () => {
willNavigate(event, 'http://someotherurl.com');
expect(event.preventDefault).toBeCalled();