Title: [275290] trunk/Tools
Revision
275290
Author
commit-qu...@webkit.org
Date
2021-03-31 10:25:40 -0700 (Wed, 31 Mar 2021)

Log Message

Add test for SOCKS5 proxy SPI
https://bugs.webkit.org/show_bug.cgi?id=223964

Patch by Alex Christensen <achristen...@webkit.org> on 2021-03-31
Reviewed by Sam Weinig.

* TestWebKitAPI/Tests/WebKitCocoa/Proxy.mm:
(TestWebKitAPI::TEST):

Modified Paths

Diff

Modified: trunk/Tools/ChangeLog (275289 => 275290)


--- trunk/Tools/ChangeLog	2021-03-31 17:21:57 UTC (rev 275289)
+++ trunk/Tools/ChangeLog	2021-03-31 17:25:40 UTC (rev 275290)
@@ -1,3 +1,13 @@
+2021-03-31  Alex Christensen  <achristen...@webkit.org>
+
+        Add test for SOCKS5 proxy SPI
+        https://bugs.webkit.org/show_bug.cgi?id=223964
+
+        Reviewed by Sam Weinig.
+
+        * TestWebKitAPI/Tests/WebKitCocoa/Proxy.mm:
+        (TestWebKitAPI::TEST):
+
 2021-03-31  Aakash Jain  <aakash_j...@apple.com>
 
         Add build step to run layout tests for multiple iterations in guard malloc mode

Modified: trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/Proxy.mm (275289 => 275290)


--- trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/Proxy.mm	2021-03-31 17:21:57 UTC (rev 275289)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/Proxy.mm	2021-03-31 17:25:40 UTC (rev 275290)
@@ -94,6 +94,70 @@
     EXPECT_WK_STREQ([delegate waitForAlert], "success!");
 }
 
+TEST(WebKit, SOCKS5)
+{
+    constexpr uint8_t socks5Version = 0x5; // https://tools.ietf.org/html/rfc1928#section-3
+    constexpr uint8_t noAuthenticationRequired = 0x00; // https://tools.ietf.org/html/rfc1928#section-3
+    constexpr uint8_t connect = 0x01; // https://tools.ietf.org/html/rfc1928#section-4
+    constexpr uint8_t reserved = 0x00; // https://tools.ietf.org/html/rfc1928#section-4
+    constexpr uint8_t domainName = 0x03; // https://tools.ietf.org/html/rfc1928#section-4
+    constexpr uint8_t requestSucceeded = 0x00; // https://tools.ietf.org/html/rfc1928#section-6
+
+    using namespace TestWebKitAPI;
+    HTTPServer server([](Connection connection) {
+        connection.receiveBytes([=] (Vector<uint8_t>&& bytes) {
+            constexpr uint8_t expectedAuthenticationMethodCount = 1;
+            Vector<uint8_t> expectedClientGreeting { socks5Version, expectedAuthenticationMethodCount, noAuthenticationRequired };
+            EXPECT_EQ(bytes, expectedClientGreeting);
+            connection.send(Vector<uint8_t> { socks5Version, noAuthenticationRequired }, [=] {
+                connection.receiveBytes([=] (Vector<uint8_t>&& bytes) {
+                    constexpr uint8_t httpPortFirstByte = 0;
+                    constexpr uint8_t httpPortSecondByte = 80;
+                    Vector<uint8_t> expectedConnectRequest {
+                        socks5Version,
+                        connect,
+                        reserved,
+                        domainName,
+                        static_cast<uint8_t>(strlen("example.com")),
+                        'e', 'x', 'a', 'm', 'p', 'l', 'e', '.', 'c', 'o', 'm',
+                        httpPortFirstByte, httpPortSecondByte
+                    };
+                    EXPECT_EQ(bytes, expectedConnectRequest);
+
+                    Vector<uint8_t> response { socks5Version, requestSucceeded, reserved,
+                        domainName,
+                        static_cast<uint8_t>(strlen("example.com")),
+                        'e', 'x', 'a', 'm', 'p', 'l', 'e', '.', 'c', 'o', 'm',
+                        httpPortFirstByte, httpPortSecondByte
+                    };
+                    connection.send(WTFMove(response), [=] {
+                        connection.receiveHTTPRequest([=] (Vector<char>&&) {
+                            connection.send(
+                                "HTTP/1.1 200 OK\r\n"
+                                "Content-Length: 34\r\n"
+                                "\r\n"
+                                "<script>alert('success!')</script>"
+                            );
+                        });
+                    });
+                });
+            });
+        });
+    });
+
+    auto storeConfiguration = adoptNS([_WKWebsiteDataStoreConfiguration new]);
+    [storeConfiguration setProxyConfiguration:@{
+        @"SOCKSProxy": @"127.0.0.1",
+        @"SOCKSPort": @(server.port())
+    }];
+    [storeConfiguration setAllowsServerPreconnect:NO];
+    auto viewConfiguration = adoptNS([WKWebViewConfiguration new]);
+    [viewConfiguration setWebsiteDataStore:adoptNS([[WKWebsiteDataStore alloc] _initWithConfiguration:storeConfiguration.get()]).get()];
+    auto webView = adoptNS([[WKWebView alloc] initWithFrame:CGRectMake(0, 0, 100, 100) configuration:viewConfiguration.get()]);
+    [webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://example.com/"]]];
+    EXPECT_WK_STREQ([webView _test_waitForAlert], "success!");
+}
+
 TEST(WebKit, HTTPProxyAuthentication)
 {
     TCPServer server([] (int socket) {
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to