Changeset 270170 in webkit


Ignore:
Timestamp:
Nov 26, 2020 4:40:58 PM (3 years ago)
Author:
commit-queue@webkit.org
Message:

[GTK] Allow WebKitTestServer to run non-loopback addresses for API tests
https://bugs.webkit.org/show_bug.cgi?id=219257

GTK API tests currently assumes that loopback IP addresses can be treated as mixed content
in order to test WEBKIT_INSECURE_CONTENT_RUN and WEBKIT_INSECURE_CONTENT_DISPLAYED APIs.
After bug 218623, this will no longer be true so this patch adds an option to
WebKitTestServer so that it can run a server listening to "localhost" instead. This approach
will work until bug 171934 is fixed, but we might add a way to launch a server listening to
non-localhost addresses (bug 219198) or review the whole mixed content handling in the
future (bug 140625). This patch also tweaks a bit WebKitTestServer options, so they use a
bitset instead.

Patch by Frederic Wang <fwang@igalia.com> on 2020-11-26
Reviewed by Michael Catanzaro.

  • TestWebKitAPI/Tests/WebKitGLib/TestSSL.cpp:

(beforeAll): Add a ServerNonLoopback bit to the HTTPS server used by the tests, so that
insecure content APIs will still work after bug 218623. Also remove explicit options for the
HTTP server since it just uses the default (no bits set).

  • TestWebKitAPI/glib/WebKitGLib/WebKitTestServer.cpp:

(WebKitTestServer::WebKitTestServer): Use the new bitset syntax. Starts a server listening to
"localhost" if the ServerNonLoopback bit is set.

  • TestWebKitAPI/glib/WebKitGLib/WebKitTestServer.h: Make the enum a list of bit positions

and the parameter a bitset of options. Add the new ServerNonLoopback option and remove
ServerHTTP, which corresponds to the default value (no bits set).

