From 56708858fbd70fc7478939535f2e24ac1e7a9cae Mon Sep 17 00:00:00 2001 From: Corey Farwell Date: Sun, 7 Jun 2015 17:27:51 -0400 Subject: [PATCH] Use HTTPS if location protocol is HTTPS in iD.Connection Relevant to https://github.com/strava/iD/issues/5#issuecomment-109800372 --- js/id/core/connection.js | 11 ++++++++--- test/spec/core/connection.js | 14 +++++++++++++- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/js/id/core/connection.js b/js/id/core/connection.js index 1f4c5ba3e..5e54acdfe 100644 --- a/js/id/core/connection.js +++ b/js/id/core/connection.js @@ -1,12 +1,17 @@ -iD.Connection = function() { +iD.Connection = function(useHttps) { + if (typeof useHttps !== 'boolean') { + useHttps = window.location.protocol === 'https:'; + } + var event = d3.dispatch('authenticating', 'authenticated', 'auth', 'loading', 'loaded'), - url = 'http://www.openstreetmap.org', + protocol = useHttps ? 'https:' : 'http:', + url = protocol + '//www.openstreetmap.org', connection = {}, inflight = {}, loadedTiles = {}, tileZoom = 16, oauth = osmAuth({ - url: 'http://www.openstreetmap.org', + url: protocol + '//www.openstreetmap.org', oauth_consumer_key: '5A043yRSEugj4DJ5TljuapfnrflWDte8jTOcWLlT', oauth_secret: 'aB3jKq1TRsCOUrfOIZ6oQMEDmv2ptV76PA54NGLL', loading: authenticating, diff --git a/test/spec/core/connection.js b/test/spec/core/connection.js index c538ce5eb..9b3eded0d 100644 --- a/test/spec/core/connection.js +++ b/test/spec/core/connection.js @@ -2,13 +2,25 @@ describe('iD.Connection', function () { var c; beforeEach(function () { - c = new iD.Connection({}); + c = new iD.Connection(); }); it('is instantiated', function () { expect(c).to.be.ok; }); + it('allows insecure connections', function () { + expect(c.changesetURL(2)).to.match(/^http:/); + + c = new iD.Connection(false); + expect(c.changesetURL(2)).to.match(/^http:/); + }); + + it('allows secure connections', function () { + c = new iD.Connection(true); + expect(c.changesetURL(2)).to.match(/^https:/); + }); + describe('#changesetUrl', function() { it('provides a changeset url', function() { expect(c.changesetURL(2)).to.eql('http://www.openstreetmap.org/changeset/2');