Commit 6635d470 authored by Chris Thompson's avatar Chris Thompson Committed by Chromium LUCI CQ

Fix flaky test LegacyTLSInterstitialTest.FixedServerDropsBypass

This replaces the use of multiple EmbeddedTestServer instances with
reused ports (which can be flaky if the ports become unavailable) with
URLLoaderInterceptor which can simulate the legacy TLS and modern TLS
connections for the same server/cert.

Bug: 1150403,1153702
Change-Id: I909199c91c030648d5e81c32d2a880ca6b8a32c8
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2601716
Auto-Submit: Chris Thompson <cthomp@chromium.org>
Reviewed-by: default avatarEmily Stark <estark@chromium.org>
Commit-Queue: Chris Thompson <cthomp@chromium.org>
Cr-Commit-Position: refs/heads/master@{#839133}
parent a0f3ef2c
...@@ -150,6 +150,7 @@ ...@@ -150,6 +150,7 @@
#include "content/public/test/test_navigation_observer.h" #include "content/public/test/test_navigation_observer.h"
#include "content/public/test/test_renderer_host.h" #include "content/public/test/test_renderer_host.h"
#include "content/public/test/test_utils.h" #include "content/public/test/test_utils.h"
#include "content/public/test/url_loader_interceptor.h"
#include "crypto/sha2.h" #include "crypto/sha2.h"
#include "extensions/browser/event_router.h" #include "extensions/browser/event_router.h"
#include "mojo/public/cpp/bindings/associated_remote.h" #include "mojo/public/cpp/bindings/associated_remote.h"
...@@ -7903,47 +7904,53 @@ IN_PROC_BROWSER_TEST_F(LegacyTLSInterstitialTest, PolicyOverridesInterstitial) { ...@@ -7903,47 +7904,53 @@ IN_PROC_BROWSER_TEST_F(LegacyTLSInterstitialTest, PolicyOverridesInterstitial) {
// Check that if we have bypassed the legacy TLS error previously and then the // Check that if we have bypassed the legacy TLS error previously and then the
// server responded with TLS 1.2, we drop the error exception. // server responded with TLS 1.2, we drop the error exception.
// Disabled due to flakiness. crbug.com/1153702 IN_PROC_BROWSER_TEST_F(LegacyTLSInterstitialTest, FixedServerDropsBypass) {
#if defined(OS_MAC) GURL kSiteWithLegacyTLS("https://example.test/legacy-tls");
#define MAYBE_FixedServerDropsBypass DISABLED_FixedServerDropsBypass GURL kSiteWithModernTLS("https://example.test/modern-tls");
#else
#define MAYBE_FixedServerDropsBypass FixedServerDropsBypass // EmbeddedTestServer can be flakey if forcing a specific port (as the port
#endif // may no longer be available on the system). URLLoaderInterceptor can mock
IN_PROC_BROWSER_TEST_F(LegacyTLSInterstitialTest, // out the responses as needed instead, reusing the same port across variants.
MAYBE_FixedServerDropsBypass) { auto url_loader_interceptor = std::make_unique<content::URLLoaderInterceptor>(
int port; // Save the port used so the different servers can be "identical". base::BindLambdaForTesting(
[=](content::URLLoaderInterceptor::RequestParams* params) {
network::URLLoaderCompletionStatus status;
status.ssl_info = net::SSLInfo();
status.ssl_info->cert = net::ImportCertFromFile(
net::GetTestCertsDirectory(), "ok_cert.pem");
status.ssl_info->unverified_cert = status.ssl_info->cert;
if (params->url_request.url == GURL(kSiteWithLegacyTLS)) {
status.error_code = net::ERR_SSL_OBSOLETE_VERSION;
status.ssl_info->cert_status = net::CERT_STATUS_LEGACY_TLS;
params->client->OnComplete(status);
return true;
}
status.error_code = net::OK;
std::string headers =
"HTTP/1.1 200 OK\nContent-Type: text/html; charset=utf-8\n";
std::string body = "<html><title>Success</title>Hello world</html>";
content::URLLoaderInterceptor::WriteResponse(headers, body,
params->client.get());
return true;
}));
// Connect over TLS 1.0 and proceed through the interstitial to set an error // Connect over TLS 1.0 and proceed through the interstitial to set an error
// bypass. // bypass.
SetTLSVersion(net::SSL_PROTOCOL_VERSION_TLS1); ui_test_utils::NavigateToURL(browser(), kSiteWithLegacyTLS);
ASSERT_TRUE(https_server()->Start());
port = https_server()->port();
ui_test_utils::NavigateToURL(browser(),
https_server()->GetURL("/ssl/google.html"));
auto* tab = browser()->tab_strip_model()->GetActiveWebContents(); auto* tab = browser()->tab_strip_model()->GetActiveWebContents();
WaitForInterstitial(tab); WaitForInterstitial(tab);
ProceedThroughInterstitial(tab); ProceedThroughInterstitial(tab);
ASSERT_TRUE(https_server()->ShutdownAndWaitUntilComplete());
// Connect over a "fixed" TLS 1.2 connection. // Connect over a "fixed" TLS 1.2 connection.
net::EmbeddedTestServer tls12_server(net::EmbeddedTestServer::TYPE_HTTPS); ui_test_utils::NavigateToURL(browser(), kSiteWithModernTLS);
ASSERT_TRUE(tls12_server.Start(port));
ui_test_utils::NavigateToURL(browser(),
tls12_server.GetURL("/ssl/google.html"));
EXPECT_FALSE( EXPECT_FALSE(
chrome_browser_interstitials::IsShowingLegacyTLSInterstitial(tab)); chrome_browser_interstitials::IsShowingLegacyTLSInterstitial(tab));
ASSERT_TRUE(tls12_server.ShutdownAndWaitUntilComplete());
// Go back to connecting over TLS 1.0. Visiting should once again show the // Go back to connecting over TLS 1.0. Visiting should once again show the
// legacy TLS interstitial // legacy TLS interstitial
net::EmbeddedTestServer tls1_server(net::EmbeddedTestServer::TYPE_HTTPS); ui_test_utils::NavigateToURL(browser(), kSiteWithLegacyTLS);
net::SSLServerConfig config;
config.version_max = net::SSL_PROTOCOL_VERSION_TLS1;
config.version_min = net::SSL_PROTOCOL_VERSION_TLS1;
tls1_server.SetSSLConfig(net::EmbeddedTestServer::CERT_OK, config);
ASSERT_TRUE(tls1_server.Start(port));
ui_test_utils::NavigateToURL(browser(),
tls1_server.GetURL("/ssl/google.html"));
WaitForInterstitial(tab); WaitForInterstitial(tab);
EXPECT_TRUE( EXPECT_TRUE(
chrome_browser_interstitials::IsShowingLegacyTLSInterstitial(tab)); chrome_browser_interstitials::IsShowingLegacyTLSInterstitial(tab));
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment