mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-11-10 13:18:45 +02:00
As originally implemented, nsISiteSecurityService.removeState allowed direct access to remove HSTS state. It also provided the implementation for when the browser encountered an HSTS header with "max-age=0". In bug 775370, it was updated to store an entry that would override preloaded information when processing such headers. However, this meant that the semantics of the direct access API had changed. Preloaded information could be overridden if a user invoked the "forget about this site" feature. This change fixes the public API (and renames it to "resetState") so it actually behaves as its consumers expect. Reviewers: jcj!, KevinJacobs! Tags: #secure-revision Bug #: 1564481 Differential Revision: https://phabricator.services.mozilla.com/D38108 --HG-- extra : rebase_source : 8dd5460d3fd3c0ce92746cc83fae220d6e2a83cf extra : amend_source : 171ebb015e9f9ae775f0caa22e161d41970f3d51
83 lines
2.5 KiB
JavaScript
83 lines
2.5 KiB
JavaScript
/* Any copyright is dedicated to the Public Domain.
|
|
* http://creativecommons.org/publicdomain/zero/1.0/
|
|
*/
|
|
/* eslint-disable mozilla/no-arbitrary-setTimeout */
|
|
|
|
var secureURL =
|
|
"https://example.com/browser/browser/base/content/test/general/browser_star_hsts.sjs";
|
|
var unsecureURL =
|
|
"http://example.com/browser/browser/base/content/test/general/browser_star_hsts.sjs";
|
|
|
|
add_task(async function test_star_redirect() {
|
|
registerCleanupFunction(async () => {
|
|
// Ensure to remove example.com from the HSTS list.
|
|
let sss = Cc["@mozilla.org/ssservice;1"].getService(
|
|
Ci.nsISiteSecurityService
|
|
);
|
|
sss.resetState(
|
|
Ci.nsISiteSecurityService.HEADER_HSTS,
|
|
NetUtil.newURI("http://example.com/"),
|
|
0
|
|
);
|
|
await PlacesUtils.bookmarks.eraseEverything();
|
|
gBrowser.removeCurrentTab();
|
|
});
|
|
|
|
let tab = (gBrowser.selectedTab = BrowserTestUtils.addTab(gBrowser));
|
|
// This will add the page to the HSTS cache.
|
|
await promiseTabLoadEvent(tab, secureURL, secureURL);
|
|
// This should transparently be redirected to the secure page.
|
|
await promiseTabLoadEvent(tab, unsecureURL, secureURL);
|
|
|
|
await promiseStarState(BookmarkingUI.STATUS_UNSTARRED);
|
|
|
|
let bookmarkPanel = document.getElementById("editBookmarkPanel");
|
|
let shownPromise = promisePopupShown(bookmarkPanel);
|
|
BookmarkingUI.star.click();
|
|
await shownPromise;
|
|
|
|
is(BookmarkingUI.status, BookmarkingUI.STATUS_STARRED, "The star is starred");
|
|
});
|
|
|
|
/**
|
|
* Waits for the star to reflect the expected state.
|
|
*/
|
|
function promiseStarState(aValue) {
|
|
return new Promise(resolve => {
|
|
let expectedStatus = aValue
|
|
? BookmarkingUI.STATUS_STARRED
|
|
: BookmarkingUI.STATUS_UNSTARRED;
|
|
(function checkState() {
|
|
if (
|
|
BookmarkingUI.status == BookmarkingUI.STATUS_UPDATING ||
|
|
BookmarkingUI.status != expectedStatus
|
|
) {
|
|
info("Waiting for star button change.");
|
|
setTimeout(checkState, 1000);
|
|
} else {
|
|
resolve();
|
|
}
|
|
})();
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Starts a load in an existing tab and waits for it to finish (via some event).
|
|
*
|
|
* @param aTab
|
|
* The tab to load into.
|
|
* @param aUrl
|
|
* The url to load.
|
|
* @param [optional] aFinalURL
|
|
* The url to wait for, same as aURL if not defined.
|
|
* @return {Promise} resolved when the event is handled.
|
|
*/
|
|
function promiseTabLoadEvent(aTab, aURL, aFinalURL) {
|
|
if (!aFinalURL) {
|
|
aFinalURL = aURL;
|
|
}
|
|
|
|
info("Wait for load tab event");
|
|
BrowserTestUtils.loadURI(aTab.linkedBrowser, aURL);
|
|
return BrowserTestUtils.browserLoaded(aTab.linkedBrowser, false, aFinalURL);
|
|
}
|