Location:
trunk/Tools
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Tools/ChangeLog

    r270168 r270170  
     12020-11-26  Frederic Wang  <fwang@igalia.com>
     2
     3        [GTK] Allow WebKitTestServer to run non-loopback addresses for API tests
     4        https://bugs.webkit.org/show_bug.cgi?id=219257
     5
     6        GTK API tests currently assumes that loopback IP addresses can be treated as mixed content
     7        in order to test WEBKIT_INSECURE_CONTENT_RUN and WEBKIT_INSECURE_CONTENT_DISPLAYED APIs.
     8        After bug 218623, this will no longer be true so this patch adds an option to
     9        WebKitTestServer so that it can run a server listening to "localhost" instead. This approach
     10        will work until bug 171934 is fixed, but we might add a way to launch a server listening to
     11        non-localhost addresses (bug 219198) or review the whole mixed content handling in the
     12        future (bug 140625). This patch also tweaks a bit WebKitTestServer options, so they use a
     13        bitset instead.
     14
     15        Reviewed by Michael Catanzaro.
     16
     17        * TestWebKitAPI/Tests/WebKitGLib/TestSSL.cpp:
     18        (beforeAll): Add a ServerNonLoopback bit to the HTTPS server used by the tests, so that
     19        insecure content APIs will still work after bug 218623. Also remove explicit options for the
     20        HTTP server since it just uses the default (no bits set).
     21        * TestWebKitAPI/glib/WebKitGLib/WebKitTestServer.cpp:
     22        (WebKitTestServer::WebKitTestServer): Use the new bitset syntax. Starts a server listening to
     23        "localhost" if the ServerNonLoopback bit is set.
     24        * TestWebKitAPI/glib/WebKitGLib/WebKitTestServer.h: Make the enum a list of bit positions
     25        and the parameter a bitset of options. Add the new ServerNonLoopback option and remove
     26        ServerHTTP, which corresponds to the default value (no bits set).
     27
    1282020-11-26  Michael Catanzaro  <mcatanzaro@gnome.org>
    229
  • trunk/Tools/TestWebKitAPI/Tests/WebKitGLib/TestSSL.cpp

    r267524 r270170  
    555555void beforeAll()
    556556{
    557     kHttpsServer = new WebKitTestServer(WebKitTestServer::ServerHTTPS);
     557    // FIXME(https://webkit.org/b/219198): This should really be a non-localhost domain but
     558    // relying on a non-loopback IP address is enough until bug 171934 is fixed.
     559    kHttpsServer = new WebKitTestServer(WebKitTestServer::ServerHTTPS | WebKitTestServer::ServerNonLoopback);
    558560    kHttpsServer->run(httpsServerCallback);
    559561
    560     kHttpServer = new WebKitTestServer(WebKitTestServer::ServerHTTP);
     562    kHttpServer = new WebKitTestServer();
    561563    kHttpServer->run(httpServerCallback);
    562564
  • trunk/Tools/TestWebKitAPI/glib/WebKitGLib/WebKitTestServer.cpp

    r270074 r270170  
    2525#include <wtf/glib/GUniquePtr.h>
    2626
    27 WebKitTestServer::WebKitTestServer(ServerOptions options)
     27WebKitTestServer::WebKitTestServer(ServerOptionsBitSet options)
    2828{
    29     if (options & ServerRunInThread) {
     29    if (options[ServerRunInThread]) {
    3030        WTF::initialize();
    3131        m_queue = WorkQueue::create("WebKitTestServer");
     
    3434    GUniquePtr<char> sslCertificateFile;
    3535    GUniquePtr<char> sslKeyFile;
    36     if (options & ServerHTTPS) {
     36    if (options[ServerHTTPS]) {
    3737        CString resourcesDir = Test::getResourcesDir();
    3838        sslCertificateFile.reset(g_build_filename(resourcesDir.data(), "test-cert.pem", NULL));
     
    4646
    4747    GUniqueOutPtr<GError> error;
    48     SoupServerListenOptions serverOptions = static_cast<SoupServerListenOptions>(options & ServerHTTPS ? SOUP_SERVER_LISTEN_IPV4_ONLY : SOUP_SERVER_LISTEN_IPV4_ONLY | SOUP_SERVER_LISTEN_HTTPS);
    49     if (!soup_server_listen_local(m_soupServer.get(), SOUP_ADDRESS_ANY_PORT, serverOptions, &error.outPtr())) {
     48    SoupServerListenOptions serverOptions = static_cast<SoupServerListenOptions>(options[ServerHTTPS] ? SOUP_SERVER_LISTEN_IPV4_ONLY : SOUP_SERVER_LISTEN_IPV4_ONLY | SOUP_SERVER_LISTEN_HTTPS);
     49    bool serverStarted = false;
     50    if (options[ServerNonLoopback]) {
     51        GRefPtr<SoupAddress> address = adoptGRef(soup_address_new("localhost", SOUP_ADDRESS_ANY_PORT));
     52        soup_address_resolve_sync(address.get(), nullptr);
     53        serverStarted = soup_server_listen(m_soupServer.get(), soup_address_get_gsockaddr(address.get()), serverOptions, &error.outPtr());
     54    } else
     55        serverStarted = soup_server_listen_local(m_soupServer.get(), SOUP_ADDRESS_ANY_PORT, serverOptions, &error.outPtr());
     56    if (!serverStarted) {
    5057        WTFLogAlways("Failed to start HTTP server: %s", error->message);
    5158        CRASH();
  • trunk/Tools/TestWebKitAPI/glib/WebKitGLib/WebKitTestServer.h

    r248762 r270170  
    2020#pragma once
    2121
     22#include <bitset>
    2223#include <libsoup/soup.h>
    2324#include <wtf/WorkQueue.h>
     
    3031
    3132    enum ServerOptions {
    32         ServerHTTP = 0,
    33         ServerHTTPS = 1 << 1,
    34         ServerRunInThread = 1 << 2,
     33        ServerHTTPS = 0,
     34        ServerRunInThread = 1,
     35        ServerNonLoopback = 2,
    3536    };
     37    using ServerOptionsBitSet = std::bitset<3>;
    3638
    37     WebKitTestServer(ServerOptions = ServerHTTP);
     39    WebKitTestServer(ServerOptionsBitSet = 0);
    3840    virtual ~WebKitTestServer();
    3941
Note: See TracChangeset for help on using the changeset viewer.