Skip to content

Commit

Permalink
fix unit
Browse files Browse the repository at this point in the history
  • Loading branch information
denysoblohin-okta committed Aug 22, 2024
1 parent 965aca5 commit 37b9af3
Showing 1 changed file with 30 additions and 7 deletions.
37 changes: 30 additions & 7 deletions test/spec/fingerprint.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,18 @@ describe('fingerprint', function() {
type: 'FingerprintAvailable',
fingerprint: 'ABCD'
}),
origin: 'http://example.okta.com'
origin: 'http://example.okta.com',
source: test.iframe.contentWindow
});
});

test.iframe = {
style: {},
parentElement: {
removeChild: jest.fn()
},
contentWindow: {
postMessage: postMessageSpy
}
};

Expand All @@ -61,23 +65,32 @@ describe('fingerprint', function() {
jest.spyOn(document.body, 'appendChild').mockImplementation(function() {
if (options.timeout) { return; }
// mimic async page load with setTimeouts
if (options.sendOtherMessage) {
if (options.sendMessageFromAnotherOrigin) {
setTimeout(function() {
listeners.message({
data: '{"not":"forUs"}',
origin: 'http://not.okta.com'
});
});
}
if (options.sendMessageFromAnotherSource) {
setTimeout(function() {
listeners.message({
data: '{"not":"forUs"}',
origin: 'http://example.okta.com',
source: {
postMessage: postMessageSpy
}
});
});
}
setTimeout(function() {
listeners.message({
data: options.firstMessage || JSON.stringify({
type: 'FingerprintServiceReady'
}),
origin: 'http://example.okta.com',
source: {
postMessage: postMessageSpy
}
source: test.iframe.contentWindow
});
});
});
Expand Down Expand Up @@ -112,8 +125,18 @@ describe('fingerprint', function() {
});
});

it('allows non-Okta postMessages', function () {
return setup({ sendOtherMessage: true }).fingerprint()
it('ignores postMessages from another origin', function () {
return setup({ sendMessageFromAnotherOrigin: true }).fingerprint()
.catch(function(err) {
expect(err).toBeUndefined();
})
.then(function(fingerprint) {
expect(fingerprint).toEqual('ABCD');
});
});

it('ignores postMessages from another source', function () {
return setup({ sendMessageFromAnotherSource: true }).fingerprint()
.catch(function(err) {
expect(err).toBeUndefined();
})
Expand Down

0 comments on commit 37b9af3

Please sign in to comment.