Skip to content

Commit

Permalink
IE11 domain check (SAP#1671)
Browse files Browse the repository at this point in the history
  • Loading branch information
JohannesDoberer authored Oct 28, 2020
1 parent c35619a commit 2817213
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 5 deletions.
8 changes: 4 additions & 4 deletions core/src/utilities/helpers/iframe-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ class IframeHelpersClass {
new RegExp(
GenericHelpers.escapeRegExp(
(parenthesis ? '{' : '') +
prefix +
entry[0] +
(parenthesis ? '}' : '')
prefix +
entry[0] +
(parenthesis ? '}' : '')
),
'g'
),
Expand Down Expand Up @@ -142,7 +142,7 @@ class IframeHelpersClass {
}

urlMatchesTheDomain(viewUrl = '', domain) {
return this.getLocation(viewUrl) === domain;
return this.getLocation(viewUrl) === this.getLocation(domain);
}

iframeIsSameDomain(viewUrl, domain) {
Expand Down
46 changes: 45 additions & 1 deletion core/test/utilities/helpers/iframe-helpers.spec.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const chai = require('chai');
const assert = chai.assert;
const expect = chai.expect;
const sinon = require('sinon');
import { afterEach } from 'mocha';

Expand Down Expand Up @@ -67,7 +68,7 @@ describe('Iframe-helpers', () => {
});

it('createIframe with interceptor', () => {
const icf = () => {};
const icf = () => { };
const interceptor = sinon.spy(icf);
sinon
.stub(LuigiConfig, 'getConfigValue')
Expand Down Expand Up @@ -110,6 +111,49 @@ describe('Iframe-helpers', () => {
);
});

describe('ie fix for domain check', () => {
const sb = sinon.createSandbox();
const href = 'https://luigi.url.com/sdf/sdf';

afterEach(() => {
sb.restore();
});

it('urlMatchesTheDomain', () => {
let domain = 'https://luigi.url.com/fd';
assert.isTrue(IframeHelpers.urlMatchesTheDomain(href, domain));
});

it('!urlMatchesTheDomain', () => {
let domain = 'http://luigi.url.com/fd';
assert.isFalse(IframeHelpers.urlMatchesTheDomain(href, domain));
});

it('ie11 urlMatchesTheDomain', () => {
let domain = 'https://luigi.url.com/bla/bli';
let a1 = document.createElement('a');
let a2 = document.createElement('a');
sb.stub(document, 'createElement').callThrough().withArgs('a').callsFake(() => {
if (a1.stubReturned) {
return a2;
} else {
a1.stubReturned = true;
return a1;
}
});
// Mimic IE11 behaviour
// no origin
sb.stub(a1, 'origin').value(undefined);
sb.stub(a2, 'origin').value(undefined);
// add port to https urls
sb.stub(a1, 'host').get(() => { return a1.protocol === 'https:' ? a1.hostname + ':443' : a1.hostname });
sb.stub(a2, 'host').get(() => { return a2.protocol === 'https:' ? a2.hostname + ':443' + a2.port : a2.hostname });
assert.isTrue(IframeHelpers.urlMatchesTheDomain(href, domain));
expect(a1.host).to.equal('luigi.url.com:443');
expect(a2.host).to.equal('luigi.url.com:443');
});
});

describe('canReuseIframe', () => {
const config = {
iframe: {
Expand Down

0 comments on commit 2817213

Please sign in to comment.