Title: [231067] trunk
Revision
231067
Author
[email protected]
Date
2018-04-26 13:39:47 -0700 (Thu, 26 Apr 2018)

Log Message

-[WKHTTPCookieStore deleteCookie:completionHandler:] doesn't delete cookies
https://bugs.webkit.org/show_bug.cgi?id=184938
<rdar://problem/34737395>

Patch by Sihui Liu <[email protected]> on 2018-04-26
Reviewed by Geoffrey Garen.

Source/WebCore:

When a Cookie object was converted to NSHTTPCookie object, the HTTPOnly property information
was lost so the delete function cannot find the proper cookie to delete.
This patch implements a workaround that compares Cookie object instead of NSHTTPCookie
object. We might want to add the ability to set HTTPOnly header during conversion if there
is an easy way to do it later.

New API test: WebKit.WKHTTPCookieStoreHttpOnly

* platform/network/cocoa/CookieCocoa.mm:
(WebCore::Cookie::operator== const):
* platform/network/cocoa/NetworkStorageSessionCocoa.mm:
(WebCore::NetworkStorageSession::deleteCookie):

Tools:

Add API test coverage.

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

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (231066 => 231067)


--- trunk/Source/WebCore/ChangeLog	2018-04-26 20:36:48 UTC (rev 231066)
+++ trunk/Source/WebCore/ChangeLog	2018-04-26 20:39:47 UTC (rev 231067)
@@ -1,3 +1,24 @@
+2018-04-26  Sihui Liu  <[email protected]>
+
+        -[WKHTTPCookieStore deleteCookie:completionHandler:] doesn't delete cookies
+        https://bugs.webkit.org/show_bug.cgi?id=184938
+        <rdar://problem/34737395>
+
+        Reviewed by Geoffrey Garen.
+
+        When a Cookie object was converted to NSHTTPCookie object, the HTTPOnly property information
+        was lost so the delete function cannot find the proper cookie to delete.
+        This patch implements a workaround that compares Cookie object instead of NSHTTPCookie 
+        object. We might want to add the ability to set HTTPOnly header during conversion if there
+        is an easy way to do it later.
+        
+        New API test: WebKit.WKHTTPCookieStoreHttpOnly
+
+        * platform/network/cocoa/CookieCocoa.mm:
+        (WebCore::Cookie::operator== const):
+        * platform/network/cocoa/NetworkStorageSessionCocoa.mm:
+        (WebCore::NetworkStorageSession::deleteCookie):
+
 2018-04-26  Commit Queue  <[email protected]>
 
         Unreviewed, rolling out r231052.

Modified: trunk/Source/WebCore/platform/network/cocoa/CookieCocoa.mm (231066 => 231067)


--- trunk/Source/WebCore/platform/network/cocoa/CookieCocoa.mm	2018-04-26 20:36:48 UTC (rev 231066)
+++ trunk/Source/WebCore/platform/network/cocoa/CookieCocoa.mm	2018-04-26 20:39:47 UTC (rev 231067)
@@ -132,8 +132,18 @@
     if (thisNull || otherNull)
         return thisNull == otherNull;
     
-    NSHTTPCookie *nsCookie(*this);
-    return [nsCookie isEqual:other];
+    return name == other.name
+    && value == other.value
+    && domain == other.domain
+    && path == other.path
+    && created == other.created
+    && expires == other.expires
+    && httpOnly == other.httpOnly
+    && secure == other.secure
+    && session == other.session
+    && comment == other.comment
+    && commentURL == other.commentURL
+    && ports == other.ports;
 }
     
 unsigned Cookie::hash() const

Modified: trunk/Source/WebCore/platform/network/cocoa/NetworkStorageSessionCocoa.mm (231066 => 231067)


--- trunk/Source/WebCore/platform/network/cocoa/NetworkStorageSessionCocoa.mm	2018-04-26 20:36:48 UTC (rev 231066)
+++ trunk/Source/WebCore/platform/network/cocoa/NetworkStorageSessionCocoa.mm	2018-04-26 20:39:47 UTC (rev 231067)
@@ -60,8 +60,14 @@
 void NetworkStorageSession::deleteCookie(const Cookie& cookie)
 {
     ASSERT(hasProcessPrivilege(ProcessPrivilege::CanAccessRawCookies));
-
-    [nsCookieStorage() deleteCookie:(NSHTTPCookie *)cookie];
+    
+    NSArray *nsCookies = [nsCookieStorage() cookies];
+    for (NSHTTPCookie *nsCookie in nsCookies) {
+        if (Cookie(nsCookie) == cookie) {
+            [nsCookieStorage() deleteCookie:nsCookie];
+            break;
+        }
+    }
 }
 
 static Vector<Cookie> nsCookiesToCookieVector(NSArray<NSHTTPCookie *> *nsCookies)

Modified: trunk/Tools/ChangeLog (231066 => 231067)


--- trunk/Tools/ChangeLog	2018-04-26 20:36:48 UTC (rev 231066)
+++ trunk/Tools/ChangeLog	2018-04-26 20:39:47 UTC (rev 231067)
@@ -1,3 +1,16 @@
+2018-04-26  Sihui Liu  <[email protected]>
+
+        -[WKHTTPCookieStore deleteCookie:completionHandler:] doesn't delete cookies
+        https://bugs.webkit.org/show_bug.cgi?id=184938
+        <rdar://problem/34737395>
+
+        Reviewed by Geoffrey Garen.
+
+        Add API test coverage.
+
+        * TestWebKitAPI/Tests/WebKitCocoa/WKHTTPCookieStore.mm:
+        (TEST):
+
 2018-04-26  Ross Kirsling  <[email protected]>
 
         WinCairo test bots should run JSC tests with options for Windows command prompt.

