[MM-61821] Automatically allow permission checks for supported permission types through for GPO configured servers (#3231)
* [MM-61821] Automatically allow permission checks for supported permission types through for GPO configured servers * Fix lint * Fix tsc
This commit is contained in:
@@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
import {dialog, systemPreferences} from 'electron';
|
import {dialog, systemPreferences} from 'electron';
|
||||||
|
|
||||||
|
import Config from 'common/config';
|
||||||
import {parseURL, isTrustedURL} from 'common/utils/url';
|
import {parseURL, isTrustedURL} from 'common/utils/url';
|
||||||
import ViewManager from 'main/views/viewManager';
|
import ViewManager from 'main/views/viewManager';
|
||||||
import CallsWidgetWindow from 'main/windows/callsWidgetWindow';
|
import CallsWidgetWindow from 'main/windows/callsWidgetWindow';
|
||||||
@@ -37,6 +38,12 @@ jest.mock('common/utils/url', () => ({
|
|||||||
isTrustedURL: jest.fn(),
|
isTrustedURL: jest.fn(),
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
jest.mock('common/config', () => ({
|
||||||
|
registryData: {
|
||||||
|
servers: [],
|
||||||
|
},
|
||||||
|
}));
|
||||||
|
|
||||||
jest.mock('main/i18nManager', () => ({
|
jest.mock('main/i18nManager', () => ({
|
||||||
localizeMessage: jest.fn(),
|
localizeMessage: jest.fn(),
|
||||||
}));
|
}));
|
||||||
@@ -72,6 +79,9 @@ describe('main/PermissionsManager', () => {
|
|||||||
if (id === 2) {
|
if (id === 2) {
|
||||||
return {view: {server: {url: new URL('http://anyurl.com')}}};
|
return {view: {server: {url: new URL('http://anyurl.com')}}};
|
||||||
}
|
}
|
||||||
|
if (id === 4) {
|
||||||
|
return {view: {server: {url: new URL('http://gposerver.com')}}};
|
||||||
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
});
|
});
|
||||||
@@ -84,6 +94,11 @@ describe('main/PermissionsManager', () => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
isTrustedURL.mockImplementation((url, baseURL) => url.toString().startsWith(baseURL.toString()));
|
isTrustedURL.mockImplementation((url, baseURL) => url.toString().startsWith(baseURL.toString()));
|
||||||
|
Config.registryData.servers = [
|
||||||
|
{
|
||||||
|
url: 'http://gposerver.com',
|
||||||
|
},
|
||||||
|
];
|
||||||
});
|
});
|
||||||
|
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
@@ -115,10 +130,17 @@ describe('main/PermissionsManager', () => {
|
|||||||
it('should deny if the server URL can not be found', async () => {
|
it('should deny if the server URL can not be found', async () => {
|
||||||
const permissionsManager = new PermissionsManager('anyfile.json');
|
const permissionsManager = new PermissionsManager('anyfile.json');
|
||||||
const cb = jest.fn();
|
const cb = jest.fn();
|
||||||
await permissionsManager.handlePermissionRequest({id: 4}, 'media', cb, {securityOrigin: 'http://anyurl.com'});
|
await permissionsManager.handlePermissionRequest({id: 5}, 'media', cb, {securityOrigin: 'http://anyurl.com'});
|
||||||
expect(cb).toHaveBeenCalledWith(false);
|
expect(cb).toHaveBeenCalledWith(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should allow if the URL is a GPO configured server', async () => {
|
||||||
|
const permissionsManager = new PermissionsManager('anyfile.json');
|
||||||
|
const cb = jest.fn();
|
||||||
|
await permissionsManager.handlePermissionRequest({id: 4}, 'media', cb, {securityOrigin: 'http://gposerver.com'});
|
||||||
|
expect(cb).toHaveBeenCalledWith(true);
|
||||||
|
});
|
||||||
|
|
||||||
it('should deny if the URL is not trusted', async () => {
|
it('should deny if the URL is not trusted', async () => {
|
||||||
const permissionsManager = new PermissionsManager('anyfile.json');
|
const permissionsManager = new PermissionsManager('anyfile.json');
|
||||||
const cb = jest.fn();
|
const cb = jest.fn();
|
||||||
|
@@ -22,6 +22,7 @@ import {
|
|||||||
OPEN_WINDOWS_MICROPHONE_PREFERENCES,
|
OPEN_WINDOWS_MICROPHONE_PREFERENCES,
|
||||||
UPDATE_PATHS,
|
UPDATE_PATHS,
|
||||||
} from 'common/communication';
|
} from 'common/communication';
|
||||||
|
import Config from 'common/config';
|
||||||
import JsonFileManager from 'common/JsonFileManager';
|
import JsonFileManager from 'common/JsonFileManager';
|
||||||
import {Logger} from 'common/log';
|
import {Logger} from 'common/log';
|
||||||
import type {MattermostServer} from 'common/servers/MattermostServer';
|
import type {MattermostServer} from 'common/servers/MattermostServer';
|
||||||
@@ -141,7 +142,7 @@ export class PermissionsManager extends JsonFileManager<PermissionsByOrigin> {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
let serverURL;
|
let serverURL: URL | undefined;
|
||||||
if (CallsWidgetWindow.isCallsWidget(webContentsId)) {
|
if (CallsWidgetWindow.isCallsWidget(webContentsId)) {
|
||||||
serverURL = CallsWidgetWindow.getViewURL();
|
serverURL = CallsWidgetWindow.getViewURL();
|
||||||
} else {
|
} else {
|
||||||
@@ -152,6 +153,12 @@ export class PermissionsManager extends JsonFileManager<PermissionsByOrigin> {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// For GPO servers, we always allow permissions since they are trusted
|
||||||
|
const serverHref = serverURL.href;
|
||||||
|
if (Config.registryData?.servers?.some((s) => parseURL(s.url)?.href === serverHref)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
// Exception for embedded videos such as YouTube
|
// Exception for embedded videos such as YouTube
|
||||||
// We still want to ask permission to do this though
|
// We still want to ask permission to do this though
|
||||||
const isExternalFullscreen = permission === 'fullscreen' && parsedURL.origin !== serverURL.origin;
|
const isExternalFullscreen = permission === 'fullscreen' && parsedURL.origin !== serverURL.origin;
|
||||||
|
Reference in New Issue
Block a user