Bug 1266433 - Indicate push subscriptions created by privileged code. r=dragana

MozReview-Commit-ID: HYKndQiU98U

--HG--
extra : rebase_source : 5671a231b02dacf71de77a0d15c284c9b6365a73
This commit is contained in:
Kit Cambridge 2016-04-23 19:41:59 -07:00
parent 6de951432a
commit 14ee7e9341
4 changed files with 19 additions and 3 deletions

View File

@ -18,6 +18,7 @@ interface nsIPushSubscription : nsISupports
readonly attribute long long pushCount;
readonly attribute long long lastPush;
readonly attribute long quota;
readonly attribute bool isSystemSubscription;
bool quotaApplies();
bool isExpired();

View File

@ -248,7 +248,7 @@ Object.assign(PushServiceParent.prototype, {
// System subscriptions can only be created by chrome callers, and are
// exempt from the background message quota and permission checks. They
// also use XPCOM observer notifications instead of service worker events.
// also do not fire service worker events.
data.systemRecord = principal.isSystemPrincipal;
data.originAttributes =
@ -489,6 +489,15 @@ PushSubscription.prototype = {
return this._props.quota;
},
/**
* Indicates whether this subscription was created with the system principal.
* System subscriptions are exempt from the background message quota and
* permission checks.
*/
get isSystemSubscription() {
return !!this._props.systemRecord;
},
/**
* Indicates whether this subscription is subject to the background message
* quota.

View File

@ -252,6 +252,7 @@ PushRecord.prototype = {
authenticationSecret: this.authenticationSecret,
appServerKey: this.appServerKey,
quota: this.quotaApplies() ? this.quota : -1,
systemRecord: this.systemRecord,
};
},
};

View File

@ -45,6 +45,7 @@ add_test(function test_subscribe_success() {
Services.scriptSecurityManager.getSystemPrincipal(),
(result, subscription) => {
ok(Components.isSuccessCode(result), 'Error creating subscription');
ok(subscription.isSystemSubscription, 'Expected system subscription');
ok(subscription.endpoint.startsWith('https://example.org/push'), 'Wrong endpoint prefix');
equal(subscription.pushCount, 0, 'Wrong push count');
equal(subscription.lastPush, 0, 'Wrong last push time');
@ -240,6 +241,8 @@ add_test(function test_subscribe_app_principal() {
ok(Components.isSuccessCode(result), 'Error creating subscription');
ok(subscription.endpoint.startsWith('https://example.org/push'),
'Wrong push endpoint in app subscription');
ok(!subscription.isSystemSubscription,
'Unexpected system subscription for app principal');
equal(subscription.quota, 16, 'Wrong quota for app subscription');
do_test_finished();
@ -256,6 +259,8 @@ add_test(function test_subscribe_origin_principal() {
PushServiceComponent.subscribe(scope, principal, (result, subscription) => {
ok(Components.isSuccessCode(result),
'Expected error creating subscription with origin principal');
ok(!subscription.isSystemSubscription,
'Unexpected system subscription for origin principal');
equal(subscription.quota, 16, 'Wrong quota for origin subscription');
do_test_finished();
@ -270,9 +275,9 @@ add_test(function test_subscribe_null_principal() {
Services.scriptSecurityManager.createNullPrincipal({}),
(result, subscription) => {
ok(!Components.isSuccessCode(result),
'Expected error creating subscription with expanded principal');
'Expected error creating subscription with null principal');
strictEqual(subscription, null,
'Unexpected subscription with expanded principal');
'Unexpected subscription with null principal');
do_test_finished();
run_next_test();