summaryrefslogtreecommitdiffstats
path: root/toolkit/components/credentialmanagement/tests/xpcshell
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
commit36d22d82aa202bb199967e9512281e9a53db42c9 (patch)
tree105e8c98ddea1c1e4784a60a5a6410fa416be2de /toolkit/components/credentialmanagement/tests/xpcshell
parentInitial commit. (diff)
downloadfirefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz
firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip
Adding upstream version 115.7.0esr.upstream/115.7.0esr
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'toolkit/components/credentialmanagement/tests/xpcshell')
-rw-r--r--toolkit/components/credentialmanagement/tests/xpcshell/head.js9
-rw-r--r--toolkit/components/credentialmanagement/tests/xpcshell/test_identity_credential_storage_service.js300
-rw-r--r--toolkit/components/credentialmanagement/tests/xpcshell/xpcshell.ini6
3 files changed, 315 insertions, 0 deletions
diff --git a/toolkit/components/credentialmanagement/tests/xpcshell/head.js b/toolkit/components/credentialmanagement/tests/xpcshell/head.js
new file mode 100644
index 0000000000..4614e91961
--- /dev/null
+++ b/toolkit/components/credentialmanagement/tests/xpcshell/head.js
@@ -0,0 +1,9 @@
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/ */
+
+const { XPCOMUtils } = ChromeUtils.importESModule(
+ "resource://gre/modules/XPCOMUtils.sys.mjs"
+);
+const { TestUtils } = ChromeUtils.importESModule(
+ "resource://testing-common/TestUtils.sys.mjs"
+);
diff --git a/toolkit/components/credentialmanagement/tests/xpcshell/test_identity_credential_storage_service.js b/toolkit/components/credentialmanagement/tests/xpcshell/test_identity_credential_storage_service.js
new file mode 100644
index 0000000000..95ee8042cd
--- /dev/null
+++ b/toolkit/components/credentialmanagement/tests/xpcshell/test_identity_credential_storage_service.js
@@ -0,0 +1,300 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+XPCOMUtils.defineLazyServiceGetter(
+ this,
+ "IdentityCredentialStorageService",
+ "@mozilla.org/browser/identity-credential-storage-service;1",
+ "nsIIdentityCredentialStorageService"
+);
+
+do_get_profile();
+
+add_task(async function test_insert_and_delete() {
+ let rpPrincipal = Services.scriptSecurityManager.createContentPrincipal(
+ Services.io.newURI("https://rp.com/"),
+ {}
+ );
+ let idpPrincipal = Services.scriptSecurityManager.createContentPrincipal(
+ Services.io.newURI("https://idp.com/"),
+ {}
+ );
+ const credentialID = "ID";
+
+ // Test initial value
+ let registered = {};
+ let allowLogout = {};
+ IdentityCredentialStorageService.getState(
+ rpPrincipal,
+ idpPrincipal,
+ credentialID,
+ registered,
+ allowLogout
+ );
+ Assert.ok(!registered.value, "Should not be registered initially.");
+ Assert.ok(!allowLogout.value, "Should not allow logout initially.");
+
+ // Set and read a value
+ IdentityCredentialStorageService.setState(
+ rpPrincipal,
+ idpPrincipal,
+ credentialID,
+ true,
+ true
+ );
+ IdentityCredentialStorageService.getState(
+ rpPrincipal,
+ idpPrincipal,
+ credentialID,
+ registered,
+ allowLogout
+ );
+ Assert.ok(registered.value, "Should be registered by set.");
+ Assert.ok(allowLogout.value, "Should now allow logout by set.");
+
+ IdentityCredentialStorageService.delete(
+ rpPrincipal,
+ idpPrincipal,
+ credentialID
+ );
+ IdentityCredentialStorageService.getState(
+ rpPrincipal,
+ idpPrincipal,
+ credentialID,
+ registered,
+ allowLogout
+ );
+ Assert.ok(!registered.value, "Should not be registered after deletion.");
+ Assert.ok(!allowLogout.value, "Should not allow logout after deletion.");
+ IdentityCredentialStorageService.clear();
+});
+
+add_task(async function test_basedomain_delete() {
+ let rpPrincipal = Services.scriptSecurityManager.createContentPrincipal(
+ Services.io.newURI("https://rp.com/"),
+ {}
+ );
+ let rpPrincipal2 = Services.scriptSecurityManager.createContentPrincipal(
+ Services.io.newURI("https://www.rp.com/"),
+ {}
+ );
+ let rpPrincipal3 = Services.scriptSecurityManager.createContentPrincipal(
+ Services.io.newURI("https://www.other.com/"),
+ {}
+ );
+ let idpPrincipal = Services.scriptSecurityManager.createContentPrincipal(
+ Services.io.newURI("https://idp.com/"),
+ {}
+ );
+ const credentialID = "ID";
+ let registered = {};
+ let allowLogout = {};
+
+ // Set values
+ IdentityCredentialStorageService.setState(
+ rpPrincipal,
+ idpPrincipal,
+ credentialID,
+ true,
+ true
+ );
+ IdentityCredentialStorageService.setState(
+ rpPrincipal2,
+ idpPrincipal,
+ credentialID,
+ true,
+ true
+ );
+ IdentityCredentialStorageService.setState(
+ rpPrincipal3,
+ idpPrincipal,
+ credentialID,
+ true,
+ true
+ );
+
+ IdentityCredentialStorageService.deleteFromBaseDomain(
+ rpPrincipal2.baseDomain
+ );
+ IdentityCredentialStorageService.getState(
+ rpPrincipal,
+ idpPrincipal,
+ credentialID,
+ registered,
+ allowLogout
+ );
+ Assert.ok(!registered.value, "Should not be registered after deletion.");
+ Assert.ok(!allowLogout.value, "Should not allow logout after deletion.");
+ IdentityCredentialStorageService.getState(
+ rpPrincipal2,
+ idpPrincipal,
+ credentialID,
+ registered,
+ allowLogout
+ );
+ Assert.ok(!registered.value, "Should not be registered after deletion.");
+ Assert.ok(!allowLogout.value, "Should not allow logout after deletion.");
+ IdentityCredentialStorageService.getState(
+ rpPrincipal3,
+ idpPrincipal,
+ credentialID,
+ registered,
+ allowLogout
+ );
+ Assert.ok(registered.value, "Should be registered by set.");
+ Assert.ok(allowLogout.value, "Should now allow logout by set.");
+ IdentityCredentialStorageService.clear();
+});
+
+add_task(async function test_principal_delete() {
+ let rpPrincipal = Services.scriptSecurityManager.createContentPrincipal(
+ Services.io.newURI("https://rp.com/"),
+ {}
+ );
+ let rpPrincipal2 = Services.scriptSecurityManager.createContentPrincipal(
+ Services.io.newURI("https://www.rp.com/"),
+ {}
+ );
+ let rpPrincipal3 = Services.scriptSecurityManager.createContentPrincipal(
+ Services.io.newURI("https://www.other.com/"),
+ {}
+ );
+ let idpPrincipal = Services.scriptSecurityManager.createContentPrincipal(
+ Services.io.newURI("https://idp.com/"),
+ {}
+ );
+ const credentialID = "ID";
+ let registered = {};
+ let allowLogout = {};
+
+ // Set values
+ IdentityCredentialStorageService.setState(
+ rpPrincipal,
+ idpPrincipal,
+ credentialID,
+ true,
+ true
+ );
+ IdentityCredentialStorageService.setState(
+ rpPrincipal2,
+ idpPrincipal,
+ credentialID,
+ true,
+ true
+ );
+ IdentityCredentialStorageService.setState(
+ rpPrincipal3,
+ idpPrincipal,
+ credentialID,
+ true,
+ true
+ );
+
+ IdentityCredentialStorageService.deleteFromPrincipal(rpPrincipal2);
+ IdentityCredentialStorageService.getState(
+ rpPrincipal,
+ idpPrincipal,
+ credentialID,
+ registered,
+ allowLogout
+ );
+ Assert.ok(registered.value, "Should be registered by set.");
+ Assert.ok(allowLogout.value, "Should now allow logout by set.");
+ IdentityCredentialStorageService.getState(
+ rpPrincipal2,
+ idpPrincipal,
+ credentialID,
+ registered,
+ allowLogout
+ );
+ Assert.ok(!registered.value, "Should not be registered after deletion.");
+ Assert.ok(!allowLogout.value, "Should not allow logout after deletion.");
+ IdentityCredentialStorageService.getState(
+ rpPrincipal3,
+ idpPrincipal,
+ credentialID,
+ registered,
+ allowLogout
+ );
+ Assert.ok(registered.value, "Should be registered by set.");
+ Assert.ok(allowLogout.value, "Should now allow logout by set.");
+ IdentityCredentialStorageService.clear();
+});
+
+add_task(async function test_principal_delete() {
+ let rpPrincipal = Services.scriptSecurityManager.createContentPrincipal(
+ Services.io.newURI("https://rp.com/"),
+ {}
+ );
+ let rpPrincipal2 = Services.scriptSecurityManager.createContentPrincipal(
+ Services.io.newURI("https://rp.com/"),
+ { privateBrowsingId: 1 }
+ );
+ let rpPrincipal3 = Services.scriptSecurityManager.createContentPrincipal(
+ Services.io.newURI("https://www.other.com/"),
+ { privateBrowsingId: 1 }
+ );
+ let idpPrincipal = Services.scriptSecurityManager.createContentPrincipal(
+ Services.io.newURI("https://idp.com/"),
+ {}
+ );
+ const credentialID = "ID";
+ let registered = {};
+ let allowLogout = {};
+
+ // Set values
+ IdentityCredentialStorageService.setState(
+ rpPrincipal,
+ idpPrincipal,
+ credentialID,
+ true,
+ true
+ );
+ IdentityCredentialStorageService.setState(
+ rpPrincipal2,
+ idpPrincipal,
+ credentialID,
+ true,
+ true
+ );
+ IdentityCredentialStorageService.setState(
+ rpPrincipal3,
+ idpPrincipal,
+ credentialID,
+ true,
+ true
+ );
+
+ IdentityCredentialStorageService.deleteFromOriginAttributesPattern(
+ '{ "privateBrowsingId": 1 }'
+ );
+ IdentityCredentialStorageService.getState(
+ rpPrincipal,
+ idpPrincipal,
+ credentialID,
+ registered,
+ allowLogout
+ );
+ Assert.ok(registered.value, "Should be registered by set.");
+ Assert.ok(allowLogout.value, "Should now allow logout by set.");
+ IdentityCredentialStorageService.getState(
+ rpPrincipal2,
+ idpPrincipal,
+ credentialID,
+ registered,
+ allowLogout
+ );
+ Assert.ok(!registered.value, "Should not be registered after deletion.");
+ Assert.ok(!allowLogout.value, "Should not allow logout after deletion.");
+ IdentityCredentialStorageService.getState(
+ rpPrincipal3,
+ idpPrincipal,
+ credentialID,
+ registered,
+ allowLogout
+ );
+ Assert.ok(!registered.value, "Should not be registered after deletion.");
+ Assert.ok(!allowLogout.value, "Should not allow logout after deletion.");
+ IdentityCredentialStorageService.clear();
+});
diff --git a/toolkit/components/credentialmanagement/tests/xpcshell/xpcshell.ini b/toolkit/components/credentialmanagement/tests/xpcshell/xpcshell.ini
new file mode 100644
index 0000000000..79536069e2
--- /dev/null
+++ b/toolkit/components/credentialmanagement/tests/xpcshell/xpcshell.ini
@@ -0,0 +1,6 @@
+[DEFAULT]
+head = head.js
+prefs =
+ dom.security.credentialmanagement.identity.enabled=true
+
+[test_identity_credential_storage_service.js]