Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extend iframe with "allow" attribute #845

Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class Settings {
};
responsiveNavigation = 'simpleMobileOnly'; // Options: simple | simpleMobileOnly | semiCollapsible
sideNavFooterText = `Luigi Client: ${version || 'unknown'}`;
// allowRules = ['microphone'];
// hideNavigation = true
// backdropDisabled = true
/* customTranslationImplementation = () => {
Expand Down
4 changes: 4 additions & 0 deletions core/src/utilities/helpers/iframe-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -232,12 +232,16 @@ class IframeHelpersClass {
const customSandboxRules = LuigiConfig.getConfigValue(
'settings.customSandboxRules'
);
const allowRules = LuigiConfig.getConfigValue('settings.allowRules');
const activeSandboxRules = customSandboxRules
? [...new Set([...luigiDefaultSandboxRules, ...customSandboxRules])]
: luigiDefaultSandboxRules;

const iframe = document.createElement('iframe');
iframe.src = viewUrl;
if (allowRules) {
iframe.allow = allowRules.join(' ');
}
iframe.sandbox = activeSandboxRules.join(' ');
iframe.luigi = {
viewUrl,
Expand Down
11 changes: 9 additions & 2 deletions core/test/utilities/helpers/iframe-helpers.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { LuigiConfig } from '../../../src/core-api';
describe('Iframe-helpers', () => {
let component;
let customSandboxRules = ['allow-scripts', 'rules1', 'rules2'];
let allowRules = ['microphone', 'geolocation'];

beforeEach(() => {
let lastObj = {};
Expand All @@ -21,7 +22,6 @@ describe('Iframe-helpers', () => {

sinon.stub(GenericHelpers);
GenericHelpers.getRandomId.returns('abc');
sinon.stub(LuigiConfig, 'getConfigValue').returns(customSandboxRules);
});
afterEach(() => {
if (document.createElement.restore) {
Expand All @@ -45,13 +45,20 @@ describe('Iframe-helpers', () => {
assert.equal(iframe.vg, 'ananas');
});

it('createIframe with cutomrules', () => {
it('createIframe with customrules', () => {
sinon.stub(LuigiConfig, 'getConfigValue').returns(customSandboxRules);
const iframe = IframeHelpers.createIframe('http://luigi.url.com/');
assert.equal(
iframe.sandbox,
'allow-forms allow-modals allow-popups allow-popups-to-escape-sandbox allow-same-origin allow-scripts rules1 rules2'
);
});

it('createIframe with allowrules', () => {
sinon.stub(LuigiConfig, 'getConfigValue').returns(allowRules);
const iframe = IframeHelpers.createIframe('http://luigi.url.com/');
assert.equal(iframe.allow, 'microphone geolocation');
});
});

describe('canReuseIframe', () => {
Expand Down