Changeset 262985 in webkit


Ignore:
Timestamp:
Jun 12, 2020, 4:32:15 PM (4 years ago)
Author:
achristensen@apple.com
Message:

Make API tests tolerant of our relatively new use of WebPageProxy::preconnectTo
https://bugs.webkit.org/show_bug.cgi?id=213144

Reviewed by Geofferey Garen.

Source/WebKit:

  • NetworkProcess/cocoa/NetworkSessionCocoa.h:
  • NetworkProcess/cocoa/NetworkSessionCocoa.mm:

(-[WKNetworkSessionDelegate URLSession:task:willPerformHTTPRedirection:newRequest:completionHandler:]):
(-[WKNetworkSessionDelegate URLSession:task:didCompleteWithError:]):
(-[WKNetworkSessionDelegate URLSession:dataTask:didReceiveResponse:completionHandler:]):
(WebKit::NetworkSessionCocoa::taskServerConnectionSucceeded):
(WebKit::NetworkSessionCocoa::taskReceivedBytes): Deleted.
Fix our logic that remembers successful client certificate connections.
If a task completes with no error (like a preconnect task does), consider that a successful connection.

  • UIProcess/Network/NetworkProcessProxy.cpp:

(WebKit::NetworkProcessProxy::preconnectTo):
Remove the check to not preconnect to loopback addresses.
This was making our tests different than the real internet and prevented me from landing a perfectly good test
in https://bugs.webkit.org/show_bug.cgi?id=213109

Tools:

Most changes are straightforward moving to HTTPServer, which is more tolerant of different numbers of connections except these two:

The ResourceLoadDelegate.Challenge API test was checking the output of _WKResourceLoadDelegate.didReceiveChallenge
by using a server trust challenge. Now that preconnecting happens, the server trust evaluation would happen with a
PreconnectTask, not the main resource load. The WKNavigationDelegate still gets the challenge and there is no problem
here, but in order to continue to test _WKResourceLoadDelegate.didReceiveChallenge I use a basic authentication challenge
instead of a server trust evaluation.

The WebKit.FastServerTrust API test now has two failed attempts (one from the preconnect attempt, one from the main resource load attempt),
but only when _strictTrustEvaluate is not available.

  • TestWebKitAPI/TCPServer.cpp:

(TestWebKitAPI::TCPServer::TCPServer):

  • TestWebKitAPI/TCPServer.h:
  • TestWebKitAPI/Tests/WebKitCocoa/Challenge.mm:

(TEST):
(TestWebKitAPI::TEST):

  • TestWebKitAPI/Tests/WebKitCocoa/ResourceLoadDelegate.mm:
  • TestWebKitAPI/Tests/WebKitCocoa/ServiceWorkerBasic.mm:
  • TestWebKitAPI/cocoa/HTTPServer.h:
  • TestWebKitAPI/cocoa/HTTPServer.mm:

(TestWebKitAPI::HTTPServer::respondWithChallengeThenOK):

