#include "quiche/quic/test_tools/quic_test_client.h"
#include <memory>
#include <optional>
#include <string>
#include <utility>
#include <vector>
#include "absl/strings/match.h"
#include "absl/strings/string_view.h"
#include "openssl/x509.h"
#include "quiche/quic/core/crypto/proof_verifier.h"
#include "quiche/quic/core/http/quic_spdy_client_stream.h"
#include "quiche/quic/core/http/spdy_utils.h"
#include "quiche/quic/core/io/quic_default_event_loop.h"
#include "quiche/quic/core/quic_default_clock.h"
#include "quiche/quic/core/quic_packet_writer_wrapper.h"
#include "quiche/quic/core/quic_server_id.h"
#include "quiche/quic/core/quic_stream_priority.h"
#include "quiche/quic/core/quic_utils.h"
#include "quiche/quic/platform/api/quic_flags.h"
#include "quiche/quic/platform/api/quic_logging.h"
#include "quiche/quic/platform/api/quic_stack_trace.h"
#include "quiche/quic/test_tools/crypto_test_utils.h"
#include "quiche/quic/test_tools/quic_connection_peer.h"
#include "quiche/quic/test_tools/quic_spdy_session_peer.h"
#include "quiche/quic/test_tools/quic_spdy_stream_peer.h"
#include "quiche/quic/test_tools/quic_test_utils.h"
#include "quiche/quic/tools/quic_url.h"
#include "quiche/common/quiche_callbacks.h"
#include "quiche/common/quiche_text_utils.h"
namespace quic {
namespace test {
namespace {
class RecordingProofVerifier : public ProofVerifier { … };
}
void MockableQuicClientDefaultNetworkHelper::ProcessPacket(
const QuicSocketAddress& self_address,
const QuicSocketAddress& peer_address, const QuicReceivedPacket& packet) { … }
SocketFd MockableQuicClientDefaultNetworkHelper::CreateUDPSocket(
QuicSocketAddress server_address, bool* overflow_supported) { … }
QuicPacketWriter*
MockableQuicClientDefaultNetworkHelper::CreateQuicPacketWriter() { … }
void MockableQuicClientDefaultNetworkHelper::set_socket_fd_configurator(
quiche::MultiUseCallback<void(SocketFd)> socket_fd_configurator) { … }
const QuicReceivedPacket*
MockableQuicClientDefaultNetworkHelper::last_incoming_packet() { … }
void MockableQuicClientDefaultNetworkHelper::set_track_last_incoming_packet(
bool track) { … }
void MockableQuicClientDefaultNetworkHelper::UseWriter(
QuicPacketWriterWrapper* writer) { … }
void MockableQuicClientDefaultNetworkHelper::set_peer_address(
const QuicSocketAddress& address) { … }
MockableQuicClient::MockableQuicClient(
QuicSocketAddress server_address, const QuicServerId& server_id,
const ParsedQuicVersionVector& supported_versions,
QuicEventLoop* event_loop)
: … { … }
MockableQuicClient::MockableQuicClient(
QuicSocketAddress server_address, const QuicServerId& server_id,
const QuicConfig& config, const ParsedQuicVersionVector& supported_versions,
QuicEventLoop* event_loop)
: … { … }
MockableQuicClient::MockableQuicClient(
QuicSocketAddress server_address, const QuicServerId& server_id,
const QuicConfig& config, const ParsedQuicVersionVector& supported_versions,
QuicEventLoop* event_loop, std::unique_ptr<ProofVerifier> proof_verifier)
: … { … }
MockableQuicClient::MockableQuicClient(
QuicSocketAddress server_address, const QuicServerId& server_id,
const QuicConfig& config, const ParsedQuicVersionVector& supported_versions,
QuicEventLoop* event_loop, std::unique_ptr<ProofVerifier> proof_verifier,
std::unique_ptr<SessionCache> session_cache)
: … { … }
MockableQuicClient::~MockableQuicClient() { … }
MockableQuicClientDefaultNetworkHelper*
MockableQuicClient::mockable_network_helper() { … }
const MockableQuicClientDefaultNetworkHelper*
MockableQuicClient::mockable_network_helper() const { … }
QuicConnectionId MockableQuicClient::GetClientConnectionId() { … }
void MockableQuicClient::UseClientConnectionId(
QuicConnectionId client_connection_id) { … }
void MockableQuicClient::UseClientConnectionIdLength(
int client_connection_id_length) { … }
void MockableQuicClient::UseWriter(QuicPacketWriterWrapper* writer) { … }
void MockableQuicClient::set_peer_address(const QuicSocketAddress& address) { … }
const QuicReceivedPacket* MockableQuicClient::last_incoming_packet() { … }
void MockableQuicClient::set_track_last_incoming_packet(bool track) { … }
QuicTestClient::QuicTestClient(
QuicSocketAddress server_address, const std::string& server_hostname,
const ParsedQuicVersionVector& supported_versions)
: … { … }
QuicTestClient::QuicTestClient(
QuicSocketAddress server_address, const std::string& server_hostname,
const QuicConfig& config, const ParsedQuicVersionVector& supported_versions)
: … { … }
QuicTestClient::QuicTestClient(
QuicSocketAddress server_address, const std::string& server_hostname,
const QuicConfig& config, const ParsedQuicVersionVector& supported_versions,
std::unique_ptr<ProofVerifier> proof_verifier)
: … { … }
QuicTestClient::QuicTestClient(
QuicSocketAddress server_address, const std::string& server_hostname,
const QuicConfig& config, const ParsedQuicVersionVector& supported_versions,
std::unique_ptr<ProofVerifier> proof_verifier,
std::unique_ptr<SessionCache> session_cache)
: … { … }
QuicTestClient::QuicTestClient(
QuicSocketAddress server_address, const std::string& server_hostname,
const QuicConfig& config, const ParsedQuicVersionVector& supported_versions,
std::unique_ptr<ProofVerifier> proof_verifier,
std::unique_ptr<SessionCache> session_cache,
std::unique_ptr<QuicEventLoop> event_loop)
: … { … }
QuicTestClient::QuicTestClient() = default;
QuicTestClient::~QuicTestClient() { … }
void QuicTestClient::Initialize() { … }
void QuicTestClient::SetUserAgentID(const std::string& user_agent_id) { … }
int64_t QuicTestClient::SendRequest(const std::string& uri) { … }
int64_t QuicTestClient::SendRequestAndRstTogether(const std::string& uri) { … }
void QuicTestClient::SendRequestsAndWaitForResponses(
const std::vector<std::string>& url_list) { … }
int64_t QuicTestClient::GetOrCreateStreamAndSendRequest(
const quiche::HttpHeaderBlock* headers, absl::string_view body, bool fin,
quiche::QuicheReferenceCountedPointer<QuicAckListenerInterface>
ack_listener) { … }
int64_t QuicTestClient::SendMessage(const quiche::HttpHeaderBlock& headers,
absl::string_view body) { … }
int64_t QuicTestClient::SendMessage(const quiche::HttpHeaderBlock& headers,
absl::string_view body, bool fin) { … }
int64_t QuicTestClient::SendMessage(const quiche::HttpHeaderBlock& headers,
absl::string_view body, bool fin,
bool flush) { … }
int64_t QuicTestClient::SendData(const std::string& data, bool last_data) { … }
int64_t QuicTestClient::SendData(
const std::string& data, bool last_data,
quiche::QuicheReferenceCountedPointer<QuicAckListenerInterface>
ack_listener) { … }
bool QuicTestClient::response_complete() const { … }
int64_t QuicTestClient::response_body_size() const { … }
bool QuicTestClient::buffer_body() const { … }
void QuicTestClient::set_buffer_body(bool buffer_body) { … }
const std::string& QuicTestClient::response_body() const { … }
std::string QuicTestClient::SendCustomSynchronousRequest(
const quiche::HttpHeaderBlock& headers, const std::string& body) { … }
std::string QuicTestClient::SendSynchronousRequest(const std::string& uri) { … }
void QuicTestClient::SendConnectivityProbing() { … }
void QuicTestClient::SetLatestCreatedStream(QuicSpdyClientStream* stream) { … }
QuicSpdyClientStream* QuicTestClient::GetOrCreateStream() { … }
QuicErrorCode QuicTestClient::connection_error() const { … }
const std::string& QuicTestClient::cert_common_name() const { … }
const std::string& QuicTestClient::cert_sct() const { … }
const QuicTagValueMap& QuicTestClient::GetServerConfig() const { … }
bool QuicTestClient::connected() const { … }
void QuicTestClient::Connect() { … }
void QuicTestClient::ResetConnection() { … }
void QuicTestClient::Disconnect() { … }
QuicSocketAddress QuicTestClient::local_address() const { … }
void QuicTestClient::ClearPerRequestState() { … }
bool QuicTestClient::HaveActiveStream() { … }
bool QuicTestClient::WaitUntil(
int timeout_ms, std::optional<quiche::UnretainedCallback<bool()>> trigger) { … }
int64_t QuicTestClient::Send(absl::string_view data) { … }
bool QuicTestClient::response_headers_complete() const { … }
const quiche::HttpHeaderBlock* QuicTestClient::response_headers() const { … }
const quiche::HttpHeaderBlock& QuicTestClient::response_trailers() const { … }
int64_t QuicTestClient::response_size() const { … }
size_t QuicTestClient::bytes_read() const { … }
size_t QuicTestClient::bytes_written() const { … }
absl::string_view QuicTestClient::partial_response_body() const { … }
void QuicTestClient::OnClose(QuicSpdyStream* stream) { … }
void QuicTestClient::UseWriter(QuicPacketWriterWrapper* writer) { … }
void QuicTestClient::UseConnectionId(QuicConnectionId server_connection_id) { … }
void QuicTestClient::UseConnectionIdLength(
uint8_t server_connection_id_length) { … }
void QuicTestClient::UseClientConnectionId(
QuicConnectionId client_connection_id) { … }
void QuicTestClient::UseClientConnectionIdLength(
uint8_t client_connection_id_length) { … }
bool QuicTestClient::MigrateSocket(const QuicIpAddress& new_host) { … }
bool QuicTestClient::MigrateSocketWithSpecifiedPort(
const QuicIpAddress& new_host, int port) { … }
QuicIpAddress QuicTestClient::bind_to_address() const { … }
void QuicTestClient::set_bind_to_address(QuicIpAddress address) { … }
const QuicSocketAddress& QuicTestClient::address() const { … }
void QuicTestClient::WaitForWriteToFlush() { … }
QuicTestClient::PerStreamState::PerStreamState(const PerStreamState& other)
: … { … }
QuicTestClient::PerStreamState::PerStreamState(
QuicRstStreamErrorCode stream_error, bool response_complete,
bool response_headers_complete,
const quiche::HttpHeaderBlock& response_headers,
const std::string& response,
const quiche::HttpHeaderBlock& response_trailers, uint64_t bytes_read,
uint64_t bytes_written, int64_t response_body_size)
: … { … }
QuicTestClient::PerStreamState::~PerStreamState() = default;
bool QuicTestClient::PopulateHeaderBlockFromUrl(
const std::string& uri, quiche::HttpHeaderBlock* headers) { … }
void QuicTestClient::ReadNextResponse() { … }
void QuicTestClient::ClearPerConnectionState() { … }
void QuicTestClient::WaitForDelayedAcks() { … }
}
}