Skip to content

Commit

Permalink
🐛 Update postMessage to call correct origin (#104)
Browse files Browse the repository at this point in the history
  • Loading branch information
jmelberg-okta authored Apr 10, 2018
1 parent 71a2172 commit 675cdd1
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
8 changes: 3 additions & 5 deletions lib/clientBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -243,11 +243,9 @@ proto.fingerprint = function(options) {
return deferred.resolve(msg.fingerprint);
}
if (msg.type === 'FingerprintServiceReady') {
if (iframe.contentWindow) {
iframe.contentWindow.postMessage(JSON.stringify({
type: 'GetFingerprint'
}), sdk.options.url);
}
e.source.postMessage(JSON.stringify({
type: 'GetFingerprint'
}), e.origin);
}
}
oauthUtil.addListener(window, 'message', listener);
Expand Down
9 changes: 5 additions & 4 deletions test/spec/fingerprint.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@ define(function(require) {

test.iframe = {
style: {},
contentWindow: {
postMessage: postMessageSpy
},
parentElement: {
removeChild: jasmine.createSpy('removeChild')
}
Expand Down Expand Up @@ -55,7 +52,10 @@ define(function(require) {
data: options.firstMessage || JSON.stringify({
type: 'FingerprintServiceReady'
}),
origin: 'http://example.okta.com'
origin: 'http://example.okta.com',
source: {
postMessage: postMessageSpy
}
});
});
});
Expand All @@ -80,6 +80,7 @@ define(function(require) {
expect(test.iframe.style.display).toEqual('none');
expect(test.iframe.src).toEqual('http://example.okta.com/auth/services/devicefingerprint');
expect(document.body.appendChild).toHaveBeenCalledWith(test.iframe);
expect(test.e.source.postMessage).toHaveBeenCalled();
expect(test.iframe.parentElement.removeChild).toHaveBeenCalled();
expect(fingerprint).toEqual('ABCD');
})
Expand Down

0 comments on commit 675cdd1

Please sign in to comment.