Skip to content

Commit 759fa21

Browse files
committed
Merge branch 'master' of https://github.com/marco-c/web-push into remove_intermediate_standard
2 parents 783a577 + ee52762 commit 759fa21

File tree

4 files changed

+107
-12
lines changed

4 files changed

+107
-12
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
44
Supports Firefox 44+ and Chromium/Chrome 42+.
55
Notifications with payloads are supported in Firefox 44+ and Chromium/Chrome 50+.
6-
[VAPID](https://tools.ietf.org/html/draft-thomson-webpush-vapid-02) is supported in Firefox 45+ (for notifications without payloads).
6+
[VAPID](https://tools.ietf.org/html/draft-thomson-webpush-vapid-02) is supported in Firefox 45+ (for notifications without payloads) and in Firefox 46+ for all notifications.
77

88
[![NPM](https://nodei.co/npm/web-push.svg?downloads=true)](https://www.npmjs.com/package/web-push)
99

index.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,22 @@ function sendNotification(endpoint, params) {
124124
console.warn('You are using the old, deprecated, interface of the `sendNotification` function.'.bold.red);
125125
}
126126

127+
if (userPublicKey) {
128+
if (typeof userPublicKey !== 'string') {
129+
throw new Error('userPublicKey should be a base64-encoded string.');
130+
} else if (urlBase64.decode(userPublicKey).length !== 65) {
131+
throw new Error('userPublicKey should be 65 bytes long.');
132+
}
133+
}
134+
135+
if (userAuth) {
136+
if (typeof userAuth !== 'string') {
137+
throw new Error('userAuth should be a base64-encoded string.');
138+
} else if (urlBase64.decode(userAuth).length < 12) {
139+
throw new Error('userAuth should be at least 12 bytes long');
140+
}
141+
}
142+
127143
const isGCM = endpoint.indexOf('https://android.googleapis.com/gcm/send') === 0;
128144

129145
var urlParts = url.parse(endpoint);

test/testSelenium.js

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,7 @@ suite('selenium', function() {
5858
.then(function(newServer) {
5959
server = newServer;
6060

61-
var profilePath = temp.mkdirSync('marco');
62-
63-
var profile = new firefox.Profile(profilePath);
61+
var profile = new firefox.Profile();
6462
profile.setPreference('security.turn_off_all_security_so_that_viruses_can_take_over_this_computer', true);
6563
profile.setPreference('extensions.checkCompatibility.nightly', false);
6664
// Only allow installation of third-party addons from the user's profile dir (needed to block the third-party
@@ -76,7 +74,7 @@ suite('selenium', function() {
7674
var chromeOptions = new chrome.Options()
7775
.setChromeBinaryPath(chromeBinaryPath)
7876
.addArguments('--no-sandbox')
79-
.addArguments('user-data-dir=' + profilePath);
77+
.addArguments('user-data-dir=' + temp.mkdirSync('marco'));
8078

8179
var builder = new webdriver.Builder()
8280
.forBrowser('firefox')
@@ -161,9 +159,10 @@ suite('selenium', function() {
161159

162160
try {
163161
console.log('Using Firefox: ' + firefoxStableBinaryPath);
164-
console.log('Version: ' + childProcess.execSync(firefoxStableBinaryPath + ' --version').replace('\n', ''));
165-
console.log('Beta Version: ' + childProcess.execSync(firefoxBetaBinaryPath + ' --version').replace('\n', ''));
166-
console.log('Aurora Version: ' + childProcess.execSync(firefoxAuroraBinaryPath + ' --version').replace('\n', ''));
162+
console.log('Version: ' + childProcess.execSync(firefoxStableBinaryPath + ' --version').toString().replace('\n', ''));
163+
console.log('Beta Version: ' + childProcess.execSync(firefoxBetaBinaryPath + ' --version').toString().replace('\n', ''));
164+
//console.log('Aurora Version: ' + childProcess.execSync(firefoxAuroraBinaryPath + ' --version').toString().replace('\n', ''));
165+
console.log('Nightly Version: ' + childProcess.execSync(firefoxNightlyBinaryPath + ' --version').toString().replace('\n', ''));
167166
} catch (e) {}
168167

169168
if (process.env.GCM_API_KEY && !fs.existsSync(chromeBinaryPath)) {
@@ -172,7 +171,7 @@ suite('selenium', function() {
172171

173172
try {
174173
console.log('Using Chromium: ' + chromeBinaryPath);
175-
console.log('Version: ' + childProcess.execSync(chromeBinaryPath + ' --version').replace('\n', ''));
174+
console.log('Version: ' + childProcess.execSync(chromeBinaryPath + ' --version').toString().replace('\n', ''));
176175
} catch (e) {}
177176
});
178177
});
@@ -260,15 +259,13 @@ suite('selenium', function() {
260259
});
261260
}
262261

263-
/*
264-
XXX: Currently broken, see https://github.com/mozilla-services/autopush/issues/426.
265262
test('send/receive notification with payload & vapid with Firefox Beta', function() {
266263
return runTest({
267264
browser: 'firefox-beta',
268265
payload: 'marco',
269266
vapid: vapidParam,
270267
});
271-
});*/
268+
});
272269

273270
if (process.env.GCM_API_KEY && process.env.TRAVIS_OS_NAME !== 'osx') {
274271
test('send/receive notification with payload & vapid with Chrome', function() {

test/testSendNotification.js

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,23 @@ suite('sendNotification', function() {
211211
});
212212
});
213213

214+
test('send/receive string (non-urlsafe base64)', function() {
215+
return startServer('hello')
216+
.then(function() {
217+
return webPush.sendNotification('https://127.0.0.1:' + serverPort, {
218+
userPublicKey: userPublicKey.toString('base64'),
219+
userAuth: userAuth.toString('base64'),
220+
payload: 'hello',
221+
});
222+
})
223+
.then(function(body) {
224+
assert(true, 'sendNotification promise resolved');
225+
assert.equal(body, 'ok');
226+
}, function(e) {
227+
assert(false, 'sendNotification promise rejected with: ' + e);
228+
});
229+
});
230+
214231
test('send/receive buffer', function() {
215232
return startServer('hello')
216233
.then(function() {
@@ -396,6 +413,71 @@ suite('sendNotification', function() {
396413
});
397414
});
398415

416+
test('userPublicKey argument isn\'t a string', function() {
417+
return webPush.sendNotification('https://127.0.0.1:' + serverPort, {
418+
userPublicKey: userPublicKey,
419+
userAuth: urlBase64.encode(userAuth),
420+
payload: 'hello',
421+
})
422+
.then(function(body) {
423+
assert(false, 'sendNotification promise resolved');
424+
}, function() {
425+
assert(true, 'sendNotification promise rejected');
426+
});
427+
});
428+
429+
test('userAuth argument isn\'t a string', function() {
430+
return webPush.sendNotification('https://127.0.0.1:' + serverPort, {
431+
userPublicKey: urlBase64.encode(userPublicKey),
432+
userAuth: userAuth,
433+
payload: 'hello',
434+
})
435+
.then(function(body) {
436+
assert(false, 'sendNotification promise resolved');
437+
}, function() {
438+
assert(true, 'sendNotification promise rejected');
439+
});
440+
});
441+
442+
test('userPublicKey argument is too long', function() {
443+
return webPush.sendNotification('https://127.0.0.1:' + serverPort, {
444+
userPublicKey: urlBase64.encode(Buffer.concat([ userPublicKey, new Buffer(1) ])),
445+
userAuth: urlBase64.encode(userAuth),
446+
payload: 'hello',
447+
})
448+
.then(function(body) {
449+
assert(false, 'sendNotification promise resolved');
450+
}, function() {
451+
assert(true, 'sendNotification promise rejected');
452+
});
453+
});
454+
455+
test('userPublicKey argument is too short', function() {
456+
return webPush.sendNotification('https://127.0.0.1:' + serverPort, {
457+
userPublicKey: urlBase64.encode(userPublicKey.slice(1)),
458+
userAuth: urlBase64.encode(userAuth),
459+
payload: 'hello',
460+
})
461+
.then(function(body) {
462+
assert(false, 'sendNotification promise resolved');
463+
}, function() {
464+
assert(true, 'sendNotification promise rejected');
465+
});
466+
});
467+
468+
test('userAuth argument is too short', function() {
469+
return webPush.sendNotification('https://127.0.0.1:' + serverPort, {
470+
userPublicKey: urlBase64.encode(userPublicKey),
471+
userAuth: urlBase64.encode(userAuth.slice(1)),
472+
payload: 'hello',
473+
})
474+
.then(function(body) {
475+
assert(false, 'sendNotification promise resolved');
476+
}, function() {
477+
assert(true, 'sendNotification promise rejected');
478+
});
479+
});
480+
399481
test('TTL with old interface', function() {
400482
return startServer(undefined, 5)
401483
.then(function() {

0 commit comments

Comments
 (0)