-
Notifications
You must be signed in to change notification settings - Fork 307
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #220 from gauntface/vapid-string
Changing vapid input / output to be base64url encoded string
- Loading branch information
Showing
5 changed files
with
194 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
'use strict'; | ||
|
||
const assert = require('assert'); | ||
const urlBase64 = require('urlsafe-base64'); | ||
const webPush = require('../src/index'); | ||
|
||
const VALID_SUBJECT_MAILTO = 'mailto: [email protected]'; | ||
const VALID_SUBJECT_URL = 'https://exampe.com/contact'; | ||
const VALID_PUBLIC_KEY = urlBase64.encode(new Buffer(65)); | ||
const VALID_PRIVATE_KEY = urlBase64.encode(new Buffer(32)); | ||
|
||
suite('setVapidDetails()', function() { | ||
test('is defined', function() { | ||
assert(webPush.setVapidDetails); | ||
}); | ||
|
||
test('Valid URL input', function() { | ||
assert.doesNotThrow(function() { | ||
webPush.setVapidDetails(VALID_SUBJECT_URL, VALID_PUBLIC_KEY, VALID_PRIVATE_KEY); | ||
}); | ||
}); | ||
|
||
test('Valid mailto: input', function() { | ||
assert.doesNotThrow(function() { | ||
webPush.setVapidDetails(VALID_SUBJECT_MAILTO, VALID_PUBLIC_KEY, VALID_PRIVATE_KEY); | ||
}); | ||
}); | ||
|
||
test('reset Vapid Details with null', function() { | ||
assert.doesNotThrow(function() { | ||
webPush.setVapidDetails(null); | ||
}); | ||
}); | ||
|
||
const invalidInputs = [ | ||
{ | ||
subject: '', | ||
publicKey: VALID_PUBLIC_KEY, | ||
privateKey: VALID_PRIVATE_KEY | ||
}, | ||
{ | ||
subject: 'This is not a valid subject', | ||
publicKey: VALID_PUBLIC_KEY, | ||
privateKey: VALID_PRIVATE_KEY | ||
}, | ||
{ | ||
subject: {}, | ||
publicKey: VALID_PUBLIC_KEY, | ||
privateKey: VALID_PRIVATE_KEY | ||
}, | ||
{ | ||
subject: true, | ||
publicKey: VALID_PUBLIC_KEY, | ||
privateKey: VALID_PRIVATE_KEY | ||
}, | ||
{ | ||
subject: VALID_SUBJECT_URL, | ||
publicKey: urlBase64.encode(new Buffer(60)), | ||
privateKey: VALID_PRIVATE_KEY | ||
}, | ||
{ | ||
subject: VALID_SUBJECT_URL, | ||
publicKey: 'This is invalid', | ||
privateKey: VALID_PRIVATE_KEY | ||
}, | ||
{ | ||
subject: VALID_SUBJECT_URL, | ||
publicKey: '', | ||
privateKey: VALID_PRIVATE_KEY | ||
}, | ||
{ | ||
subject: VALID_SUBJECT_URL, | ||
publicKey: {}, | ||
privateKey: VALID_PRIVATE_KEY | ||
}, | ||
{ | ||
subject: VALID_SUBJECT_URL, | ||
publicKey: true, | ||
privateKey: VALID_PRIVATE_KEY | ||
}, | ||
{ | ||
subject: VALID_SUBJECT_URL, | ||
publicKey: VALID_PUBLIC_KEY, | ||
privateKey: urlBase64.encode(new Buffer(60)) | ||
}, | ||
{ | ||
subject: VALID_SUBJECT_URL, | ||
publicKey: VALID_PUBLIC_KEY, | ||
privateKey: 'This is invalid' | ||
}, | ||
{ | ||
subject: VALID_SUBJECT_URL, | ||
publicKey: VALID_PUBLIC_KEY, | ||
privateKey: '' | ||
}, | ||
{ | ||
subject: VALID_SUBJECT_URL, | ||
publicKey: VALID_PUBLIC_KEY, | ||
privateKey: {} | ||
}, | ||
{ | ||
subject: VALID_SUBJECT_URL, | ||
publicKey: VALID_PUBLIC_KEY, | ||
privateKey: true | ||
} | ||
]; | ||
|
||
test('Invalid input should throw an error', function() { | ||
invalidInputs.forEach(function(invalidInput, index) { | ||
assert.throws(function() { | ||
webPush.setVapidDetails( | ||
invalidInput.subject, | ||
invalidInput.publicKey, | ||
invalidInput.privateKey | ||
); | ||
}, 'Error not thrown on input index: ' + index); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,15 @@ | ||
'use strict'; | ||
|
||
const assert = require('assert'); | ||
const urlBase64 = require('urlsafe-base64'); | ||
const webPush = require('../src/index'); | ||
const vapidHelper = require('../src/vapid-helper'); | ||
|
||
const VALID_AUDIENCE = 'https://example.com'; | ||
const VALID_SUBJECT_MAILTO = 'mailto: [email protected]'; | ||
const VALID_SUBJECT_URL = 'https://exampe.com/contact'; | ||
const VALID_PUBLIC_KEY = new Buffer(65); | ||
const VALID_PRIVATE_KEY = new Buffer(32); | ||
const VALID_PUBLIC_KEY = urlBase64.encode(new Buffer(65)); | ||
const VALID_PRIVATE_KEY = urlBase64.encode(new Buffer(32)); | ||
const VALID_EXPIRATION = Math.floor(Date.now() / 1000) + (60 * 60 * 12); | ||
|
||
suite('Test Vapid Helpers', function() { | ||
|
@@ -21,11 +22,11 @@ suite('Test Vapid Helpers', function() { | |
assert(keys.privateKey); | ||
assert(keys.publicKey); | ||
|
||
assert.equal(keys.privateKey instanceof Buffer, true); | ||
assert.equal(keys.publicKey instanceof Buffer, true); | ||
assert.equal(typeof keys.privateKey, 'string'); | ||
assert.equal(typeof keys.publicKey, 'string'); | ||
|
||
assert.equal(keys.privateKey.length, 32); | ||
assert.equal(keys.publicKey.length, 65); | ||
assert.equal(urlBase64.decode(keys.privateKey).length, 32); | ||
assert.equal(urlBase64.decode(keys.publicKey).length, 65); | ||
}); | ||
|
||
test('generate new vapid keys between calls', function() { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,6 @@ | |
} | ||
|
||
/* eslint-disable global-require */ | ||
const urlBase64 = require('urlsafe-base64'); | ||
const seleniumAssistant = require('selenium-assistant'); | ||
const webdriver = require('selenium-webdriver'); | ||
const seleniumFirefox = require('selenium-webdriver/firefox'); | ||
|
@@ -26,11 +25,13 @@ | |
require('chromedriver'); | ||
/* eslint-enable global-require */ | ||
|
||
const vapidKeys = webPush.generateVAPIDKeys(); | ||
|
||
const PUSH_TEST_TIMEOUT = 120 * 1000; | ||
const VAPID_PARAM = { | ||
subject: 'mailto:[email protected]', | ||
privateKey: new Buffer('H6tqEMswzHOFlPHFi2JPfDQRiKN32ZJIwvSPWZl1VTA=', 'base64'), | ||
publicKey: new Buffer('BIx6khu9Z/5lBwNEXYNEOQiL70IKYDpDxsTyoiCb82puQ/V4c/NFdyrBFpWdsz3mikmV6sWARNuhRbbbLTMOmB0=', 'base64') | ||
privateKey: vapidKeys.privateKey, | ||
publicKey: vapidKeys.publicKey | ||
}; | ||
const testDirectory = './test/output/'; | ||
|
||
|
@@ -119,7 +120,7 @@ | |
globalDriver = driver; | ||
|
||
if (options.vapid) { | ||
testServerURL += '?vapid=' + urlBase64.encode(options.vapid.publicKey); | ||
testServerURL += '?vapid=' + options.vapid.publicKey; | ||
} | ||
|
||
return globalDriver.get(testServerURL) | ||
|