chromium/net/http/http_proxy_connect_job_unittest.cc

// Copyright 2019 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "net/http/http_proxy_connect_job.h"

#include <algorithm>
#include <map>
#include <string>
#include <utility>

#include "base/metrics/field_trial.h"
#include "base/metrics/field_trial_param_associator.h"
#include "base/metrics/field_trial_params.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_util.h"
#include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.h"
#include "base/test/metrics/histogram_tester.h"
#include "base/test/scoped_feature_list.h"
#include "base/test/task_environment.h"
#include "base/time/time.h"
#include "build/build_config.h"
#include "net/base/features.h"
#include "net/base/hex_utils.h"
#include "net/base/host_port_pair.h"
#include "net/base/net_errors.h"
#include "net/base/network_anonymization_key.h"
#include "net/base/proxy_chain.h"
#include "net/base/proxy_string_util.h"
#include "net/base/session_usage.h"
#include "net/base/test_proxy_delegate.h"
#include "net/cert/mock_cert_verifier.h"
#include "net/dns/mock_host_resolver.h"
#include "net/dns/public/secure_dns_policy.h"
#include "net/http/http_network_session.h"
#include "net/http/http_response_headers.h"
#include "net/http/http_server_properties.h"
#include "net/http/transport_security_state.h"
#include "net/nqe/network_quality_estimator_test_util.h"
#include "net/quic/quic_context.h"
#include "net/quic/quic_session_pool.h"
#include "net/socket/client_socket_handle.h"
#include "net/socket/connect_job_test_util.h"
#include "net/socket/socket_test_util.h"
#include "net/socket/socks_connect_job.h"
#include "net/socket/ssl_client_socket.h"
#include "net/socket/ssl_connect_job.h"
#include "net/socket/transport_connect_job.h"
#include "net/spdy/spdy_test_util_common.h"
#include "net/ssl/ssl_connection_status_flags.h"
#include "net/test/cert_test_util.h"
#include "net/test/gtest_util.h"
#include "net/test/test_data_directory.h"
#include "net/test/test_with_task_environment.h"
#include "net/third_party/quiche/src/quiche/quic/core/quic_versions.h"
#include "net/traffic_annotation/network_traffic_annotation_test_helper.h"
#include "net/url_request/static_http_user_agent_settings.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "url/gurl.h"
#include "url/scheme_host_port.h"

_;

