Changeset 267448 in webkit


Ignore:
Timestamp:
Sep 22, 2020, 5:11:00 PM (5 years ago)
Author:
achristensen@apple.com
Message:

Make TLSVersion API tests more robust.
https://bugs.webkit.org/show_bug.cgi?id=216704

Like I did in r267278, the TLSVersion.ShouldAllowDeprecatedTLS API test was also asserting with TCPServer,
so use HTTPServer which gracefully handles a variable number of connection attempts.
The NetworkSession tests that use NSUserDefaults need to be split into a separate test for bug 216041,
so may as well do that here, too.

  • TestWebKitAPI/Tests/WebKitCocoa/TLSDeprecation.mm:

(TestWebKitAPI::makeWebViewWith):
(TestWebKitAPI::TEST):

Location:
trunk/Tools
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Tools/ChangeLog

    r267447 r267448  
     12020-09-22  Alex Christensen  <achristensen@webkit.org>
     2
     3        Make TLSVersion API tests more robust.
     4        https://bugs.webkit.org/show_bug.cgi?id=216704
     5
     6        Like I did in r267278, the TLSVersion.ShouldAllowDeprecatedTLS API test was also asserting with TCPServer,
     7        so use HTTPServer which gracefully handles a variable number of connection attempts.
     8        The NetworkSession tests that use NSUserDefaults need to be split into a separate test for bug 216041,
     9        so may as well do that here, too.
     10
     11        * TestWebKitAPI/Tests/WebKitCocoa/TLSDeprecation.mm:
     12        (TestWebKitAPI::makeWebViewWith):
     13        (TestWebKitAPI::TEST):
     14
    1152020-09-22  Aakash Jain  <aakash_jain@apple.com>
    216
  • trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/TLSDeprecation.mm

    r267278 r267448  
    141141
    142142const uint16_t tls1_1 = 0x0302;
    143 static NSString *defaultsKey = @"WebKitEnableLegacyTLS";
    144143
    145144#if HAVE(TLS_PROTOCOL_VERSION_T)
     
    163162#if HAVE(TLS_VERSION_DURING_CHALLENGE)
    164163
     164RetainPtr<WKWebView> makeWebViewWith(WKWebsiteDataStore *store, RetainPtr<TestNavigationDelegate> delegate)
     165{
     166    WKWebViewConfiguration *configuration = [[[WKWebViewConfiguration alloc] init] autorelease];
     167    configuration.websiteDataStore = store;
     168    auto webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration]);
     169    [webView setNavigationDelegate:delegate.get()];
     170    [delegate setDidReceiveAuthenticationChallenge:^(WKWebView *, NSURLAuthenticationChallenge *challenge, void (^callback)(NSURLSessionAuthChallengeDisposition, NSURLCredential *)) {
     171        EXPECT_WK_STREQ(challenge.protectionSpace.authenticationMethod, NSURLAuthenticationMethodServerTrust);
     172        callback(NSURLSessionAuthChallengeUseCredential, [NSURLCredential credentialForTrust:challenge.protectionSpace.serverTrust]);
     173    }];
     174    return webView;
     175};
     176
    165177TEST(TLSVersion, NetworkSession)
    166178{
    167179    HTTPServer server(HTTPServer::respondWithOK, HTTPServer::Protocol::HttpsWithLegacyTLS);
    168     static auto delegate = adoptNS([TestNavigationDelegate new]);
    169     auto makeWebViewWith = [&] (WKWebsiteDataStore *store) {
    170         WKWebViewConfiguration *configuration = [[[WKWebViewConfiguration alloc] init] autorelease];
    171         configuration.websiteDataStore = store;
    172         auto webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration]);
    173         [webView setNavigationDelegate:delegate.get()];
    174         [delegate setDidReceiveAuthenticationChallenge:^(WKWebView *, NSURLAuthenticationChallenge *challenge, void (^callback)(NSURLSessionAuthChallengeDisposition, NSURLCredential *)) {
    175             EXPECT_WK_STREQ(challenge.protectionSpace.authenticationMethod, NSURLAuthenticationMethodServerTrust);
    176             callback(NSURLSessionAuthChallengeUseCredential, [NSURLCredential credentialForTrust:challenge.protectionSpace.serverTrust]);
    177         }];
    178         return webView;
    179     };
    180     {
    181         auto webView = makeWebViewWith([WKWebsiteDataStore defaultDataStore]);
     180    auto delegate = adoptNS([TestNavigationDelegate new]);
     181    {
     182        auto webView = makeWebViewWith([WKWebsiteDataStore defaultDataStore], delegate);
    182183        [webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"https://127.0.0.1:%d/", server.port()]]]];
    183184        [delegate waitForDidFinishNavigation];
    184185    }
    185186    {
    186         auto webView = makeWebViewWith([WKWebsiteDataStore nonPersistentDataStore]);
     187        auto webView = makeWebViewWith([WKWebsiteDataStore nonPersistentDataStore], delegate);
    187188        [webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"https://127.0.0.1:%d/", server.port()]]]];
    188189        [delegate waitForDidFinishNavigation];
     
    192193        [configuration setLegacyTLSEnabled:NO];
    193194        auto dataStore = adoptNS([[WKWebsiteDataStore alloc] _initWithConfiguration:configuration.get()]);
    194         auto webView = makeWebViewWith(dataStore.get());
     195        auto webView = makeWebViewWith(dataStore.get(), delegate);
    195196        [webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"https://127.0.0.1:%d/", server.port()]]]];
    196197        [delegate waitForDidFailProvisionalNavigation];
    197198    }
     199}
     200
     201TEST(TLSVersion, NetworkSessionNSUserDefaults)
     202{
     203    NSString *defaultsKey = @"WebKitEnableLegacyTLS";
    198204    [[NSUserDefaults standardUserDefaults] setBool:NO forKey:defaultsKey];
    199     {
    200         auto webView = makeWebViewWith([WKWebsiteDataStore defaultDataStore]);
     205
     206    HTTPServer server(HTTPServer::respondWithOK, HTTPServer::Protocol::HttpsWithLegacyTLS);
     207    auto delegate = adoptNS([TestNavigationDelegate new]);
     208    {
     209        auto webView = makeWebViewWith([WKWebsiteDataStore defaultDataStore], delegate);
    201210        [webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"https://127.0.0.1:%d/", server.port()]]]];
    202211        [delegate waitForDidFailProvisionalNavigation];
    203212    }
    204213    {
    205         auto webView = makeWebViewWith([WKWebsiteDataStore nonPersistentDataStore]);
     214        auto webView = makeWebViewWith([WKWebsiteDataStore nonPersistentDataStore], delegate);
    206215        [webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"https://127.0.0.1:%d/", server.port()]]]];
    207216        [delegate waitForDidFailProvisionalNavigation];
     
    212221TEST(TLSVersion, ShouldAllowDeprecatedTLS)
    213222{
     223    HTTPServer server(HTTPServer::respondWithOK, HTTPServer::Protocol::HttpsWithLegacyTLS);
    214224    {
    215225        auto delegate = adoptNS([TLSNavigationDelegate new]);
    216         TCPServer server(TCPServer::Protocol::HTTPS, [](SSL *ssl) {
    217             EXPECT_FALSE(ssl);
    218         }, tls1_1);
    219226        auto webView = adoptNS([WKWebView new]);
    220227        [webView setNavigationDelegate:delegate.get()];
    221         [webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"https://127.0.0.1:%d/", server.port()]]]];
     228        [webView loadRequest:server.request()];
    222229        [delegate waitForDidFailProvisionalNavigation];
    223230        EXPECT_TRUE([delegate receivedShouldAllowDeprecatedTLS]);
     
    226233        auto delegate = adoptNS([TLSNavigationDelegate new]);
    227234        delegate.get().shouldAllowDeprecatedTLS = YES;
    228         TCPServer server(TCPServer::Protocol::HTTPS, TCPServer::respondWithOK, tls1_1);
    229235        auto webView = adoptNS([WKWebView new]);
    230236        [webView setNavigationDelegate:delegate.get()];
    231         [webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"https://127.0.0.1:%d/", server.port()]]]];
     237        [webView loadRequest:server.request()];
    232238        [delegate waitForDidFinishNavigation];
    233239        EXPECT_TRUE([delegate receivedShouldAllowDeprecatedTLS]);
Note: See TracChangeset for help on using the changeset viewer.