Skip to content

Commit

Permalink
[FEATURE] Les iframes autorisent l'utilisation du presse papier de l'…
Browse files Browse the repository at this point in the history
…utilisateur (PIX-16746)

 #11523
  • Loading branch information
pix-service-auto-merge authored Mar 4, 2025
2 parents edeffab + 5f84914 commit e3495c1
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 0 deletions.
1 change: 1 addition & 0 deletions mon-pix/app/components/challenge-embed-simulator.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
{{modifier-did-insert this.configureIframe @embedDocument.url this}}
frameBorder="0"
style="{{this.embedDocumentHeightStyle}}"
allow="{{this.permissionToClipboardWrite}}"
></iframe>
</div>

Expand Down
7 changes: 7 additions & 0 deletions mon-pix/app/components/challenge-embed-simulator.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@ export default class ChallengeEmbedSimulator extends Component {
return '';
}

get permissionToClipboardWrite() {
if (!this.args.embedDocument?.url) {
return null;
}
return isEmbedAllowedOrigin(this.args.embedDocument.url) ? 'clipboard-write' : null;
}

configureIframe = (iframe, embedUrl, thisComponent) => {
thisComponent.isLoadingEmbed = true;
thisComponent.isSimulatorLaunched = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { render } from '@1024pix/ember-testing-library';
import { find } from '@ember/test-helpers';
import { hbs } from 'ember-cli-htmlbars';
import { t } from 'ember-intl/test-support';
import ENV from 'mon-pix/config/environment';
import { module, test } from 'qunit';

import { clickByLabel } from '../../helpers/click-by-label';
Expand Down Expand Up @@ -172,4 +173,35 @@ module('Integration | Component | Challenge Embed Simulator', function (hooks) {
});
});
});

module('allow clipboard-write', function () {
test('it should allow `clipboard-write` when the embed origin is allowed ', async function (assert) {
// given
this.set('embedDocument', {
url: `${ENV.APP.EMBED_ALLOWED_ORIGINS[0]}/embed-simulator.url`,
title: 'Embed simulator',
height: 200,
});

// when
await render(hbs`<ChallengeEmbedSimulator @embedDocument={{this.embedDocument}} />`);

// then
assert.strictEqual(find('.embed__iframe').allow, 'clipboard-write');
});
test('it should not allow `clipboard-write` when the embed origin is not allowed', async function (assert) {
// given
this.set('embedDocument', {
url: 'http://notAllowedOrigin/embed-simulator.url',
title: 'Embed simulator',
height: 200,
});

// when
await render(hbs`<ChallengeEmbedSimulator @embedDocument={{this.embedDocument}} />`);

// then
assert.notOk(find('.embed__iframe').allow);
});
});
});

0 comments on commit e3495c1

Please sign in to comment.