Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix auth paths #28

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -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'
51 changes: 51 additions & 0 deletions lib/includes.polyfill.js
Original file line number Diff line number Diff line change
@@ -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;
}
});
}
6 changes: 5 additions & 1 deletion lib/ovh.es5.js
Original file line number Diff line number Diff line change
Expand Up @@ -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; }; }();
Expand All @@ -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) {
Expand Down Expand Up @@ -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
Expand Down
8 changes: 6 additions & 2 deletions lib/ovh.es6.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@
*/
'use strict';

// Array.includes polyfill
require('./includes.polyfill');

let https = require('https'),
Bluebird = require('bluebird'),
querystring = require('querystring'),
Expand All @@ -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) {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -487,4 +491,4 @@ class Ovh {

module.exports = function (params) {
return new Ovh(params || {});
};
};