2015-04-21 21:10:50 +03:00
|
|
|
/* Any copyright is dedicated to the Public Domain.
|
|
|
|
http://creativecommons.org/publicdomain/zero/1.0/ */
|
|
|
|
|
|
|
|
'use strict';
|
|
|
|
|
2015-06-02 14:14:00 +03:00
|
|
|
const {PushDB, PushService, PushServiceWebSocket} = serviceExports;
|
2015-04-21 21:10:50 +03:00
|
|
|
|
|
|
|
const userAgentID = '7f0af1bb-7e1f-4fb8-8e4a-e8de434abde3';
|
|
|
|
|
|
|
|
function run_test() {
|
|
|
|
do_get_profile();
|
|
|
|
setPrefs({
|
|
|
|
userAgentID,
|
|
|
|
requestTimeout: 150,
|
|
|
|
retryBaseInterval: 150
|
|
|
|
});
|
|
|
|
run_next_test();
|
|
|
|
}
|
|
|
|
|
2017-06-22 13:51:42 +03:00
|
|
|
add_task(async function test_unregister_invalid_json() {
|
2015-06-02 14:14:00 +03:00
|
|
|
let db = PushServiceWebSocket.newPushDB();
|
2017-12-21 13:10:23 +03:00
|
|
|
registerCleanupFunction(() => {return db.drop().then(_ => db.close());});
|
2015-04-21 21:10:50 +03:00
|
|
|
let records = [{
|
|
|
|
channelID: '87902e90-c57e-4d18-8354-013f4a556559',
|
|
|
|
pushEndpoint: 'https://example.org/update/1',
|
|
|
|
scope: 'https://example.edu/page/1',
|
2015-06-24 23:34:54 +03:00
|
|
|
originAttributes: '',
|
2015-06-26 00:52:57 +03:00
|
|
|
version: 1,
|
|
|
|
quota: Infinity,
|
2015-04-21 21:10:50 +03:00
|
|
|
}, {
|
|
|
|
channelID: '057caa8f-9b99-47ff-891c-adad18ce603e',
|
|
|
|
pushEndpoint: 'https://example.com/update/2',
|
|
|
|
scope: 'https://example.net/page/1',
|
2015-06-24 23:34:54 +03:00
|
|
|
originAttributes: '',
|
2015-06-26 00:52:57 +03:00
|
|
|
version: 1,
|
|
|
|
quota: Infinity,
|
2015-04-21 21:10:50 +03:00
|
|
|
}];
|
|
|
|
for (let record of records) {
|
2017-06-22 13:51:42 +03:00
|
|
|
await db.put(record);
|
2015-04-21 21:10:50 +03:00
|
|
|
}
|
|
|
|
|
2015-08-15 03:26:07 +03:00
|
|
|
let unregisterDone;
|
|
|
|
let unregisterPromise = new Promise(resolve => unregisterDone = after(2, resolve));
|
2015-04-21 21:10:50 +03:00
|
|
|
PushService.init({
|
2015-06-02 14:14:00 +03:00
|
|
|
serverURI: "wss://push.example.org/",
|
2015-04-21 21:10:50 +03:00
|
|
|
db,
|
|
|
|
makeWebSocket(uri) {
|
|
|
|
return new MockWebSocket(uri, {
|
|
|
|
onHello(request) {
|
|
|
|
this.serverSendMsg(JSON.stringify({
|
|
|
|
messageType: 'hello',
|
|
|
|
status: 200,
|
2016-06-08 16:13:15 +03:00
|
|
|
uaid: userAgentID,
|
|
|
|
use_webpush: true,
|
2015-04-21 21:10:50 +03:00
|
|
|
}));
|
|
|
|
},
|
|
|
|
onUnregister(request) {
|
|
|
|
this.serverSendMsg(');alert(1);(');
|
|
|
|
unregisterDone();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2017-06-22 13:51:42 +03:00
|
|
|
await rejects(
|
2016-06-08 16:13:15 +03:00
|
|
|
PushService.unregister({
|
|
|
|
scope: 'https://example.edu/page/1',
|
|
|
|
originAttributes: '',
|
|
|
|
}),
|
2018-06-15 19:36:54 +03:00
|
|
|
/Request timed out/,
|
2016-06-08 16:13:15 +03:00
|
|
|
'Expected error for first invalid JSON response'
|
|
|
|
);
|
|
|
|
|
2017-06-22 13:51:42 +03:00
|
|
|
let record = await db.getByKeyID(
|
2015-04-21 21:10:50 +03:00
|
|
|
'87902e90-c57e-4d18-8354-013f4a556559');
|
|
|
|
ok(!record, 'Failed to delete unregistered record');
|
|
|
|
|
2017-06-22 13:51:42 +03:00
|
|
|
await rejects(
|
2016-06-08 16:13:15 +03:00
|
|
|
PushService.unregister({
|
|
|
|
scope: 'https://example.net/page/1',
|
|
|
|
originAttributes: ChromeUtils.originAttributesToSuffix(
|
|
|
|
{ appId: Ci.nsIScriptSecurityManager.NO_APP_ID, inIsolatedMozBrowser: false }),
|
|
|
|
}),
|
2018-06-15 19:36:54 +03:00
|
|
|
/Request timed out/,
|
2016-06-08 16:13:15 +03:00
|
|
|
'Expected error for second invalid JSON response'
|
|
|
|
);
|
|
|
|
|
2017-06-22 13:51:42 +03:00
|
|
|
record = await db.getByKeyID(
|
2015-04-21 21:10:50 +03:00
|
|
|
'057caa8f-9b99-47ff-891c-adad18ce603e');
|
|
|
|
ok(!record,
|
|
|
|
'Failed to delete unregistered record after receiving invalid JSON');
|
|
|
|
|
2017-06-22 13:51:42 +03:00
|
|
|
await unregisterPromise;
|
2015-04-21 21:10:50 +03:00
|
|
|
});
|