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

View File

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

View File

@ -3,6 +3,7 @@
// can be found in the LICENSE file. // can be found in the LICENSE file.
#include "include/base/cef_callback.h" #include "include/base/cef_callback.h"
#include "include/test/cef_test_helpers.h"
#include "include/wrapper/cef_closure_task.h" #include "include/wrapper/cef_closure_task.h"
#include "tests/ceftests/test_handler.h" #include "tests/ceftests/test_handler.h"
#include "tests/ceftests/test_server.h" #include "tests/ceftests/test_server.h"
@ -178,13 +179,18 @@ class HSTSRedirectTest : public TestHandler {
// explicit port component that is not equal to "80", the port component // explicit port component that is not equal to "80", the port component
// value MUST be preserved; otherwise, if the URI does not contain an // value MUST be preserved; otherwise, if the URI does not contain an
// explicit port component, the UA MUST NOT add one. // explicit port component, the UA MUST NOT add one.
const std::string& expected_https_url = //
client::AsciiStrReplace(http_url_, "http:", "https:"); // This behavior is changed in M132 with
EXPECT_STREQ(expected_https_url.c_str(), new_url.ToString().c_str()) // https://issues.chromium.org/issues/41251622.
<< nav_ct_; 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())
<< nav_ct_;
// Redirect to the correct HTTPS URL instead. // Redirect to the correct HTTPS URL instead.
new_url = https_url_; new_url = https_url_;
}
} }
} }