Mholloway has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/294391

Change subject: Detect scheme based on request domain
......................................................................

Detect scheme based on request domain

We need to start using HTTPS for all requests to prod endpoints (they've
started serving 403s to a percentage of non-HTTPS requests).  For now
let's detect whether we're requesting from a labs machine (which still use
https:) and adjust accordingly.

Change-Id: Id3896c9bda3a9a0172550c5d82deb0146c83f688
---
M config.dev.yaml
M lib/api-util.js
M test/features/featured/pagecontent.js
M test/features/media/pagecontent.js
M test/features/mobile-summary/pagecontent.js
5 files changed, 13 insertions(+), 10 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/services/mobileapps 
refs/changes/91/294391/1

diff --git a/config.dev.yaml b/config.dev.yaml
index 6bc9d80..b3f0858 100644
--- a/config.dev.yaml
+++ b/config.dev.yaml
@@ -64,14 +64,14 @@
       # the template used for contacting the MW API
       mwapi_req:
         method: post
-        uri: http://{{domain}}/w/api.php
+        uri: '{{scheme}}://{{domain}}/w/api.php'
         headers:
           user-agent: '{{user-agent}}'
         body: '{{ default(request.query, {}) }}'
       # the template used for contacting RESTBase
       restbase_req:
         method: get
-        uri: http://{{domain}}/api/rest_v1/{+path}
+        uri: '{{scheme}}://{{domain}}/api/rest_v1/{+path}'
         query: '{{ default(request.query, {}) }}'
         headers: '{{request.headers}}'
         body: '{{request.body}}'
diff --git a/lib/api-util.js b/lib/api-util.js
index 998f2bd..1377b4b 100644
--- a/lib/api-util.js
+++ b/lib/api-util.js
@@ -23,7 +23,8 @@
 
     var request = app.mwapi_tpl.expand({
         request: {
-            params: { domain: domain },
+            params: { domain: domain, 
+                      scheme: domain.indexOf('beta.wmflabs.org') !== -1 ? 
'http' : 'https' },
             headers: { 'user-agent': app.conf.user_agent },
             query: query
         }
@@ -59,7 +60,7 @@
  * @return {Promise} a promise resolving as the response object from the REST 
API
  *
  */
-function restApiGet(app, domain, path, restReq) {
+function restApiGet(app, domain, path, restReq, scheme) {
 
     restReq = restReq || {};
     path = path[0] === '/' ? path.slice(1) : path;
@@ -67,7 +68,9 @@
     var request = app.restbase_tpl.expand({
         request: {
             method: restReq.method,
-            params: { domain: domain, path: path },
+            params: { domain: domain, 
+                      path: path, 
+                      scheme: domain.indexOf('beta.wmflabs.org') !== -1 ? 
'http' : 'https' },
             query: restReq.query,
             headers: Object.assign({ 'user-agent': app.conf.user_agent }, 
restReq.headers),
             body: restReq.body
diff --git a/test/features/featured/pagecontent.js 
b/test/features/featured/pagecontent.js
index f1a46c8..9f2dde8 100644
--- a/test/features/featured/pagecontent.js
+++ b/test/features/featured/pagecontent.js
@@ -22,9 +22,9 @@
                 // the page id should be stable but not the revision:
                 assert.ok(res.headers.etag.indexOf('50089449/') == 0);
                 assert.equal(res.body.title, 'Cosmic Stories and Stirring 
Science Stories');
-                assert.equal(res.body.thumbnail['60'], 
'http://upload.wikimedia.org/wikipedia/commons/thumb/1/19/Cosmic_Science-Fiction_May_1941.jpg/60px-Cosmic_Science-Fiction_May_1941.jpg');
-                assert.equal(res.body.thumbnail['120'], 
'http://upload.wikimedia.org/wikipedia/commons/thumb/1/19/Cosmic_Science-Fiction_May_1941.jpg/120px-Cosmic_Science-Fiction_May_1941.jpg');
-                assert.equal(res.body.thumbnail['320'], 
'http://upload.wikimedia.org/wikipedia/commons/thumb/1/19/Cosmic_Science-Fiction_May_1941.jpg/226px-Cosmic_Science-Fiction_May_1941.jpg');
+                assert.equal(res.body.thumbnail['60'], 
'https://upload.wikimedia.org/wikipedia/commons/thumb/1/19/Cosmic_Science-Fiction_May_1941.jpg/60px-Cosmic_Science-Fiction_May_1941.jpg');
+                assert.equal(res.body.thumbnail['120'], 
'https://upload.wikimedia.org/wikipedia/commons/thumb/1/19/Cosmic_Science-Fiction_May_1941.jpg/120px-Cosmic_Science-Fiction_May_1941.jpg');
+                assert.equal(res.body.thumbnail['320'], 
'https://upload.wikimedia.org/wikipedia/commons/thumb/1/19/Cosmic_Science-Fiction_May_1941.jpg/226px-Cosmic_Science-Fiction_May_1941.jpg');
                 assert.ok(res.body.extract.indexOf('Cosmic Stories ') >= 0);
             });
     });
diff --git a/test/features/media/pagecontent.js 
b/test/features/media/pagecontent.js
index d7d38f2..0fc4fd7 100644
--- a/test/features/media/pagecontent.js
+++ b/test/features/media/pagecontent.js
@@ -12,7 +12,7 @@
 
     function checkItemHasExpectedProperties(item) {
         assert.ok(item.title.indexOf('File:') === 0, 'Expected title to start 
with "File:"');
-        assert.ok(item.url.indexOf('http://upload.wikimedia.org/') === 0, 
'Expected url to start with certain text');
+        assert.ok(item.url.indexOf('https://upload.wikimedia.org/') === 0, 
'Expected url to start with certain text');
     }
 
     it('should respond to GET request with expected headers, incl. CORS and 
CSP headers', function() {
diff --git a/test/features/mobile-summary/pagecontent.js 
b/test/features/mobile-summary/pagecontent.js
index e45b2f6..4c2aef0 100644
--- a/test/features/mobile-summary/pagecontent.js
+++ b/test/features/mobile-summary/pagecontent.js
@@ -22,7 +22,7 @@
                 assert.deepEqual(body.title, 'Ann Arbor Charter Township, 
Michigan');
                 assert.ok(body.extract.indexOf('Ann Arbor Charter Township is 
a charter township') === 0, 'Expected different start of extract');
                 assert.deepEqual(body.thumbnail, {
-                    "source": 
"http://upload.wikimedia.org/wikipedia/commons/thumb/9/9c/Ann_Arbor_Township_hall_and_fire_station.JPG/320px-Ann_Arbor_Township_hall_and_fire_station.JPG";
+                    "source": 
"https://upload.wikimedia.org/wikipedia/commons/thumb/9/9c/Ann_Arbor_Township_hall_and_fire_station.JPG/320px-Ann_Arbor_Township_hall_and_fire_station.JPG";
                 });
             });
     });

-- 
To view, visit https://gerrit.wikimedia.org/r/294391
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Id3896c9bda3a9a0172550c5d82deb0146c83f688
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/services/mobileapps
Gerrit-Branch: master
Gerrit-Owner: Mholloway <mhollo...@wikimedia.org>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to