#ifdef UNSAFE_BUFFERS_BUILD
#pragma allow_unsafe_buffers
#endif
#include "net/test/embedded_test_server/embedded_test_server.h"
#include <stdint.h>
#include <memory>
#include <optional>
#include <string_view>
#include <utility>
#include "base/files/file_path.h"
#include "base/functional/bind.h"
#include "base/functional/callback_forward.h"
#include "base/functional/callback_helpers.h"
#include "base/location.h"
#include "base/logging.h"
#include "base/message_loop/message_pump_type.h"
#include "base/path_service.h"
#include "base/process/process_metrics.h"
#include "base/run_loop.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_util.h"
#include "base/strings/stringprintf.h"
#include "base/task/current_thread.h"
#include "base/task/single_thread_task_executor.h"
#include "base/task/single_thread_task_runner.h"
#include "base/test/bind.h"
#include "base/threading/thread_restrictions.h"
#include "crypto/rsa_private_key.h"
#include "net/base/hex_utils.h"
#include "net/base/ip_address.h"
#include "net/base/ip_endpoint.h"
#include "net/base/net_errors.h"
#include "net/base/port_util.h"
#include "net/log/net_log_source.h"
#include "net/socket/next_proto.h"
#include "net/socket/ssl_server_socket.h"
#include "net/socket/stream_socket.h"
#include "net/socket/tcp_server_socket.h"
#include "net/spdy/spdy_test_util_common.h"
#include "net/ssl/ssl_info.h"
#include "net/ssl/ssl_server_config.h"
#include "net/test/cert_builder.h"
#include "net/test/cert_test_util.h"
#include "net/test/embedded_test_server/default_handlers.h"
#include "net/test/embedded_test_server/embedded_test_server_connection_listener.h"
#include "net/test/embedded_test_server/http_request.h"
#include "net/test/embedded_test_server/http_response.h"
#include "net/test/embedded_test_server/request_handler_util.h"
#include "net/test/key_util.h"
#include "net/test/revocation_builder.h"
#include "net/test/test_data_directory.h"
#include "net/third_party/quiche/src/quiche/spdy/core/spdy_frame_builder.h"
#include "third_party/boringssl/src/pki/extended_key_usage.h"
#include "url/origin.h"
namespace net::test_server {
namespace {
std::unique_ptr<HttpResponse> ServeResponseForPath(
const std::string& expected_path,
HttpStatusCode status_code,
const std::string& content_type,
const std::string& content,
const HttpRequest& request) { … }
std::unique_ptr<HttpResponse> ServeResponseForSubPaths(
const std::string& expected_path,
HttpStatusCode status_code,
const std::string& content_type,
const std::string& content,
const HttpRequest& request) { … }
bool MaybeCreateOCSPResponse(CertBuilder* target,
const EmbeddedTestServer::OCSPConfig& config,
std::string* out_response) { … }
void DispatchResponseToDelegate(std::unique_ptr<HttpResponse> response,
base::WeakPtr<HttpResponseDelegate> delegate) { … }
}
EmbeddedTestServerHandle::EmbeddedTestServerHandle(
EmbeddedTestServerHandle&& other) { … }
EmbeddedTestServerHandle& EmbeddedTestServerHandle::operator=(
EmbeddedTestServerHandle&& other) { … }
EmbeddedTestServerHandle::EmbeddedTestServerHandle(
EmbeddedTestServer* test_server)
: … { … }
EmbeddedTestServerHandle::~EmbeddedTestServerHandle() { … }
EmbeddedTestServer::OCSPConfig::OCSPConfig() = default;
EmbeddedTestServer::OCSPConfig::OCSPConfig(ResponseType response_type)
: … { … }
EmbeddedTestServer::OCSPConfig::OCSPConfig(
std::vector<SingleResponse> single_responses,
Produced produced)
: … { … }
EmbeddedTestServer::OCSPConfig::OCSPConfig(const OCSPConfig&) = default;
EmbeddedTestServer::OCSPConfig::OCSPConfig(OCSPConfig&&) = default;
EmbeddedTestServer::OCSPConfig::~OCSPConfig() = default;
EmbeddedTestServer::OCSPConfig& EmbeddedTestServer::OCSPConfig::operator=(
const OCSPConfig&) = default;
EmbeddedTestServer::OCSPConfig& EmbeddedTestServer::OCSPConfig::operator=(
OCSPConfig&&) = default;
EmbeddedTestServer::ServerCertificateConfig::ServerCertificateConfig() =
default;
EmbeddedTestServer::ServerCertificateConfig::ServerCertificateConfig(
const ServerCertificateConfig&) = default;
EmbeddedTestServer::ServerCertificateConfig::ServerCertificateConfig(
ServerCertificateConfig&&) = default;
EmbeddedTestServer::ServerCertificateConfig::~ServerCertificateConfig() =
default;
EmbeddedTestServer::ServerCertificateConfig&
EmbeddedTestServer::ServerCertificateConfig::operator=(
const ServerCertificateConfig&) = default;
EmbeddedTestServer::ServerCertificateConfig&
EmbeddedTestServer::ServerCertificateConfig::operator=(
ServerCertificateConfig&&) = default;
EmbeddedTestServer::EmbeddedTestServer() : … { … }
EmbeddedTestServer::EmbeddedTestServer(Type type,
HttpConnection::Protocol protocol)
: … { … }
EmbeddedTestServer::~EmbeddedTestServer() { … }
ScopedTestRoot EmbeddedTestServer::RegisterTestCerts() { … }
void EmbeddedTestServer::SetConnectionListener(
EmbeddedTestServerConnectionListener* listener) { … }
EmbeddedTestServerHandle EmbeddedTestServer::StartAndReturnHandle(int port) { … }
bool EmbeddedTestServer::Start(int port, std::string_view address) { … }
bool EmbeddedTestServer::InitializeAndListen(int port,
std::string_view address) { … }
bool EmbeddedTestServer::UsingStaticCert() const { … }
bool EmbeddedTestServer::InitializeCertAndKeyFromFile() { … }
bool EmbeddedTestServer::GenerateCertAndKey() { … }
bool EmbeddedTestServer::InitializeSSLServerContext() { … }
EmbeddedTestServerHandle
EmbeddedTestServer::StartAcceptingConnectionsAndReturnHandle() { … }
void EmbeddedTestServer::StartAcceptingConnections() { … }
bool EmbeddedTestServer::ShutdownAndWaitUntilComplete() { … }
base::FilePath EmbeddedTestServer::GetRootCertPemPath() { … }
void EmbeddedTestServer::ShutdownOnIOThread() { … }
HttpConnection* EmbeddedTestServer::GetConnectionForSocket(
const StreamSocket* socket) { … }
void EmbeddedTestServer::HandleRequest(
base::WeakPtr<HttpResponseDelegate> delegate,
std::unique_ptr<HttpRequest> request,
const StreamSocket* socket) { … }
GURL EmbeddedTestServer::GetURL(std::string_view relative_url) const { … }
GURL EmbeddedTestServer::GetURL(std::string_view hostname,
std::string_view relative_url) const { … }
url::Origin EmbeddedTestServer::GetOrigin(
const std::optional<std::string>& hostname) const { … }
bool EmbeddedTestServer::GetAddressList(AddressList* address_list) const { … }
std::string EmbeddedTestServer::GetIPLiteralString() const { … }
void EmbeddedTestServer::SetSSLConfigInternal(
ServerCertificate cert,
const ServerCertificateConfig* cert_config,
const SSLServerConfig& ssl_config) { … }
void EmbeddedTestServer::SetSSLConfig(ServerCertificate cert,
const SSLServerConfig& ssl_config) { … }
void EmbeddedTestServer::SetSSLConfig(ServerCertificate cert) { … }
void EmbeddedTestServer::SetSSLConfig(
const ServerCertificateConfig& cert_config,
const SSLServerConfig& ssl_config) { … }
void EmbeddedTestServer::SetSSLConfig(
const ServerCertificateConfig& cert_config) { … }
void EmbeddedTestServer::SetCertHostnames(std::vector<std::string> hostnames) { … }
bool EmbeddedTestServer::ResetSSLConfigOnIOThread(
ServerCertificate cert,
const SSLServerConfig& ssl_config) { … }
bool EmbeddedTestServer::ResetSSLConfig(ServerCertificate cert,
const SSLServerConfig& ssl_config) { … }
std::string EmbeddedTestServer::GetCertificateName() const { … }
scoped_refptr<X509Certificate> EmbeddedTestServer::GetCertificate() { … }
scoped_refptr<X509Certificate> EmbeddedTestServer::GetGeneratedIntermediate() { … }
scoped_refptr<X509Certificate> EmbeddedTestServer::GetRoot() { … }
void EmbeddedTestServer::ServeFilesFromDirectory(
const base::FilePath& directory) { … }
void EmbeddedTestServer::ServeFilesFromSourceDirectory(
std::string_view relative) { … }
void EmbeddedTestServer::ServeFilesFromSourceDirectory(
const base::FilePath& relative) { … }
void EmbeddedTestServer::AddDefaultHandlers(const base::FilePath& directory) { … }
void EmbeddedTestServer::AddDefaultHandlers() { … }
base::FilePath EmbeddedTestServer::GetFullPathFromSourceDirectory(
const base::FilePath& relative) { … }
void EmbeddedTestServer::RegisterUpgradeRequestHandler(
const HandleUpgradeRequestCallback& callback) { … }
void EmbeddedTestServer::RegisterRequestHandler(
const HandleRequestCallback& callback) { … }
void EmbeddedTestServer::RegisterRequestMonitor(
const MonitorRequestCallback& callback) { … }
void EmbeddedTestServer::RegisterDefaultHandler(
const HandleRequestCallback& callback) { … }
std::unique_ptr<SSLServerSocket> EmbeddedTestServer::DoSSLUpgrade(
std::unique_ptr<StreamSocket> connection) { … }
void EmbeddedTestServer::DoAcceptLoop() { … }
bool EmbeddedTestServer::FlushAllSocketsAndConnectionsOnUIThread() { … }
void EmbeddedTestServer::FlushAllSocketsAndConnections() { … }
void EmbeddedTestServer::SetAlpsAcceptCH(std::string hostname,
std::string accept_ch) { … }
void EmbeddedTestServer::OnAcceptCompleted(int rv) { … }
void EmbeddedTestServer::OnHandshakeDone(HttpConnection* connection, int rv) { … }
void EmbeddedTestServer::HandleAcceptResult(
std::unique_ptr<StreamSocket> socket_ptr) { … }
HttpConnection* EmbeddedTestServer::AddConnection(
std::unique_ptr<StreamSocket> socket_ptr) { … }
void EmbeddedTestServer::RemoveConnection(
HttpConnection* connection,
EmbeddedTestServerConnectionListener* listener) { … }
bool EmbeddedTestServer::PostTaskToIOThreadAndWait(base::OnceClosure closure) { … }
bool EmbeddedTestServer::PostTaskToIOThreadAndWaitWithResult(
base::OnceCallback<bool()> task) { … }
}