commit e12b6e7c96d014b109f51d5111c4bb9005226ff0 parent 2ecea69e46575a3f443de32919e65ac6e1743218 Author: agoloman <agoloman@mozilla.com> Date: Tue, 16 Dec 2025 23:36:20 +0200 Revert "Bug 1915371 - Part 3: Make test_http_auth_cache mochitest automatically accept password prompt r=necko-reviewers,jesup" for causing failures @test_http_auth_cache.html. This reverts commit ee661ef511d82f1db62701569c139ad8057d0e88. Revert "Bug 1915371 - Part 2: Add a mochitest for HTTP Authentication Cache XPIDL r=edgul,necko-reviewers,jesup" This reverts commit 3bcfc371da7089be3137d5c2a4910a5a0ca33487. Revert "Bug 1915371 - Part 1: Add XPIDL interface for HTTP Authentication Cache r=necko-reviewers,jesup" This reverts commit 979eed83e5f099d7e9875fbfd870f80670d6f390. Diffstat:
14 files changed, 75 insertions(+), 380 deletions(-)
diff --git a/netwerk/build/components.conf b/netwerk/build/components.conf @@ -305,16 +305,6 @@ Classes = [ 'headers': ['/netwerk/protocol/http/nsCORSListenerProxy.h'], }, { - 'name': 'HttpAuthCache', - 'cid': '{e4aa6025-e0d8-40f0-92c7-f0100c6d6174}', - 'contract_ids': ['@mozilla.org/network/http-auth-cache;1'], - 'singleton': True, - 'processes': ProcessSelector.MAIN_PROCESS_ONLY, - 'type': 'nsIHttpAuthCache', - 'constructor': 'mozilla::net::nsHttpAuthManager::GetHttpAuthCacheSingleton', - 'headers': ['/netwerk/protocol/http/nsHttpAuthCache.h'], - }, - { 'cid': '{9e3b6c90-2f75-11d3-8cd0-0060b0fc14a3}', 'contract_ids': ['@mozilla.org/network/protocol;1?name=about'], 'singleton': True, diff --git a/netwerk/protocol/http/moz.build b/netwerk/protocol/http/moz.build @@ -14,10 +14,8 @@ XPIDL_SOURCES += [ "nsICORSPreflightCacheEntry.idl", "nsIEarlyHintObserver.idl", "nsIHttpActivityObserver.idl", - "nsIHttpAuthCache.idl", "nsIHttpAuthenticableChannel.idl", "nsIHttpAuthenticator.idl", - "nsIHttpAuthEntry.idl", "nsIHttpAuthManager.idl", "nsIHttpChannel.idl", "nsIHttpChannelAuthProvider.idl", diff --git a/netwerk/protocol/http/nsHttpAuthCache.cpp b/netwerk/protocol/http/nsHttpAuthCache.cpp @@ -37,47 +37,14 @@ static inline void GetAuthKey(const nsACString& scheme, const nsACString& host, //----------------------------------------------------------------------------- // nsHttpAuthCache <public> //----------------------------------------------------------------------------- -NS_IMPL_ISUPPORTS(nsHttpAuthCache, nsIHttpAuthCache) -NS_IMETHODIMP -nsHttpAuthCache::GetEntries(nsTArray<RefPtr<nsIHttpAuthEntry>>& aEntries) { - for (auto iter = mDB.Iter(); !iter.Done(); iter.Next()) { - nsHttpAuthNode* node = iter.Data().get(); - for (auto& entry : node->mList) { - auto* tmp = entry.get(); - aEntries.AppendElement(tmp); - } - } - - return NS_OK; -} - -NS_IMETHODIMP -nsHttpAuthCache::ClearEntry(nsIHttpAuthEntry* aEntry) { - NS_ENSURE_ARG_POINTER(aEntry); - - for (auto iter = mDB.Iter(); !iter.Done(); iter.Next()) { - nsHttpAuthNode* node = iter.Data().get(); - - for (auto& entry : node->mList) { - if (entry.get() == aEntry) { - node->mList.RemoveElement(entry); - if (node->EntryCount() == 0) { - iter.Remove(); - } - return NS_OK; - } - } - } - return NS_ERROR_NOT_AVAILABLE; -} - -nsHttpAuthCache::nsHttpAuthCache() : mDB(128) { +nsHttpAuthCache::nsHttpAuthCache() + : mDB(128), mObserver(new OriginClearObserver(this)) { LOG(("nsHttpAuthCache::nsHttpAuthCache %p", this)); nsCOMPtr<nsIObserverService> obsSvc = services::GetObserverService(); if (obsSvc) { - obsSvc->AddObserver(this, "clear-origin-attributes-data", true); + obsSvc->AddObserver(mObserver, "clear-origin-attributes-data", false); } } @@ -87,7 +54,8 @@ nsHttpAuthCache::~nsHttpAuthCache() { ClearAll(); nsCOMPtr<nsIObserverService> obsSvc = services::GetObserverService(); if (obsSvc) { - obsSvc->RemoveObserver(this, "clear-origin-attributes-data"); + obsSvc->RemoveObserver(mObserver, "clear-origin-attributes-data"); + mObserver->mOwner = nullptr; } } @@ -96,7 +64,7 @@ nsresult nsHttpAuthCache::GetAuthEntryForPath(const nsACString& scheme, int32_t port, const nsACString& path, nsACString const& originSuffix, - RefPtr<nsHttpAuthEntry>& entry) { + nsHttpAuthEntry** entry) { LOG(("nsHttpAuthCache::GetAuthEntryForPath %p [path=%s]\n", this, path.BeginReading())); @@ -104,9 +72,9 @@ nsresult nsHttpAuthCache::GetAuthEntryForPath(const nsACString& scheme, nsHttpAuthNode* node = LookupAuthNode(scheme, host, port, originSuffix, key); if (!node) return NS_ERROR_NOT_AVAILABLE; - entry = node->LookupEntryByPath(path); - LOG((" returning %p", entry.get())); - return entry ? NS_OK : NS_ERROR_NOT_AVAILABLE; + *entry = node->LookupEntryByPath(path); + LOG((" returning %p", *entry)); + return *entry ? NS_OK : NS_ERROR_NOT_AVAILABLE; } nsresult nsHttpAuthCache::GetAuthEntryForDomain(const nsACString& scheme, @@ -114,7 +82,7 @@ nsresult nsHttpAuthCache::GetAuthEntryForDomain(const nsACString& scheme, int32_t port, const nsACString& realm, nsACString const& originSuffix, - RefPtr<nsHttpAuthEntry>& entry) + nsHttpAuthEntry** entry) { LOG(("nsHttpAuthCache::GetAuthEntryForDomain %p [realm=%s]\n", this, @@ -124,9 +92,9 @@ nsresult nsHttpAuthCache::GetAuthEntryForDomain(const nsACString& scheme, nsHttpAuthNode* node = LookupAuthNode(scheme, host, port, originSuffix, key); if (!node) return NS_ERROR_NOT_AVAILABLE; - entry = node->LookupEntryByRealm(realm); - LOG((" returning %p", entry.get())); - return entry ? NS_OK : NS_ERROR_NOT_AVAILABLE; + *entry = node->LookupEntryByRealm(realm); + LOG((" returning %p", *entry)); + return *entry ? NS_OK : NS_ERROR_NOT_AVAILABLE; } nsresult nsHttpAuthCache::SetAuthEntry( @@ -190,16 +158,21 @@ nsHttpAuthNode* nsHttpAuthCache::LookupAuthNode(const nsACString& scheme, return result; } +NS_IMPL_ISUPPORTS(nsHttpAuthCache::OriginClearObserver, nsIObserver) + NS_IMETHODIMP -nsHttpAuthCache::Observe(nsISupports* subject, const char* topic, - const char16_t* data_unicode) { +nsHttpAuthCache::OriginClearObserver::Observe(nsISupports* subject, + const char* topic, + const char16_t* data_unicode) { + NS_ENSURE_TRUE(mOwner, NS_ERROR_NOT_AVAILABLE); + OriginAttributesPattern pattern; if (!pattern.Init(nsDependentString(data_unicode))) { NS_ERROR("Cannot parse origin attributes pattern"); return NS_ERROR_FAILURE; } - ClearOriginData(pattern); + mOwner->ClearOriginData(pattern); return NS_OK; } @@ -246,74 +219,9 @@ bool nsHttpAuthIdentity::Equals(const nsHttpAuthIdentity& ident) const { mDomain == ident.mDomain; } -NS_IMPL_ISUPPORTS(AuthIdentity, nsIHttpAuthIdentity) - -NS_IMETHODIMP -AuthIdentity::GetDomain(nsAString& aDomain) { - aDomain = mIdent.Domain(); - return NS_OK; -} - -NS_IMETHODIMP -AuthIdentity::GetUser(nsAString& aUser) { - aUser = mIdent.User(); - return NS_OK; -} - -NS_IMETHODIMP -AuthIdentity::GetPassword(nsAString& aPassword) { - aPassword = mIdent.Password(); - return NS_OK; -} - //----------------------------------------------------------------------------- // nsHttpAuthEntry //----------------------------------------------------------------------------- -NS_IMPL_ISUPPORTS(nsHttpAuthEntry, nsIHttpAuthEntry) - -NS_IMETHODIMP -nsHttpAuthEntry::GetRealm(nsACString& aRealm) { - aRealm = mRealm; - return NS_OK; -} - -NS_IMETHODIMP -nsHttpAuthEntry::GetCreds(nsACString& aCreds) { - aCreds = mCreds; - return NS_OK; -} - -NS_IMETHODIMP -nsHttpAuthEntry::GetChallenge(nsACString& aChallenge) { - aChallenge = mChallenge; - return NS_OK; -} - -NS_IMETHODIMP -nsHttpAuthEntry::GetDomain(nsAString& aDomain) { - aDomain = mIdent.Domain(); - return NS_OK; -} - -NS_IMETHODIMP -nsHttpAuthEntry::GetUser(nsAString& aUser) { - aUser = mIdent.User(); - return NS_OK; -} - -NS_IMETHODIMP -nsHttpAuthEntry::GetPassword(nsAString& aPass) { - aPass = mIdent.Password(); - return NS_OK; -} - -NS_IMETHODIMP -nsHttpAuthEntry::GetIdentity(nsIHttpAuthIdentity** aIdentity) { - NS_ENSURE_ARG_POINTER(aIdentity); - RefPtr<nsIHttpAuthIdentity> ident = new AuthIdentity(mIdent); - ident.forget(aIdentity); - return NS_OK; -} nsresult nsHttpAuthEntry::AddPath(const nsACString& aPath) { for (const auto& p : mPaths) { @@ -412,13 +320,14 @@ nsresult nsHttpAuthNode::SetAuthEntry(const nsACString& path, const nsHttpAuthIdentity* ident, nsISupports* metadata) { // look for an entry with a matching realm - RefPtr<nsHttpAuthEntry> entry = LookupEntryByRealm(realm); + nsHttpAuthEntry* entry = LookupEntryByRealm(realm); if (!entry) { // We want the latest identity be at the begining of the list so that // the newest working credentials are sent first on new requests. // Changing a realm is sometimes used to "timeout" authrozization. - entry = new nsHttpAuthEntry(path, realm, creds, challenge, ident, metadata); - mList.InsertElementAt(0, entry); + mList.InsertElementAt( + 0, WrapUnique(new nsHttpAuthEntry(path, realm, creds, challenge, ident, + metadata))); } else { // update the entry... nsresult rv = entry->Set(path, realm, creds, challenge, ident, metadata); diff --git a/netwerk/protocol/http/nsHttpAuthCache.h b/netwerk/protocol/http/nsHttpAuthCache.h @@ -12,7 +12,6 @@ #include "nsCOMPtr.h" #include "nsHashKeys.h" #include "nsStringFwd.h" -#include "nsIHttpAuthCache.h" #include "nsIObserver.h" namespace mozilla { @@ -50,36 +49,12 @@ class nsHttpAuthIdentity { nsString mDomain; }; -// This is an XPCOM wrapper for nsHttpAuthIdentity -class AuthIdentity final : public nsIHttpAuthIdentity { - public: - NS_DECL_ISUPPORTS - NS_DECL_NSIHTTPAUTHIDENTITY - - explicit AuthIdentity(const nsHttpAuthIdentity& aIdent) : mIdent(aIdent) {} - - private: - virtual ~AuthIdentity() = default; - nsHttpAuthIdentity mIdent; -}; - //----------------------------------------------------------------------------- // nsHttpAuthEntry //----------------------------------------------------------------------------- -class nsHttpAuthEntry : public nsIHttpAuthEntry { +class nsHttpAuthEntry { public: - NS_DECL_ISUPPORTS - NS_DECL_NSIHTTPAUTHENTRY - - nsHttpAuthEntry(const nsACString& path, const nsACString& realm, - const nsACString& creds, const nsACString& challenge, - const nsHttpAuthIdentity* ident, nsISupports* metadata) { - DebugOnly<nsresult> rv = - Set(path, realm, creds, challenge, ident, metadata); - MOZ_ASSERT(NS_SUCCEEDED(rv)); - } - const nsCString& Realm() const { return mRealm; } const nsCString& Creds() const { return mCreds; } const nsCString& Challenge() const { return mChallenge; } @@ -94,7 +69,14 @@ class nsHttpAuthEntry : public nsIHttpAuthEntry { nsCOMPtr<nsISupports> mMetaData; private: - virtual ~nsHttpAuthEntry() = default; + nsHttpAuthEntry(const nsACString& path, const nsACString& realm, + const nsACString& creds, const nsACString& challenge, + const nsHttpAuthIdentity* ident, nsISupports* metadata) { + DebugOnly<nsresult> rv = + Set(path, realm, creds, challenge, ident, metadata); + MOZ_ASSERT(NS_SUCCEEDED(rv)); + } + ~nsHttpAuthEntry() = default; [[nodiscard]] nsresult Set(const nsACString& path, const nsACString& realm, const nsACString& creds, @@ -122,7 +104,7 @@ class nsHttpAuthEntry : public nsIHttpAuthEntry { class nsHttpAuthNode { private: - using EntryList = nsTArray<RefPtr<nsHttpAuthEntry>>; + using EntryList = nsTArray<UniquePtr<nsHttpAuthEntry>>; nsHttpAuthNode(); ~nsHttpAuthNode(); @@ -161,13 +143,10 @@ class nsHttpAuthNode { // (holds a hash table from host:port to nsHttpAuthNode) //----------------------------------------------------------------------------- -class nsHttpAuthCache : public nsIHttpAuthCache, public nsIObserver { +class nsHttpAuthCache { public: - NS_DECL_ISUPPORTS - NS_DECL_NSIHTTPAUTHCACHE - NS_DECL_NSIOBSERVER - nsHttpAuthCache(); + ~nsHttpAuthCache(); // |scheme|, |host|, and |port| are required // |path| can be null @@ -177,7 +156,7 @@ class nsHttpAuthCache : public nsIHttpAuthCache, public nsIObserver { int32_t port, const nsACString& path, nsACString const& originSuffix, - RefPtr<nsHttpAuthEntry>& entry); + nsHttpAuthEntry** entry); // |scheme|, |host|, and |port| are required // |realm| must not be null @@ -187,7 +166,7 @@ class nsHttpAuthCache : public nsIHttpAuthCache, public nsIObserver { int32_t port, const nsACString& realm, nsACString const& originSuffix, - RefPtr<nsHttpAuthEntry>& entry); + nsHttpAuthEntry** entry); // |scheme|, |host|, and |port| are required // |path| can be null @@ -215,13 +194,23 @@ class nsHttpAuthCache : public nsIHttpAuthCache, public nsIObserver { const nsACString& host, int32_t port, nsACString const& originSuffix, nsCString& key); + + class OriginClearObserver : public nsIObserver { + virtual ~OriginClearObserver() = default; + + public: + NS_DECL_ISUPPORTS + NS_DECL_NSIOBSERVER + explicit OriginClearObserver(nsHttpAuthCache* aOwner) : mOwner(aOwner) {} + nsHttpAuthCache* mOwner; + }; + void ClearOriginData(OriginAttributesPattern const& pattern); private: - virtual ~nsHttpAuthCache(); - using AuthNodeTable = nsClassHashtable<nsCStringHashKey, nsHttpAuthNode>; AuthNodeTable mDB; // "host:port" --> nsHttpAuthNode + RefPtr<OriginClearObserver> mObserver; }; } // namespace net diff --git a/netwerk/protocol/http/nsHttpAuthManager.cpp b/netwerk/protocol/http/nsHttpAuthManager.cpp @@ -16,15 +16,6 @@ namespace net { NS_IMPL_ISUPPORTS(nsHttpAuthManager, nsIHttpAuthManager) -/* static */ -already_AddRefed<nsIHttpAuthCache> -nsHttpAuthManager::GetHttpAuthCacheSingleton() { - NS_ASSERTION(!IsNeckoChild(), "not a parent process"); - - // Return only the non-private cache - return do_AddRef(gHttpHandler->AuthCache(/* aPrivate = */ false)); -} - nsresult nsHttpAuthManager::Init() { // get reference to the auth cache. we assume that we will live // as long as gHttpHandler. instantiate it if necessary. @@ -55,9 +46,8 @@ nsHttpAuthManager::GetAuthIdentity( const nsACString& aAuthType, const nsACString& aRealm, const nsACString& aPath, nsAString& aUserDomain, nsAString& aUserName, nsAString& aUserPassword, bool aIsPrivate, nsIPrincipal* aPrincipal) { - RefPtr<nsHttpAuthCache> auth_cache = - aIsPrivate ? mPrivateAuthCache : mAuthCache; - RefPtr<nsHttpAuthEntry> entry = nullptr; + nsHttpAuthCache* auth_cache = aIsPrivate ? mPrivateAuthCache : mAuthCache; + nsHttpAuthEntry* entry = nullptr; nsresult rv; nsAutoCString originSuffix; @@ -67,10 +57,10 @@ nsHttpAuthManager::GetAuthIdentity( if (!aPath.IsEmpty()) { rv = auth_cache->GetAuthEntryForPath(aScheme, aHost, aPort, aPath, - originSuffix, entry); + originSuffix, &entry); } else { rv = auth_cache->GetAuthEntryForDomain(aScheme, aHost, aPort, aRealm, - originSuffix, entry); + originSuffix, &entry); } if (NS_FAILED(rv)) return rv; @@ -96,8 +86,7 @@ nsHttpAuthManager::SetAuthIdentity( aPrincipal->OriginAttributesRef().CreateSuffix(originSuffix); } - RefPtr<nsHttpAuthCache> auth_cache = - aIsPrivate ? mPrivateAuthCache : mAuthCache; + nsHttpAuthCache* auth_cache = aIsPrivate ? mPrivateAuthCache : mAuthCache; return auth_cache->SetAuthEntry(aScheme, aHost, aPort, aPath, aRealm, ""_ns, // credentials ""_ns, // challenge diff --git a/netwerk/protocol/http/nsHttpAuthManager.h b/netwerk/protocol/http/nsHttpAuthManager.h @@ -18,16 +18,14 @@ class nsHttpAuthManager : public nsIHttpAuthManager { NS_DECL_ISUPPORTS NS_DECL_NSIHTTPAUTHMANAGER - static already_AddRefed<nsIHttpAuthCache> GetHttpAuthCacheSingleton(); - nsHttpAuthManager() = default; [[nodiscard]] nsresult Init(); protected: virtual ~nsHttpAuthManager() = default; - RefPtr<nsHttpAuthCache> mAuthCache; - RefPtr<nsHttpAuthCache> mPrivateAuthCache; + nsHttpAuthCache* mAuthCache{nullptr}; + nsHttpAuthCache* mPrivateAuthCache{nullptr}; }; } // namespace net diff --git a/netwerk/protocol/http/nsHttpChannelAuthProvider.cpp b/netwerk/protocol/http/nsHttpChannelAuthProvider.cpp @@ -825,9 +825,9 @@ nsresult nsHttpChannelAuthProvider::GetCredentialsForChallenge( // in the cache have changed, in which case we'd want to give them a // try instead. // - RefPtr<nsHttpAuthEntry> entry; + nsHttpAuthEntry* entry = nullptr; (void)authCache->GetAuthEntryForDomain(scheme, host, port, realm, suffix, - entry); + &entry); // hold reference to the auth session state (in case we clear our // reference to the entry). @@ -1385,9 +1385,9 @@ NS_IMETHODIMP nsHttpChannelAuthProvider::OnAuthAvailable( } nsHttpAuthCache* authCache = gHttpHandler->AuthCache(mIsPrivate); - RefPtr<nsHttpAuthEntry> entry; + nsHttpAuthEntry* entry = nullptr; (void)authCache->GetAuthEntryForDomain(scheme, host, port, realm, suffix, - entry); + &entry); nsCOMPtr<nsISupports> sessionStateGrip; if (entry) sessionStateGrip = entry->mMetaData; @@ -1570,7 +1570,7 @@ void nsHttpChannelAuthProvider::SetAuthorizationHeader( nsHttpAuthCache* authCache, const nsHttpAtom& header, const nsACString& scheme, const nsACString& host, int32_t port, const nsACString& path, nsHttpAuthIdentity& ident) { - RefPtr<nsHttpAuthEntry> entry; + nsHttpAuthEntry* entry = nullptr; nsresult rv; // set informations that depend on whether @@ -1601,7 +1601,7 @@ void nsHttpChannelAuthProvider::SetAuthorizationHeader( GetOriginAttributesSuffix(chan, suffix); } - rv = authCache->GetAuthEntryForPath(scheme, host, port, path, suffix, entry); + rv = authCache->GetAuthEntryForPath(scheme, host, port, path, suffix, &entry); if (NS_SUCCEEDED(rv)) { // if we are trying to add a header for origin server auth and if the // URL contains an explicit username, then try the given username first. diff --git a/netwerk/protocol/http/nsHttpHandler.cpp b/netwerk/protocol/http/nsHttpHandler.cpp @@ -259,9 +259,7 @@ static nsCString DocumentAcceptHeader() { Atomic<bool, Relaxed> nsHttpHandler::sParentalControlsEnabled(false); nsHttpHandler::nsHttpHandler() - : mAuthCache(new nsHttpAuthCache()), - mPrivateAuthCache(new nsHttpAuthCache()), - mIdleTimeout(PR_SecondsToInterval(10)), + : mIdleTimeout(PR_SecondsToInterval(10)), mSpdyTimeout( PR_SecondsToInterval(StaticPrefs::network_http_http2_timeout())), mResponseTimeout(PR_SecondsToInterval(300)), @@ -2271,8 +2269,8 @@ nsHttpHandler::GetAltSvcCacheKeys(nsTArray<nsCString>& value) { NS_IMETHODIMP nsHttpHandler::GetAuthCacheKeys(nsTArray<nsCString>& aValues) { - mAuthCache->CollectKeys(aValues); - mPrivateAuthCache->CollectKeys(aValues); + mAuthCache.CollectKeys(aValues); + mPrivateAuthCache.CollectKeys(aValues); return NS_OK; } @@ -2292,8 +2290,8 @@ nsHttpHandler::Observe(nsISupports* subject, const char* topic, mHandlerActive = false; // clear cache of all authentication credentials. - mAuthCache->ClearAll(); - mPrivateAuthCache->ClearAll(); + mAuthCache.ClearAll(); + mPrivateAuthCache.ClearAll(); if (mWifiTickler) mWifiTickler->Cancel(); // Inform nsIOService that network is tearing down. @@ -2322,8 +2320,8 @@ nsHttpHandler::Observe(nsISupports* subject, const char* topic, MOZ_ASSERT(NS_SUCCEEDED(rv)); mAltSvcCache = MakeUnique<AltSvcCache>(); } else if (!strcmp(topic, "net:clear-active-logins")) { - mAuthCache->ClearAll(); - mPrivateAuthCache->ClearAll(); + mAuthCache.ClearAll(); + mPrivateAuthCache.ClearAll(); } else if (!strcmp(topic, "net:cancel-all-connections")) { if (mConnMgr) { mConnMgr->AbortAndCloseAllConnections(0, nullptr); @@ -2356,7 +2354,7 @@ nsHttpHandler::Observe(nsISupports* subject, const char* topic, nsCOMPtr<nsIURI> uri = do_QueryInterface(subject); #endif } else if (!strcmp(topic, "last-pb-context-exited")) { - mPrivateAuthCache->ClearAll(); + mPrivateAuthCache.ClearAll(); if (mAltSvcCache) { mAltSvcCache->ClearAltServiceMappings(); } diff --git a/netwerk/protocol/http/nsHttpHandler.h b/netwerk/protocol/http/nsHttpHandler.h @@ -226,7 +226,7 @@ class nsHttpHandler final : public nsIHttpProtocolHandler, FrameCheckLevel GetEnforceH1Framing() { return mEnforceH1Framing; } nsHttpAuthCache* AuthCache(bool aPrivate) { - return aPrivate ? mPrivateAuthCache : mAuthCache; + return aPrivate ? &mPrivateAuthCache : &mAuthCache; } nsHttpConnectionMgr* ConnMgr() { MOZ_ASSERT_IF(nsIOService::UseSocketProcess(), XRE_IsSocketProcess()); @@ -560,8 +560,8 @@ class nsHttpHandler final : public nsIHttpProtocolHandler, nsMainThreadPtrHandle<nsISiteSecurityService> mSSService; // the authentication credentials cache - RefPtr<nsHttpAuthCache> mAuthCache; - RefPtr<nsHttpAuthCache> mPrivateAuthCache; + nsHttpAuthCache mAuthCache; + nsHttpAuthCache mPrivateAuthCache; // the connection manager RefPtr<HttpConnectionMgrShell> mConnMgr; diff --git a/netwerk/protocol/http/nsIHttpAuthCache.idl b/netwerk/protocol/http/nsIHttpAuthCache.idl @@ -1,28 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* 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/. */ - -#include "nsISupports.idl" -#include "nsIHttpAuthEntry.idl" - -/** - * nsIHttpAuthCache - * - * Provides methods for iterating across the HTTP authentication cache entries - * for access and modification - * - */ -[builtinclass, scriptable, uuid(6ef2115c-7c67-41de-8de3-f7d412660a03)] -interface nsIHttpAuthCache : nsISupports -{ - /** - * Retrieve all HTTP auth cache entries. - */ - Array<nsIHttpAuthEntry> getEntries(); - - /** - * Clears a specified cache entry from the HTTP auth cache. - */ - void clearEntry(in nsIHttpAuthEntry entry); -}; diff --git a/netwerk/protocol/http/nsIHttpAuthEntry.idl b/netwerk/protocol/http/nsIHttpAuthEntry.idl @@ -1,43 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* 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/. */ - -#include "nsISupports.idl" - -/** - * nsIHttpAuthIdentity - * Defines an interface (domain, user, and password) - * identifying the HTTP authentication cache entry. - * - */ -[scriptable, builtinclass, uuid(5a88870b-92bd-4c2f-817a-04132caef74c)] -interface nsIHttpAuthIdentity : nsISupports -{ - readonly attribute AString domain; - readonly attribute AString user; - readonly attribute AString password; -}; - -/** - * nsIHttpAuthEntry - * Defines an interface representing a cache entry in the HTTP authentication cache. - * - */ -[scriptable, builtinclass, uuid(9bdf473d-63c2-4cf8-92f8-270e80b8aeba)] -interface nsIHttpAuthEntry : nsISupports -{ - readonly attribute ACString realm; - - readonly attribute ACString creds; - - readonly attribute ACString challenge; - - readonly attribute AString domain; - - readonly attribute AString user; - - readonly attribute AString password; - - readonly attribute nsIHttpAuthIdentity identity; -}; diff --git a/netwerk/test/mochitests/authenticate.sjs b/netwerk/test/mochitests/authenticate.sjs @@ -1,20 +0,0 @@ -/* 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/. */ - -function handleRequest(request, response) { - const expectedAuth = "Basic " + btoa("user:pass"); - - let actualAuth = request.hasHeader("Authorization") - ? request.getHeader("Authorization") - : null; - - if (actualAuth === expectedAuth) { - response.setStatusLine("1.1", 200, "OK"); - response.write("Authenticated"); - } else { - response.setStatusLine("1.1", 401, "Unauthorized"); - response.setHeader("WWW-Authenticate", 'Basic realm="TestRealm"'); - response.write("Authentication required"); - } -} diff --git a/netwerk/test/mochitests/mochitest.toml b/netwerk/test/mochitests/mochitest.toml @@ -140,9 +140,6 @@ skip-if = [ ["test_fetch_lnk.html"] -["test_http_auth_cache.html"] -support-files = ["authenticate.sjs", "../../../toolkit/components/prompts/test/prompt_common.js", "../../../toolkit/components/prompts/test/chromeScript.js"] - ["test_idn_redirect.html"] skip-if = [ "http2", diff --git a/netwerk/test/mochitests/test_http_auth_cache.html b/netwerk/test/mochitests/test_http_auth_cache.html @@ -1,82 +0,0 @@ -<!DOCTYPE HTML> -<!-- Any copyright is dedicated to the Public Domain. - - http://creativecommons.org/publicdomain/zero/1.0/ --> -<html> - <head> - <script src="/tests/SimpleTest/SimpleTest.js"></script> - <script type="text/javascript" src="../../../toolkit/components/prompts/test/prompt_common.js"></script> - </head> -<body> - <script type="application/javascript"> - - async function populateHttpAuthCache() { - await fetch("authenticate.sjs"); - } - - async function clearHttpAuthCacheTest() { - let script = SpecialPowers.loadChromeScript(function () { - /* eslint-env mozilla/chrome-script */ - const {addMessageListener, sendAsyncMessage} = this; - addMessageListener("start", function () { - try { - let httpAuthCache = Cc["@mozilla.org/network/http-auth-cache;1"] - .getService(Ci.nsIHttpAuthCache); - - let entries = httpAuthCache.getEntries(); - sendAsyncMessage("before", entries.length); - - for (let entry of entries) { - console.log(entry.realm); - httpAuthCache.clearEntry(entry); - } - - let afterEntries = httpAuthCache.getEntries(); - sendAsyncMessage("after", afterEntries.length); - } catch (e) { - console.error("Failed to get or clear the HTTP auth cache", e); - sendAsyncMessage("before", -1); - sendAsyncMessage("after", -1); - } - }); - }); - - script.sendAsyncMessage("start"); - await script.promiseOneMessage("before").then(val => { - ok(val > 0, `got ${val}, cache size before clearing should be above 0`); - }); - await script.promiseOneMessage("after").then(val => { - is(val, 0, "cache should be empty after clearing"); - }); - } - -add_task(async function () { - const state = { - msg: "This site is asking you to sign in.", - title: "Authentication Required", - textValue: "", - passValue: "", - iconClass: "authentication-icon question-icon", - titleHidden: true, - textHidden: false, - passHidden: false, - checkHidden: true, - checkMsg: "", - checked: false, - focused: "textField", - defButton: "button0", - }; - const action = { - buttonClick: "ok", - textField: "user", - passField: "pass", - }; - let promptDone = handlePrompt(state, action); - - await populateHttpAuthCache(); - await promptDone; - await clearHttpAuthCacheTest(); -}); - -</script> -</body> -</html>