From 30371707b9a696ff5927cd73b68f67fdf16d05f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aur=C3=A9lien=20GASTON?= Date: Thu, 13 Sep 2018 11:04:55 +0200 Subject: [PATCH 1/2] Drop support for node < 4 (Not maintained anymore) --- .travis.yml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 7e93c66..1065473 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,9 +1,10 @@ language: node_js node_js: - - '0.10' - - '0.11' - - '0.12' - '4' - '5' - '6' + - '7' + - '8' + - '9' + - '10' after_script: 'npm install coveralls && cat ./coverage/lcov.info | node_modules/.bin/coveralls' From c09f7b41573dc5f078766e06c185150876121654 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aur=C3=A9lien=20GASTON?= Date: Thu, 13 Sep 2018 11:32:24 +0200 Subject: [PATCH 2/2] Fix authentication for some auth paths fixes #20 --- lib/includes.polyfill.js | 51 ++++++++++++++++++++++++++++++++++++++++ lib/ovh.es5.js | 6 ++++- lib/ovh.es6.js | 8 +++++-- 3 files changed, 62 insertions(+), 3 deletions(-) create mode 100644 lib/includes.polyfill.js diff --git a/lib/includes.polyfill.js b/lib/includes.polyfill.js new file mode 100644 index 0000000..6a50b25 --- /dev/null +++ b/lib/includes.polyfill.js @@ -0,0 +1,51 @@ +// https://tc39.github.io/ecma262/#sec-array.prototype.includes +if (!Array.prototype.includes) { + Object.defineProperty(Array.prototype, 'includes', { + value: function(searchElement, fromIndex) { + + if (this == null) { + throw new TypeError('"this" is null or not defined'); + } + + // 1. Let O be ? ToObject(this value). + var o = Object(this); + + // 2. Let len be ? ToLength(? Get(O, "length")). + var len = o.length >>> 0; + + // 3. If len is 0, return false. + if (len === 0) { + return false; + } + + // 4. Let n be ? ToInteger(fromIndex). + // (If fromIndex is undefined, this step produces the value 0.) + var n = fromIndex | 0; + + // 5. If n ≥ 0, then + // a. Let k be n. + // 6. Else n < 0, + // a. Let k be len + n. + // b. If k < 0, let k be 0. + var k = Math.max(n >= 0 ? n : len - Math.abs(n), 0); + + function sameValueZero(x, y) { + return x === y || (typeof x === 'number' && typeof y === 'number' && isNaN(x) && isNaN(y)); + } + + // 7. Repeat, while k < len + while (k < len) { + // a. Let elementK be the result of ? Get(O, ! ToString(k)). + // b. If SameValueZero(searchElement, elementK) is true, return true. + if (sameValueZero(o[k], searchElement)) { + return true; + } + // c. Increase k by 1. + k++; + } + + // 8. Return false + return false; + } + }); + } diff --git a/lib/ovh.es5.js b/lib/ovh.es5.js index 98c51af..3b2bf2a 100644 --- a/lib/ovh.es5.js +++ b/lib/ovh.es5.js @@ -26,6 +26,9 @@ */ 'use strict'; +// Array.includes polyfill +require('./includes.polyfill'); + var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol ? "symbol" : typeof obj; }; var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); @@ -51,6 +54,7 @@ var Ovh = function () { this.timeout = params.timeout; this.apiTimeDiff = params.apiTimeDiff || null; this.endpoint = params.endpoint || null; + this.noAuthPaths = params.noAuthPaths || ['/auth/credential', '/auth/time']; // Preconfigured API endpoints if (this.endpoint) { @@ -363,7 +367,7 @@ var Ovh = function () { } } - if (path.indexOf('/auth') < 0) { + if (!this.noAuthPaths.includes(path)) { options.headers['X-Ovh-Timestamp'] = Math.round(Date.now() / 1000) + this.apiTimeDiff; // Sign request diff --git a/lib/ovh.es6.js b/lib/ovh.es6.js index 3d0013b..7641e41 100644 --- a/lib/ovh.es6.js +++ b/lib/ovh.es6.js @@ -26,6 +26,9 @@ */ 'use strict'; +// Array.includes polyfill +require('./includes.polyfill'); + let https = require('https'), Bluebird = require('bluebird'), querystring = require('querystring'), @@ -43,6 +46,7 @@ class Ovh { this.timeout = params.timeout; this.apiTimeDiff = params.apiTimeDiff || null; this.endpoint = params.endpoint || null; + this.noAuthPaths = params.noAuthPaths || ['/auth/credential', '/auth/time']; // Preconfigured API endpoints if (this.endpoint) { @@ -356,7 +360,7 @@ class Ovh { } } - if (path.indexOf('/auth') < 0) { + if (!this.noAuthPaths.includes(path)) { options.headers['X-Ovh-Timestamp'] = Math.round(Date.now() / 1000) + this.apiTimeDiff; // Sign request @@ -487,4 +491,4 @@ class Ovh { module.exports = function (params) { return new Ovh(params || {}); -}; \ No newline at end of file +};