namespace net {

namespace {

const char kEndpointHost[] =;

enum HttpProxyType {};

const char kHttpProxyHost[] =;
const char kHttpsProxyHost[] =;
const char kQuicProxyHost[] =;
const char kHttpsNestedProxyHost[] =;

const ProxyServer kHttpProxyServer{};
const ProxyServer kHttpsProxyServer{};
const ProxyServer kHttpsNestedProxyServer{};

const ProxyChain kHttpProxyChain{};
const ProxyChain kHttpsProxyChain{};
const ProxyChain kHttpsNestedProxyChain{};

constexpr char kTestHeaderName[] =;
// Note: `kTestSpdyHeaderName` should be a lowercase version of
// `kTestHeaderName`.
constexpr char kTestSpdyHeaderName[] =;

// Match QuicStreamRequests' proxy chains.
MATCHER_P(QSRHasProxyChain,
          proxy_chain,
          base::StringPrintf("QuicStreamRequest %s ProxyChain %s",
                             negation ? "does not have" : "has",
                             proxy_chain.ToDebugString().c_str())) {}

MATCHER_P(
    IsQuicVersion,
    quic_version,
    base::StringPrintf("QUIC version %s %s",
                       negation ? "is not" : "is",
                       quic::ParsedQuicVersionToString(quic_version).c_str())) {}

}  // namespace

class HttpProxyConnectJobTestBase : public WithTaskEnvironment {};

class HttpProxyConnectJobTest : public HttpProxyConnectJobTestBase,
                                public ::testing::TestWithParam<HttpProxyType> {};

// All tests are run with three different proxy types: HTTP, HTTPS (non-SPDY)
// and SPDY.
INSTANTIATE_TEST_SUITE_P();

TEST_P(HttpProxyConnectJobTest, NoTunnel) {}

// Pauses an HttpProxyConnectJob at various states, and check the value of
// HasEstablishedConnection().
TEST_P(HttpProxyConnectJobTest, HasEstablishedConnectionNoTunnel) {}

// Pauses an HttpProxyConnectJob at various states, and check the value of
// HasEstablishedConnection().
TEST_P(HttpProxyConnectJobTest, HasEstablishedConnectionTunnel) {}

TEST_P(HttpProxyConnectJobTest, ProxyDelegateExtraHeaders) {}

// Test HTTP CONNECTs and SPDY CONNECTs through two proxies
// (HTTPS -> HTTPS -> HTTPS and SPDY -> SPDY -> HTTPS).
TEST_P(HttpProxyConnectJobTest, NestedProxyProxyDelegateExtraHeaders) {}

// Test the case where auth credentials are not cached.
TEST_P(HttpProxyConnectJobTest, NeedAuth) {}

// Test the case where auth credentials are not cached and the first time
// credentials are sent, they are rejected.
TEST_P(HttpProxyConnectJobTest, NeedAuthTwice) {}

// Test the case where auth credentials are cached.
TEST_P(HttpProxyConnectJobTest, HaveAuth) {}

TEST_P(HttpProxyConnectJobTest, HostResolutionFailure) {}

TEST_P(HttpProxyConnectJobTest, RequestPriority) {}

TEST_P(HttpProxyConnectJobTest, SecureDnsPolicy) {}

TEST_P(HttpProxyConnectJobTest, SpdySessionKeyDisableSecureDns) {}

// Make sure that HttpProxyConnectJob does not pass on its priority to its
// SPDY session's socket request on Init, or on SetPriority.
TEST_P(HttpProxyConnectJobTest, SetSpdySessionSocketRequestPriority) {}

TEST_P(HttpProxyConnectJobTest, SpdyInadequateTransportSecurity) {}

TEST_P(HttpProxyConnectJobTest, SpdyValidAlps) {}

TEST_P(HttpProxyConnectJobTest, SpdyInvalidAlpsCheckEnabled) {}

TEST_P(HttpProxyConnectJobTest, SpdyInvalidAlpsCheckDisabled) {}

TEST_P(HttpProxyConnectJobTest, TCPError) {}

TEST_P(HttpProxyConnectJobTest, SSLError) {}

TEST_P(HttpProxyConnectJobTest, TunnelUnexpectedClose) {}

TEST_P(HttpProxyConnectJobTest, Tunnel1xxResponse) {}

TEST_P(HttpProxyConnectJobTest, TunnelSetupError) {}

TEST_P(HttpProxyConnectJobTest, SslClientAuth) {}

TEST_P(HttpProxyConnectJobTest, TunnelSetupRedirect) {}

// Test timeouts in the case of an auth challenge and response.
TEST_P(HttpProxyConnectJobTest, TestTimeoutsAuthChallenge) {}

// Same as above, except test the case the first connection cannot be reused
// once credentials are received.
TEST_P(HttpProxyConnectJobTest, TestTimeoutsAuthChallengeNewConnection) {}

TEST_P(HttpProxyConnectJobTest, ConnectionTimeoutNoNQE) {}

TEST_P(HttpProxyConnectJobTest, ConnectionTimeoutMin) {}

TEST_P(HttpProxyConnectJobTest, ConnectionTimeoutMax) {}

// Tests the connection timeout values when the field trial parameters are
// specified.
TEST_P(HttpProxyConnectJobTest, ConnectionTimeoutWithExperiment) {}

// Tests the connection timeout values when the field trial parameters are
// specified.
TEST_P(HttpProxyConnectJobTest, ConnectionTimeoutExperimentDifferentParams) {}

TEST_P(HttpProxyConnectJobTest, ConnectionTimeoutWithConnectionProperty) {}

// Tests the connection timeout values when the field trial parameters are not
// specified.
TEST_P(HttpProxyConnectJobTest, ProxyPoolTimeoutWithExperimentDefaultParams) {}

// A Mock QuicSessionPool which can intercept calls to RequestSession.
class MockQuicSessionPool : public QuicSessionPool {};

class HttpProxyConnectQuicJobTest : public HttpProxyConnectJobTestBase,
                                    public testing::Test {};

// Test that a QUIC session is properly requested from the QuicSessionPool.
TEST_F(HttpProxyConnectQuicJobTest, RequestQuicProxy) {}

// Test that for QUIC sessions to the proxy, version RFCv1 is used.
TEST_F(HttpProxyConnectQuicJobTest, QuicProxyRequestUsesRfcV1) {}

// Test that a QUIC session is properly requested from the QuicSessionPool,
// including a ProxyChain containing additional QUIC proxies, but excluding any
// proxies later in the chain.
TEST_F(HttpProxyConnectQuicJobTest, RequestMultipleQuicProxies) {}

}  // namespace net