From d210403ef88e773b1ef4290c03e6b87c648d0b4b Mon Sep 17 00:00:00 2001 From: Lucas Holmquist Date: Tue, 11 Dec 2018 14:35:17 -0500 Subject: [PATCH 1/2] fix: change base url to use https --- README.md | 58 ++++++++++++++++----------------- lib/swapi-node.js | 2 +- test/swapi-api-tests.js | 34 +++++++++---------- test/swapi-paging-test.js | 20 ++++++------ test/swapi-subresources-test.js | 10 +++--- 5 files changed, 62 insertions(+), 62 deletions(-) diff --git a/README.md b/README.md index 37c6e1e..6acccbd 100644 --- a/README.md +++ b/README.md @@ -27,17 +27,17 @@ A Node.js helper library for http://swapi.co/ - the Star Wars API There is a general `get` method that takes a `url`. So this is also possible: - swapi.get('http://swapi.co/api/people/?page=2').then((result) => { + swapi.get('https://swapi.co/api/people/?page=2').then((result) => { console.log(result); }); -When you call a "Base URL", like http://swapi.co/api/people/, it will include a `next` and `previous` parameter. These will be the link to the next/previous page of data. +When you call a "Base URL", like https://swapi.co/api/people/, it will include a `next` and `previous` parameter. These will be the link to the next/previous page of data. There are helper methods to get results from the next/previous page called `nextPage` and `previousPage`. Each of these returns a Promise Here is an example - swapi.get('http://swapi.co/api/people/').then((result) => { + swapi.get('https://swapi.co/api/people/').then((result) => { console.log(result); return result.nextPage(); }).then((result) => { @@ -65,25 +65,25 @@ For example, a call to `getPerson(1)` might return this json: "eye_color": "blue", "birth_year": "19BBY", "gender": "male", - "homeworld": "http://swapi.co/api/planets/1/", + "homeworld": "https://swapi.co/api/planets/1/", "films": [ - "http://swapi.co/api/films/1/", - "http://swapi.co/api/films/2/", - "http://swapi.co/api/films/3/", - "http://swapi.co/api/films/6/" + "https://swapi.co/api/films/1/", + "https://swapi.co/api/films/2/", + "https://swapi.co/api/films/3/", + "https://swapi.co/api/films/6/" ], "species": [], "vehicles": [ - "http://swapi.co/api/vehicles/14/", - "http://swapi.co/api/vehicles/30/" + "https://swapi.co/api/vehicles/14/", + "https://swapi.co/api/vehicles/30/" ], "starships": [ - "http://swapi.co/api/starships/12/", - "http://swapi.co/api/starships/22/" + "https://swapi.co/api/starships/12/", + "https://swapi.co/api/starships/22/" ], "created": "2014-12-09T13:50:51.644000Z", "edited": "2014-12-20T21:17:56.891000Z", - "url": "http://swapi.co/api/people/1/" + "url": "https://swapi.co/api/people/1/" } taking "homeworld" as an example, you can now call `getHomeworld()`, which will return a Promise @@ -106,27 +106,27 @@ This might produce some json like this: "surface_water": "1", "population": "200000", "residents": [ - "http://swapi.co/api/people/1/", - "http://swapi.co/api/people/2/", - "http://swapi.co/api/people/4/", - "http://swapi.co/api/people/6/", - "http://swapi.co/api/people/7/", - "http://swapi.co/api/people/8/", - "http://swapi.co/api/people/9/", - "http://swapi.co/api/people/11/", - "http://swapi.co/api/people/43/", - "http://swapi.co/api/people/62/" + "https://swapi.co/api/people/1/", + "https://swapi.co/api/people/2/", + "https://swapi.co/api/people/4/", + "https://swapi.co/api/people/6/", + "https://swapi.co/api/people/7/", + "https://swapi.co/api/people/8/", + "https://swapi.co/api/people/9/", + "https://swapi.co/api/people/11/", + "https://swapi.co/api/people/43/", + "https://swapi.co/api/people/62/" ], "films": [ - "http://swapi.co/api/films/1/", - "http://swapi.co/api/films/3/", - "http://swapi.co/api/films/4/", - "http://swapi.co/api/films/5/", - "http://swapi.co/api/films/6/" + "https://swapi.co/api/films/1/", + "https://swapi.co/api/films/3/", + "https://swapi.co/api/films/4/", + "https://swapi.co/api/films/5/", + "https://swapi.co/api/films/6/" ], "created": "2014-12-09T13:50:49.641000Z", "edited": "2014-12-21T20:48:04.175778Z", - "url": "http://swapi.co/api/planets/1/" + "url": "https://swapi.co/api/planets/1/" } ### Note diff --git a/lib/swapi-node.js b/lib/swapi-node.js index 2f10d79..cb425f6 100644 --- a/lib/swapi-node.js +++ b/lib/swapi-node.js @@ -1,7 +1,7 @@ var request = require('request'), util = require('./util'); -const BASE_URL = 'http://swapi.co/api/'; +const BASE_URL = 'https://swapi.co/api/'; function sendRequest(options) { return new Promise((resolve, reject) => { diff --git a/test/swapi-api-tests.js b/test/swapi-api-tests.js index 637767c..e43dc34 100644 --- a/test/swapi-api-tests.js +++ b/test/swapi-api-tests.js @@ -8,20 +8,20 @@ const test = require('tape'); nock.disableNetConnect(); test('GET a resource', (t) => { - nock('http://swapi.co/api/') + nock('https://swapi.co/api/') .matchHeader('User-Agent', 'swapi-node') .matchHeader('SWAPI-Node-Version', version) .get('/people/?page=2') .reply(200, {}); - swapi.get('http://swapi.co/api/people/?page=2').then((result) => { + swapi.get('https://swapi.co/api/people/?page=2').then((result) => { t.pass('return success'); t.end(); }); }); test('GET People - Return a Promise', (t) => { - nock('http://swapi.co/api/') + nock('https://swapi.co/api/') .matchHeader('User-Agent', 'swapi-node') .matchHeader('SWAPI-Node-Version', version) .get('/people/1') @@ -36,7 +36,7 @@ test('GET People - Return a Promise', (t) => { }); test('GET People - using options', (t) => { - nock('http://swapi.co/api/') + nock('https://swapi.co/api/') .matchHeader('User-Agent', 'swapi-node') .matchHeader('SWAPI-Node-Version', version) .get('/people/1') @@ -49,7 +49,7 @@ test('GET People - using options', (t) => { }); test('GET People - error returned', (t) => { - nock('http://swapi.co/api/') + nock('https://swapi.co/api/') .matchHeader('User-Agent', 'swapi-node') .matchHeader('SWAPI-Node-Version', version) .get('/people/1') @@ -62,7 +62,7 @@ test('GET People - error returned', (t) => { }); test('GET films', (t) => { - nock('http://swapi.co/api/') + nock('https://swapi.co/api/') .matchHeader('User-Agent', 'swapi-node') .matchHeader('SWAPI-Node-Version', version) .get('/films/1') @@ -77,7 +77,7 @@ test('GET films', (t) => { }); test('GET films - with options', (t) => { - nock('http://swapi.co/api/') + nock('https://swapi.co/api/') .matchHeader('User-Agent', 'swapi-node') .matchHeader('SWAPI-Node-Version', version) .get('/films/1') @@ -90,7 +90,7 @@ test('GET films - with options', (t) => { }); test('GET films - with error', (t) => { - nock('http://swapi.co/api/') + nock('https://swapi.co/api/') .matchHeader('User-Agent', 'swapi-node') .matchHeader('SWAPI-Node-Version', version) .get('/films/1') @@ -103,7 +103,7 @@ test('GET films - with error', (t) => { }); test('GET starship', (t) => { - nock('http://swapi.co/api/') + nock('https://swapi.co/api/') .matchHeader('User-Agent', 'swapi-node') .matchHeader('SWAPI-Node-Version', version) .get('/starships/1') @@ -118,7 +118,7 @@ test('GET starship', (t) => { }); test('GET starship - with options', (t) => { - nock('http://swapi.co/api/') + nock('https://swapi.co/api/') .matchHeader('User-Agent', 'swapi-node') .matchHeader('SWAPI-Node-Version', version) .get('/starships/1') @@ -131,7 +131,7 @@ test('GET starship - with options', (t) => { }); test('GET starship - with error', (t) => { - nock('http://swapi.co/api/') + nock('https://swapi.co/api/') .matchHeader('User-Agent', 'swapi-node') .matchHeader('SWAPI-Node-Version', version) .get('/starships/1') @@ -144,7 +144,7 @@ test('GET starship - with error', (t) => { }); test('GET vehicles', (t) => { - nock('http://swapi.co/api/') + nock('https://swapi.co/api/') .matchHeader('User-Agent', 'swapi-node') .matchHeader('SWAPI-Node-Version', version) .get('/vehicles/1') @@ -159,7 +159,7 @@ test('GET vehicles', (t) => { }); test('GET vehicles - with options', (t) => { - nock('http://swapi.co/api/') + nock('https://swapi.co/api/') .matchHeader('User-Agent', 'swapi-node') .matchHeader('SWAPI-Node-Version', version) .get('/vehicles/1') @@ -172,7 +172,7 @@ test('GET vehicles - with options', (t) => { }); test('GET vehicles - with error', (t) => { - nock('http://swapi.co/api/') + nock('https://swapi.co/api/') .matchHeader('User-Agent', 'swapi-node') .matchHeader('SWAPI-Node-Version', version) .get('/vehicles/1') @@ -185,7 +185,7 @@ test('GET vehicles - with error', (t) => { }); test('GET species', (t) => { - nock('http://swapi.co/api/') + nock('https://swapi.co/api/') .matchHeader('User-Agent', 'swapi-node') .matchHeader('SWAPI-Node-Version', version) .get('/species/1') @@ -200,7 +200,7 @@ test('GET species', (t) => { }); test('GET species - with options', (t) => { - nock('http://swapi.co/api/') + nock('https://swapi.co/api/') .matchHeader('User-Agent', 'swapi-node') .matchHeader('SWAPI-Node-Version', version) .get('/species/1') @@ -213,7 +213,7 @@ test('GET species - with options', (t) => { }); test('GET species - with error', (t) => { - nock('http://swapi.co/api/') + nock('https://swapi.co/api/') .matchHeader('User-Agent', 'swapi-node') .matchHeader('SWAPI-Node-Version', version) .get('/species/1') diff --git a/test/swapi-paging-test.js b/test/swapi-paging-test.js index ee2c631..dab5573 100644 --- a/test/swapi-paging-test.js +++ b/test/swapi-paging-test.js @@ -8,26 +8,26 @@ const test = require('tape'); nock.disableNetConnect(); test('returned value should have a nextPage added', (t) => { - nock('http://swapi.co/api/') + nock('https://swapi.co/api/') .matchHeader('User-Agent', 'swapi-node') .matchHeader('SWAPI-Node-Version', version) .get('/people/') .reply(200, { count: 82, - next: 'http://swapi.co/api/people/?page=2', + next: 'https://swapi.co/api/people/?page=2', previous: null }); - swapi.get('http://swapi.co/api/people/').then((result) => { + swapi.get('https://swapi.co/api/people/').then((result) => { t.equal(typeof result.nextPage, 'function', 'should be a next function'); - nock('http://swapi.co/api/') + nock('https://swapi.co/api/') .matchHeader('User-Agent', 'swapi-node') .matchHeader('SWAPI-Node-Version', version) .get('/people/?page=2') .reply(200, { count: 82, - next: 'http://swapi.co/api/people/?page=3', + next: 'https://swapi.co/api/people/?page=3', previous: null }); @@ -39,25 +39,25 @@ test('returned value should have a nextPage added', (t) => { }); test('returned value should have a previousPage added', (t) => { - nock('http://swapi.co/api/') + nock('https://swapi.co/api/') .matchHeader('User-Agent', 'swapi-node') .matchHeader('SWAPI-Node-Version', version) .get('/people/') .reply(200, { count: 82, - previous: 'http://swapi.co/api/people/?page=2' + previous: 'https://swapi.co/api/people/?page=2' }); - swapi.get('http://swapi.co/api/people/').then((result) => { + swapi.get('https://swapi.co/api/people/').then((result) => { t.equal(typeof result.previousPage, 'function', 'should be a next function'); - nock('http://swapi.co/api/') + nock('https://swapi.co/api/') .matchHeader('User-Agent', 'swapi-node') .matchHeader('SWAPI-Node-Version', version) .get('/people/?page=2') .reply(200, { count: 82, - previous: 'http://swapi.co/api/people/?page=1' + previous: 'https://swapi.co/api/people/?page=1' }); result.nextPage().then((result) => { diff --git a/test/swapi-subresources-test.js b/test/swapi-subresources-test.js index d77e861..b68a494 100644 --- a/test/swapi-subresources-test.js +++ b/test/swapi-subresources-test.js @@ -8,19 +8,19 @@ const test = require('tape'); nock.disableNetConnect(); test('property with link should have a corresponding getter', (t) => { - nock('http://swapi.co/api/') + nock('https://swapi.co/api/') .matchHeader('User-Agent', 'swapi-node') .matchHeader('SWAPI-Node-Version', version) .get('/people/1') .reply(200, { name: 'Luke Skywalker', - 'homeworld': 'http://swapi.co/api/planets/1/', + 'homeworld': 'https://swapi.co/api/planets/1/', }); swapi.getPerson(1).then((result) => { t.equal((typeof result.getHomeworld === 'function'), true, 'should be a function'); - nock('http://swapi.co/api/') + nock('https://swapi.co/api/') .matchHeader('User-Agent', 'swapi-node') .matchHeader('SWAPI-Node-Version', version) .get('/planets/1/') @@ -37,13 +37,13 @@ test('property with link should have a corresponding getter', (t) => { test('property with out link should have a corresponding getter anyway', (t) => { - nock('http://swapi.co/api/') + nock('https://swapi.co/api/') .matchHeader('User-Agent', 'swapi-node') .matchHeader('SWAPI-Node-Version', version) .get('/people/1') .reply(200, { name: 'Luke Skywalker', - 'homeworld': 'http://swapi.co/api/planets/1/', + 'homeworld': 'https://swapi.co/api/planets/1/', }); swapi.getPerson(1).then((result) => { From c3c204705d5fb040ede43b19dd6daaaf84dfad0d Mon Sep 17 00:00:00 2001 From: Lucas Holmquist Date: Tue, 11 Dec 2018 14:41:14 -0500 Subject: [PATCH 2/2] chore: update package-lock.json with security fixes --- package-lock.json | 68 +++++++++++++++++++++++++++-------------------- 1 file changed, 39 insertions(+), 29 deletions(-) diff --git a/package-lock.json b/package-lock.json index 7ab3bf1..3a9bded 100644 --- a/package-lock.json +++ b/package-lock.json @@ -11,14 +11,14 @@ "dev": true }, "ajv": { - "version": "5.5.2", - "resolved": "https://registry.npmjs.org/ajv/-/ajv-5.5.2.tgz", - "integrity": "sha1-c7Xuyj+rZT49P5Qis0GtQiBdyWU=", + "version": "6.6.1", + "resolved": "https://registry.npmjs.org/ajv/-/ajv-6.6.1.tgz", + "integrity": "sha512-ZoJjft5B+EJBjUyu9C9Hc0OZyPZSSlOF+plzouTrg6UlA8f+e/n8NIgBFG/9tppJtpPWfthHakK7juJdNDODww==", "requires": { - "co": "^4.6.0", - "fast-deep-equal": "^1.0.0", + "fast-deep-equal": "^2.0.1", "fast-json-stable-stringify": "^2.0.0", - "json-schema-traverse": "^0.3.0" + "json-schema-traverse": "^0.4.1", + "uri-js": "^4.2.2" } }, "amdefine": { @@ -126,11 +126,6 @@ "integrity": "sha1-V00xLt2Iu13YkS6Sht1sCu1KrII=", "dev": true }, - "co": { - "version": "4.6.0", - "resolved": "https://registry.npmjs.org/co/-/co-4.6.0.tgz", - "integrity": "sha1-bqa989hTrlTMuOR7+gvz+QMfsYQ=" - }, "combined-stream": { "version": "1.0.7", "resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.7.tgz", @@ -312,9 +307,9 @@ "integrity": "sha1-lpGEQOMEGnpBT4xS48V06zw+HgU=" }, "fast-deep-equal": { - "version": "1.1.0", - "resolved": "http://registry.npmjs.org/fast-deep-equal/-/fast-deep-equal-1.1.0.tgz", - "integrity": "sha1-wFNHeBfIa1HaqFPIHgWbcz0CNhQ=" + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/fast-deep-equal/-/fast-deep-equal-2.0.1.tgz", + "integrity": "sha1-ewUhjd+WZ79/Nwv3/bLLFf3Qqkk=" }, "fast-json-stable-stringify": { "version": "2.0.0", @@ -431,11 +426,11 @@ "integrity": "sha1-qUwiJOvKwEeCoNkDVSHyRzW37JI=" }, "har-validator": { - "version": "5.1.0", - "resolved": "https://registry.npmjs.org/har-validator/-/har-validator-5.1.0.tgz", - "integrity": "sha512-+qnmNjI4OfH2ipQ9VQOw23bBd/ibtfbVdK2fYbY4acTDqKTW/YDp9McimZdDbG8iV9fZizUqQMD5xvriB146TA==", + "version": "5.1.3", + "resolved": "https://registry.npmjs.org/har-validator/-/har-validator-5.1.3.tgz", + "integrity": "sha512-sNvOCzEQNr/qrvJgc3UG/kD4QtlHycrzwS+6mfTrrSq97BvaYcPZZI1ZSqGSPR73Cxn4LKTD4PttRwfU7jWq5g==", "requires": { - "ajv": "^5.3.0", + "ajv": "^6.5.5", "har-schema": "^2.0.0" } }, @@ -583,9 +578,9 @@ "integrity": "sha1-tIDIkuWaLwWVTOcnvT8qTogvnhM=" }, "json-schema-traverse": { - "version": "0.3.1", - "resolved": "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-0.3.1.tgz", - "integrity": "sha1-NJptRMU6Ud6JtAgFxdXlm0F9M0A=" + "version": "0.4.1", + "resolved": "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-0.4.1.tgz", + "integrity": "sha512-xbbCH5dCYU5T8LcEhhuh7HJ88HXuW3qsI3Y0zOZFKfZEHcpWiHU/Jxzk629Brsab/mMiHQti9wMP+845RPe3Vg==" }, "json-stringify-safe": { "version": "5.0.1", @@ -774,7 +769,7 @@ }, "path-is-absolute": { "version": "1.0.1", - "resolved": "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz", + "resolved": "http://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz", "integrity": "sha1-F0uSaHNVNP+8es5r9TpanhtcX18=", "dev": true }, @@ -813,9 +808,9 @@ "integrity": "sha512-AeUmQ0oLN02flVHXWh9sSJF7mcdFq0ppid/JkErufc3hGIV/AMa8Fo9VgDo/cT2jFdOWoFvHp90qqBH54W+gjQ==" }, "punycode": { - "version": "1.4.1", - "resolved": "https://registry.npmjs.org/punycode/-/punycode-1.4.1.tgz", - "integrity": "sha1-wNWmOycYgArY4esPpSachN1BhF4=" + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/punycode/-/punycode-2.1.1.tgz", + "integrity": "sha512-XRsRjdf+j5ml+y/6GKHPZbrF/8p2Yga0JPtdqTIY2Xe5ohJPD9saDJJLPvp9+NSBprVvevdXZybnj2cv8OEd0A==" }, "qs": { "version": "6.5.2", @@ -851,7 +846,7 @@ }, "resolve": { "version": "1.1.7", - "resolved": "https://registry.npmjs.org/resolve/-/resolve-1.1.7.tgz", + "resolved": "http://registry.npmjs.org/resolve/-/resolve-1.1.7.tgz", "integrity": "sha1-IDEU2CrSxe2ejgQRs5ModeiJ6Xs=", "dev": true }, @@ -882,7 +877,7 @@ }, "source-map": { "version": "0.2.0", - "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.2.0.tgz", + "resolved": "http://registry.npmjs.org/source-map/-/source-map-0.2.0.tgz", "integrity": "sha1-2rc/vPwrqBm03gO9b26qSBZLP50=", "dev": true, "optional": true, @@ -892,7 +887,7 @@ }, "sprintf-js": { "version": "1.0.3", - "resolved": "https://registry.npmjs.org/sprintf-js/-/sprintf-js-1.0.3.tgz", + "resolved": "http://registry.npmjs.org/sprintf-js/-/sprintf-js-1.0.3.tgz", "integrity": "sha1-BOaSb2YolTVPPdAVIDYzuFcpfiw=", "dev": true }, @@ -969,7 +964,7 @@ }, "resolve": { "version": "1.7.1", - "resolved": "https://registry.npmjs.org/resolve/-/resolve-1.7.1.tgz", + "resolved": "http://registry.npmjs.org/resolve/-/resolve-1.7.1.tgz", "integrity": "sha512-c7rwLofp8g1U+h1KNyHL/jicrKg1Ek4q+Lr33AL65uZTinUZHe30D5HlyN5V9NW0JX1D5dXQ4jqW5l7Sy/kGfw==", "dev": true, "requires": { @@ -991,6 +986,13 @@ "requires": { "psl": "^1.1.24", "punycode": "^1.4.1" + }, + "dependencies": { + "punycode": { + "version": "1.4.1", + "resolved": "https://registry.npmjs.org/punycode/-/punycode-1.4.1.tgz", + "integrity": "sha1-wNWmOycYgArY4esPpSachN1BhF4=" + } } }, "tunnel-agent": { @@ -1041,6 +1043,14 @@ } } }, + "uri-js": { + "version": "4.2.2", + "resolved": "https://registry.npmjs.org/uri-js/-/uri-js-4.2.2.tgz", + "integrity": "sha512-KY9Frmirql91X2Qgjry0Wd4Y+YTdrdZheS8TFwvkbLWf/G5KNJDCh6pKL5OZctEW4+0Baa5idK2ZQuELRwPznQ==", + "requires": { + "punycode": "^2.1.0" + } + }, "uuid": { "version": "3.3.2", "resolved": "https://registry.npmjs.org/uuid/-/uuid-3.3.2.tgz",