Skip to content

Commit

Permalink
Update eslint-config-airbnb to v17 (#417)
Browse files Browse the repository at this point in the history
  • Loading branch information
rub1e authored and marco-c committed Feb 7, 2019
1 parent dfeda72 commit 5388395
Show file tree
Hide file tree
Showing 10 changed files with 616 additions and 519 deletions.
970 changes: 537 additions & 433 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"chromedriver": "2.46.0",
"del": "3.0.0",
"eslint": "5.13.0",
"eslint-config-airbnb": "16.1.0",
"eslint-config-airbnb": "17.1.0",
"eslint-plugin-import": "2.16.0",
"geckodriver": "1.14.1",
"istanbul": "0.4.5",
Expand Down
8 changes: 4 additions & 4 deletions src/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@ const generateVapidKeys = returnJson => {
outputText = JSON.stringify(vapidKeys);
} else {
const outputLine = '\n=======================================\n';
outputText = outputLine + '\n' +
'Public Key:\n' + vapidKeys.publicKey + '\n\n' +
'Private Key:\n' + vapidKeys.privateKey + '\n' +
outputLine;
outputText = outputLine + '\n'
+ 'Public Key:\n' + vapidKeys.publicKey + '\n\n'
+ 'Private Key:\n' + vapidKeys.privateKey + '\n'
+ outputLine;
}

console.log(outputText);
Expand Down
4 changes: 2 additions & 2 deletions src/encryption-helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ const encrypt = function(userPublicKey, userAuth, payload, contentEncoding) {
}

if (urlBase64.decode(userAuth).length < 16) {
throw new Error('The subscription auth key should be at least 16 ' +
'bytes long');
throw new Error('The subscription auth key should be at least 16 '
+ 'bytes long');
}

if (typeof payload !== 'string' && !Buffer.isBuffer(payload)) {
Expand Down
19 changes: 10 additions & 9 deletions src/vapid-helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ function validateSubject(subject) {
}

if (typeof subject !== 'string' || subject.length === 0) {
throw new Error('The subject value must be a string containing a URL or ' +
'mailto: address. ' + subject);
throw new Error('The subject value must be a string containing a URL or '
+ 'mailto: address. ' + subject);
}

if (subject.indexOf('mailto:') !== 0) {
Expand All @@ -89,8 +89,8 @@ function validatePublicKey(publicKey) {
}

if (typeof publicKey !== 'string') {
throw new Error('Vapid public key is must be a URL safe Base 64 ' +
'encoded string.');
throw new Error('Vapid public key is must be a URL safe Base 64 '
+ 'encoded string.');
}

publicKey = urlBase64.decode(publicKey);
Expand All @@ -106,8 +106,8 @@ function validatePrivateKey(privateKey) {
}

if (typeof privateKey !== 'string') {
throw new Error('Vapid private key must be a URL safe Base 64 ' +
'encoded string.');
throw new Error('Vapid private key must be a URL safe Base 64 '
+ 'encoded string.');
}

privateKey = urlBase64.decode(privateKey);
Expand Down Expand Up @@ -174,8 +174,8 @@ function getVapidHeaders(audience, subject, publicKey, privateKey, contentEncodi
}

if (typeof audience !== 'string' || audience.length === 0) {
throw new Error('The audience value must be a string containing the ' +
'origin of a push service. ' + audience);
throw new Error('The audience value must be a string containing the '
+ 'origin of a push service. ' + audience);
}

const audienceParseResult = url.parse(audience);
Expand Down Expand Up @@ -217,7 +217,8 @@ function getVapidHeaders(audience, subject, publicKey, privateKey, contentEncodi
return {
Authorization: 'vapid t=' + jwt + ', k=' + urlBase64.encode(publicKey)
};
} else if (contentEncoding === WebPushConstants.supportedContentEncodings.AES_GCM) {
}
if (contentEncoding === WebPushConstants.supportedContentEncodings.AES_GCM) {
return {
Authorization: 'WebPush ' + jwt,
'Crypto-Key': 'p256ecdsa=' + urlBase64.encode(publicKey)
Expand Down
74 changes: 36 additions & 38 deletions src/web-push-lib.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,9 @@ WebPushLib.prototype.setGCMAPIKey = function(apiKey) {
return;
}

if (typeof apiKey === 'undefined' || typeof apiKey !== 'string' ||
apiKey.length === 0) {
if (typeof apiKey === 'undefined'
|| typeof apiKey !== 'string'
|| apiKey.length === 0) {
throw new Error('The GCM API Key should be a non-empty string or null.');
}

Expand All @@ -50,8 +51,7 @@ WebPushLib.prototype.setGCMAPIKey = function(apiKey) {
* @param {string} publicKey The public VAPID key, a URL safe, base64 encoded string
* @param {string} privateKey The private VAPID key, a URL safe, base64 encoded string.
*/
WebPushLib.prototype.setVapidDetails =
function(subject, publicKey, privateKey) {
WebPushLib.prototype.setVapidDetails = function(subject, publicKey, privateKey) {
if (arguments.length === 1 && arguments[0] === null) {
vapidDetails = null;
return;
Expand Down Expand Up @@ -83,25 +83,24 @@ WebPushLib.prototype.setVapidDetails =
* @return {Object} This method returns an Object which
* contains 'endpoint', 'method', 'headers' and 'payload'.
*/
WebPushLib.prototype.generateRequestDetails =
function(subscription, payload, options) {
WebPushLib.prototype.generateRequestDetails = function(subscription, payload, options) {
if (!subscription || !subscription.endpoint) {
throw new Error('You must pass in a subscription with at least ' +
'an endpoint.');
throw new Error('You must pass in a subscription with at least '
+ 'an endpoint.');
}

if (typeof subscription.endpoint !== 'string' ||
subscription.endpoint.length === 0) {
throw new Error('The subscription endpoint must be a string with ' +
'a valid URL.');
if (typeof subscription.endpoint !== 'string'
|| subscription.endpoint.length === 0) {
throw new Error('The subscription endpoint must be a string with '
+ 'a valid URL.');
}

if (payload) {
// Validate the subscription keys
if (!subscription.keys || !subscription.keys.p256dh ||
!subscription.keys.auth) {
throw new Error('To send a message with a payload, the ' +
'subscription must have \'auth\' and \'p256dh\' keys.');
if (!subscription.keys || !subscription.keys.p256dh
|| !subscription.keys.auth) {
throw new Error('To send a message with a payload, the '
+ 'subscription must have \'auth\' and \'p256dh\' keys.');
}
}

Expand All @@ -125,9 +124,9 @@ WebPushLib.prototype.generateRequestDetails =
for (let i = 0; i < optionKeys.length; i += 1) {
const optionKey = optionKeys[i];
if (validOptionKeys.indexOf(optionKey) === -1) {
throw new Error('\'' + optionKey + '\' is an invalid option. ' +
'The valid options are [\'' + validOptionKeys.join('\', \'') +
'\'].');
throw new Error('\'' + optionKey + '\' is an invalid option. '
+ 'The valid options are [\'' + validOptionKeys.join('\', \'')
+ '\'].');
}
}

Expand All @@ -139,9 +138,9 @@ WebPushLib.prototype.generateRequestDetails =
});

if (duplicates.length > 0) {
throw new Error('Duplicated headers defined [' +
duplicates.join(',') + ']. Please either define the header in the' +
'top level options OR in the \'headers\' key.');
throw new Error('Duplicated headers defined ['
+ duplicates.join(',') + ']. Please either define the header in the'
+ 'top level options OR in the \'headers\' key.');
}
}

Expand Down Expand Up @@ -191,13 +190,13 @@ WebPushLib.prototype.generateRequestDetails =
let requestPayload = null;

if (payload) {
if (!subscription.keys ||
typeof subscription !== 'object' ||
!subscription.keys.p256dh ||
!subscription.keys.auth) {
throw new Error(new Error('Unable to send a message with ' +
'payload to this subscription since it doesn\'t have the ' +
'required encryption keys'));
if (!subscription.keys
|| typeof subscription !== 'object'
|| !subscription.keys.p256dh
+ !subscription.keys.auth) {
throw new Error(new Error('Unable to send a message with '
+ 'payload to this subscription since it doesn\'t have the '
+ 'required encryption keys'));
}

const encrypted = encryptionHelper
Expand All @@ -223,16 +222,16 @@ WebPushLib.prototype.generateRequestDetails =
// VAPID isn't supported by GCM hence the if, else if.
if (isGCM) {
if (!currentGCMAPIKey) {
console.warn('Attempt to send push notification to GCM endpoint, ' +
'but no GCM key is defined. Please use setGCMApiKey() or add ' +
'\'gcmAPIKey\' as an option.');
console.warn('Attempt to send push notification to GCM endpoint, '
+ 'but no GCM key is defined. Please use setGCMApiKey() or add '
+ '\'gcmAPIKey\' as an option.');
} else {
requestDetails.headers.Authorization = 'key=' + currentGCMAPIKey;
}
} else if (currentVapidDetails) {
const parsedUrl = url.parse(subscription.endpoint);
const audience = parsedUrl.protocol + '//' +
parsedUrl.host;
const audience = parsedUrl.protocol + '//'
+ parsedUrl.host;

const vapidHeaders = vapidHelper.getVapidHeaders(
audience,
Expand All @@ -246,8 +245,8 @@ WebPushLib.prototype.generateRequestDetails =

if (contentEncoding === webPushConstants.supportedContentEncodings.AES_GCM) {
if (requestDetails.headers['Crypto-Key']) {
requestDetails.headers['Crypto-Key'] += ';' +
vapidHeaders['Crypto-Key'];
requestDetails.headers['Crypto-Key'] += ';'
+ vapidHeaders['Crypto-Key'];
} else {
requestDetails.headers['Crypto-Key'] = vapidHeaders['Crypto-Key'];
}
Expand Down Expand Up @@ -278,8 +277,7 @@ WebPushLib.prototype.generateRequestDetails =
* resolves if the sending of the notification was successful, otherwise it
* rejects.
*/
WebPushLib.prototype.sendNotification =
function(subscription, payload, options) {
WebPushLib.prototype.sendNotification = function(subscription, payload, options) {
let requestDetails;
try {
requestDetails = this.generateRequestDetails(subscription, payload, options);
Expand Down
7 changes: 3 additions & 4 deletions test/test-generate-request-details.js
Original file line number Diff line number Diff line change
Expand Up @@ -206,13 +206,12 @@ suite('Test Generate Request Details', function() {
invalidRequests.forEach(function(invalidRequest) {
test(invalidRequest.testTitle, function() {
if (invalidRequest.addEndpoint) {
invalidRequest.requestOptions.subscription.endpoint =
'https://127.0.0.1:8080';
invalidRequest.requestOptions.subscription.endpoint = 'https://127.0.0.1:8080';
}

if (invalidRequest.serverFlags) {
invalidRequest.requestOptions.subscription.endpoint += '?' +
invalidRequest.serverFlags.join('&');
invalidRequest.requestOptions.subscription.endpoint += '?'
+ invalidRequest.serverFlags.join('&');
}

assert.throws(function() {
Expand Down
4 changes: 2 additions & 2 deletions test/test-vapid-helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,8 @@ suite('Test Vapid Helpers', function() {
assert(headers['Crypto-Key']);
}
} catch (err) {
console.warn('Valid input call for getVapidHeaders() threw an ' +
'error. [' + index + ']');
console.warn('Valid input call for getVapidHeaders() threw an '
+ 'error. [' + index + ']');
throw err;
}
});
Expand Down
8 changes: 4 additions & 4 deletions test/testSelenium.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ let testServerURL;
function runTest(browser, options) {
options = options || {};

if (browser.getId() === 'firefox' &&
process.env.TRAVIS === 'true') {
if (browser.getId() === 'firefox'
&& process.env.TRAVIS === 'true') {
try {
which.sync('geckodriver');
} catch (err) {
Expand Down Expand Up @@ -223,8 +223,8 @@ availableBrowsers.forEach(function(browser) {

return del(testDirectory)
.catch(function() {
console.warn('Unable to delete test directory, going to wait 2 ' +
'seconds and try again');
console.warn('Unable to delete test directory, going to wait 2 '
+ 'seconds and try again');
// Add a timeout so that if the browser
// changes any files in the test directory
// it doesn't cause del to throw an error
Expand Down
39 changes: 17 additions & 22 deletions test/testSendNotification.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,8 @@ suite('sendNotification', function() {

assert.equal(requestDetails.headers['content-length'], requestBody.length, 'Check Content-Length header');

if (typeof options.extraOptions !== 'undefined' &&
typeof options.extraOptions.TTL !== 'undefined') {
if (typeof options.extraOptions !== 'undefined'
&& typeof options.extraOptions.TTL !== 'undefined') {
assert.equal(requestDetails.headers.ttl, options.extraOptions.TTL, 'Check TTL header');
} else if (!isGCM) {
assert.equal(requestDetails.headers.ttl, 2419200, 'Check default TTL header');
Expand Down Expand Up @@ -183,8 +183,8 @@ suite('sendNotification', function() {
}

if (isGCM) {
if (typeof options.extraOptions !== 'undefined' &&
typeof options.extraOptions.gcmAPIKey !== 'undefined') {
if (typeof options.extraOptions !== 'undefined'
&& typeof options.extraOptions.gcmAPIKey !== 'undefined') {
assert.equal(requestDetails.headers.authorization, 'key=' + options.extraOptions.gcmAPIKey, 'Check GCM Authorization header');
} else {
assert.equal(requestDetails.headers.authorization, 'key=my_gcm_key', 'Check GCM Authorization header');
Expand Down Expand Up @@ -331,13 +331,12 @@ suite('sendNotification', function() {
test(validRequest.testTitle + ' (aesgcm)', function() {
// Set the default endpoint if it's not already configured
if (!validRequest.requestOptions.subscription.endpoint) {
validRequest.requestOptions.subscription.endpoint =
'https://127.0.0.1:' + serverPort;
validRequest.requestOptions.subscription.endpoint = 'https://127.0.0.1:' + serverPort;
}

if (validRequest.serverFlags) {
validRequest.requestOptions.subscription.endpoint += '?' +
validRequest.serverFlags.join('&');
validRequest.requestOptions.subscription.endpoint += '?'
+ validRequest.serverFlags.join('&');
}

validRequest.requestOptions.extraOptions = validRequest.requestOptions.extraOptions || {};
Expand All @@ -360,13 +359,12 @@ suite('sendNotification', function() {
test(validRequest.testTitle + ' (aes128gcm)', function() {
// Set the default endpoint if it's not already configured
if (!validRequest.requestOptions.subscription.endpoint) {
validRequest.requestOptions.subscription.endpoint =
'https://127.0.0.1:' + serverPort;
validRequest.requestOptions.subscription.endpoint = 'https://127.0.0.1:' + serverPort;
}

if (validRequest.serverFlags) {
validRequest.requestOptions.subscription.endpoint += '?' +
validRequest.serverFlags.join('&');
validRequest.requestOptions.subscription.endpoint += '?'
+ validRequest.serverFlags.join('&');
}

validRequest.requestOptions.extraOptions = validRequest.requestOptions.extraOptions || {};
Expand Down Expand Up @@ -458,8 +456,7 @@ suite('sendNotification', function() {

// Set the default endpoint if it's not already configured
if (!validGCMRequest.requestOptions.subscription.endpoint) {
validGCMRequest.requestOptions.subscription.endpoint =
'https://android.googleapis.com/gcm/send/someSubscriptionID';
validGCMRequest.requestOptions.subscription.endpoint = 'https://android.googleapis.com/gcm/send/someSubscriptionID';
}

const webPush = require('../src/index');
Expand Down Expand Up @@ -659,13 +656,12 @@ suite('sendNotification', function() {
invalidRequests.forEach(function(invalidRequest) {
test(invalidRequest.testTitle + ' (aesgcm)', function() {
if (invalidRequest.addEndpoint) {
invalidRequest.requestOptions.subscription.endpoint =
'https://127.0.0.1:' + serverPort;
invalidRequest.requestOptions.subscription.endpoint = 'https://127.0.0.1:' + serverPort;
}

if (invalidRequest.serverFlags) {
invalidRequest.requestOptions.subscription.endpoint += '?' +
invalidRequest.serverFlags.join('&');
invalidRequest.requestOptions.subscription.endpoint += '?'
+ invalidRequest.serverFlags.join('&');
}

invalidRequest.requestOptions.extraOptions = invalidRequest.requestOptions.extraOptions || {};
Expand All @@ -686,13 +682,12 @@ suite('sendNotification', function() {

test(invalidRequest.testTitle + ' (aes128gcm)', function() {
if (invalidRequest.addEndpoint) {
invalidRequest.requestOptions.subscription.endpoint =
'https://127.0.0.1:' + serverPort;
invalidRequest.requestOptions.subscription.endpoint = 'https://127.0.0.1:' + serverPort;
}

if (invalidRequest.serverFlags) {
invalidRequest.requestOptions.subscription.endpoint += '?' +
invalidRequest.serverFlags.join('&');
invalidRequest.requestOptions.subscription.endpoint += '?'
+ invalidRequest.serverFlags.join('&');
}

invalidRequest.requestOptions.extraOptions = invalidRequest.requestOptions.extraOptions || {};
Expand Down

0 comments on commit 5388395

Please sign in to comment.