Title: [283934] trunk/Tools
Revision
283934
Author
[email protected]
Date
2021-10-11 13:37:27 -0700 (Mon, 11 Oct 2021)

Log Message

Reduce use of TCPServer
https://bugs.webkit.org/show_bug.cgi?id=231518

Patch by Alex Christensen <[email protected]> on 2021-10-11
Reviewed by Chris Dumez.

HTTPServer runs its logic on the main thread and doesn't hang in its destructor
when the number of connections and requests isn't exactly what was expected.

verifyCertificateAndPublicKey needed its expected bytes to be changed because it is
using the identity from TCPServer::testCertificate instead of TCPServer::startSecureConnection now.

I also moved the proxy basic authentication check from proxyAuthenticationServer to proxyDefinition.

* TestWebKitAPI/Tests/WebKitCocoa/Challenge.mm:
(TEST):
(verifyCertificateAndPublicKey):
(TestWebKitAPI::TEST):
* TestWebKitAPI/Tests/WebKitCocoa/Proxy.mm:
(TestWebKitAPI::proxyAuthenticationServer):
(TestWebKitAPI::webViewAndDelegate):
(TestWebKitAPI::TEST):
* TestWebKitAPI/Tests/WebKitCocoa/ServiceWorkerBasic.mm:
* TestWebKitAPI/Tests/WebKitCocoa/TLSDeprecation.mm:
(TestWebKitAPI::TEST):
* TestWebKitAPI/Tests/WebKitCocoa/TestSOAuthorization.mm:
(TestWebKitAPI::TEST):
* TestWebKitAPI/Tests/WebKitCocoa/_WKWebAuthenticationPanel.mm:
(TestWebKitAPI::TEST):
* TestWebKitAPI/cocoa/HTTPServer.h:
* TestWebKitAPI/cocoa/HTTPServer.mm:
(TestWebKitAPI::proxyDefinition):
(TestWebKitAPI::shouldDisableTLS):
(TestWebKitAPI::HTTPServer::listenerParameters):
(TestWebKitAPI::statusText):
(TestWebKitAPI::HTTPServer::request const):

Modified Paths

Diff

Modified: trunk/Tools/ChangeLog (283933 => 283934)


--- trunk/Tools/ChangeLog	2021-10-11 20:27:58 UTC (rev 283933)
+++ trunk/Tools/ChangeLog	2021-10-11 20:37:27 UTC (rev 283934)
@@ -1,3 +1,41 @@
+2021-10-11  Alex Christensen  <[email protected]>
+
+        Reduce use of TCPServer
+        https://bugs.webkit.org/show_bug.cgi?id=231518
+
+        Reviewed by Chris Dumez.
+
+        HTTPServer runs its logic on the main thread and doesn't hang in its destructor
+        when the number of connections and requests isn't exactly what was expected.
+
+        verifyCertificateAndPublicKey needed its expected bytes to be changed because it is
+        using the identity from TCPServer::testCertificate instead of TCPServer::startSecureConnection now.
+
+        I also moved the proxy basic authentication check from proxyAuthenticationServer to proxyDefinition.
+
+        * TestWebKitAPI/Tests/WebKitCocoa/Challenge.mm:
+        (TEST):
+        (verifyCertificateAndPublicKey):
+        (TestWebKitAPI::TEST):
+        * TestWebKitAPI/Tests/WebKitCocoa/Proxy.mm:
+        (TestWebKitAPI::proxyAuthenticationServer):
+        (TestWebKitAPI::webViewAndDelegate):
+        (TestWebKitAPI::TEST):
+        * TestWebKitAPI/Tests/WebKitCocoa/ServiceWorkerBasic.mm:
+        * TestWebKitAPI/Tests/WebKitCocoa/TLSDeprecation.mm:
+        (TestWebKitAPI::TEST):
+        * TestWebKitAPI/Tests/WebKitCocoa/TestSOAuthorization.mm:
+        (TestWebKitAPI::TEST):
+        * TestWebKitAPI/Tests/WebKitCocoa/_WKWebAuthenticationPanel.mm:
+        (TestWebKitAPI::TEST):
+        * TestWebKitAPI/cocoa/HTTPServer.h:
+        * TestWebKitAPI/cocoa/HTTPServer.mm:
+        (TestWebKitAPI::proxyDefinition):
+        (TestWebKitAPI::shouldDisableTLS):
+        (TestWebKitAPI::HTTPServer::listenerParameters):
+        (TestWebKitAPI::statusText):
+        (TestWebKitAPI::HTTPServer::request const):
+
 2021-10-11  Ryan Haddad  <[email protected]>
 
         Bring up an iOS GPU Process tester

Modified: trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/Challenge.mm (283933 => 283934)


--- trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/Challenge.mm	2021-10-11 20:27:58 UTC (rev 283933)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/Challenge.mm	2021-10-11 20:37:27 UTC (rev 283934)
@@ -222,7 +222,7 @@
 TEST(Challenge, SecIdentity)
 {
     using namespace TestWebKitAPI;
-    TCPServer server(TCPServer::respondWithChallengeThenOK);
+    HTTPServer server(HTTPServer::respondWithChallengeThenOK);
 
     auto webView = adoptNS([WKWebView new]);
     auto delegate = adoptNS([ChallengeDelegate new]);
@@ -291,16 +291,18 @@
 
 @end
 
-#if HAVE(SEC_KEY_PROXY) && HAVE(SSL)
+#if HAVE(SEC_KEY_PROXY)
 TEST(Challenge, ClientCertificate)
 {
     using namespace TestWebKitAPI;
-    TCPServer server(TCPServer::Protocol::HTTPSWithClientCertificateRequest, TCPServer::respondWithOK);
+    HTTPServer server({ { "/", { "hello" } } }, HTTPServer::Protocol::Https, [](sec_protocol_metadata_t, sec_trust_t, sec_protocol_verify_complete_t complete) {
+        complete(true);
+    });
 
     auto webView = adoptNS([WKWebView new]);
     auto delegate = adoptNS([ClientCertificateDelegate new]);
     [webView setNavigationDelegate:delegate.get()];
-    [webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"https://127.0.0.1:%d/", server.port()]]]];
+    [webView loadRequest:server.request()];
     
     Util::run(&navigationFinished);
     auto& methods = [delegate authenticationMethods];
@@ -405,6 +407,8 @@
     auto compareData = [] (const RetainPtr<CFDataRef>& data, const Vector<uint8_t>& expected) {
         size_t length = CFDataGetLength(data.get());
         EXPECT_EQ(length, expected.size());
+        if (length != expected.size())
+            return;
         const UInt8* bytes = CFDataGetBytePtr(data.get());
         for (size_t i = 0; i < length; ++i)
             EXPECT_EQ(expected[i], bytes[i]);
@@ -412,15 +416,39 @@
 
     auto publicKey = adoptCF(SecKeyCopyExternalRepresentation(adoptCF(SecTrustCopyPublicKey(trust)).get(), nullptr));
     compareData(publicKey, {
-        0x30, 0x81, 0x89, 0x02, 0x81, 0x81, 0x00, 0xd8, 0x2b, 0xc8, 0xa6, 0x32, 0xe4, 0x62, 0xff, 0x4d,
-        0xf3, 0xd0, 0xad, 0x59, 0x8b, 0x45, 0xa7, 0xbd, 0xf1, 0x47, 0xbf, 0x09, 0x58, 0x7b, 0x22, 0xbd,
-        0x35, 0xae, 0x97, 0x25, 0x86, 0x94, 0xa0, 0x80, 0xc0, 0xb4, 0x1f, 0x76, 0x91, 0x67, 0x46, 0x31,
-        0xd0, 0x10, 0x84, 0xb7, 0x22, 0x1e, 0x70, 0x23, 0x91, 0x72, 0xc8, 0xe9, 0x6d, 0x79, 0x3a, 0x85,
-        0x77, 0x80, 0x0f, 0xc4, 0x95, 0x16, 0x75, 0xc5, 0x4a, 0x71, 0x4c, 0xc8, 0x63, 0x3f, 0xa3, 0xf2,
-        0x63, 0x9c, 0x2a, 0x4f, 0x9a, 0xfa, 0xcb, 0xc1, 0x71, 0x6e, 0x28, 0x85, 0x28, 0xa0, 0x27, 0x1e,
-        0x65, 0x1c, 0xae, 0x07, 0xd5, 0x5b, 0x6f, 0x2d, 0x43, 0xed, 0x2b, 0x90, 0xb1, 0x8c, 0xaf, 0x24,
-        0x6d, 0xae, 0xe9, 0x17, 0x3a, 0x05, 0xc1, 0xbf, 0xb8, 0x1c, 0xae, 0x65, 0x3b, 0x1b, 0x58, 0xc2,
-        0xd9, 0xae, 0xd6, 0xaa, 0x67, 0x88, 0xf1, 0x02, 0x03, 0x01, 0x00, 0x01
+        0x30, 0x82, 0x02, 0x0a, 0x02, 0x82, 0x02, 0x01, 0x00, 0xde, 0xb8, 0x4d, 0xe1, 0x23, 0xe0, 0xf1,
+        0x56, 0x3f, 0x3e, 0xd1, 0x83, 0x34, 0xa6, 0x37, 0x4f, 0xd2, 0x48, 0x4a, 0x06, 0xf2, 0xf1, 0x81,
+        0x8c, 0x27, 0x1d, 0x2f, 0x3b, 0xe6, 0x19, 0x15, 0x99, 0xb7, 0x1b, 0x77, 0xec, 0x4d, 0x4b, 0x32,
+        0xbc, 0x3c, 0x84, 0x1f, 0x0a, 0xa9, 0xe5, 0xa6, 0xc2, 0x65, 0x10, 0x7f, 0x07, 0x2d, 0x4f, 0xc1,
+        0x69, 0x0d, 0xad, 0xfc, 0x67, 0xfd, 0x73, 0xfc, 0x3f, 0x4d, 0xf8, 0x24, 0xf9, 0x44, 0xea, 0x2a,
+        0xd5, 0x8a, 0xe0, 0x18, 0x42, 0xba, 0x94, 0x87, 0xa9, 0x3b, 0x65, 0x1f, 0x02, 0xa4, 0xe3, 0x39,
+        0x18, 0x47, 0x11, 0x66, 0x00, 0x14, 0x24, 0x61, 0x90, 0xc0, 0xd9, 0x4e, 0x90, 0x4c, 0x1a, 0x1e,
+        0x73, 0x06, 0x73, 0xc4, 0xac, 0x1e, 0xea, 0xe0, 0x0c, 0xf8, 0x79, 0x5c, 0x1a, 0x60, 0x6c, 0x3c,
+        0xad, 0x77, 0xb0, 0x49, 0xb8, 0x1d, 0x4d, 0xa0, 0x8f, 0xca, 0x26, 0x68, 0x5c, 0x6a, 0x39, 0x00,
+        0xb9, 0x5d, 0xef, 0x6a, 0xb4, 0xbe, 0xb8, 0xf2, 0xe8, 0x7c, 0xf1, 0xcd, 0xa9, 0xef, 0x9c, 0x2f,
+        0xc8, 0x4d, 0x9e, 0x36, 0x50, 0xc0, 0x75, 0x9a, 0xac, 0xfe, 0x39, 0x92, 0xce, 0x1e, 0x05, 0xc3,
+        0x83, 0xee, 0xdc, 0x2a, 0xc6, 0xe1, 0xe7, 0x56, 0x6f, 0xc5, 0x58, 0x4a, 0xe9, 0x63, 0xc5, 0xac,
+        0xe6, 0xcd, 0x4c, 0xac, 0xf4, 0xe1, 0x51, 0xd0, 0xda, 0x86, 0x31, 0x0c, 0x7f, 0xe6, 0x1f, 0x0c,
+        0x9f, 0x4a, 0x2f, 0xcc, 0xb7, 0xd3, 0x8c, 0x92, 0xf0, 0x9f, 0x1f, 0x78, 0x2c, 0x58, 0x7d, 0xc1,
+        0xf8, 0x06, 0xf8, 0x0b, 0xb4, 0x99, 0x81, 0x34, 0x72, 0x60, 0x8f, 0x77, 0x8d, 0x0f, 0xf1, 0x0c,
+        0x66, 0x32, 0x60, 0xcf, 0x61, 0x6c, 0x06, 0x3a, 0xc9, 0x93, 0xc9, 0x0a, 0x0f, 0x7d, 0x5c, 0xc3,
+        0xee, 0x16, 0xa7, 0xc5, 0x05, 0xe2, 0xc9, 0x16, 0x5c, 0x27, 0xf8, 0xeb, 0xe9, 0x8d, 0x38, 0x7a,
+        0x75, 0xdc, 0xf7, 0x92, 0x09, 0x92, 0xf2, 0x17, 0x86, 0x40, 0x1d, 0xac, 0xd4, 0x56, 0x49, 0xc3,
+        0x3d, 0xc7, 0x36, 0x60, 0xda, 0xd6, 0x55, 0x5d, 0x62, 0xea, 0x7d, 0xd3, 0xd7, 0x99, 0x08, 0xd1,
+        0x3e, 0x59, 0xed, 0xbb, 0x2d, 0x76, 0x60, 0x0b, 0xb9, 0x29, 0x04, 0xd9, 0xcb, 0x89, 0x49, 0x53,
+        0x4e, 0xea, 0x04, 0x7e, 0x66, 0xc5, 0x51, 0x4e, 0x77, 0xae, 0x43, 0x1c, 0x16, 0x4d, 0x4d, 0x0c,
+        0x34, 0x48, 0x40, 0x3c, 0x53, 0x97, 0xd8, 0x18, 0x46, 0x3f, 0x97, 0xa2, 0xb2, 0x01, 0x14, 0xce,
+        0x49, 0xf1, 0x30, 0x97, 0x5d, 0x14, 0x39, 0xfd, 0x5b, 0x19, 0x25, 0xbb, 0x52, 0x61, 0x82, 0x4c,
+        0xc0, 0x48, 0x0f, 0xfe, 0xdc, 0x09, 0xa5, 0xac, 0x56, 0x4c, 0x3e, 0x13, 0xa1, 0x8c, 0x4b, 0xa5,
+        0xd3, 0x38, 0xe0, 0x35, 0x1e, 0x51, 0x06, 0x5d, 0x46, 0xf0, 0x7c, 0xfd, 0xd8, 0xb0, 0x31, 0xe5,
+        0x41, 0x03, 0x06, 0xd7, 0x4b, 0x83, 0xbd, 0x48, 0xf8, 0x8f, 0x00, 0xcd, 0x03, 0xa1, 0x77, 0xa2,
+        0xed, 0x05, 0xe9, 0x04, 0x0b, 0x10, 0x35, 0xea, 0x94, 0x9a, 0xa6, 0x98, 0x39, 0xbd, 0xc5, 0xbd,
+        0x67, 0xff, 0x0d, 0xe9, 0x99, 0x6c, 0x1e, 0x76, 0x76, 0x17, 0x3b, 0x40, 0xd2, 0x70, 0x8e, 0x7e,
+        0x59, 0x28, 0x3b, 0xd8, 0x9e, 0x8c, 0xea, 0x5c, 0xb8, 0x53, 0x78, 0x11, 0x56, 0x03, 0xc4, 0x8b,
+        0x70, 0x72, 0xd2, 0xb0, 0xd4, 0xb0, 0x9e, 0x34, 0x3f, 0xec, 0xe2, 0x49, 0xa8, 0x45, 0x19, 0xd7,
+        0x6d, 0x7e, 0xe4, 0xf4, 0xee, 0x9c, 0x23, 0x55, 0x14, 0x58, 0xce, 0x7d, 0xe4, 0x6b, 0x2e, 0xe6,
+        0xd3, 0xda, 0xdf, 0x73, 0x39, 0x01, 0x91, 0x42, 0x6a, 0xfd, 0xa0, 0x39, 0x5b, 0x98, 0x76, 0x3a,
+        0x69, 0x4b, 0x41, 0xce, 0x7e, 0x8e, 0x61, 0xbf, 0xa7, 0x02, 0x03, 0x01, 0x00, 0x01
     });
     
     EXPECT_EQ(1, SecTrustGetCertificateCount(trust));
@@ -431,44 +459,95 @@
     auto certificate = adoptCF(SecCertificateCopyData(SecTrustGetCertificateAtIndex(trust, 0)));
 #endif
     compareData(certificate, {
-        0x30, 0x82, 0x02, 0x58, 0x30, 0x82, 0x01, 0xc1, 0xa0, 0x03, 0x02, 0x01, 0x02, 0x02, 0x09, 0x00,
-        0xfb, 0xb0, 0x4c, 0x2e, 0xab, 0x10, 0x9b, 0x0c, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86,
-        0xf7, 0x0d, 0x01, 0x01, 0x05, 0x05, 0x00, 0x30, 0x45, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55,
-        0x04, 0x06, 0x13, 0x02, 0x41, 0x55, 0x31, 0x13, 0x30, 0x11, 0x06, 0x03, 0x55, 0x04, 0x08, 0x0c,
-        0x0a, 0x53, 0x6f, 0x6d, 0x65, 0x2d, 0x53, 0x74, 0x61, 0x74, 0x65, 0x31, 0x21, 0x30, 0x1f, 0x06,
-        0x03, 0x55, 0x04, 0x0a, 0x0c, 0x18, 0x49, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x65, 0x74, 0x20, 0x57,
-        0x69, 0x64, 0x67, 0x69, 0x74, 0x73, 0x20, 0x50, 0x74, 0x79, 0x20, 0x4c, 0x74, 0x64, 0x30, 0x1e,
-        0x17, 0x0d, 0x31, 0x34, 0x30, 0x34, 0x32, 0x33, 0x32, 0x30, 0x35, 0x30, 0x34, 0x30, 0x5a, 0x17,
-        0x0d, 0x31, 0x37, 0x30, 0x34, 0x32, 0x32, 0x32, 0x30, 0x35, 0x30, 0x34, 0x30, 0x5a, 0x30, 0x45,
-        0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02, 0x41, 0x55, 0x31, 0x13, 0x30,
-        0x11, 0x06, 0x03, 0x55, 0x04, 0x08, 0x0c, 0x0a, 0x53, 0x6f, 0x6d, 0x65, 0x2d, 0x53, 0x74, 0x61,
-        0x74, 0x65, 0x31, 0x21, 0x30, 0x1f, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x0c, 0x18, 0x49, 0x6e, 0x74,
-        0x65, 0x72, 0x6e, 0x65, 0x74, 0x20, 0x57, 0x69, 0x64, 0x67, 0x69, 0x74, 0x73, 0x20, 0x50, 0x74,
-        0x79, 0x20, 0x4c, 0x74, 0x64, 0x30, 0x81, 0x9f, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86,
-        0xf7, 0x0d, 0x01, 0x01, 0x01, 0x05, 0x00, 0x03, 0x81, 0x8d, 0x00, 0x30, 0x81, 0x89, 0x02, 0x81,
-        0x81, 0x00, 0xd8, 0x2b, 0xc8, 0xa6, 0x32, 0xe4, 0x62, 0xff, 0x4d, 0xf3, 0xd0, 0xad, 0x59, 0x8b,
-        0x45, 0xa7, 0xbd, 0xf1, 0x47, 0xbf, 0x09, 0x58, 0x7b, 0x22, 0xbd, 0x35, 0xae, 0x97, 0x25, 0x86,
-        0x94, 0xa0, 0x80, 0xc0, 0xb4, 0x1f, 0x76, 0x91, 0x67, 0x46, 0x31, 0xd0, 0x10, 0x84, 0xb7, 0x22,
-        0x1e, 0x70, 0x23, 0x91, 0x72, 0xc8, 0xe9, 0x6d, 0x79, 0x3a, 0x85, 0x77, 0x80, 0x0f, 0xc4, 0x95,
-        0x16, 0x75, 0xc5, 0x4a, 0x71, 0x4c, 0xc8, 0x63, 0x3f, 0xa3, 0xf2, 0x63, 0x9c, 0x2a, 0x4f, 0x9a,
-        0xfa, 0xcb, 0xc1, 0x71, 0x6e, 0x28, 0x85, 0x28, 0xa0, 0x27, 0x1e, 0x65, 0x1c, 0xae, 0x07, 0xd5,
-        0x5b, 0x6f, 0x2d, 0x43, 0xed, 0x2b, 0x90, 0xb1, 0x8c, 0xaf, 0x24, 0x6d, 0xae, 0xe9, 0x17, 0x3a,
-        0x05, 0xc1, 0xbf, 0xb8, 0x1c, 0xae, 0x65, 0x3b, 0x1b, 0x58, 0xc2, 0xd9, 0xae, 0xd6, 0xaa, 0x67,
-        0x88, 0xf1, 0x02, 0x03, 0x01, 0x00, 0x01, 0xa3, 0x50, 0x30, 0x4e, 0x30, 0x1d, 0x06, 0x03, 0x55,
-        0x1d, 0x0e, 0x04, 0x16, 0x04, 0x14, 0x8b, 0x75, 0xd5, 0xac, 0xcb, 0x08, 0xbe, 0x0e, 0x1f, 0x65,
-        0xb7, 0xfa, 0x56, 0xbe, 0x6c, 0xa7, 0x75, 0xda, 0x85, 0xaf, 0x30, 0x1f, 0x06, 0x03, 0x55, 0x1d,
-        0x23, 0x04, 0x18, 0x30, 0x16, 0x80, 0x14, 0x8b, 0x75, 0xd5, 0xac, 0xcb, 0x08, 0xbe, 0x0e, 0x1f,
-        0x65, 0xb7, 0xfa, 0x56, 0xbe, 0x6c, 0xa7, 0x75, 0xda, 0x85, 0xaf, 0x30, 0x0c, 0x06, 0x03, 0x55,
-        0x1d, 0x13, 0x04, 0x05, 0x30, 0x03, 0x01, 0x01, 0xff, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48,
-        0x86, 0xf7, 0x0d, 0x01, 0x01, 0x05, 0x05, 0x00, 0x03, 0x81, 0x81, 0x00, 0x3b, 0xe8, 0x78, 0x6d,
-        0x95, 0xd6, 0x3d, 0x6a, 0xf7, 0x13, 0x19, 0x2c, 0x1b, 0xc2, 0x88, 0xae, 0x22, 0xab, 0xf4, 0x8d,
-        0x32, 0xf5, 0x7c, 0x71, 0x67, 0xcf, 0x2d, 0xd1, 0x1c, 0xc2, 0xc3, 0x87, 0xe2, 0xe9, 0xbe, 0x89,
-        0x5c, 0xe4, 0x34, 0xab, 0x48, 0x91, 0xc2, 0x3f, 0x95, 0xae, 0x2b, 0x47, 0x9e, 0x25, 0x78, 0x6b,
-        0x4f, 0x9a, 0x10, 0xa4, 0x72, 0xfd, 0xcf, 0xf7, 0x02, 0x0c, 0xb0, 0x0a, 0x08, 0xa4, 0x5a, 0xe2,
-        0xe5, 0x74, 0x7e, 0x11, 0x1d, 0x39, 0x60, 0x6a, 0xc9, 0x1f, 0x69, 0xf3, 0x2e, 0x63, 0x26, 0xdc,
-        0x9e, 0xef, 0x6b, 0x7a, 0x0a, 0xe1, 0x54, 0x57, 0x98, 0xaa, 0x72, 0x91, 0x78, 0x04, 0x7e, 0x1f,
-        0x8f, 0x65, 0x4d, 0x1f, 0x0b, 0x12, 0xac, 0x9c, 0x24, 0x0f, 0x84, 0x14, 0x1a, 0x55, 0x2d, 0x1f,
-        0xbb, 0xf0, 0x9d, 0x09, 0xb2, 0x08, 0x5c, 0x59, 0x32, 0x65, 0x80, 0x26
+        0x30, 0x82, 0x05, 0x80, 0x30, 0x82, 0x03, 0x68, 0x02, 0x09, 0x00, 0x8a, 0x1e, 0x23, 0xd1, 0x53,
+        0x93, 0x10, 0xb8, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x0b,
+        0x05, 0x00, 0x30, 0x81, 0x81, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02,
+        0x55, 0x53, 0x31, 0x13, 0x30, 0x11, 0x06, 0x03, 0x55, 0x04, 0x08, 0x0c, 0x0a, 0x4e, 0x65, 0x77,
+        0x20, 0x4d, 0x65, 0x78, 0x69, 0x63, 0x6f, 0x31, 0x11, 0x30, 0x0f, 0x06, 0x03, 0x55, 0x04, 0x07,
+        0x0c, 0x08, 0x53, 0x61, 0x6e, 0x74, 0x61, 0x20, 0x46, 0x65, 0x31, 0x0d, 0x30, 0x0b, 0x06, 0x03,
+        0x55, 0x04, 0x0a, 0x0c, 0x04, 0x53, 0x65, 0x6c, 0x66, 0x31, 0x0f, 0x30, 0x0d, 0x06, 0x03, 0x55,
+        0x04, 0x0b, 0x0c, 0x06, 0x4d, 0x79, 0x73, 0x65, 0x6c, 0x66, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03,
+        0x55, 0x04, 0x03, 0x0c, 0x02, 0x4d, 0x65, 0x31, 0x1d, 0x30, 0x1b, 0x06, 0x09, 0x2a, 0x86, 0x48,
+        0x86, 0xf7, 0x0d, 0x01, 0x09, 0x01, 0x16, 0x0e, 0x6d, 0x65, 0x40, 0x65, 0x78, 0x61, 0x6d, 0x70,
+        0x6c, 0x65, 0x2e, 0x63, 0x6f, 0x6d, 0x30, 0x1e, 0x17, 0x0d, 0x31, 0x39, 0x30, 0x33, 0x32, 0x33,
+        0x30, 0x35, 0x35, 0x30, 0x31, 0x34, 0x5a, 0x17, 0x0d, 0x32, 0x30, 0x30, 0x33, 0x32, 0x32, 0x30,
+        0x35, 0x35, 0x30, 0x31, 0x34, 0x5a, 0x30, 0x81, 0x81, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55,
+        0x04, 0x06, 0x13, 0x02, 0x55, 0x53, 0x31, 0x13, 0x30, 0x11, 0x06, 0x03, 0x55, 0x04, 0x08, 0x0c,
+        0x0a, 0x4e, 0x65, 0x77, 0x20, 0x4d, 0x65, 0x78, 0x69, 0x63, 0x6f, 0x31, 0x11, 0x30, 0x0f, 0x06,
+        0x03, 0x55, 0x04, 0x07, 0x0c, 0x08, 0x53, 0x61, 0x6e, 0x74, 0x61, 0x20, 0x46, 0x65, 0x31, 0x0d,
+        0x30, 0x0b, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x0c, 0x04, 0x53, 0x65, 0x6c, 0x66, 0x31, 0x0f, 0x30,
+        0x0d, 0x06, 0x03, 0x55, 0x04, 0x0b, 0x0c, 0x06, 0x4d, 0x79, 0x73, 0x65, 0x6c, 0x66, 0x31, 0x0b,
+        0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, 0x02, 0x4d, 0x65, 0x31, 0x1d, 0x30, 0x1b, 0x06,
+        0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x09, 0x01, 0x16, 0x0e, 0x6d, 0x65, 0x40, 0x65,
+        0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x2e, 0x63, 0x6f, 0x6d, 0x30, 0x82, 0x02, 0x22, 0x30, 0x0d,
+        0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x01, 0x05, 0x00, 0x03, 0x82, 0x02,
+        0x0f, 0x00, 0x30, 0x82, 0x02, 0x0a, 0x02, 0x82, 0x02, 0x01, 0x00, 0xde, 0xb8, 0x4d, 0xe1, 0x23,
+        0xe0, 0xf1, 0x56, 0x3f, 0x3e, 0xd1, 0x83, 0x34, 0xa6, 0x37, 0x4f, 0xd2, 0x48, 0x4a, 0x06, 0xf2,
+        0xf1, 0x81, 0x8c, 0x27, 0x1d, 0x2f, 0x3b, 0xe6, 0x19, 0x15, 0x99, 0xb7, 0x1b, 0x77, 0xec, 0x4d,
+        0x4b, 0x32, 0xbc, 0x3c, 0x84, 0x1f, 0x0a, 0xa9, 0xe5, 0xa6, 0xc2, 0x65, 0x10, 0x7f, 0x07, 0x2d,
+        0x4f, 0xc1, 0x69, 0x0d, 0xad, 0xfc, 0x67, 0xfd, 0x73, 0xfc, 0x3f, 0x4d, 0xf8, 0x24, 0xf9, 0x44,
+        0xea, 0x2a, 0xd5, 0x8a, 0xe0, 0x18, 0x42, 0xba, 0x94, 0x87, 0xa9, 0x3b, 0x65, 0x1f, 0x02, 0xa4,
+        0xe3, 0x39, 0x18, 0x47, 0x11, 0x66, 0x00, 0x14, 0x24, 0x61, 0x90, 0xc0, 0xd9, 0x4e, 0x90, 0x4c,
+        0x1a, 0x1e, 0x73, 0x06, 0x73, 0xc4, 0xac, 0x1e, 0xea, 0xe0, 0x0c, 0xf8, 0x79, 0x5c, 0x1a, 0x60,
+        0x6c, 0x3c, 0xad, 0x77, 0xb0, 0x49, 0xb8, 0x1d, 0x4d, 0xa0, 0x8f, 0xca, 0x26, 0x68, 0x5c, 0x6a,
+        0x39, 0x00, 0xb9, 0x5d, 0xef, 0x6a, 0xb4, 0xbe, 0xb8, 0xf2, 0xe8, 0x7c, 0xf1, 0xcd, 0xa9, 0xef,
+        0x9c, 0x2f, 0xc8, 0x4d, 0x9e, 0x36, 0x50, 0xc0, 0x75, 0x9a, 0xac, 0xfe, 0x39, 0x92, 0xce, 0x1e,
+        0x05, 0xc3, 0x83, 0xee, 0xdc, 0x2a, 0xc6, 0xe1, 0xe7, 0x56, 0x6f, 0xc5, 0x58, 0x4a, 0xe9, 0x63,
+        0xc5, 0xac, 0xe6, 0xcd, 0x4c, 0xac, 0xf4, 0xe1, 0x51, 0xd0, 0xda, 0x86, 0x31, 0x0c, 0x7f, 0xe6,
+        0x1f, 0x0c, 0x9f, 0x4a, 0x2f, 0xcc, 0xb7, 0xd3, 0x8c, 0x92, 0xf0, 0x9f, 0x1f, 0x78, 0x2c, 0x58,
+        0x7d, 0xc1, 0xf8, 0x06, 0xf8, 0x0b, 0xb4, 0x99, 0x81, 0x34, 0x72, 0x60, 0x8f, 0x77, 0x8d, 0x0f,
+        0xf1, 0x0c, 0x66, 0x32, 0x60, 0xcf, 0x61, 0x6c, 0x06, 0x3a, 0xc9, 0x93, 0xc9, 0x0a, 0x0f, 0x7d,
+        0x5c, 0xc3, 0xee, 0x16, 0xa7, 0xc5, 0x05, 0xe2, 0xc9, 0x16, 0x5c, 0x27, 0xf8, 0xeb, 0xe9, 0x8d,
+        0x38, 0x7a, 0x75, 0xdc, 0xf7, 0x92, 0x09, 0x92, 0xf2, 0x17, 0x86, 0x40, 0x1d, 0xac, 0xd4, 0x56,
+        0x49, 0xc3, 0x3d, 0xc7, 0x36, 0x60, 0xda, 0xd6, 0x55, 0x5d, 0x62, 0xea, 0x7d, 0xd3, 0xd7, 0x99,
+        0x08, 0xd1, 0x3e, 0x59, 0xed, 0xbb, 0x2d, 0x76, 0x60, 0x0b, 0xb9, 0x29, 0x04, 0xd9, 0xcb, 0x89,
+        0x49, 0x53, 0x4e, 0xea, 0x04, 0x7e, 0x66, 0xc5, 0x51, 0x4e, 0x77, 0xae, 0x43, 0x1c, 0x16, 0x4d,
+        0x4d, 0x0c, 0x34, 0x48, 0x40, 0x3c, 0x53, 0x97, 0xd8, 0x18, 0x46, 0x3f, 0x97, 0xa2, 0xb2, 0x01,
+        0x14, 0xce, 0x49, 0xf1, 0x30, 0x97, 0x5d, 0x14, 0x39, 0xfd, 0x5b, 0x19, 0x25, 0xbb, 0x52, 0x61,
+        0x82, 0x4c, 0xc0, 0x48, 0x0f, 0xfe, 0xdc, 0x09, 0xa5, 0xac, 0x56, 0x4c, 0x3e, 0x13, 0xa1, 0x8c,
+        0x4b, 0xa5, 0xd3, 0x38, 0xe0, 0x35, 0x1e, 0x51, 0x06, 0x5d, 0x46, 0xf0, 0x7c, 0xfd, 0xd8, 0xb0,
+        0x31, 0xe5, 0x41, 0x03, 0x06, 0xd7, 0x4b, 0x83, 0xbd, 0x48, 0xf8, 0x8f, 0x00, 0xcd, 0x03, 0xa1,
+        0x77, 0xa2, 0xed, 0x05, 0xe9, 0x04, 0x0b, 0x10, 0x35, 0xea, 0x94, 0x9a, 0xa6, 0x98, 0x39, 0xbd,
+        0xc5, 0xbd, 0x67, 0xff, 0x0d, 0xe9, 0x99, 0x6c, 0x1e, 0x76, 0x76, 0x17, 0x3b, 0x40, 0xd2, 0x70,
+        0x8e, 0x7e, 0x59, 0x28, 0x3b, 0xd8, 0x9e, 0x8c, 0xea, 0x5c, 0xb8, 0x53, 0x78, 0x11, 0x56, 0x03,
+        0xc4, 0x8b, 0x70, 0x72, 0xd2, 0xb0, 0xd4, 0xb0, 0x9e, 0x34, 0x3f, 0xec, 0xe2, 0x49, 0xa8, 0x45,
+        0x19, 0xd7, 0x6d, 0x7e, 0xe4, 0xf4, 0xee, 0x9c, 0x23, 0x55, 0x14, 0x58, 0xce, 0x7d, 0xe4, 0x6b,
+        0x2e, 0xe6, 0xd3, 0xda, 0xdf, 0x73, 0x39, 0x01, 0x91, 0x42, 0x6a, 0xfd, 0xa0, 0x39, 0x5b, 0x98,
+        0x76, 0x3a, 0x69, 0x4b, 0x41, 0xce, 0x7e, 0x8e, 0x61, 0xbf, 0xa7, 0x02, 0x03, 0x01, 0x00, 0x01,
+        0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x0b, 0x05, 0x00, 0x03,
+        0x82, 0x02, 0x01, 0x00, 0x63, 0xc1, 0x16, 0x68, 0x01, 0x44, 0x7f, 0x0e, 0xce, 0x57, 0xea, 0x03,
+        0x5d, 0x46, 0x52, 0x21, 0x85, 0xea, 0xdc, 0x41, 0xf6, 0x13, 0x9a, 0x77, 0xab, 0x7f, 0x00, 0x84,
+        0x83, 0x8b, 0x46, 0x30, 0x6e, 0x07, 0xeb, 0xad, 0xca, 0xee, 0xd0, 0xea, 0xbc, 0x4c, 0x30, 0x7b,
+        0xb0, 0xd9, 0x3b, 0x6c, 0x37, 0xec, 0xdb, 0x01, 0x1e, 0xf2, 0xae, 0x37, 0xec, 0xb1, 0xe0, 0x37,
+        0xe1, 0x33, 0x35, 0xc5, 0xee, 0x0d, 0x93, 0xb3, 0x55, 0x34, 0x74, 0x68, 0x65, 0x0f, 0x82, 0xd0,
+        0x8a, 0x9f, 0xf5, 0xfb, 0xdc, 0x8a, 0x83, 0x2f, 0x4f, 0x5b, 0x53, 0xae, 0x66, 0xb4, 0x32, 0x12,
+        0x92, 0x8c, 0x54, 0x29, 0xc7, 0xe3, 0xef, 0xc8, 0xb5, 0x5b, 0x0f, 0xb6, 0x1d, 0x3f, 0xce, 0x8b,
+        0x99, 0xe7, 0xa1, 0x2a, 0xa5, 0x3b, 0x87, 0x5a, 0x4b, 0x18, 0x08, 0x86, 0xc2, 0x3a, 0x1a, 0x67,
+        0xd6, 0x1b, 0x87, 0xa2, 0xae, 0xab, 0xf3, 0x13, 0x00, 0x7c, 0xb7, 0x0f, 0xcf, 0xb0, 0x93, 0xb0,
+        0x77, 0xe9, 0x50, 0x71, 0x17, 0xa7, 0x62, 0x56, 0x55, 0x0f, 0x64, 0x96, 0x50, 0x58, 0xa2, 0x72,
+        0x30, 0xac, 0xbd, 0x1b, 0x7b, 0x33, 0x7b, 0x56, 0x46, 0xb7, 0xd5, 0x9e, 0x13, 0x40, 0x0c, 0xbe,
+        0x43, 0x76, 0x1c, 0x87, 0x9f, 0xd0, 0x74, 0xca, 0x09, 0x46, 0x77, 0x78, 0x1b, 0xde, 0x70, 0xe3,
+        0x22, 0x8f, 0x12, 0xf4, 0x5a, 0x15, 0xa8, 0xe5, 0x0c, 0x9f, 0xe6, 0x4e, 0xb2, 0x94, 0x26, 0x94,
+        0xd9, 0xfc, 0x7e, 0x33, 0xc0, 0xdf, 0x0d, 0xcc, 0x05, 0xa3, 0xbb, 0x52, 0x80, 0xbc, 0x52, 0x2b,
+        0x71, 0x82, 0x16, 0x9c, 0x4f, 0x7e, 0x20, 0xed, 0xe9, 0x09, 0x3c, 0x73, 0xdb, 0x50, 0x9f, 0x94,
+        0xb5, 0x81, 0x8d, 0xed, 0xe8, 0xb2, 0x6e, 0xc1, 0x50, 0x85, 0xc1, 0x42, 0x17, 0x94, 0xd9, 0x01,
+        0x24, 0x3e, 0xfe, 0x71, 0x9d, 0x59, 0xfe, 0xd0, 0xab, 0x12, 0x1c, 0xe3, 0xdd, 0x80, 0xa4, 0xd2,
+        0xe5, 0x14, 0xf0, 0x28, 0x9f, 0xa1, 0x4f, 0xb8, 0x14, 0x6f, 0x87, 0x18, 0x53, 0xfe, 0x48, 0xfc,
+        0xed, 0xb1, 0x81, 0x34, 0xe7, 0x99, 0x92, 0x8f, 0x7f, 0x84, 0xb2, 0x1f, 0xa8, 0xca, 0x85, 0x41,
+        0x80, 0x11, 0xfd, 0xd2, 0xc1, 0x36, 0x4f, 0x58, 0xb4, 0x78, 0xd2, 0x3c, 0x7f, 0xad, 0x68, 0x4a,
+        0x0c, 0x18, 0x15, 0xe1, 0xec, 0x7f, 0xb7, 0xc2, 0xef, 0x55, 0xc4, 0x5c, 0xb1, 0x51, 0xf8, 0x6c,
+        0x0d, 0x76, 0x6c, 0x2a, 0x96, 0x6c, 0x25, 0x0d, 0x91, 0x29, 0x4e, 0xee, 0xc1, 0xa0, 0xd3, 0x7e,
+        0xab, 0xbf, 0x93, 0x7e, 0x4d, 0x4c, 0x46, 0x42, 0x65, 0x2f, 0x53, 0xc7, 0xe9, 0x8b, 0xbf, 0x20,
+        0xf8, 0x59, 0x88, 0xd8, 0x78, 0xb7, 0x22, 0x2a, 0x0c, 0xeb, 0x65, 0x61, 0xfc, 0xe9, 0xe7, 0xbe,
+        0xc0, 0xf8, 0xe5, 0x14, 0xfa, 0xae, 0x4f, 0x3d, 0x11, 0x51, 0x22, 0xca, 0xa1, 0x78, 0xec, 0x6d,
+        0x98, 0xd9, 0x47, 0xc7, 0x85, 0x33, 0x77, 0x85, 0x37, 0x21, 0x37, 0xe6, 0xa2, 0x02, 0x5a, 0xce,
+        0x3a, 0xb0, 0x60, 0xed, 0xaf, 0x88, 0x16, 0x58, 0xe2, 0x35, 0x10, 0x9b, 0x26, 0x6c, 0xef, 0x97,
+        0x87, 0xfe, 0x38, 0x94, 0x14, 0x75, 0x91, 0xb2, 0x16, 0xb7, 0x01, 0xd9, 0xd6, 0xe4, 0xb5, 0x9a,
+        0x1b, 0x73, 0xc5, 0x9d, 0x86, 0xd6, 0xf2, 0xea, 0xc7, 0xd0, 0xd4, 0x89, 0x1b, 0xf5, 0xbe, 0xff,
+        0xd0, 0xc0, 0xf9, 0x8e, 0xc0, 0x6b, 0x47, 0x2c, 0xe1, 0x33, 0xe9, 0xb8, 0x11, 0x99, 0xd0, 0xd5,
+        0x35, 0x5b, 0xde, 0x0e, 0xa0, 0x23, 0x28, 0xe2, 0x59, 0x0e, 0xe8, 0x7f, 0xf2, 0xe8, 0xb7, 0xae,
+        0xde, 0xf8, 0xd9, 0x0f, 0x7c, 0xbd, 0x91, 0x99, 0x3b, 0x9a, 0xb7, 0xbd, 0x5c, 0x7c, 0x24, 0x23,
+        0xc3, 0x1d, 0x2b, 0x9b,
     });
 }
 
