Title: [270170] trunk/Tools
Revision
270170
Author
[email protected]
Date
2020-11-26 16:40:58 -0800 (Thu, 26 Nov 2020)

Log 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 <[email protected]> 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).

Modified Paths

Diff

Modified: trunk/Tools/ChangeLog (270169 => 270170)


--- trunk/Tools/ChangeLog	2020-11-27 00:38:56 UTC (rev 270169)
+++ trunk/Tools/ChangeLog	2020-11-27 00:40:58 UTC (rev 270170)
@@ -1,3 +1,30 @@
+2020-11-26  Frederic Wang  <[email protected]>
+
+        [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.
+
+        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).
+
 2020-11-26  Michael Catanzaro  <[email protected]>
 
         [WPE][GTK] Use Internet Explorer quirk for Google Docs

Modified: trunk/Tools/TestWebKitAPI/Tests/WebKitGLib/TestSSL.cpp (270169 => 270170)


--- trunk/Tools/TestWebKitAPI/Tests/WebKitGLib/TestSSL.cpp	2020-11-27 00:38:56 UTC (rev 270169)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitGLib/TestSSL.cpp	2020-11-27 00:40:58 UTC (rev 270170)
@@ -554,10 +554,12 @@
 
 void beforeAll()
 {
-    kHttpsServer = new WebKitTestServer(WebKitTestServer::ServerHTTPS);
+    // FIXME(https://webkit.org/b/219198): This should really be a non-localhost domain but
+    // relying on a non-loopback IP address is enough until bug 171934 is fixed.
+    kHttpsServer = new WebKitTestServer(WebKitTestServer::ServerHTTPS | WebKitTestServer::ServerNonLoopback);
     kHttpsServer->run(httpsServerCallback);
 
-    kHttpServer = new WebKitTestServer(WebKitTestServer::ServerHTTP);
+    kHttpServer = new WebKitTestServer();
     kHttpServer->run(httpServerCallback);
 
     SSLTest::add("WebKitWebView", "ssl", testSSL);

Modified: trunk/Tools/TestWebKitAPI/glib/WebKitGLib/WebKitTestServer.cpp (270169 => 270170)


--- trunk/Tools/TestWebKitAPI/glib/WebKitGLib/WebKitTestServer.cpp	2020-11-27 00:38:56 UTC (rev 270169)
+++ trunk/Tools/TestWebKitAPI/glib/WebKitGLib/WebKitTestServer.cpp	2020-11-27 00:40:58 UTC (rev 270170)
@@ -24,9 +24,9 @@
 #include <wtf/Threading.h>
 #include <wtf/glib/GUniquePtr.h>
 
-WebKitTestServer::WebKitTestServer(ServerOptions options)
+WebKitTestServer::WebKitTestServer(ServerOptionsBitSet options)
 {
-    if (options & ServerRunInThread) {
+    if (options[ServerRunInThread]) {
         WTF::initialize();
         m_queue = WorkQueue::create("WebKitTestServer");
     }
@@ -33,7 +33,7 @@
 
     GUniquePtr<char> sslCertificateFile;
     GUniquePtr<char> sslKeyFile;
-    if (options & ServerHTTPS) {
+    if (options[ServerHTTPS]) {
         CString resourcesDir = Test::getResourcesDir();
         sslCertificateFile.reset(g_build_filename(resourcesDir.data(), "test-cert.pem", NULL));
         sslKeyFile.reset(g_build_filename(resourcesDir.data(), "test-key.pem", NULL));
@@ -45,8 +45,15 @@
         SOUP_SERVER_SSL_KEY_FILE, sslKeyFile.get(), nullptr));
 
     GUniqueOutPtr<GError> error;
-    SoupServerListenOptions serverOptions = static_cast<SoupServerListenOptions>(options & ServerHTTPS ? SOUP_SERVER_LISTEN_IPV4_ONLY : SOUP_SERVER_LISTEN_IPV4_ONLY | SOUP_SERVER_LISTEN_HTTPS);
-    if (!soup_server_listen_local(m_soupServer.get(), SOUP_ADDRESS_ANY_PORT, serverOptions, &error.outPtr())) {
+    SoupServerListenOptions serverOptions = static_cast<SoupServerListenOptions>(options[ServerHTTPS] ? SOUP_SERVER_LISTEN_IPV4_ONLY : SOUP_SERVER_LISTEN_IPV4_ONLY | SOUP_SERVER_LISTEN_HTTPS);
+    bool serverStarted = false;
+    if (options[ServerNonLoopback]) {
+        GRefPtr<SoupAddress> address = adoptGRef(soup_address_new("localhost", SOUP_ADDRESS_ANY_PORT));
+        soup_address_resolve_sync(address.get(), nullptr);
+        serverStarted = soup_server_listen(m_soupServer.get(), soup_address_get_gsockaddr(address.get()), serverOptions, &error.outPtr());
+    } else
+        serverStarted = soup_server_listen_local(m_soupServer.get(), SOUP_ADDRESS_ANY_PORT, serverOptions, &error.outPtr());
+    if (!serverStarted) {
         WTFLogAlways("Failed to start HTTP server: %s", error->message);
         CRASH();
     }

Modified: trunk/Tools/TestWebKitAPI/glib/WebKitGLib/WebKitTestServer.h (270169 => 270170)


--- trunk/Tools/TestWebKitAPI/glib/WebKitGLib/WebKitTestServer.h	2020-11-27 00:38:56 UTC (rev 270169)
+++ trunk/Tools/TestWebKitAPI/glib/WebKitGLib/WebKitTestServer.h	2020-11-27 00:40:58 UTC (rev 270170)
@@ -19,6 +19,7 @@
 
 #pragma once
 
+#include <bitset>
 #include <libsoup/soup.h>
 #include <wtf/WorkQueue.h>
 #include <wtf/glib/GRefPtr.h>
@@ -29,12 +30,13 @@
 public:
 
     enum ServerOptions {
-        ServerHTTP = 0,
-        ServerHTTPS = 1 << 1,
-        ServerRunInThread = 1 << 2,
+        ServerHTTPS = 0,
+        ServerRunInThread = 1,
+        ServerNonLoopback = 2,
     };
+    using ServerOptionsBitSet = std::bitset<3>;
 
-    WebKitTestServer(ServerOptions = ServerHTTP);
+    WebKitTestServer(ServerOptionsBitSet = 0);
     virtual ~WebKitTestServer();
 
     SoupURI* baseURI() const { return m_baseURI; }
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to