tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

commit 7638a4348e53857fdf135192073a6254dee3b840
parent cf480d4cec629836555a8ef75a1bc1feb6558180
Author: Sandra Qu <squiles@mozilla.com>
Date:   Mon, 27 Oct 2025 15:23:18 +0000

Bug 1993231 Failing test assertion in browser_aboutCertError_clockSkew.js r=niklas

Differential Revision: https://phabricator.services.mozilla.com/D267955

Diffstat:
Mbrowser/base/content/test/about/browser_aboutCertError_clockSkew.js | 217++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---
Mtoolkit/content/net-error-card.mjs | 5++++-
2 files changed, 215 insertions(+), 7 deletions(-)

diff --git a/browser/base/content/test/about/browser_aboutCertError_clockSkew.js b/browser/base/content/test/about/browser_aboutCertError_clockSkew.js @@ -8,7 +8,9 @@ const PREF_SERVICES_SETTINGS_CLOCK_SKEW_SECONDS = const PREF_SERVICES_SETTINGS_LAST_FETCHED = "services.settings.last_update_seconds"; -add_task(async function checkWrongSystemTimeWarning() { +// Security CertError Felt Privacy set to false +add_task(async function checkWrongSystemTimeWarning_feltPrivacyToFalse() { + await setSecurityCertErrorsFeltPrivacyToFalse(); async function setUpPage() { let browser; let certErrorLoaded; @@ -101,16 +103,15 @@ add_task(async function checkWrongSystemTimeWarning() { Services.prefs.clearUserPref(PREF_SERVICES_SETTINGS_CLOCK_SKEW_SECONDS); }); -add_task(async function checkCertError() { +add_task(async function checkCertError_feltPrivacyToFalse() { + await setSecurityCertErrorsFeltPrivacyToFalse(); async function setUpPage() { - let browser; - let certErrorLoaded; gBrowser.selectedTab = BrowserTestUtils.addTab( gBrowser, "https://expired.example.com/" ); - browser = gBrowser.selectedBrowser; - certErrorLoaded = BrowserTestUtils.waitForErrorPage(browser); + let browser = gBrowser.selectedBrowser; + let certErrorLoaded = BrowserTestUtils.waitForErrorPage(browser); info("Loading and waiting for the cert error"); await certErrorLoaded; @@ -151,3 +152,207 @@ add_task(async function checkCertError() { Services.prefs.clearUserPref(PREF_SERVICES_SETTINGS_LAST_FETCHED); Services.prefs.clearUserPref(PREF_SERVICES_SETTINGS_CLOCK_SKEW_SECONDS); }); + +// Security CertError Felt Privacy set to true +add_task(async function checkWrongSystemTimeWarning_feltPrivacyToTrue() { + await setSecurityCertErrorsFeltPrivacyToTrue(); + async function setUpPage() { + let browser; + let certErrorLoaded; + await BrowserTestUtils.openNewForegroundTab( + gBrowser, + () => { + gBrowser.selectedTab = BrowserTestUtils.addTab( + gBrowser, + "https://expired.example.com/" + ); + browser = gBrowser.selectedBrowser; + certErrorLoaded = BrowserTestUtils.waitForErrorPage(browser); + }, + false + ); + + info("Loading and waiting for the cert error"); + await certErrorLoaded; + + return SpecialPowers.spawn(browser, [], async function () { + const netErrorCard = + content.document.querySelector("net-error-card").wrappedJSObject; + await netErrorCard.getUpdateComplete(); + + Assert.ok( + netErrorCard.certErrorBodyTitle, + "The error page title should exist." + ); + + const shortDesc = netErrorCard.certErrorIntro; + const advancedButton = netErrorCard.advancedButton; + Assert.ok(advancedButton, "The advanced button should exist."); + + Assert.equal( + advancedButton.dataset.l10nId, + "fp-certerror-advanced-button", + "Button should have the 'advanced' l10n ID." + ); + + // Perform user button click interaction + EventUtils.synthesizeMouseAtCenter(advancedButton, {}, content); + + // Wait for the exception button to be enabled + // This ensures that the advanced section is fully loaded + await ContentTaskUtils.waitForCondition( + () => + netErrorCard.exceptionButton && + !netErrorCard.exceptionButton.disabled, + "Wait for the exception button to be created." + ); + + const whatCanYouDo = netErrorCard.whatCanYouDo; + Assert.equal( + whatCanYouDo.dataset.l10nId, + "fp-certerror-expired-what-can-you-do-body", + "What can you do section should have fp-certerror-expired-what-can-you-do-body l10n ID." + ); + + const whatCanYouDoArgs = JSON.parse(whatCanYouDo.dataset.l10nArgs); + Assert.ok( + whatCanYouDoArgs.date, + "What can you do section should have timestamp." + ); + + return { + divDisplay: content.getComputedStyle(shortDesc).display, + text: shortDesc.textContent, + learnMoreLink: netErrorCard.learnMoreLink.href, + whatCanYouDoText: whatCanYouDo.textContent, + }; + }); + } + + // Pretend that we recently updated our kinto clock skew pref + SpecialPowers.pushPrefEnv({ + set: [[PREF_SERVICES_SETTINGS_LAST_FETCHED, Math.floor(Date.now() / 1000)]], + }); + + // For this test, we want to trick Firefox into believing that + // the local system time (as returned by Date.now()) is wrong. + // Because we don't want to actually change the local system time, + // we will do the following: + + // Take the validity date of our test page (expired.example.com). + let expiredDate = new Date("2010/01/05 12:00"); + let localDate = Date.now(); + + // Compute the difference between the server date and the correct + // local system date. + let skew = Math.floor((localDate - expiredDate) / 1000); + + // Make it seem like our reference server agrees that the certificate + // date is correct by recording the difference as clock skew. + SpecialPowers.pushPrefEnv({ + set: [[PREF_SERVICES_SETTINGS_CLOCK_SKEW_SECONDS, skew]], + }); + + let localDateFmt = new Intl.DateTimeFormat("en-US", { + year: "numeric", + month: "numeric", + day: "numeric", + }).format(localDate); + + info("Loading a bad cert page with a skewed clock"); + let contentData = await setUpPage(); + + Assert.notEqual( + contentData.divDisplay, + "none", + "Wrong time message information is visible" + ); + + Assert.ok( + contentData.text.includes("expired.example.com"), + "URL found in error message" + ); + + Assert.ok( + contentData.whatCanYouDoText.includes(localDateFmt), + "Correct local date displayed" + ); + Assert.ok( + contentData.learnMoreLink.includes("time-errors"), + "time-errors in the Learn More URL" + ); + + BrowserTestUtils.removeTab(gBrowser.selectedTab); +}); + +add_task(async function checkCertError_feltPrivacyToTrue() { + await setSecurityCertErrorsFeltPrivacyToTrue(); + + async function setUpPage() { + gBrowser.selectedTab = BrowserTestUtils.addTab( + gBrowser, + "https://expired.example.com/" + ); + let browser = gBrowser.selectedBrowser; + let certErrorLoaded = BrowserTestUtils.waitForErrorPage(browser); + + info("Loading and waiting for the cert error"); + await certErrorLoaded; + + return SpecialPowers.spawn(browser, [], async function () { + const netErrorCard = + content.document.querySelector("net-error-card").wrappedJSObject; + await netErrorCard.getUpdateComplete(); + + // Get the advanced container + // Perform user button click interaction + EventUtils.synthesizeMouseAtCenter( + netErrorCard.advancedButton, + {}, + content + ); + + await ContentTaskUtils.waitForCondition( + () => + netErrorCard.exceptionButton && + !netErrorCard.exceptionButton.disabled, + "Wait for the exception button to be created." + ); + + const whatCanYouDo = netErrorCard.whatCanYouDo; + await ContentTaskUtils.waitForCondition(() => whatCanYouDo.textContent); + Assert.equal( + whatCanYouDo.dataset.l10nId, + "fp-certerror-expired-what-can-you-do-body", + "Should have the fp-certerror-expired-what-can-you-do-body l10n ID." + ); + return whatCanYouDo.textContent; + }); + } + + // The particular error message will be displayed only when clock_skew_seconds is + // less or equal to a day and the difference between date.now() and last_fetched is less than + // or equal to 5 days. Setting the prefs accordingly. + + let skew = 60 * 60 * 24; + SpecialPowers.pushPrefEnv({ + set: [ + [PREF_SERVICES_SETTINGS_LAST_FETCHED, Math.floor(Date.now() / 1000)], + [PREF_SERVICES_SETTINGS_CLOCK_SKEW_SECONDS, skew], + ], + }); + + info("Loading a bad cert page"); + let message = await setUpPage(); + + let localDate = Date.now(); + let localDateFmt = new Intl.DateTimeFormat("en-US", { + year: "numeric", + month: "numeric", + day: "numeric", + }).format(localDate); + + Assert.ok(message.includes(localDateFmt), "Message has local date displayed"); + + BrowserTestUtils.removeTab(gBrowser.selectedTab); +}); diff --git a/toolkit/content/net-error-card.mjs b/toolkit/content/net-error-card.mjs @@ -42,6 +42,8 @@ export class NetErrorCard extends MozLitElement { viewCertificate: "#viewCertificate", certErrorBodyTitle: "#certErrorBodyTitle", returnButton: "#returnButton", + learnMoreLink: "#learnMoreLink", + whatCanYouDo: "#whatCanYouDo", }; static ERROR_CODES = new Set([ @@ -86,7 +88,6 @@ export class NetErrorCard extends MozLitElement { connectedCallback() { super.connectedCallback(); - this.init(); } @@ -318,6 +319,7 @@ export class NetErrorCard extends MozLitElement { ? html`<p> <strong data-l10n-id="fp-certerror-what-can-you-do"></strong> <span + id="whatCanYouDo" data-l10n-id=${whatCanYouDoL10nId} data-l10n-args=${JSON.stringify(whatCanYouDoL10nArgs)} ></span> @@ -332,6 +334,7 @@ export class NetErrorCard extends MozLitElement { data-l10n-id=${learnMoreL10nId} data-l10n-args=${JSON.stringify(learnMoreL10nArgs)} data-telemetry-id="learn_more_link" + id="learnMoreLink" @click=${this.handleTelemetryClick} ></a> </p>`