Skip to content

Truly independent web browser

RequestServer+LibWebView: Resolve .test names to loopback in test mode

Luke Wilde0e65c22c18dd
diff --git a/Libraries/LibWebView/HelperProcess.cpp b/Libraries/LibWebView/HelperProcess.cpp
index bcdefaebda2..a74f814a36e 100644
--- a/Libraries/LibWebView/HelperProcess.cpp
+++ b/Libraries/LibWebView/HelperProcess.cpp
@@ -640,6 +640,9 @@ ErrorOr<NonnullRefPtr<Requests::RequestControlClient>> launch_request_server_pro
if (request_server_options.resource_substitution_map_path.has_value())
arguments.append(ByteString::formatted("--resource-map={}", *request_server_options.resource_substitution_map_path));
+ if (Application::web_content_options().is_test_mode == IsTestMode::Yes)
+ arguments.append("--test-mode"sv);
+
RefPtr<Requests::RequestControlClient> client;
TRY(launch_helper_process("RequestServer"sv, move(arguments), [&](Core::ProcessSpawnOptions const& options, bool capture_output) -> ErrorOr<Process> {
auto [process, new_client] = TRY(Process::spawn<Requests::RequestControlClient>(ProcessType::RequestServer, options, capture_output));
diff --git a/Services/RequestServer/Resolver.cpp b/Services/RequestServer/Resolver.cpp
index 8fb73a87ef7..08d2f6c4d94 100644
--- a/Services/RequestServer/Resolver.cpp
+++ b/Services/RequestServer/Resolver.cpp
@@ -107,7 +107,7 @@ void Resolver::reset_connections()
NonnullRefPtr<Resolver> Resolver::create()
{
- return adopt_ref(*new Resolver([] -> ErrorOr<Optional<DNS::Resolver::SocketResult>> {
+ auto resolver = adopt_ref(*new Resolver([] -> ErrorOr<Optional<DNS::Resolver::SocketResult>> {
auto& dns_info = DNSInfo::the();
if (!dns_info.server_address.has_value()) {
@@ -142,6 +142,8 @@ NonnullRefPtr<Resolver> Resolver::create()
},
};
}));
+ resolver->dns.set_loopback_domains(DNSInfo::the().loopback_domains);
+ return resolver;
}
Resolver::Resolver(Function<ErrorOr<Optional<DNS::Resolver::SocketResult>>()> create_socket)
diff --git a/Services/RequestServer/Resolver.h b/Services/RequestServer/Resolver.h
index 6056a909002..e02fcb73d1a 100644
--- a/Services/RequestServer/Resolver.h
+++ b/Services/RequestServer/Resolver.h
@@ -25,6 +25,7 @@ struct DNSInfo {
u16 port { 0 };
bool use_dns_over_tls { true };
bool validate_dnssec_locally { false };
+ Vector<ByteString> loopback_domains;
// Only configured DNS gives us the full address pool to distribute requests over.
bool uses_configured_dns_server() const { return server_address.has_value() || server_hostname.has_value(); }
diff --git a/Services/RequestServer/main.cpp b/Services/RequestServer/main.cpp
index a7a01084925..9ff9a60fc29 100644
--- a/Services/RequestServer/main.cpp
+++ b/Services/RequestServer/main.cpp
@@ -55,6 +55,7 @@ ErrorOr<int> ladybird_main(Main::Arguments arguments)
bool sites_have_their_own = false;
bool wait_for_debugger = false;
bool disable_sandbox = false;
+ bool enable_test_mode = false;
int crash_report_fd = -1;
StringView stats_log_directory;
@@ -70,6 +71,7 @@ ErrorOr<int> ladybird_main(Main::Arguments arguments)
args_parser.add_option(sites_have_their_own, "Sites have RequestServers of their own; keep none of their responses", "sites-have-their-own");
args_parser.add_option(wait_for_debugger, "Wait for debugger", "wait-for-debugger");
args_parser.add_option(disable_sandbox, "Disable process sandboxing", "disable-sandbox");
+ args_parser.add_option(enable_test_mode, "Enable test mode", "test-mode");
args_parser.parse(arguments);
auto stats_log = TRY(Core::StatsLog::create(stats_log_directory, "RequestServer"sv));
@@ -87,6 +89,9 @@ ErrorOr<int> ladybird_main(Main::Arguments arguments)
if (auto result = Core::Platform::set_current_thread_qos(Core::Platform::ThreadQoS::UserInitiated); result.is_error())
warnln("Could not set main thread QoS: {}", result.error());
+ if (enable_test_mode)
+ RequestServer::DNSInfo::the().loopback_domains.append("test"sv);
+
// FIXME: Update RequestServer to support multiple custom root certificates.
if (!certificates.is_empty())
RequestServer::set_default_certificate_path(certificates.first());