From fd3c32969d608239d644d65820b44d269b0ed91a Mon Sep 17 00:00:00 2001 From: Olivier Berho Date: Tue, 3 Dec 2013 16:03:44 +0100 Subject: [PATCH 1/3] Change link.origin with linbk.host for compatibility with firefox. --- packages/ember-simple-auth/lib/core.js | 2 +- packages/ember-simple-auth/tests/core_test.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/ember-simple-auth/lib/core.js b/packages/ember-simple-auth/lib/core.js index d003da664..e32ce4917 100644 --- a/packages/ember-simple-auth/lib/core.js +++ b/packages/ember-simple-auth/lib/core.js @@ -67,7 +67,7 @@ Ember.SimpleAuth.setup = function(container, application, options) { Ember.SimpleAuth._links[url] = link; return link; }(); - return this.crossOriginWhitelist.indexOf(link.origin) > -1 || link.origin === window.location.origin; + return this.crossOriginWhitelist.indexOf(link.host) > -1 || link.host === window.location.host; }, /** diff --git a/packages/ember-simple-auth/tests/core_test.js b/packages/ember-simple-auth/tests/core_test.js index ca0fa6936..3cd13254d 100644 --- a/packages/ember-simple-auth/tests/core_test.js +++ b/packages/ember-simple-auth/tests/core_test.js @@ -144,7 +144,7 @@ test('registers an AJAX prefilter that adds the authToken for same-origin reques equal(xhrMock.requestHeaders['Authorization'], undefined, 'Ember.SimpleAuth registers an AJAX prefilter that does not add the authToken for cross-origin requests during setup.'); xhrMock.requestHeaders = {}; - Ember.SimpleAuth.setup(containerMock, applicationMock, { crossOriginWhitelist: ['https://a.different.domain:1234'] }); + Ember.SimpleAuth.setup(containerMock, applicationMock, { crossOriginWhitelist: ['a.different.domain:1234'] }); ajaxPrefilterMock.registeredAjaxPrefilter({ url: 'https://a.different.domain:1234' }, {}, xhrMock); equal(xhrMock.requestHeaders['Authorization'], 'Bearer ' + token, 'Ember.SimpleAuth registers an AJAX prefilter that adds the authToken for cross-origin requests when the origin is in the crossOriginWhitelist during setup.'); }); From 79936af5b7040755e06f557f7f8b8116b7a5f91c Mon Sep 17 00:00:00 2001 From: Olivier Berho Date: Tue, 3 Dec 2013 17:54:34 +0100 Subject: [PATCH 2/3] Join protocol, host and port of link for test of crossOriginWhitelist. --- packages/ember-simple-auth/lib/core.js | 4 +++- packages/ember-simple-auth/tests/core_test.js | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/ember-simple-auth/lib/core.js b/packages/ember-simple-auth/lib/core.js index e32ce4917..2060f8fe5 100644 --- a/packages/ember-simple-auth/lib/core.js +++ b/packages/ember-simple-auth/lib/core.js @@ -67,7 +67,9 @@ Ember.SimpleAuth.setup = function(container, application, options) { Ember.SimpleAuth._links[url] = link; return link; }(); - return this.crossOriginWhitelist.indexOf(link.host) > -1 || link.host === window.location.host; + var linkUrl = link.protocol+'//'+link.hostname+':'+link.port; + var windowLocationUrl = window.location.protocol+'//'+window.location.hostname+':'+window.location.port; + return this.crossOriginWhitelist.indexOf(linkUrl) > -1 || linkUrl === windowLocationUrl; }, /** diff --git a/packages/ember-simple-auth/tests/core_test.js b/packages/ember-simple-auth/tests/core_test.js index 3cd13254d..ca0fa6936 100644 --- a/packages/ember-simple-auth/tests/core_test.js +++ b/packages/ember-simple-auth/tests/core_test.js @@ -144,7 +144,7 @@ test('registers an AJAX prefilter that adds the authToken for same-origin reques equal(xhrMock.requestHeaders['Authorization'], undefined, 'Ember.SimpleAuth registers an AJAX prefilter that does not add the authToken for cross-origin requests during setup.'); xhrMock.requestHeaders = {}; - Ember.SimpleAuth.setup(containerMock, applicationMock, { crossOriginWhitelist: ['a.different.domain:1234'] }); + Ember.SimpleAuth.setup(containerMock, applicationMock, { crossOriginWhitelist: ['https://a.different.domain:1234'] }); ajaxPrefilterMock.registeredAjaxPrefilter({ url: 'https://a.different.domain:1234' }, {}, xhrMock); equal(xhrMock.requestHeaders['Authorization'], 'Bearer ' + token, 'Ember.SimpleAuth registers an AJAX prefilter that adds the authToken for cross-origin requests when the origin is in the crossOriginWhitelist during setup.'); }); From 49b9177ea41227d92943b72d077d7e9f2a578a81 Mon Sep 17 00:00:00 2001 From: Olivier Berho Date: Tue, 3 Dec 2013 18:02:18 +0100 Subject: [PATCH 3/3] Add test presence for link.port before join it. --- packages/ember-simple-auth/lib/core.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/ember-simple-auth/lib/core.js b/packages/ember-simple-auth/lib/core.js index 2060f8fe5..b2a78794a 100644 --- a/packages/ember-simple-auth/lib/core.js +++ b/packages/ember-simple-auth/lib/core.js @@ -67,8 +67,8 @@ Ember.SimpleAuth.setup = function(container, application, options) { Ember.SimpleAuth._links[url] = link; return link; }(); - var linkUrl = link.protocol+'//'+link.hostname+':'+link.port; - var windowLocationUrl = window.location.protocol+'//'+window.location.hostname+':'+window.location.port; + var linkUrl = link.protocol+'//'+link.hostname+(link.port !== '' ? ':'+link.port : ''); + var windowLocationUrl = window.location.protocol+'//'+window.location.hostname+(window.location.port !== '' ? ':'+window.location.port : ''); return this.crossOriginWhitelist.indexOf(linkUrl) > -1 || linkUrl === windowLocationUrl; },