Modified: trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/WKHTTPCookieStore.mm (231066 => 231067)


--- trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/WKHTTPCookieStore.mm	2018-04-26 20:36:48 UTC (rev 231066)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/WKHTTPCookieStore.mm	2018-04-26 20:39:47 UTC (rev 231067)
@@ -192,6 +192,90 @@
     runTestWithWebsiteDataStore([WKWebsiteDataStore defaultDataStore]);
 }
 
+TEST(WebKit, WKHTTPCookieStoreHttpOnly) 
+{
+    WKWebsiteDataStore* dataStore = [WKWebsiteDataStore defaultDataStore];
+
+    auto configuration = adoptNS([[WKWebViewConfiguration alloc] init]);
+    configuration.get().websiteDataStore = dataStore;
+    auto webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get()]);
+
+    [webView loadHTMLString:@"WebKit Test" baseURL:[NSURL URLWithString:@"http://webkit.org"]];
+    [webView _test_waitForDidFinishNavigation];
+
+    [dataStore removeDataOfTypes:[WKWebsiteDataStore allWebsiteDataTypes] modifiedSince:[NSDate distantPast] completionHandler:[] {
+        gotFlag = true;
+    }];
+
+    TestWebKitAPI::Util::run(&gotFlag);
+    gotFlag = false;
+
+    id pool = [WKProcessPool _sharedProcessPool];
+    EXPECT_EQ([pool _pluginProcessCount], static_cast<size_t>(0));
+
+    globalCookieStore = dataStore.httpCookieStore;
+
+    NSArray<NSHTTPCookie *> *cookies = nil;
+    [globalCookieStore getAllCookies:[cookiesPtr = &cookies](NSArray<NSHTTPCookie *> *nsCookies) {
+        *cookiesPtr = [nsCookies retain];
+        gotFlag = true;
+    }];
+
+    TestWebKitAPI::Util::run(&gotFlag);
+    gotFlag = false;
+
+    ASSERT_EQ(cookies.count, 0u);
+    [cookies release];
+
+    CFMutableDictionaryRef cookieProperties = CFDictionaryCreateMutable(NULL, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
+    CFDictionarySetValue(cookieProperties, CFSTR("Name"), CFSTR("httpCookie"));
+    CFDictionarySetValue(cookieProperties, CFSTR("Value"), CFSTR("httpCookieValue"));
+    CFDictionarySetValue(cookieProperties, CFSTR("Domain"), CFSTR(".www.webkit.org"));
+    CFDictionarySetValue(cookieProperties, CFSTR("Path"), CFSTR("/httpPath"));
+    CFDictionarySetValue(cookieProperties, CFSTR("HttpOnly"), kCFBooleanTrue);
+    RetainPtr<NSHTTPCookie> httpOnlyCookie = [NSHTTPCookie cookieWithProperties:(NSDictionary*) cookieProperties];
+    CFDictionaryRemoveValue(cookieProperties, CFSTR("HttpOnly"));
+    RetainPtr<NSHTTPCookie> notHttpOnlyCookie = [NSHTTPCookie cookieWithProperties:(NSDictionary*) cookieProperties];
+    EXPECT_TRUE(httpOnlyCookie.get().HTTPOnly);
+    EXPECT_FALSE(notHttpOnlyCookie.get().HTTPOnly);
+
+    [globalCookieStore setCookie:notHttpOnlyCookie.get() completionHandler:[]() {
+        gotFlag = true;
+    }];
+
+    TestWebKitAPI::Util::run(&gotFlag);
+    gotFlag = false;
+
+    [globalCookieStore getAllCookies:[cookiesPtr = &cookies](NSArray<NSHTTPCookie *> *nsCookies) {
+        *cookiesPtr = [nsCookies retain];
+        gotFlag = true;
+    }];
+
+    TestWebKitAPI::Util::run(&gotFlag);
+    gotFlag = false;
+
+    ASSERT_EQ(cookies.count, 1u);
+    [cookies release];
+
+    [globalCookieStore deleteCookie:httpOnlyCookie.get() completionHandler:[]() {
+        gotFlag = true;
+    }];
+
+    TestWebKitAPI::Util::run(&gotFlag);
+    gotFlag = false;
+    [globalCookieStore getAllCookies:[cookiesPtr = &cookies](NSArray<NSHTTPCookie *> *nsCookies) {
+        *cookiesPtr = [nsCookies retain];
+        gotFlag = true;
+    }];
+
+    TestWebKitAPI::Util::run(&gotFlag);
+    gotFlag = false;
+
+    // Delete httpOnlyCookie should fail because it is different from notHttpOnlyCookie. 
+    ASSERT_EQ(cookies.count, 1u);
+    [cookies release];
+}
+
 // FIXME: This should be removed once <rdar://problem/35344202> is resolved and bots are updated.
 #if (PLATFORM(MAC) && __MAC_OS_X_VERSION_MAX_ALLOWED <= 101301) || (PLATFORM(IOS) && __IPHONE_OS_VERSION_MAX_ALLOWED <= 110102)
 TEST(WebKit, WKHTTPCookieStoreNonPersistent)
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to