@@ -525,16 +604,8 @@
 
 TEST(WebKit, ServerTrust)
 {
-    TCPServer server(TCPServer::Protocol::HTTPS, [] (SSL* ssl) {
-        TCPServer::read(ssl);
+    HTTPServer server(HTTPServer::respondWithOK, HTTPServer::Protocol::Https);
 
-        const char* reply = ""
-        "HTTP/1.1 200 OK\r\n"
-        "Content-Length: 13\r\n\r\n"
-        "Hello, World!";
-        TCPServer::write(ssl, reply, strlen(reply));
-    });
-
     auto webView = adoptNS([WKWebView new]);
     auto delegate = adoptNS([ServerTrustDelegate new]);
     [webView setNavigationDelegate:delegate.get()];
@@ -549,8 +620,9 @@
 TEST(WebKit, FastServerTrust)
 {
 #if HAVE(CFNETWORK_NSURLSESSION_STRICTRUSTEVALUATE)
-    TCPServer server(TCPServer::Protocol::HTTPS, TCPServer::respondWithOK);
+    HTTPServer server(HTTPServer::respondWithOK, HTTPServer::Protocol::Https);
 #else
+    // FIXME: Remove this. HAVE(CFNETWORK_NSURLSESSION_STRICTRUSTEVALUATE) is now true on all supported platforms.
     TCPServer server(TCPServer::Protocol::HTTPS, [](SSL* ssl) {
         EXPECT_FALSE(ssl);
     }, std::nullopt, 2);

Modified: trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/Proxy.mm (283933 => 283934)


--- trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/Proxy.mm	2021-10-11 20:27:58 UTC (rev 283933)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/Proxy.mm	2021-10-11 20:37:27 UTC (rev 283934)
@@ -27,7 +27,6 @@
 
 #import "HTTPServer.h"
 #import "PlatformUtilities.h"
-#import "TCPServer.h"
 #import "TestNavigationDelegate.h"
 #import "TestUIDelegate.h"
 #import "TestWKWebView.h"
@@ -158,36 +157,12 @@
     EXPECT_WK_STREQ([webView _test_waitForAlert], "success!");
 }
 
-static TCPServer proxyAuthenticationServer()
+static HTTPServer proxyAuthenticationServer()
 {
-    return TCPServer([] (int socket) {
-        auto requestShouldContain = [] (const auto& request, const char* str) {
-            EXPECT_TRUE(strnstr(reinterpret_cast<const char*>(request.data()), str, request.size()));
-        };
-
-        auto connectRequest = TCPServer::read(socket);
-        requestShouldContain(connectRequest, "CONNECT example.com:443");
-        const char* response1 =
-            "HTTP/1.1 407 Proxy Authentication Required\r\n"
-            "Proxy-Authenticate: Basic realm=\"testrealm\"\r\n"
-            "Content-Length: 0\r\n"
-            "\r\n";
-        TCPServer::write(socket, response1, strlen(response1));
-
-        auto connectRequestWithCredentials = TCPServer::read(socket);
-        requestShouldContain(connectRequestWithCredentials, "CONNECT example.com:443");
-        requestShouldContain(connectRequestWithCredentials, "Proxy-Authorization: Basic dGVzdHVzZXI6dGVzdHBhc3N3b3Jk");
-        const char* response2 =
-            "HTTP/1.1 200 Connection Established\r\n"
-            "Connection: close\r\n"
-            "\r\n";
-        TCPServer::write(socket, response2, strlen(response2));
-
-        TCPServer::startSecureConnection(socket, TCPServer::respondWithOK);
-    });
+    return HTTPServer(HTTPServer::respondWithOK, HTTPServer::Protocol::HttpsProxyWithAuthentication);
 }
 
-static std::pair<RetainPtr<WKWebView>, RetainPtr<ProxyDelegate>> webViewAndDelegate(const TCPServer& server)
+static std::pair<RetainPtr<WKWebView>, RetainPtr<ProxyDelegate>> webViewAndDelegate(const HTTPServer& server)
 {
     auto storeConfiguration = adoptNS([_WKWebsiteDataStoreConfiguration new]);
     [storeConfiguration setProxyConfiguration:@{
@@ -226,26 +201,27 @@
 
 TEST(WebKit, SecureProxyConnection)
 {
-    std::atomic<bool> receivedValidClientHello = false;
-    TCPServer server([&] (int socket) {
-        // Check that the client sends what looks like the beginning of a TLS handshake.
-        // We can't test more than this because CFNetwork requires a certificate chain signed by a trusted CA,
-        // and we wouldn't want to include such a certificate's private key in this repository.
-        auto clientHelloBytes = TCPServer::read(socket);
+    bool receivedValidClientHello = false;
+    HTTPServer server([&] (const Connection& connection) {
+        connection.receiveBytes([&](Vector<uint8_t>&& clientHelloBytes) {
+            // Check that the client sends what looks like the beginning of a TLS handshake.
+            // We can't test more than this because CFNetwork requires a certificate chain signed by a trusted CA,
+            // and we wouldn't want to include such a certificate's private key in this repository.
 
-        // https://tools.ietf.org/html/rfc5246#section-6.2.1
-        enum class ContentType : uint8_t { Handshake = 22 };
-        EXPECT_EQ(clientHelloBytes[0], static_cast<uint8_t>(ContentType::Handshake));
-        uint16_t tlsPlaintextLength = clientHelloBytes[3] * 256u + clientHelloBytes[4];
-        uint32_t clientHelloBytesLength = clientHelloBytes[6] * 65536u + clientHelloBytes[7] * 256u + clientHelloBytes[8];
-        EXPECT_EQ(clientHelloBytes.size(), tlsPlaintextLength + sizeof(ContentType) + 2 * sizeof(uint8_t) + sizeof(uint16_t));
-        
-        // https://tools.ietf.org/html/rfc5246#section-7.4
-        enum class HandshakeType : uint8_t { ClientHello = 1 };
-        EXPECT_EQ(clientHelloBytes[5], static_cast<uint8_t>(HandshakeType::ClientHello));
-        EXPECT_EQ(tlsPlaintextLength, clientHelloBytesLength + sizeof(HandshakeType) + 3);
+            // https://tools.ietf.org/html/rfc5246#section-6.2.1
+            enum class ContentType : uint8_t { Handshake = 22 };
+            EXPECT_EQ(clientHelloBytes[0], static_cast<uint8_t>(ContentType::Handshake));
+            uint16_t tlsPlaintextLength = clientHelloBytes[3] * 256u + clientHelloBytes[4];
+            uint32_t clientHelloBytesLength = clientHelloBytes[6] * 65536u + clientHelloBytes[7] * 256u + clientHelloBytes[8];
+            EXPECT_EQ(clientHelloBytes.size(), tlsPlaintextLength + sizeof(ContentType) + 2 * sizeof(uint8_t) + sizeof(uint16_t));
+            
+            // https://tools.ietf.org/html/rfc5246#section-7.4
+            enum class HandshakeType : uint8_t { ClientHello = 1 };
+            EXPECT_EQ(clientHelloBytes[5], static_cast<uint8_t>(HandshakeType::ClientHello));
+            EXPECT_EQ(tlsPlaintextLength, clientHelloBytesLength + sizeof(HandshakeType) + 3);
 
-        receivedValidClientHello = true;
+            receivedValidClientHello = true;
+        });
     });
     
     auto storeConfiguration = adoptNS([_WKWebsiteDataStoreConfiguration new]);
@@ -260,8 +236,7 @@
     [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:@"https://example.com/"]]];
-    while (!receivedValidClientHello)
-        TestWebKitAPI::Util::spinRunLoop();
+    TestWebKitAPI::Util::run(&receivedValidClientHello);
 }
 
 } // namespace TestWebKitAPI

Modified: trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/ServiceWorkerBasic.mm (283933 => 283934)


--- trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/ServiceWorkerBasic.mm	2021-10-11 20:27:58 UTC (rev 283933)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/ServiceWorkerBasic.mm	2021-10-11 20:37:27 UTC (rev 283934)
@@ -662,10 +662,8 @@
     TestWebKitAPI::Util::run(&done);
     done = false;
 
-    ServiceWorkerTCPServer server({
-        { "text/html", mainCacheStorageBytes }
-    }, {
-        { "text/html", mainCacheStorageBytes }
+    TestWebKitAPI::HTTPServer server({
+        { "/", { mainCacheStorageBytes } }
     });
 
     auto configuration = adoptNS([[WKWebViewConfiguration alloc] init]);
@@ -713,15 +711,12 @@
     RetainPtr<SWMessageHandlerForFetchTest> messageHandler = adoptNS([[SWMessageHandlerForFetchTest alloc] init]);
     [[configuration userContentController] addScriptMessageHandler:messageHandler.get() name:@"sw"];
 
-    ServiceWorkerTCPServer server({
-        { "text/html", mainForFetchTestBytes },
-        { "application/_javascript_", scriptHandlingFetchBytes },
-    }, {
-        { "text/html", mainForFetchTestBytes },
-        { "application/_javascript_", scriptHandlingFetchBytes },
+    TestWebKitAPI::HTTPServer server({
+        { "/", { mainForFetchTestBytes } },
+        { "/sw.js", { { { "Content-Type", "application/_javascript_" } }, scriptHandlingFetchBytes } },
     });
 
-    RetainPtr<WKWebView> webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get()]);
+    auto webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get()]);
 
     [webView loadRequest:server.request()];
 

Modified: trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/TLSDeprecation.mm (283933 => 283934)


--- trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/TLSDeprecation.mm	2021-10-11 20:27:58 UTC (rev 283933)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/TLSDeprecation.mm	2021-10-11 20:37:27 UTC (rev 283934)
@@ -25,11 +25,8 @@
 
 #import "config.h"
 
-#if HAVE(SSL)
-
 #import "HTTPServer.h"
 #import "PlatformUtilities.h"
-#import "TCPServer.h"
 #import "TestNavigationDelegate.h"
 #import "TestWKWebView.h"
 #import "WebCoreTestSupport.h"
@@ -239,10 +236,9 @@
 TEST(TLSVersion, Preconnect)
 {
     bool connectionAttempted = false;
-    TCPServer server(TCPServer::Protocol::HTTPS, [&](SSL *ssl) {
-        EXPECT_FALSE(ssl);
+    HTTPServer server([&](const Connection&) {
         connectionAttempted = true;
-    }, tls1_1);
+    }, HTTPServer::Protocol::HttpsWithLegacyTLS);
 
     auto webView = adoptNS([WKWebView new]);
     [webView loadHTMLString:makeString("<head><link rel='preconnect' href=''></link></head>") baseURL:nil];
@@ -494,5 +490,3 @@
 #endif // HAVE(TLS_VERSION_DURING_CHALLENGE)
 
 }
-
-#endif // HAVE(SSL)

Modified: trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/TestSOAuthorization.mm (283933 => 283934)


--- trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/TestSOAuthorization.mm	2021-10-11 20:27:58 UTC (rev 283933)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/TestSOAuthorization.mm	2021-10-11 20:37:27 UTC (rev 283934)
@@ -29,9 +29,9 @@
 #if HAVE(APP_SSO)
 
 #import "ClassMethodSwizzler.h"
+#import "HTTPServer.h"
 #import "InstanceMethodSwizzler.h"
 #import "PlatformUtilities.h"
-#import "TCPServer.h"
 #import "TestWKWebView.h"
 #import <WebKit/WKNavigationActionPrivate.h>
 #import <WebKit/WKNavigationDelegatePrivate.h>
@@ -2643,8 +2643,8 @@
     ClassMethodSwizzler swizzler4([AKAuthorizationController class], @selector(isURLFromAppleOwnedDomain:), reinterpret_cast<IMP>(overrideIsURLFromAppleOwnedDomain));
     InstanceMethodSwizzler swizzler5(PAL::getSOAuthorizationClass(), @selector(getAuthorizationHintsWithURL:responseCode:completion:), reinterpret_cast<IMP>(overrideGetAuthorizationHintsWithURL));
 
-    TCPServer server([parentHtml = generateHtml(parentTemplate, "simple.html"), frameHtml = generateHtml(iframeTemplate, "parent.postMessage('Referrer: ' + document.referrer, '*');")] (int socket) {
-        NSString *firstResponse = [NSString stringWithFormat:
+    HTTPServer server([parentHtml = generateHtml(parentTemplate, "simple.html"), frameHtml = generateHtml(iframeTemplate, "parent.postMessage('Referrer: ' + document.referrer, '*');")] (const Connection& connection) {
+        RetainPtr<NSString> firstResponse = [NSString stringWithFormat:
             @"HTTP/1.1 200 OK\r\n"
             "Content-Length: %d\r\n\r\n"
             "%@",
@@ -2651,7 +2651,7 @@
             parentHtml.length(),
             (id)parentHtml
         ];
-        NSString *secondResponse = [NSString stringWithFormat:
+        RetainPtr<NSString> secondResponse = [NSString stringWithFormat:
             @"HTTP/1.1 200 OK\r\n"
             "Content-Length: %d\r\n\r\n"
             "%@",
@@ -2659,10 +2659,13 @@
             (id)frameHtml
         ];
 
-        TCPServer::read(socket);
-        TCPServer::write(socket, firstResponse.UTF8String, firstResponse.length);
-        TCPServer::read(socket);
-        TCPServer::write(socket, secondResponse.UTF8String, secondResponse.length);
+        connection.receiveHTTPRequest([=](Vector<char>&&) {
+            connection.send(firstResponse.get(), [=] {
+                connection.receiveHTTPRequest([=](Vector<char>&&) {
+                    connection.send(secondResponse.get());
+                });
+            });
+        });
     });
 
     auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 500)]);

Modified: trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/_WKWebAuthenticationPanel.mm (283933 => 283934)


--- trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/_WKWebAuthenticationPanel.mm	2021-10-11 20:27:58 UTC (rev 283933)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/_WKWebAuthenticationPanel.mm	2021-10-11 20:37:27 UTC (rev 283934)
@@ -28,8 +28,8 @@
 
 #if ENABLE(WEB_AUTHN)
 
+#import "HTTPServer.h"
 #import "PlatformUtilities.h"
-#import "TCPServer.h"
 #import "TestWKWebView.h"
 #import "WKWebViewConfigurationExtras.h"
 #import <LocalAuthentication/LocalAuthentication.h>
@@ -655,8 +655,8 @@
 
 TEST(WebAuthenticationPanel, SubFrameChangeLocationHidCancel)
 {
-    TCPServer server([parentFrame = String(parentFrame), subFrame = String(subFrame)] (int socket) {
-        NSString *firstResponse = [NSString stringWithFormat:
+    HTTPServer server([parentFrame = String(parentFrame), subFrame = String(subFrame)] (const Connection& connection) {
+        RetainPtr<NSString> firstResponse = [NSString stringWithFormat:
             @"HTTP/1.1 200 OK\r\n"
             "Content-Length: %d\r\n\r\n"
             "%@",
@@ -663,7 +663,7 @@
             parentFrame.length(),
             (id)parentFrame
         ];
-        NSString *secondResponse = [NSString stringWithFormat:
+        RetainPtr<NSString> secondResponse = [NSString stringWithFormat:
             @"HTTP/1.1 200 OK\r\n"
             "Content-Length: %d\r\n\r\n"
             "%@",
@@ -670,11 +670,13 @@
             subFrame.length(),
             (id)subFrame
         ];
-
-        TCPServer::read(socket);
-        TCPServer::write(socket, firstResponse.UTF8String, firstResponse.length);
-        TCPServer::read(socket);
-        TCPServer::write(socket, secondResponse.UTF8String, secondResponse.length);
+        connection.receiveHTTPRequest([=] (Vector<char>&&) {
+            connection.send(firstResponse.get(), [=] {
+                connection.receiveHTTPRequest([=] (Vector<char>&&) {
+                    connection.send(secondResponse.get());
+                });
+            });
+        });
     });
 
     auto *configuration = [WKWebViewConfiguration _test_configurationWithTestPlugInClassName:@"WebProcessPlugInWithInternals" configureJSCForTesting:YES];
@@ -700,8 +702,8 @@
 
 TEST(WebAuthenticationPanel, SubFrameDestructionHidCancel)
 {
-    TCPServer server([parentFrame = String(parentFrame), subFrame = String(subFrame)] (int socket) {
-        NSString *firstResponse = [NSString stringWithFormat:
+    HTTPServer server([parentFrame = String(parentFrame), subFrame = String(subFrame)] (const Connection& connection) {
+        RetainPtr<NSString> firstResponse = [NSString stringWithFormat:
             @"HTTP/1.1 200 OK\r\n"
             "Content-Length: %d\r\n\r\n"
             "%@",
@@ -708,7 +710,7 @@
             parentFrame.length(),
             (id)parentFrame
         ];
-        NSString *secondResponse = [NSString stringWithFormat:
+        RetainPtr<NSString> secondResponse = [NSString stringWithFormat:
             @"HTTP/1.1 200 OK\r\n"
             "Content-Length: %d\r\n\r\n"
             "%@",
@@ -716,10 +718,13 @@
             (id)subFrame
         ];
 
-        TCPServer::read(socket);
-        TCPServer::write(socket, firstResponse.UTF8String, firstResponse.length);
-        TCPServer::read(socket);
-        TCPServer::write(socket, secondResponse.UTF8String, secondResponse.length);
+        connection.receiveHTTPRequest([=] (Vector<char>&&) {
+            connection.send(firstResponse.get(), [=] {
+                connection.receiveHTTPRequest([=] (Vector<char>&&) {
+                    connection.send(secondResponse.get());
+                });
+            });
+        });
     });
 
     auto *configuration = [WKWebViewConfiguration _test_configurationWithTestPlugInClassName:@"WebProcessPlugInWithInternals" configureJSCForTesting:YES];

Modified: trunk/Tools/TestWebKitAPI/cocoa/HTTPServer.h (283933 => 283934)


--- trunk/Tools/TestWebKitAPI/cocoa/HTTPServer.h	2021-10-11 20:27:58 UTC (rev 283933)
+++ trunk/Tools/TestWebKitAPI/cocoa/HTTPServer.h	2021-10-11 20:37:27 UTC (rev 283934)
@@ -41,7 +41,7 @@
     WTF_MAKE_FAST_ALLOCATED;
 public:
     struct RequestData;
-    enum class Protocol : uint8_t { Http, Https, HttpsWithLegacyTLS, Http2, HttpsProxy };
+    enum class Protocol : uint8_t { Http, Https, HttpsWithLegacyTLS, Http2, HttpsProxy, HttpsProxyWithAuthentication };
     using CertificateVerifier = Function<void(sec_protocol_metadata_t, sec_trust_t, sec_protocol_verify_complete_t)>;
 
     HTTPServer(std::initializer_list<std::pair<String, HTTPResponse>>, Protocol = Protocol::Http, CertificateVerifier&& = nullptr, RetainPtr<SecIdentityRef>&& = nullptr, std::optional<uint16_t> port = { });

Modified: trunk/Tools/TestWebKitAPI/cocoa/HTTPServer.mm (283933 => 283934)


--- trunk/Tools/TestWebKitAPI/cocoa/HTTPServer.mm	2021-10-11 20:27:58 UTC (rev 283933)
+++ trunk/Tools/TestWebKitAPI/cocoa/HTTPServer.mm	2021-10-11 20:37:27 UTC (rev 283934)
@@ -52,11 +52,26 @@
     Vector<Connection> connections;
 };
 
-static RetainPtr<nw_protocol_definition_t> proxyDefinition()
+static RetainPtr<nw_protocol_definition_t> proxyDefinition(HTTPServer::Protocol protocol)
 {
-    return adoptNS(nw_framer_create_definition("HttpsProxy", NW_FRAMER_CREATE_FLAGS_DEFAULT, [] (nw_framer_t framer) -> nw_framer_start_result_t {
-        nw_framer_set_input_handler(framer, [] (nw_framer_t framer) -> size_t {
-            nw_framer_parse_input(framer, 1, std::numeric_limits<uint32_t>::max(), nullptr, [retainedFramer = retainPtr(framer)](uint8_t*, size_t bufferLength, bool) mutable -> size_t {
+    return adoptNS(nw_framer_create_definition("HttpsProxy", NW_FRAMER_CREATE_FLAGS_DEFAULT, [protocol] (nw_framer_t framer) -> nw_framer_start_result_t {
+        __block bool askedForCredentials = false;
+        nw_framer_set_input_handler(framer, ^size_t(nw_framer_t framer) {
+            __block RetainPtr<nw_framer_t> retainedFramer = framer;
+            nw_framer_parse_input(framer, 1, std::numeric_limits<uint32_t>::max(), nullptr, ^size_t(uint8_t* buffer, size_t bufferLength, bool) {
+                if (protocol == HTTPServer::Protocol::HttpsProxyWithAuthentication) {
+                    if (!std::exchange(askedForCredentials, true)) {
+                        const char* challengeResponse =
+                            "HTTP/1.1 407 Proxy Authentication Required\r\n"
+                            "Proxy-Authenticate: Basic realm=\"testrealm\"\r\n"
+                            "Content-Length: 0\r\n"
+                            "\r\n";
+                        auto response = adoptNS(dispatch_data_create(challengeResponse, strlen(challengeResponse), nullptr, nullptr));
+                        nw_framer_write_output_data(retainedFramer.get(), response.get());
+                        return bufferLength;
+                    }
+                    EXPECT_TRUE(strnstr(reinterpret_cast<const char*>(buffer), "Proxy-Authorization: Basic dGVzdHVzZXI6dGVzdHBhc3N3b3Jk", bufferLength));
+                }
                 const char* negotiationResponse = ""
                     "HTTP/1.1 200 Connection Established\r\n"
                     "Connection: close\r\n\r\n";
@@ -74,6 +89,20 @@
     }));
 }
 
+static bool shouldDisableTLS(HTTPServer::Protocol protocol)
+{
+    switch (protocol) {
+    case HTTPServer::Protocol::Http:
+    case HTTPServer::Protocol::HttpsProxy:
+    case HTTPServer::Protocol::HttpsProxyWithAuthentication:
+        return true;
+    case HTTPServer::Protocol::Https:
+    case HTTPServer::Protocol::HttpsWithLegacyTLS:
+    case HTTPServer::Protocol::Http2:
+        return false;
+    }
+}
+
 RetainPtr<nw_parameters_t> HTTPServer::listenerParameters(Protocol protocol, CertificateVerifier&& verifier, RetainPtr<SecIdentityRef>&& customTestIdentity, std::optional<uint16_t> port)
 {
     if (protocol != Protocol::Http && !customTestIdentity)
@@ -95,14 +124,14 @@
             sec_protocol_options_add_tls_application_protocol(options.get(), "h2");
     };
 
-    auto configureTLSBlock = protocol == Protocol::Http || protocol == Protocol::HttpsProxy ? makeBlockPtr(NW_PARAMETERS_DISABLE_PROTOCOL) : makeBlockPtr(WTFMove(configureTLS));
+    auto configureTLSBlock = shouldDisableTLS(protocol) ? makeBlockPtr(NW_PARAMETERS_DISABLE_PROTOCOL) : makeBlockPtr(WTFMove(configureTLS));
     auto parameters = adoptNS(nw_parameters_create_secure_tcp(configureTLSBlock.get(), NW_PARAMETERS_DEFAULT_CONFIGURATION));
     if (port)
         nw_parameters_set_local_endpoint(parameters.get(), nw_endpoint_create_host("::", makeString(*port).utf8().data()));
 
-    if (protocol == Protocol::HttpsProxy) {
+    if (protocol == Protocol::HttpsProxy || protocol == Protocol::HttpsProxyWithAuthentication) {
         auto stack = adoptNS(nw_parameters_copy_default_protocol_stack(parameters.get()));
-        auto options = adoptNS(nw_framer_create_options(proxyDefinition().get()));
+        auto options = adoptNS(nw_framer_create_options(proxyDefinition(protocol).get()));
         nw_protocol_stack_prepend_application_protocol(stack.get(), options.get());
 
         auto tlsOptions = adoptNS(nw_tls_create_options());
@@ -208,7 +237,7 @@
     return m_requestData->requestCount;
 }
 
-static String statusText(unsigned statusCode)
+static ASCIILiteral statusText(unsigned statusCode)
 {
     switch (statusCode) {
     case 101:
@@ -217,11 +246,13 @@
         return "OK"_s;
     case 301:
         return "Moved Permanently"_s;
+    case 302:
+        return "Found"_s;
     case 404:
         return "Not Found"_s;
     }
     ASSERT_NOT_REACHED();
-    return { };
+    return "Unknown Status Code"_s;
 }
 
 static RetainPtr<dispatch_data_t> dataFromString(String&& s)
@@ -316,6 +347,7 @@
         format = @"https://127.0.0.1:%d%s";
         break;
     case Protocol::HttpsProxy:
+    case Protocol::HttpsProxyWithAuthentication:
         RELEASE_ASSERT_NOT_REACHED();
     }
     return [NSURLRequest requestWithURL:[NSURL URLWithString:[NSString stringWithFormat:format, port(), path.utf8().data()]]];
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to