From deb11a669ac8f669085cd9a9d63b9bfeb242cf96 Mon Sep 17 00:00:00 2001 From: Andrew Kaster Date: Fri, 9 Feb 2024 13:47:27 -0700 Subject: [PATCH] LibWeb: Stub out WebDriver deserialize as a proxy capability AO This prevents us from returning an 'unrecognized capability' error when a WebDriver client sends us a proxy capability. We still don't actually support setting or returning a non-empty proxy capability, though. We just don't choke on the input capability request from the server. This patch also doesn't actually validate the input proxy requests. --- .../LibWeb/WebDriver/Capabilities.cpp | 34 +++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/Userland/Libraries/LibWeb/WebDriver/Capabilities.cpp b/Userland/Libraries/LibWeb/WebDriver/Capabilities.cpp index 83405eed82..c1bdf83cb5 100644 --- a/Userland/Libraries/LibWeb/WebDriver/Capabilities.cpp +++ b/Userland/Libraries/LibWeb/WebDriver/Capabilities.cpp @@ -45,6 +45,33 @@ static Response deserialize_as_an_unhandled_prompt_behavior(JsonValue value) return value; } +// https://w3c.github.io/webdriver/#dfn-deserialize-as-a-proxy +static ErrorOr deserialize_as_a_proxy(JsonValue parameter) +{ + // 1. If parameter is not a JSON Object return an error with error code invalid argument. + if (!parameter.is_object()) + return Error::from_code(ErrorCode::InvalidArgument, "Capability proxy must be an object"sv); + + // 2. Let proxy be a new, empty proxy configuration object. + JsonObject proxy; + + // 3. For each enumerable own property in parameter run the following substeps: + TRY(parameter.as_object().try_for_each_member([&](auto const& key, JsonValue const& value) -> ErrorOr { + // 1. Let key be the name of the property. + // 2. Let value be the result of getting a property named name from capability. + + // FIXME: 3. If there is no matching key for key in the proxy configuration table return an error with error code invalid argument. + // FIXME: 4. If value is not one of the valid values for that key, return an error with error code invalid argument. + + // 5. Set a property key to value on proxy. + proxy.set(key, value); + + return {}; + })); + + return proxy; +} + static Response deserialize_as_ladybird_options(JsonValue value) { if (!value.is_object()) @@ -113,8 +140,11 @@ static ErrorOr validate_capabilities(JsonValue const& capabil deserialized = TRY(deserialize_as_a_page_load_strategy(value)); } - // FIXME: -> name equals "proxy" - // FIXME: Let deserialized be the result of trying to deserialize as a proxy with argument value. + // -> name equals "proxy" + else if (name == "proxy"sv) { + // Let deserialized be the result of trying to deserialize as a proxy with argument value. + deserialized = TRY(deserialize_as_a_proxy(value)); + } // -> name equals "strictFileInteractability" else if (name == "strictFileInteractability"sv) {