Location:
trunk
Files:
12 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit/ChangeLog

    r262984 r262985  
     12020-06-12  Alex Christensen  <achristensen@webkit.org>
     2
     3        Make API tests tolerant of our relatively new use of WebPageProxy::preconnectTo
     4        https://bugs.webkit.org/show_bug.cgi?id=213144
     5
     6        Reviewed by Geofferey Garen.
     7
     8        * NetworkProcess/cocoa/NetworkSessionCocoa.h:
     9        * NetworkProcess/cocoa/NetworkSessionCocoa.mm:
     10        (-[WKNetworkSessionDelegate URLSession:task:willPerformHTTPRedirection:newRequest:completionHandler:]):
     11        (-[WKNetworkSessionDelegate URLSession:task:didCompleteWithError:]):
     12        (-[WKNetworkSessionDelegate URLSession:dataTask:didReceiveResponse:completionHandler:]):
     13        (WebKit::NetworkSessionCocoa::taskServerConnectionSucceeded):
     14        (WebKit::NetworkSessionCocoa::taskReceivedBytes): Deleted.
     15        Fix our logic that remembers successful client certificate connections.
     16        If a task completes with no error (like a preconnect task does), consider that a successful connection.
     17
     18        * UIProcess/Network/NetworkProcessProxy.cpp:
     19        (WebKit::NetworkProcessProxy::preconnectTo):
     20        Remove the check to not preconnect to loopback addresses.
     21        This was making our tests different than the real internet and prevented me from landing a perfectly good test
     22        in https://bugs.webkit.org/show_bug.cgi?id=213109
     23
    1242020-06-12  Per Arne Vollan  <pvollan@apple.com>
    225
  • trunk/Source/WebKit/NetworkProcess/cocoa/NetworkSessionCocoa.h

    r260900 r262985  
    103103   
    104104    void clientCertificateSuggestedForHost(NetworkDataTaskCocoa::TaskIdentifier, NSURLCredential *, const String& host, uint16_t port);
    105     void taskReceivedBytes(NetworkDataTaskCocoa::TaskIdentifier);
     105    void taskServerConnectionSucceeded(NetworkDataTaskCocoa::TaskIdentifier);
    106106    void taskFailed(NetworkDataTaskCocoa::TaskIdentifier);
    107107    NSURLCredential *successfulClientCertificateForHost(const String& host, uint16_t port) const;
  • trunk/Source/WebKit/NetworkProcess/cocoa/NetworkSessionCocoa.mm

    r262930 r262985  
    533533
    534534        if (auto* sessionCocoa = [self sessionFromTask:task])
    535             sessionCocoa->taskReceivedBytes(taskIdentifier);
     535            sessionCocoa->taskServerConnectionSucceeded(taskIdentifier);
    536536
    537537        bool shouldIgnoreHSTS = false;
     
    731731
    732732    if (auto* networkDataTask = [self existingTask:task]) {
    733         if (auto* sessionCocoa = [self sessionFromTask:task])
    734             sessionCocoa->taskFailed(task.taskIdentifier);
     733        if (auto* sessionCocoa = [self sessionFromTask:task]) {
     734            if (error)
     735                sessionCocoa->taskFailed(task.taskIdentifier);
     736            else
     737                sessionCocoa->taskServerConnectionSucceeded(task.taskIdentifier);
     738        }
    735739        networkDataTask->didCompleteWithError(error, networkDataTask->networkLoadMetrics());
    736740    } else if (error) {
     
    873877
    874878        if (auto* sessionCocoa = [self sessionFromTask:dataTask])
    875             sessionCocoa->taskReceivedBytes(taskIdentifier);
     879            sessionCocoa->taskServerConnectionSucceeded(taskIdentifier);
    876880
    877881        NegotiatedLegacyTLS negotiatedLegacyTLS = NegotiatedLegacyTLS::No;
     
    10621066}
    10631067
    1064 void NetworkSessionCocoa::taskReceivedBytes(NetworkDataTaskCocoa::TaskIdentifier identifier)
     1068void NetworkSessionCocoa::taskServerConnectionSucceeded(NetworkDataTaskCocoa::TaskIdentifier identifier)
    10651069{
    10661070    if (LIKELY(m_suggestedClientCertificates.isEmpty()))
  • trunk/Source/WebKit/UIProcess/Network/NetworkProcessProxy.cpp

    r262487 r262985  
    14731473void NetworkProcessProxy::preconnectTo(PAL::SessionID sessionID, WebPageProxyIdentifier webPageProxyID, WebCore::PageIdentifier webPageID, const URL& url, const String& userAgent, WebCore::StoredCredentialsPolicy storedCredentialsPolicy, Optional<NavigatingToAppBoundDomain> isNavigatingToAppBoundDomain)
    14741474{
    1475     if (!url.isValid() || !url.protocolIsInHTTPFamily() || SecurityOrigin::isLocalHostOrLoopbackIPAddress(url.host()))
     1475    if (!url.isValid() || !url.protocolIsInHTTPFamily())
    14761476        return;
    14771477    send(Messages::NetworkProcess::PreconnectTo(sessionID, webPageProxyID, webPageID, url, userAgent, storedCredentialsPolicy, isNavigatingToAppBoundDomain), 0);
  • trunk/Tools/ChangeLog

    r262975 r262985  
     12020-06-12  Alex Christensen  <achristensen@webkit.org>
     2
     3        Make API tests tolerant of our relatively new use of WebPageProxy::preconnectTo
     4        https://bugs.webkit.org/show_bug.cgi?id=213144
     5
     6        Reviewed by Geofferey Garen.
     7
     8        Most changes are straightforward moving to HTTPServer, which is more tolerant of different numbers of connections except these two:
     9
     10        The ResourceLoadDelegate.Challenge API test was checking the output of _WKResourceLoadDelegate.didReceiveChallenge
     11        by using a server trust challenge.  Now that preconnecting happens, the server trust evaluation would happen with a
     12        PreconnectTask, not the main resource load.  The WKNavigationDelegate still gets the challenge and there is no problem
     13        here, but in order to continue to test _WKResourceLoadDelegate.didReceiveChallenge I use a basic authentication challenge
     14        instead of a server trust evaluation.
     15
     16        The WebKit.FastServerTrust API test now has two failed attempts (one from the preconnect attempt, one from the main resource load attempt),
     17        but only when _strictTrustEvaluate is not available.
     18
     19        * TestWebKitAPI/TCPServer.cpp:
     20        (TestWebKitAPI::TCPServer::TCPServer):
     21        * TestWebKitAPI/TCPServer.h:
     22        * TestWebKitAPI/Tests/WebKitCocoa/Challenge.mm:
     23        (TEST):
     24        (TestWebKitAPI::TEST):
     25        * TestWebKitAPI/Tests/WebKitCocoa/ResourceLoadDelegate.mm:
     26        * TestWebKitAPI/Tests/WebKitCocoa/ServiceWorkerBasic.mm:
     27        * TestWebKitAPI/cocoa/HTTPServer.h:
     28        * TestWebKitAPI/cocoa/HTTPServer.mm:
     29        (TestWebKitAPI::HTTPServer::respondWithChallengeThenOK):
     30
    1312020-06-12  Diego Pino Garcia  <dpino@igalia.com>
    232
  • trunk/Tools/TestWebKitAPI/TCPServer.cpp

    r259910 r262985  
    208208};
    209209
    210 TCPServer::TCPServer(Protocol protocol, Function<void(SSL*)>&& secureConnectionHandler, Optional<uint16_t> maxTLSVersion)
     210TCPServer::TCPServer(Protocol protocol, Function<void(SSL*)>&& secureConnectionHandler, Optional<uint16_t> maxTLSVersion, size_t connections)
    211211{
    212212    switch (protocol) {
     
    233233        break;
    234234    }
    235     listenForConnections(1);
     235    listenForConnections(connections);
    236236}
    237237#endif // HAVE(SSL)
  • trunk/Tools/TestWebKitAPI/TCPServer.h

    r259910 r262985  
    4848        HTTPS, HTTPSProxy, HTTPSWithClientCertificateRequest
    4949    };
    50     TCPServer(Protocol, Function<void(SSL*)>&&, Optional<uint16_t> maxTLSVersion = WTF::nullopt);
     50    TCPServer(Protocol, Function<void(SSL*)>&&, Optional<uint16_t> maxTLSVersion = WTF::nullopt, size_t connections = 1);
    5151#endif // HAVE(SSL)
    5252    ~TCPServer();
  • trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/Challenge.mm

    r260322 r262985  
    204204@end
    205205
     206#if HAVE(NETWORK_FRAMEWORK)
     207
    206208TEST(Challenge, BasicProposedCredential)
    207209{
    208210    using namespace TestWebKitAPI;
    209     TCPServer server(TCPServer::respondWithChallengeThenOK, 2);
     211    HTTPServer server(HTTPServer::respondWithChallengeThenOK);
    210212    auto configuration = retainPtr([WKWebViewConfiguration _test_configurationWithTestPlugInClassName:@"BasicProposedCredentialPlugIn"]);
    211213    auto webView = adoptNS([[WKWebView alloc] initWithFrame:CGRectZero configuration:configuration.get()]);
     
    217219    [[webView configuration].processPool _clearPermanentCredentialsForProtectionSpace:protectionSpace];
    218220
    219     RetainPtr<NSURLRequest> request = [NSURLRequest requestWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://127.0.0.1:%d/", server.port()]]];
     221    RetainPtr<NSURLRequest> request = server.request();
    220222    [webView loadRequest:request.get()];
    221223    Util::run(&navigationFinished);
     
    228230    [[webView configuration].processPool _clearPermanentCredentialsForProtectionSpace:protectionSpace];
    229231}
     232
     233#endif // HAVE(NETWORK_FRAMEWORK)
    230234
    231235#if HAVE(SSL)
     
    380384    TCPServer server(TCPServer::Protocol::HTTPS, [](SSL* ssl) {
    381385        EXPECT_FALSE(ssl);
    382     });
     386    }, WTF::nullopt, 2);
    383387#endif
    384388    WKWebViewConfiguration *configuration = [[[WKWebViewConfiguration alloc] init] autorelease];
     
    493497    [webView loadRequest:server.request()];
    494498    [delegate waitForDidFinishNavigation];
    495     EXPECT_EQ(countClientCertChallenges(methods), certChallengesAfterInitialFailure + 1);
     499    EXPECT_EQ(countClientCertChallenges(methods), certChallengesAfterInitialFailure);
    496500}
    497501
  • trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/ResourceLoadDelegate.mm

    r259307 r262985  
    391391// FIXME: Add a test for loadedFromCache.
    392392
    393 #endif // HAVE(NETWORK_FRAMEWORK)
    394 
    395 #if HAVE(SSL)
    396 
    397393TEST(ResourceLoadDelegate, Challenge)
    398394{
    399395    using namespace TestWebKitAPI;
    400     TCPServer server(TCPServer::Protocol::HTTPS, [] (SSL* ssl) {
    401         EXPECT_TRUE(!!ssl); // Connection should succeed after a server trust challenge.
    402         // Send nothing to make the resource load fail.
    403     });
     396    HTTPServer server(HTTPServer::respondWithChallengeThenOK);
    404397
    405398    auto navigationDelegate = adoptNS([TestNavigationDelegate new]);
    406399    [navigationDelegate setDidReceiveAuthenticationChallenge:^(WKWebView *, NSURLAuthenticationChallenge *challenge, void (^completionHandler)(NSURLSessionAuthChallengeDisposition, NSURLCredential *)) {
    407         EXPECT_WK_STREQ(challenge.protectionSpace.authenticationMethod, NSURLAuthenticationMethodServerTrust);
    408         completionHandler(NSURLSessionAuthChallengeUseCredential, [NSURLCredential credentialForTrust:challenge.protectionSpace.serverTrust]);
     400        EXPECT_WK_STREQ(challenge.protectionSpace.authenticationMethod, NSURLAuthenticationMethodHTTPBasic);
     401        completionHandler(NSURLSessionAuthChallengeUseCredential, [NSURLCredential credentialWithUser:@"testuser" password:@"testpassword" persistence:NSURLCredentialPersistenceNone]);
    409402    }];
    410403
     
    413406    auto resourceLoadDelegate = adoptNS([TestResourceLoadDelegate new]);
    414407    [resourceLoadDelegate setDidReceiveChallenge:^(WKWebView *, _WKResourceLoadInfo *, NSURLAuthenticationChallenge *challenge) {
    415         EXPECT_WK_STREQ(challenge.protectionSpace.authenticationMethod, NSURLAuthenticationMethodServerTrust);
     408        EXPECT_WK_STREQ(challenge.protectionSpace.authenticationMethod, NSURLAuthenticationMethodHTTPBasic);
    416409        receivedChallengeNotificiation = true;
    417410    }];
    418411    [resourceLoadDelegate setDidCompleteWithError:^(WKWebView *, _WKResourceLoadInfo *, NSError *error, NSURLResponse *) {
    419         EXPECT_EQ(error.code, kCFURLErrorCannotConnectToHost);
    420         EXPECT_WK_STREQ(error.domain, NSURLErrorDomain);
     412        EXPECT_FALSE(error);
    421413        receivedErrorNotification = true;
    422414    }];
     
    425417    [webView setNavigationDelegate:navigationDelegate.get()];
    426418    [webView _setResourceLoadDelegate:resourceLoadDelegate.get()];
    427     [webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"https://127.0.0.1:%d/", server.port()]]]];
     419    [webView loadRequest:server.request()];
    428420    TestWebKitAPI::Util::run(&receivedErrorNotification);
    429421    EXPECT_TRUE(receivedChallengeNotificiation);
    430422}
    431423
    432 #endif // HAVE(SSL)
     424#endif // HAVE(NETWORK_FRAMEWORK)
  • trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/ServiceWorkerBasic.mm

    r262493 r262985  
    15741574}
    15751575
     1576#if HAVE(NETWORK_FRAMEWORK)
     1577
    15761578static size_t launchServiceWorkerProcess(bool useSeparateServiceWorkerProcess, bool loadAboutBlankBeforePage)
    15771579{
     
    15901592    [[configuration userContentController] addScriptMessageHandler:messageHandler.get() name:@"sw"];
    15911593
    1592     ServiceWorkerTCPServer server({
    1593         { "text/html", mainBytes },
    1594         { "application/javascript", scriptBytes },
     1594    TestWebKitAPI::HTTPServer server({
     1595        { "/", { mainBytes } },
     1596        { "/sw.js", { {{ "Content-Type", "application/javascript" }}, scriptBytes } }
    15951597    });
    15961598
     
    16351637    EXPECT_EQ(2u, launchServiceWorkerProcess(useSeparateServiceWorkerProcess, firstLoadAboutBlank));
    16361638}
     1639
     1640#endif // HAVE(NETWORK_FRAMEWORK)
    16371641
    16381642void waitUntilServiceWorkerProcessForegroundActivityState(WKWebView *page, bool shouldHaveActivity)
  • trunk/Tools/TestWebKitAPI/cocoa/HTTPServer.h

    r262018 r262985  
    5454    size_t totalRequests() const;
    5555
     56    static void respondWithChallengeThenOK(Connection);
     57   
    5658private:
    5759    static RetainPtr<nw_parameters_t> listenerParameters(Protocol, CertificateVerifier&&);
  • trunk/Tools/TestWebKitAPI/cocoa/HTTPServer.mm

    r262018 r262985  
    116116HTTPServer::~HTTPServer() = default;
    117117
     118void HTTPServer::respondWithChallengeThenOK(Connection connection)
     119{
     120    connection.receiveHTTPRequest([connection] (Vector<char>&&) {
     121        const char* challengeHeader =
     122        "HTTP/1.1 401 Unauthorized\r\n"
     123        "Date: Sat, 23 Mar 2019 06:29:01 GMT\r\n"
     124        "Content-Length: 0\r\n"
     125        "WWW-Authenticate: Basic realm=\"testrealm\"\r\n\r\n";
     126        connection.send(challengeHeader, [connection] {
     127            connection.receiveHTTPRequest([connection] (Vector<char>&&) {
     128                connection.send(
     129                    "HTTP/1.1 200 OK\r\n"
     130                    "Content-Length: 13\r\n\r\n"
     131                    "Hello, World!"
     132                );
     133            });
     134        });
     135    });
     136}
     137
    118138size_t HTTPServer::totalRequests() const
    119139{
Note: See TracChangeset for help on using the changeset viewer.