Bug 1033238 - Cannot revoke Mobile ID permission. r=jedp

This commit is contained in:
Fernando Jiménez 2014-07-11 14:56:57 +02:00
parent 9a27f6101c
commit 5885aa0953
2 changed files with 51 additions and 32 deletions

View File

@ -359,6 +359,25 @@ this.MobileIdentityManager = {
this.doVerification();
},
/*********************************************************
* Result helpers
*********************************************************/
success: function(aPromiseId, aResult) {
let mm = this.messageManagers[aPromiseId];
mm.sendAsyncMessage("MobileId:GetAssertion:Return:OK", {
promiseId: aPromiseId,
result: aResult
});
},
error: function(aPromiseId, aError) {
let mm = this.messageManagers[aPromiseId];
mm.sendAsyncMessage("MobileId:GetAssertion:Return:KO", {
promiseId: aPromiseId,
error: aError
});
},
/*********************************************************
* Permissions helper
********************************************************/
@ -779,9 +798,20 @@ this.MobileIdentityManager = {
let uri = Services.io.newURI(aPrincipal.origin, null, null);
let principal = securityManager.getAppCodebasePrincipal(
uri, aPrincipal.appid, aPrincipal.isInBrowserElement);
uri, aPrincipal.appId, aPrincipal.isInBrowserElement);
let manifestURL = appsService.getManifestURLByLocalId(aPrincipal.appId);
let permission = permissionManager.testPermissionFromPrincipal(
principal,
MOBILEID_PERM
);
if (permission == Ci.nsIPermissionManager.DENY_ACTION ||
permission == Ci.nsIPermissionManager.UNKNOWN_ACTION) {
this.error(aPromiseId, ERROR_PERMISSION_DENIED);
return;
}
let _creds;
// First of all we look if we already have credentials for this origin.
@ -864,15 +894,8 @@ this.MobileIdentityManager = {
// If we've just prompted the user in the previous step, the permission
// is already granted and stored so we just progress the credentials.
if (creds) {
let permission = permissionManager.testPermissionFromPrincipal(
principal,
MOBILEID_PERM
);
if (permission == Ci.nsIPermissionManager.ALLOW_ACTION) {
return creds;
} else if (permission == Ci.nsIPermissionManager.DENY_ACTION ||
permission == Ci.nsIPermissionManager.UNKNOWN_ACTION) {
return Promise.reject(ERROR_PERMISSION_DENIED);
}
return this.promptAndVerify(principal, manifestURL, creds);
}
@ -910,11 +933,7 @@ this.MobileIdentityManager = {
this.ui.verified(decodedPayload.verifiedMSISDN);
let mm = this.messageManagers[aPromiseId];
mm.sendAsyncMessage("MobileId:GetAssertion:Return:OK", {
promiseId: aPromiseId,
result: assertion
});
this.success(aPromiseId, assertion);
}
)
.then(
@ -938,11 +957,7 @@ this.MobileIdentityManager = {
// Notify the error to the UI.
this.ui.error(error);
let mm = this.messageManagers[aPromiseId];
mm.sendAsyncMessage("MobileId:GetAssertion:Return:KO", {
promiseId: aPromiseId,
error: error
});
this.error(aPromiseId, error);
}
);
},

View File

@ -29,9 +29,10 @@ const GET_ASSERTION_RETURN_KO = "MobileId:GetAssertion:Return:KO";
// === Globals ===
const ORIGIN = "app://afakeorigin";
const APP_ID = 1;
const PRINCIPAL = {
origin: ORIGIN,
appId: "123"
appId: APP_ID
};
const PHONE_NUMBER = "+34666555444";
const ANOTHER_PHONE_NUMBER = "+44123123123";
@ -45,25 +46,25 @@ const CERTIFICATE = "eyJhbGciOiJEUzI1NiJ9.eyJsYXN0QXV0aEF0IjoxNDA0NDY5NzkyODc3LC
// === Helpers ===
function addPermission(aOrigin, aAction) {
function addPermission(aAction) {
let uri = Cc["@mozilla.org/network/io-service;1"]
.getService(Ci.nsIIOService)
.newURI(aOrigin, null, null);
.newURI(ORIGIN, null, null);
let _principal = Cc["@mozilla.org/scriptsecuritymanager;1"]
.getService(Ci.nsIScriptSecurityManager)
.getNoAppCodebasePrincipal(uri);
.getAppCodebasePrincipal(uri, APP_ID, false);
let pm = Cc["@mozilla.org/permissionmanager;1"]
.getService(Ci.nsIPermissionManager);
pm.addFromPrincipal(_principal, MOBILEID_PERM, aAction);
}
function removePermission(aOrigin) {
function removePermission() {
let uri = Cc["@mozilla.org/network/io-service;1"]
.getService(Ci.nsIIOService)
.newURI(aOrigin, null, null);
.newURI(ORIGIN, null, null);
let _principal = Cc["@mozilla.org/scriptsecuritymanager;1"]
.getService(Ci.nsIScriptSecurityManager)
.getNoAppCodebasePrincipal(uri);
.getAppCodebasePrincipal(uri, APP_ID, false);
let pm = Cc["@mozilla.org/permissionmanager;1"]
.getService(Ci.nsIPermissionManager);
pm.removeFromPrincipal(_principal, MOBILEID_PERM);
@ -362,6 +363,7 @@ function cleanup() {
MobileIdentityManager.client = kMobileIdentityClient;
MobileIdentityManager.ui = null;
MobileIdentityManager.iccInfo = null;
removePermission(ORIGIN);
}
// Unregister mocks and restore original code.
@ -447,6 +449,8 @@ add_test(function() {
}
};
addPermission(Ci.nsIPermissionManager.ALLOW_ACTION);
MobileIdentityManager.receiveMessage({
name: GET_ASSERTION_IPC_MSG,
principal: PRINCIPAL,
@ -735,7 +739,7 @@ add_test(function() {
}
};
addPermission(ORIGIN, Ci.nsIPermissionManager.ALLOW_ACTION);
addPermission(Ci.nsIPermissionManager.ALLOW_ACTION);
MobileIdentityManager.receiveMessage({
name: GET_ASSERTION_IPC_MSG,
@ -795,7 +799,7 @@ add_test(function() {
}
};
addPermission(ORIGIN, Ci.nsIPermissionManager.PROMPT_ACTION);
addPermission(Ci.nsIPermissionManager.PROMPT_ACTION);
MobileIdentityManager.receiveMessage({
name: GET_ASSERTION_IPC_MSG,
@ -843,13 +847,11 @@ add_test(function() {
// Check spied calls.
// MockCredStore.
credStore._("getByOrigin").callsLength(1);
credStore._("getByOrigin").call(1).arg(1, ORIGIN);
credStore._("getByOrigin").callsLength(0);
// MockUI.
ui._("startFlow").callsLength(0);
ui._("error").callsLength(1);
ui._("error").call(1).arg(1, ERROR_PERMISSION_DENIED);
ui._("error").callsLength(0);
do_test_finished();
run_next_test();
@ -933,6 +935,8 @@ add_test(function() {
}
};
addPermission(Ci.nsIPermissionManager.ALLOW_ACTION);
MobileIdentityManager.receiveMessage({
name: GET_ASSERTION_IPC_MSG,
principal: PRINCIPAL,
@ -1292,7 +1296,7 @@ add_test(function() {
}
};
addPermission(ORIGIN, Ci.nsIPermissionManager.ALLOW_ACTION);
addPermission(Ci.nsIPermissionManager.ALLOW_ACTION);
MobileIdentityManager.receiveMessage({
name: GET_ASSERTION_IPC_MSG,