summaryrefslogtreecommitdiffstats
path: root/browser/base/content/test/caps
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 /browser/base/content/test/caps
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 'browser/base/content/test/caps')
-rw-r--r--browser/base/content/test/caps/browser.ini6
-rw-r--r--browser/base/content/test/caps/browser_principalSerialization_csp.js106
-rw-r--r--browser/base/content/test/caps/browser_principalSerialization_json.js161
-rw-r--r--browser/base/content/test/caps/browser_principalSerialization_version1.js159
4 files changed, 432 insertions, 0 deletions
diff --git a/browser/base/content/test/caps/browser.ini b/browser/base/content/test/caps/browser.ini
new file mode 100644
index 0000000000..18464cdf77
--- /dev/null
+++ b/browser/base/content/test/caps/browser.ini
@@ -0,0 +1,6 @@
+[DEFAULT]
+
+[browser_principalSerialization_csp.js]
+[browser_principalSerialization_json.js]
+skip-if = debug # deliberately bypass assertions when deserializing. Bug 965637 removed the CSP from Principals, but the remaining bits in such Principals should deserialize correctly.
+[browser_principalSerialization_version1.js]
diff --git a/browser/base/content/test/caps/browser_principalSerialization_csp.js b/browser/base/content/test/caps/browser_principalSerialization_csp.js
new file mode 100644
index 0000000000..909e728794
--- /dev/null
+++ b/browser/base/content/test/caps/browser_principalSerialization_csp.js
@@ -0,0 +1,106 @@
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+
+/*
+ * Within Bug 965637 we move the CSP away from the Principal. Serialized Principals however
+ * might still have CSPs serialized within them. This tests ensures that we do not
+ * encounter a memory corruption when deserializing. It's fine that the deserialized
+ * CSP is null, but the Principal itself should deserialize correctly.
+ */
+
+add_task(async function test_deserialize_principal_with_csp() {
+ /*
+ This test should be resilient to changes in principal serialization, if these are failing then it's likely the code will break session storage.
+ To recreate this for another version, copy the function into the browser console, browse some pages and printHistory.
+
+ Generated with:
+ function printHistory() {
+ let tests = [];
+ let entries = SessionStore.getSessionHistory(gBrowser.selectedTab).entries.map((entry) => { return entry.triggeringPrincipal_base64 });
+ entries.push(E10SUtils.serializePrincipal(gBrowser.selectedTab.linkedBrowser._contentPrincipal));
+ for (let entry of entries) {
+ console.log(entry);
+ let testData = {};
+ testData.input = entry;
+ let principal = E10SUtils.deserializePrincipal(testData.input);
+ testData.output = {};
+ if (principal.URI === null) {
+ testData.output.URI = false;
+ } else {
+ testData.output.URISpec = principal.URI.spec;
+ }
+ testData.output.originAttributes = principal.originAttributes;
+ testData.output.cspJSON = principal.cspJSON;
+
+ tests.push(testData);
+ }
+ return tests;
+ }
+ printHistory(); // Copy this into: serializedPrincipalsFromFirefox
+ */
+
+ let serializedPrincipalsFromFirefox = [
+ {
+ input:
+ "ZT4OTT7kRfqycpfCC8AeuAAAAAAAAAAAwAAAAAAAAEYB3pRy0IA0EdOTmQAQS6D9QJIHOlRteE8wkTq4cYEyCMYAAAAC/////wAAAbsBAAAAHmh0dHBzOi8vd3d3Lm1vemlsbGEub3JnL2VuLVVTLwAAAAAAAAAFAAAACAAAAA8AAAAA/////wAAAAD/////AAAACAAAAA8AAAAXAAAABwAAABcAAAAHAAAAFwAAAAcAAAAeAAAAAAAAAAD/////AAAAAP////8AAAAA/////wAAAAD/////AQAAAAAAAAAAAAAAAQnZ7Rrl1EAEv+Anzrkj2ayzxMCuvV5MrYfgjSENuz+fAd6UctCANBHTk5kAEEug/UCSBzpUbXhPMJE6uHGBMgjGAAAAAv////8AAAG7AQAAAB5odHRwczovL3d3dy5tb3ppbGxhLm9yZy9lbi1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AHUAbgB0AHMALgBmAGkAcgBlAGYAbwB4AC4AYwBvAG0ALwAgAGgAdAB0AHAAcwA6AC8ALwBhAGMAYwBvAHUAbgB0AHMALgBmAGkAcgBlAGYAbwB4AC4AYwBvAG0ALgBjAG4ALwA7ACAAYwBoAGkAbABkAC0AcwByAGMAIABoAHQAdABwAHMAOgAvAC8AdwB3AHcALgBnAG8AbwBnAGwAZQB0AGEAZwBtAGEAbgBhAGcAZQByAC4AYwBvAG0AIABoAHQAdABwAHMAOgAvAC8AdwB3AHcALgBnAG8AbwBnAGwAZQAtAGEAbgBhAGwAeQB0AGkAYwBzAC4AYwBvAG0AIABoAHQAdABwAHMAOgAvAC8AdwB3AHcALgB5AG8AdQB0AHUAYgBlAC0AbgBvAGMAbwBvAGsAaQBlAC4AYwBvAG0AIABoAHQAdABwAHMAOgAvAC8AdAByAGEAYwBrAGUAcgB0AGUAcwB0AC4AbwByAGcAIABoAHQAdABwAHMAOgAvAC8AdwB3AHcALgBzAHUAcgB2AGUAeQBnAGkAegBtAG8ALgBjAG8AbQAgAGgAdAB0AHAAcwA6AC8ALwBhAGMAYwBvAHUAbgB0AHMALgBmAGkAcgBlAGYAbwB4AC4AYwBvAG0AIABoAHQAdABwAHMAOgAvAC8AYQBjAGMAbwB1AG4AdABzAC4AZgBpAHIAZQBmAG8AeAAuAGMAbwBtAC4AYwBuACAAaAB0AHQAcABzADoALwAvAHcAdwB3AC4AeQBvAHUAdAB1AGIAZQAuAGMAbwBtAAA=",
+ output: {
+ // Within Bug 965637 we removed CSP from Principals. Already serialized Principals however should still deserialize correctly (just without the CSP).
+ // "cspJSON": "{\"csp-policies\":[{\"child-src\":[\"https://www.googletagmanager.com\",\"https://www.google-analytics.com\",\"https://www.youtube-nocookie.com\",\"https://trackertest.org\",\"https://www.surveygizmo.com\",\"https://accounts.firefox.com\",\"https://accounts.firefox.com.cn\",\"https://www.youtube.com\"],\"connect-src\":[\"'self'\",\"https://*.mozilla.net\",\"https://*.mozilla.org\",\"https://*.mozilla.com\",\"https://www.googletagmanager.com\",\"https://www.google-analytics.com\",\"https://accounts.firefox.com/\",\"https://accounts.firefox.com.cn/\"],\"default-src\":[\"'self'\",\"https://*.mozilla.net\",\"https://*.mozilla.org\",\"https://*.mozilla.com\"],\"frame-src\":[\"https://www.googletagmanager.com\",\"https://www.google-analytics.com\",\"https://www.youtube-nocookie.com\",\"https://trackertest.org\",\"https://www.surveygizmo.com\",\"https://accounts.firefox.com\",\"https://accounts.firefox.com.cn\",\"https://www.youtube.com\"],\"img-src\":[\"'self'\",\"https://*.mozilla.net\",\"https://*.mozilla.org\",\"https://*.mozilla.com\",\"data:\",\"https://mozilla.org\",\"https://www.googletagmanager.com\",\"https://www.google-analytics.com\",\"https://adservice.google.com\",\"https://adservice.google.de\",\"https://adservice.google.dk\",\"https://creativecommons.org\",\"https://ad.doubleclick.net\"],\"report-only\":false,\"script-src\":[\"'self'\",\"https://*.mozilla.net\",\"https://*.mozilla.org\",\"https://*.mozilla.com\",\"'unsafe-inline'\",\"'unsafe-eval'\",\"https://www.googletagmanager.com\",\"https://www.google-analytics.com\",\"https://tagmanager.google.com\",\"https://www.youtube.com\",\"https://s.ytimg.com\"],\"style-src\":[\"'self'\",\"https://*.mozilla.net\",\"https://*.mozilla.org\",\"https://*.mozilla.com\",\"'unsafe-inline'\"]}]}",
+ URISpec: "https://www.mozilla.org/en-US/",
+ originAttributes: {
+ firstPartyDomain: "",
+ inIsolatedMozBrowser: false,
+ privateBrowsingId: 0,
+ userContextId: 0,
+ geckoViewSessionContextId: "",
+ partitionKey: "",
+ },
+ },
+ },
+ {
+ input:
+ "ZT4OTT7kRfqycpfCC8AeuAAAAAAAAAAAwAAAAAAAAEYB3pRy0IA0EdOTmQAQS6D9QJIHOlRteE8wkTq4cYEyCMYAAAAC/////wAAAbsBAAAAL2h0dHBzOi8vd3d3Lm1vemlsbGEub3JnL2VuLVVTL2ZpcmVmb3gvYWNjb3VudHMvAAAAAAAAAAUAAAAIAAAADwAA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ALgBjAG8AbQAA",
+ output: {
+ URISpec: "https://www.mozilla.org/en-US/firefox/accounts/",
+ originAttributes: {
+ firstPartyDomain: "",
+ inIsolatedMozBrowser: false,
+ privateBrowsingId: 0,
+ userContextId: 0,
+ geckoViewSessionContextId: "",
+ partitionKey: "",
+ },
+ // Within Bug 965637 we removed CSP from Principals. Already serialized Principals however should still deserialize correctly (just without the CSP).
+ // "cspJSON": "{\"csp-policies\":[{\"child-src\":[\"https://www.googletagmanager.com\",\"https://www.google-analytics.com\",\"https://www.youtube-nocookie.com\",\"https://trackertest.org\",\"https://www.surveygizmo.com\",\"https://accounts.firefox.com\",\"https://accounts.firefox.com.cn\",\"https://www.youtube.com\"],\"connect-src\":[\"'self'\",\"https://*.mozilla.net\",\"https://*.mozilla.org\",\"https://*.mozilla.com\",\"https://www.googletagmanager.com\",\"https://www.google-analytics.com\",\"https://accounts.firefox.com/\",\"https://accounts.firefox.com.cn/\"],\"default-src\":[\"'self'\",\"https://*.mozilla.net\",\"https://*.mozilla.org\",\"https://*.mozilla.com\"],\"frame-src\":[\"https://www.googletagmanager.com\",\"https://www.google-analytics.com\",\"https://www.youtube-nocookie.com\",\"https://trackertest.org\",\"https://www.surveygizmo.com\",\"https://accounts.firefox.com\",\"https://accounts.firefox.com.cn\",\"https://www.youtube.com\"],\"img-src\":[\"'self'\",\"https://*.mozilla.net\",\"https://*.mozilla.org\",\"https://*.mozilla.com\",\"data:\",\"https://mozilla.org\",\"https://www.googletagmanager.com\",\"https://www.google-analytics.com\",\"https://adservice.google.com\",\"https://adservice.google.de\",\"https://adservice.google.dk\",\"https://creativecommons.org\",\"https://ad.doubleclick.net\"],\"report-only\":false,\"script-src\":[\"'self'\",\"https://*.mozilla.net\",\"https://*.mozilla.org\",\"https://*.mozilla.com\",\"'unsafe-inline'\",\"'unsafe-eval'\",\"https://www.googletagmanager.com\",\"https://www.google-analytics.com\",\"https://tagmanager.google.com\",\"https://www.youtube.com\",\"https://s.ytimg.com\"],\"style-src\":[\"'self'\",\"https://*.mozilla.net\",\"https://*.mozilla.org\",\"https://*.mozilla.com\",\"'unsafe-inline'\"]}]}",
+ },
+ },
+ ];
+
+ for (let test of serializedPrincipalsFromFirefox) {
+ let principal = E10SUtils.deserializePrincipal(test.input);
+
+ for (let key in principal.originAttributes) {
+ is(
+ principal.originAttributes[key],
+ test.output.originAttributes[key],
+ `Ensure value of ${key} is ${test.output.originAttributes[key]}`
+ );
+ }
+
+ if ("URI" in test.output && test.output.URI === false) {
+ is(
+ principal.isContentPrincipal,
+ false,
+ "Should have not have a URI for system"
+ );
+ } else {
+ is(
+ principal.spec,
+ test.output.URISpec,
+ `Should have spec ${test.output.URISpec}`
+ );
+ }
+ }
+});
diff --git a/browser/base/content/test/caps/browser_principalSerialization_json.js b/browser/base/content/test/caps/browser_principalSerialization_json.js
new file mode 100644
index 0000000000..f79f269fd7
--- /dev/null
+++ b/browser/base/content/test/caps/browser_principalSerialization_json.js
@@ -0,0 +1,161 @@
+"use strict";
+
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/ */
+
+/*
+ This test file exists to ensure whenever changes to principal serialization happens,
+ we guarantee that the data can be restored and generated into a new principal.
+
+ The tests are written to be brittle so we encode all versions of the changes into the tests.
+*/
+
+add_task(async function test_nullPrincipal() {
+ const nullId = "0";
+ // fields
+ const uri = 0;
+ const suffix = 1;
+
+ const nullReplaceRegex =
+ /moz-nullprincipal:{[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}}/;
+ const NULL_REPLACE = "NULL_PRINCIPAL_URL";
+
+ /*
+ This test should NOT be resilient to changes in versioning,
+ however it exists purely to verify the code doesn't unintentionally change without updating versioning and migration code.
+ */
+ let tests = [
+ {
+ input: { OA: {} },
+ expected: `{"${nullId}":{"${uri}":"${NULL_REPLACE}"}}`,
+ },
+ {
+ input: { OA: {} },
+ expected: `{"${nullId}":{"${uri}":"${NULL_REPLACE}"}}`,
+ },
+ {
+ input: { OA: { userContextId: 0 } },
+ expected: `{"${nullId}":{"${uri}":"${NULL_REPLACE}"}}`,
+ },
+ {
+ input: { OA: { userContextId: 2 } },
+ expected: `{"${nullId}":{"${uri}":"${NULL_REPLACE}","${suffix}":"^userContextId=2"}}`,
+ },
+ {
+ input: { OA: { privateBrowsingId: 1 } },
+ expected: `{"${nullId}":{"${uri}":"${NULL_REPLACE}","${suffix}":"^privateBrowsingId=1"}}`,
+ },
+ {
+ input: { OA: { privateBrowsingId: 0 } },
+ expected: `{"${nullId}":{"${uri}":"${NULL_REPLACE}"}}`,
+ },
+ ];
+
+ for (let test of tests) {
+ let p = Services.scriptSecurityManager.createNullPrincipal(test.input.OA);
+ let sp = E10SUtils.serializePrincipal(p);
+ // Not sure why cppjson is adding a \n here
+ let spr = sp.replace(nullReplaceRegex, NULL_REPLACE);
+ is(
+ test.expected,
+ spr,
+ "Expected serialized object for " + JSON.stringify(test.input)
+ );
+ let dp = E10SUtils.deserializePrincipal(sp);
+
+ // Check all the origin attributes
+ for (let key in test.input.OA) {
+ is(
+ dp.originAttributes[key],
+ test.input.OA[key],
+ "Ensure value of " + key + " is " + test.input.OA[key]
+ );
+ }
+ }
+});
+
+add_task(async function test_contentPrincipal() {
+ const contentId = "1";
+ // fields
+ const content = 0;
+ // const domain = 1;
+ const suffix = 2;
+ // const csp = 3;
+
+ /*
+ This test should NOT be resilient to changes in versioning,
+ however it exists purely to verify the code doesn't unintentionally change without updating versioning and migration code.
+ */
+ let tests = [
+ {
+ // eslint-disable-next-line @microsoft/sdl/no-insecure-url
+ input: { uri: "http://example.com/", OA: {} },
+ expected: `{"${contentId}":{"${content}":"http://example.com/"}}`,
+ },
+ {
+ // eslint-disable-next-line @microsoft/sdl/no-insecure-url
+ input: { uri: "http://mozilla1.com/", OA: {} },
+ expected: `{"${contentId}":{"${content}":"http://mozilla1.com/"}}`,
+ },
+ {
+ // eslint-disable-next-line @microsoft/sdl/no-insecure-url
+ input: { uri: "http://mozilla2.com/", OA: { userContextId: 0 } },
+ expected: `{"${contentId}":{"${content}":"http://mozilla2.com/"}}`,
+ },
+ {
+ // eslint-disable-next-line @microsoft/sdl/no-insecure-url
+ input: { uri: "http://mozilla3.com/", OA: { userContextId: 2 } },
+ expected: `{"${contentId}":{"${content}":"http://mozilla3.com/","${suffix}":"^userContextId=2"}}`,
+ },
+ {
+ // eslint-disable-next-line @microsoft/sdl/no-insecure-url
+ input: { uri: "http://mozilla4.com/", OA: { privateBrowsingId: 1 } },
+ expected: `{"${contentId}":{"${content}":"http://mozilla4.com/","${suffix}":"^privateBrowsingId=1"}}`,
+ },
+ {
+ // eslint-disable-next-line @microsoft/sdl/no-insecure-url
+ input: { uri: "http://mozilla5.com/", OA: { privateBrowsingId: 0 } },
+ expected: `{"${contentId}":{"${content}":"http://mozilla5.com/"}}`,
+ },
+ ];
+
+ for (let test of tests) {
+ let uri = Services.io.newURI(test.input.uri);
+ let p = Services.scriptSecurityManager.createContentPrincipal(
+ uri,
+ test.input.OA
+ );
+ let sp = E10SUtils.serializePrincipal(p);
+ is(test.expected, sp, "Expected serialized object for " + test.input.uri);
+ let dp = E10SUtils.deserializePrincipal(sp);
+ is(dp.URI.spec, test.input.uri, "Ensure spec is the same");
+
+ // Check all the origin attributes
+ for (let key in test.input.OA) {
+ is(
+ dp.originAttributes[key],
+ test.input.OA[key],
+ "Ensure value of " + key + " is " + test.input.OA[key]
+ );
+ }
+ }
+});
+
+add_task(async function test_systemPrincipal() {
+ const systemId = "3";
+ /*
+ This test should NOT be resilient to changes in versioning,
+ however it exists purely to verify the code doesn't unintentionally change without updating versioning and migration code.
+ */
+ const expected = `{"${systemId}":{}}`;
+
+ let p = Services.scriptSecurityManager.getSystemPrincipal();
+ let sp = E10SUtils.serializePrincipal(p);
+ is(expected, sp, "Expected serialized object for system principal");
+ let dp = E10SUtils.deserializePrincipal(sp);
+ is(
+ dp,
+ Services.scriptSecurityManager.getSystemPrincipal(),
+ "Deserialized the system principal"
+ );
+});
diff --git a/browser/base/content/test/caps/browser_principalSerialization_version1.js b/browser/base/content/test/caps/browser_principalSerialization_version1.js
new file mode 100644
index 0000000000..6c4a41e911
--- /dev/null
+++ b/browser/base/content/test/caps/browser_principalSerialization_version1.js
@@ -0,0 +1,159 @@
+"use strict";
+
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/ */
+
+/*
+ This test file exists to ensure whenever changes to principal serialization happens,
+ we guarantee that the data can be restored and generated into a new principal.
+
+ The tests are written to be brittle so we encode all versions of the changes into the tests.
+*/
+
+add_task(function test_nullPrincipal() {
+ /*
+ As Null principals are designed to be non deterministic we just need to ensure that
+ a previous serialized version matches what it was generated as.
+
+ This test should be resilient to changes in versioning, however it should also be duplicated for a new serialization change.
+ */
+ // Principal created with: E10SUtils.serializePrincipal(Services.scriptSecurityManager.createNullPrincipal({ }));
+ let p = E10SUtils.deserializePrincipal(
+ "vQZuXxRvRHKDMXv9BbHtkAAAAAAAAAAAwAAAAAAAAEYAAAA4bW96LW51bGxwcmluY2lwYWw6ezU2Y2FjNTQwLTg2NGQtNDdlNy04ZTI1LTE2MTRlYWI1MTU1ZX0AAAAA"
+ );
+ is(
+ "moz-nullprincipal:{56cac540-864d-47e7-8e25-1614eab5155e}",
+ p.URI.spec,
+ "Deserialized principal doesn't have the correct URI"
+ );
+
+ // Principal created with: E10SUtils.serializePrincipal(Services.scriptSecurityManager.createNullPrincipal({ userContextId: 2 }));
+ let p2 = E10SUtils.deserializePrincipal(
+ "vQZuXxRvRHKDMXv9BbHtkAAAAAAAAAAAwAAAAAAAAEYAAAA4bW96LW51bGxwcmluY2lwYWw6ezA1ZjllN2JhLWIwODMtNDJhMi1iNDdkLTZiODRmNmYwYTM3OX0AAAAQXnVzZXJDb250ZXh0SWQ9Mg=="
+ );
+ is(
+ "moz-nullprincipal:{05f9e7ba-b083-42a2-b47d-6b84f6f0a379}",
+ p2.URI.spec,
+ "Deserialized principal doesn't have the correct URI"
+ );
+ is(p2.originAttributes.userContextId, 2, "Expected a userContextId of 2");
+});
+
+add_task(async function test_realHistoryCheck() {
+ /*
+ This test should be resilient to changes in principal serialization, if these are failing then it's likely the code will break session storage.
+ To recreate this for another version, copy the function into the browser console, browse some pages and printHistory.
+
+ Generated with:
+ function printHistory() {
+ let tests = [];
+ let entries = SessionStore.getSessionHistory(gBrowser.selectedTab).entries.map((entry) => { return entry.triggeringPrincipal_base64 });
+ entries.push(E10SUtils.serializePrincipal(gBrowser.selectedTab.linkedBrowser._contentPrincipal));
+ for (let entry of entries) {
+ console.log(entry);
+ let testData = {};
+ testData.input = entry;
+ let principal = E10SUtils.deserializePrincipal(testData.input);
+ testData.output = {};
+ if (principal.URI === null) {
+ testData.output.URI = false;
+ } else {
+ testData.output.URISpec = principal.URI.spec;
+ }
+ testData.output.originAttributes = principal.originAttributes;
+
+ tests.push(testData);
+ }
+ return tests;
+ }
+ printHistory(); // Copy this into: serializedPrincipalsFromFirefox
+ */
+
+ let serializedPrincipalsFromFirefox = [
+ {
+ input: "SmIS26zLEdO3ZQBgsLbOywAAAAAAAAAAwAAAAAAAAEY=",
+ output: {
+ URI: false,
+ originAttributes: {
+ firstPartyDomain: "",
+ inIsolatedMozBrowser: false,
+ privateBrowsingId: 0,
+ userContextId: 0,
+ geckoViewSessionContextId: "",
+ partitionKey: "",
+ },
+ },
+ },
+ {
+ input:
+ "ZT4OTT7kRfqycpfCC8AeuAAAAAAAAAAAwAAAAAAAAEYB3pRy0IA0EdOTmQAQS6D9QJIHOlRteE8wkTq4cYEyCMYAAAAC/////wAAAbsBAAAAe2h0dHBzOi8vZGV2ZWxvcGVyLm1vemlsbGEub3JnL2VuLVVTLz91dG1fc291cmNlPXd3dy5tb3ppbGxhLm9yZyZ1dG1fbWVkaXVtPXJlZmVycmFsJnV0bV9jYW1wYWlnbj1uYXYmdXRtX2NvbnRlbnQ9ZGV2ZWxvcGVycwAAAAAAAAAFAAAACAAAABUAAAAA/////wAAAAD/////AAAACAAAABUAAAAdAAAAXgAAAB0AAAAHAAAAHQAAAAcAAAAkAAAAAAAAAAD/////AAAAAP////8AAAAlAAAAVgAAAAD/////AQAAAAAAAAAAAAAAAA==",
+ output: {
+ URISpec:
+ "https://developer.mozilla.org/en-US/?utm_source=www.mozilla.org&utm_medium=referral&utm_campaign=nav&utm_content=developers",
+ originAttributes: {
+ firstPartyDomain: "",
+ inIsolatedMozBrowser: false,
+ privateBrowsingId: 0,
+ userContextId: 0,
+ geckoViewSessionContextId: "",
+ partitionKey: "",
+ },
+ },
+ },
+ {
+ input: "SmIS26zLEdO3ZQBgsLbOywAAAAAAAAAAwAAAAAAAAEY=",
+ output: {
+ URI: false,
+ originAttributes: {
+ firstPartyDomain: "",
+ inIsolatedMozBrowser: false,
+ privateBrowsingId: 0,
+ userContextId: 0,
+ geckoViewSessionContextId: "",
+ partitionKey: "",
+ },
+ },
+ },
+ {
+ input:
+ "vQZuXxRvRHKDMXv9BbHtkAAAAAAAAAAAwAAAAAAAAEYAAAA4bW96LW51bGxwcmluY2lwYWw6ezA0NWNhMThkLTQzNmMtNDc0NC1iYmI2LWIxYTE1MzY2ZGY3OX0AAAAA",
+ output: {
+ URISpec: "moz-nullprincipal:{045ca18d-436c-4744-bbb6-b1a15366df79}",
+ originAttributes: {
+ firstPartyDomain: "",
+ inIsolatedMozBrowser: false,
+ privateBrowsingId: 0,
+ userContextId: 0,
+ geckoViewSessionContextId: "",
+ partitionKey: "",
+ },
+ },
+ },
+ ];
+
+ for (let test of serializedPrincipalsFromFirefox) {
+ let principal = E10SUtils.deserializePrincipal(test.input);
+
+ for (let key in principal.originAttributes) {
+ is(
+ principal.originAttributes[key],
+ test.output.originAttributes[key],
+ `Ensure value of ${key} is ${test.output.originAttributes[key]}`
+ );
+ }
+
+ if ("URI" in test.output && test.output.URI === false) {
+ is(
+ principal.isContentPrincipal,
+ false,
+ "Should have not have a URI for system"
+ );
+ } else {
+ is(
+ principal.spec,
+ test.output.URISpec,
+ `Should have spec ${test.output.URISpec}`
+ );
+ }
+ }
+});