tests: Fix HSTS-related test failures

This commit is contained in:
Marshall Greenblatt 2024-11-15 13:57:38 -05:00
parent 7abba8b86d
commit 89ab864065
3 changed files with 19 additions and 37 deletions

View File

@ -7,6 +7,7 @@
#include "base/files/file_path.h"
#include "base/path_service.h"
#include "cef/include/test/cef_test_helpers.h"
#include "net/base/features.h"
#include "services/network/public/cpp/features.h"
void CefSetDataDirectoryForTests(const CefString& dir) {
@ -18,6 +19,7 @@ void CefSetDataDirectoryForTests(const CefString& dir) {
bool CefIsFeatureEnabledForTests(const CefString& feature_name) {
// Only includes values that are queried by unit tests.
const base::Feature* features[] = {
&net::features::kIgnoreHSTSForLocalhost,
&base::features::kUseRustJsonParser,
&network::features::kReduceAcceptLanguage,
};

View File

@ -357,13 +357,11 @@ namespace {
class RedirectMismatchedFromHandlerTest : public CertificateErrorTest {
public:
RedirectMismatchedFromHandlerTest(bool continue_invalid_certificate,
bool redirect_from_https)
RedirectMismatchedFromHandlerTest(bool continue_invalid_certificate)
: CertificateErrorTest(
/*cert_type=*/CEF_TEST_CERT_OK_DOMAIN,
/*expect_load_success=*/continue_invalid_certificate,
/*expect_certificate_error=*/true),
redirect_from_https_(redirect_from_https) {}
/*expect_certificate_error=*/true) {}
CefRefPtr<CefResourceHandler> GetResourceHandler(
CefRefPtr<CefBrowser> browser,
@ -384,8 +382,7 @@ class RedirectMismatchedFromHandlerTest : public CertificateErrorTest {
protected:
std::string GetStartURL() const override {
return redirect_from_https_ ? "https://certificate-test.com/index.html"
: "http://certificate-test.com/index.html";
return "https://certificate-test.com/index.html";
}
std::string GetEndURL() const override {
@ -393,9 +390,6 @@ class RedirectMismatchedFromHandlerTest : public CertificateErrorTest {
return client::AsciiStrReplace(server_origin(), "localhost", "127.0.0.1") +
"/index.html";
}
private:
const bool redirect_from_https_;
};
} // namespace
@ -403,8 +397,7 @@ class RedirectMismatchedFromHandlerTest : public CertificateErrorTest {
TEST(CertificateErrorTest, RedirectMismatchedFromHttpsResourceCancel) {
CefRefPtr<RedirectMismatchedFromHandlerTest> handler =
new RedirectMismatchedFromHandlerTest(
/*continue_invalid_certificate=*/false,
/*redirect_from_https=*/true);
/*continue_invalid_certificate=*/false);
handler->ExecuteTest();
ReleaseAndWaitForDestructor(handler);
}
@ -412,26 +405,7 @@ TEST(CertificateErrorTest, RedirectMismatchedFromHttpsResourceCancel) {
TEST(CertificateErrorTest, RedirectMismatchedFromHttpsResourceContinue) {
CefRefPtr<RedirectMismatchedFromHandlerTest> handler =
new RedirectMismatchedFromHandlerTest(
/*continue_invalid_certificate=*/true,
/*redirect_from_https=*/true);
handler->ExecuteTest();
ReleaseAndWaitForDestructor(handler);
}
TEST(CertificateErrorTest, RedirectMismatchedFromHttpResourceCancel) {
CefRefPtr<RedirectMismatchedFromHandlerTest> handler =
new RedirectMismatchedFromHandlerTest(
/*continue_invalid_certificate=*/false,
/*redirect_from_https=*/false);
handler->ExecuteTest();
ReleaseAndWaitForDestructor(handler);
}
TEST(CertificateErrorTest, RedirectMismatchedFromHttpResourceContinue) {
CefRefPtr<RedirectMismatchedFromHandlerTest> handler =
new RedirectMismatchedFromHandlerTest(
/*continue_invalid_certificate=*/true,
/*redirect_from_https=*/false);
/*continue_invalid_certificate=*/true);
handler->ExecuteTest();
ReleaseAndWaitForDestructor(handler);
}

View File

@ -3,6 +3,7 @@
// can be found in the LICENSE file.
#include "include/base/cef_callback.h"
#include "include/test/cef_test_helpers.h"
#include "include/wrapper/cef_closure_task.h"
#include "tests/ceftests/test_handler.h"
#include "tests/ceftests/test_server.h"
@ -178,6 +179,10 @@ class HSTSRedirectTest : public TestHandler {
// explicit port component that is not equal to "80", the port component
// value MUST be preserved; otherwise, if the URI does not contain an
// explicit port component, the UA MUST NOT add one.
//
// This behavior is changed in M132 with
// https://issues.chromium.org/issues/41251622.
if (!CefIsFeatureEnabledForTests("IgnoreHSTSForLocalhost")) {
const std::string& expected_https_url =
client::AsciiStrReplace(http_url_, "http:", "https:");
EXPECT_STREQ(expected_https_url.c_str(), new_url.ToString().c_str())
@ -187,6 +192,7 @@ class HSTSRedirectTest : public TestHandler {
new_url = https_url_;
}
}
}
void OnLoadEnd(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,