Changeset 247270 in webkit
- Timestamp:
- Jul 9, 2019 12:25:57 PM (5 years ago)
- Location:
- trunk
- Files:
-
- 17 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r247266 r247270 1 2019-07-09 Sihui Liu <sihui_liu@apple.com> 2 3 Only allow fetching and removing session credentials from WebsiteDataStore 4 https://bugs.webkit.org/show_bug.cgi?id=199385 5 <rdar://problem/52622080> 6 7 Reviewed by Alex Christensen. 8 9 Fetch and remove only session credentials from NSURLCredentialStorage. 10 11 Modified existing API tests: WKWebsiteDataStore.FetchPersistentCredentials 12 13 * platform/network/CredentialStorage.cpp: 14 (WebCore::CredentialStorage::originsWithCredentials const): 15 (WebCore::CredentialStorage::originsWithSessionCredentials): 16 (WebCore::CredentialStorage::removeSessionCredentialsWithOrigins): 17 (WebCore::CredentialStorage::clearSessionCredentials): 18 (WebCore::CredentialStorage::clearPermanentCredentialsForProtectionSpace): 19 * platform/network/CredentialStorage.h: 20 * platform/network/mac/CredentialStorageMac.mm: 21 (WebCore::CredentialStorage::originsWithSessionCredentials): 22 (WebCore::CredentialStorage::removeSessionCredentialsWithOrigins): 23 (WebCore::CredentialStorage::clearSessionCredentials): 24 (WebCore::CredentialStorage::clearPermanentCredentialsForProtectionSpace): 25 (WebCore::CredentialStorage::originsWithPersistentCredentials): Deleted. 26 1 27 2019-07-09 Alex Christensen <achristensen@webkit.org> 2 28 -
trunk/Source/WebCore/platform/network/CredentialStorage.cpp
r247162 r247270 103 103 } 104 104 105 Vector<SecurityOriginData> CredentialStorage::originsWithCredentials() const106 { 107 Vector<SecurityOriginData> origins;105 HashSet<SecurityOriginData> CredentialStorage::originsWithCredentials() const 106 { 107 HashSet<SecurityOriginData> origins; 108 108 for (auto& keyValuePair : m_protectionSpaceToCredentialMap) { 109 109 auto& protectionSpace = keyValuePair.key.second; … … 130 130 131 131 SecurityOriginData origin { protocol, protectionSpace.host(), static_cast<uint16_t>(protectionSpace.port())}; 132 origins.a ppend(WTFMove(origin));132 origins.add(WTFMove(origin)); 133 133 } 134 134 return origins; … … 188 188 } 189 189 190 #if !PLATFORM(COCOA) 191 HashSet<SecurityOriginData> CredentialStorage::originsWithSessionCredentials() 192 { 193 return { }; 194 } 195 196 void CredentialStorage::removeSessionCredentialsWithOrigins(const Vector<SecurityOriginData>&) 197 { 198 } 199 200 void CredentialStorage::clearSessionCredentials() 201 { 202 } 203 204 void CredentialStorage::clearPermanentCredentialsForProtectionSpace(const ProtectionSpace&) 205 { 206 } 207 #endif 208 190 209 } // namespace WebCore -
trunk/Source/WebCore/platform/network/CredentialStorage.h
r247162 r247270 46 46 WEBCORE_EXPORT void removeCredentialsWithOrigin(const SecurityOriginData&); 47 47 48 // OS persistentstorage.48 // OS credential storage. 49 49 WEBCORE_EXPORT static Credential getFromPersistentStorage(const ProtectionSpace&); 50 WEBCORE_EXPORT static Vector<SecurityOriginData> originsWithPersistentCredentials(); 50 WEBCORE_EXPORT static HashSet<SecurityOriginData> originsWithSessionCredentials(); 51 WEBCORE_EXPORT static void removeSessionCredentialsWithOrigins(const Vector<SecurityOriginData>& origins); 52 WEBCORE_EXPORT static void clearSessionCredentials(); 53 WEBCORE_EXPORT static void clearPermanentCredentialsForProtectionSpace(const ProtectionSpace&); 51 54 52 55 WEBCORE_EXPORT void clearCredentials(); … … 57 60 WEBCORE_EXPORT Credential get(const String&, const URL&); 58 61 59 WEBCORE_EXPORT Vector<SecurityOriginData> originsWithCredentials() const;62 WEBCORE_EXPORT HashSet<SecurityOriginData> originsWithCredentials() const; 60 63 61 64 private: -
trunk/Source/WebCore/platform/network/mac/CredentialStorageMac.mm
r247162 r247270 39 39 } 40 40 41 Vector<WebCore::SecurityOriginData> CredentialStorage::originsWithPersistentCredentials()41 HashSet<SecurityOriginData> CredentialStorage::originsWithSessionCredentials() 42 42 { 43 Vector<WebCore::SecurityOriginData> origins;43 HashSet<SecurityOriginData> origins; 44 44 auto allCredentials = [[NSURLCredentialStorage sharedCredentialStorage] allCredentials]; 45 for (NSURLProtectionSpace* key in allCredentials.keyEnumerator) 46 origins.append(WebCore::SecurityOriginData { String(key.protocol), String(key.host), key.port }); 45 for (NSURLProtectionSpace* key in allCredentials.keyEnumerator) { 46 for (NSURLProtectionSpace* space in allCredentials) { 47 auto credentials = allCredentials[space]; 48 for (NSString* user in credentials) { 49 if (credentials[user].persistence == NSURLCredentialPersistenceForSession) { 50 origins.add(WebCore::SecurityOriginData { String(key.protocol), String(key.host), key.port }); 51 break; 52 } 53 } 54 } 55 } 47 56 return origins; 48 57 } 49 58 59 void CredentialStorage::removeSessionCredentialsWithOrigins(const Vector<SecurityOriginData>& origins) 60 { 61 auto sharedStorage = [NSURLCredentialStorage sharedCredentialStorage]; 62 auto allCredentials = [sharedStorage allCredentials]; 63 for (auto& origin : origins) { 64 for (NSURLProtectionSpace* space in allCredentials) { 65 if (origin.protocol == String(space.protocol) 66 && origin.host == String(space.host) 67 && origin.port 68 && *origin.port == space.port) { 69 auto credentials = allCredentials[space]; 70 for (NSString* user in credentials) { 71 auto credential = credentials[user]; 72 if (credential.persistence == NSURLCredentialPersistenceForSession) 73 [sharedStorage removeCredential:credential forProtectionSpace:space]; 74 } 75 } 76 } 77 } 78 } 79 80 void CredentialStorage::clearSessionCredentials() 81 { 82 auto sharedStorage = [NSURLCredentialStorage sharedCredentialStorage]; 83 auto allCredentials = [sharedStorage allCredentials]; 84 for (NSURLProtectionSpace* space in allCredentials.keyEnumerator) { 85 auto credentials = allCredentials[space]; 86 for (NSString* user in credentials) { 87 auto credential = credentials[user]; 88 if (credential.persistence == NSURLCredentialPersistenceForSession) 89 [sharedStorage removeCredential:credential forProtectionSpace:space]; 90 } 91 } 92 } 93 94 void CredentialStorage::clearPermanentCredentialsForProtectionSpace(const ProtectionSpace& protectionSpace) 95 { 96 auto sharedStorage = [NSURLCredentialStorage sharedCredentialStorage]; 97 auto allCredentials = [sharedStorage allCredentials]; 98 auto credentials = allCredentials[protectionSpace.nsSpace()]; 99 for (NSString* user in credentials) { 100 auto credential = credentials[user]; 101 if (credential.persistence == NSURLCredentialPersistencePermanent) 102 [sharedStorage removeCredential:credentials[user] forProtectionSpace:protectionSpace.nsSpace()]; 103 } 104 } 105 50 106 } // namespace WebCore -
trunk/Source/WebKit/ChangeLog
r247265 r247270 1 2019-07-09 Sihui Liu <sihui_liu@apple.com> 2 3 Only allow fetching and removing session credentials from WebsiteDataStore 4 https://bugs.webkit.org/show_bug.cgi?id=199385 5 <rdar://problem/52622080> 6 7 Reviewed by Alex Christensen. 8 9 Stop sending an extra message to network process for fetching or removing persistent credentials. 10 11 Also introduce a new SPI for clearing persistent credentials created in test. 12 13 * NetworkProcess/NetworkProcess.cpp: 14 (WebKit::NetworkProcess::clearPermanentCredentialsForProtectionSpace): 15 (WebKit::NetworkProcess::fetchWebsiteData): 16 (WebKit::NetworkProcess::deleteWebsiteData): 17 (WebKit::NetworkProcess::deleteWebsiteDataForOrigins): 18 (WebKit::NetworkProcess::deleteWebsiteDataForRegistrableDomains): 19 (WebKit::NetworkProcess::originsWithPersistentCredentials): Deleted. 20 (WebKit::NetworkProcess::removeCredentialsWithOrigins): Deleted. 21 * NetworkProcess/NetworkProcess.h: 22 * NetworkProcess/NetworkProcess.messages.in: 23 * NetworkProcess/cocoa/NetworkProcessCocoa.mm: 24 (WebKit::NetworkProcess::originsWithPersistentCredentials): Deleted. 25 (WebKit::NetworkProcess::removeCredentialsWithOrigins): Deleted. 26 * UIProcess/API/Cocoa/WKProcessPool.mm: 27 (-[WKProcessPool _clearPermanentCredentialsForProtectionSpace:completionHandler:]): 28 * UIProcess/API/Cocoa/WKProcessPoolPrivate.h: 29 * UIProcess/WebProcessPool.cpp: 30 (WebKit::WebProcessPool::clearPermanentCredentialsForProtectionSpace): 31 * UIProcess/WebProcessPool.h: 32 * UIProcess/WebsiteData/WebsiteDataStore.cpp: 33 (WebKit::WebsiteDataStore::fetchDataAndApply): 34 (WebKit::computeWebProcessAccessTypeForDataRemoval): 35 (WebKit::WebsiteDataStore::removeData): 36 1 37 2019-07-09 Antoine Quint <graouts@apple.com> 2 38 -
trunk/Source/WebKit/NetworkProcess/NetworkProcess.cpp
r247230 r247270 456 456 } 457 457 458 void NetworkProcess::clearPermanentCredentialsForProtectionSpace(const ProtectionSpace& protectionSpace, CompletionHandler<void()>&& completionHandler) 459 { 460 WebCore::CredentialStorage::clearPermanentCredentialsForProtectionSpace(protectionSpace); 461 completionHandler(); 462 } 463 458 464 void NetworkProcess::addWebsiteDataStore(WebsiteDataStoreParameters&& parameters) 459 465 { … … 1297 1303 callbackAggregator->m_websiteData.entries.append({ securityOrigin, WebsiteDataType::Credentials, 0 }); 1298 1304 } 1305 auto securityOrigins = WebCore::CredentialStorage::originsWithSessionCredentials(); 1306 for (auto& securityOrigin : securityOrigins) 1307 callbackAggregator->m_websiteData.entries.append({ securityOrigin, WebsiteDataType::Credentials, 0 }); 1299 1308 } 1300 1309 … … 1378 1387 if (auto* session = storageSession(sessionID)) 1379 1388 session->credentialStorage().clearCredentials(); 1389 WebCore::CredentialStorage::clearSessionCredentials(); 1380 1390 } 1381 1391 … … 1515 1525 session->credentialStorage().removeCredentialsWithOrigin(originData); 1516 1526 } 1527 WebCore::CredentialStorage::removeSessionCredentialsWithOrigins(originDatas); 1517 1528 } 1518 1529 … … 1659 1670 #endif 1660 1671 1661 /*1662 // FIXME: No API to delete credentials by origin1663 HashSet<String> originsWithCredentials;1664 1672 if (websiteDataTypes.contains(WebsiteDataType::Credentials)) { 1665 if (storageSession(sessionID)) 1666 originsWithCredentials = storageSession(sessionID)->credentialStorage().originsWithCredentials(); 1667 } 1668 */ 1673 if (auto* session = storageSession(sessionID)) { 1674 auto origins = session->credentialStorage().originsWithCredentials(); 1675 auto originsToDelete = filterForRegistrableDomains(origins, domainsToDeleteAllButCookiesFor, callbackAggregator->m_domains); 1676 for (auto& origin : originsToDelete) 1677 session->credentialStorage().removeCredentialsWithOrigin(origin); 1678 } 1679 1680 auto origins = WebCore::CredentialStorage::originsWithSessionCredentials(); 1681 auto originsToDelete = filterForRegistrableDomains(origins, domainsToDeleteAllButCookiesFor, callbackAggregator->m_domains); 1682 WebCore::CredentialStorage::removeSessionCredentialsWithOrigins(originsToDelete); 1683 } 1669 1684 1670 1685 if (websiteDataTypes.contains(WebsiteDataType::DOMCache)) { … … 2562 2577 2563 2578 #if !PLATFORM(COCOA) 2564 void NetworkProcess::originsWithPersistentCredentials(CompletionHandler<void(Vector<WebCore::SecurityOriginData>)>&& completionHandler)2565 {2566 completionHandler(Vector<WebCore::SecurityOriginData>());2567 }2568 2569 void NetworkProcess::removeCredentialsWithOrigins(const Vector<WebCore::SecurityOriginData>&, CompletionHandler<void()>&& completionHandler)2570 {2571 completionHandler();2572 }2573 2574 2579 void NetworkProcess::initializeProcess(const AuxiliaryProcessInitializationParameters&) 2575 2580 { -
trunk/Source/WebKit/NetworkProcess/NetworkProcess.h
r247162 r247270 394 394 395 395 void clearCachedCredentials(); 396 void clearPermanentCredentialsForProtectionSpace(const WebCore::ProtectionSpace&, CompletionHandler<void()>&&); 396 397 397 398 void setCacheStorageParameters(PAL::SessionID, String&& cacheStorageDirectory, SandboxExtension::Handle&&); … … 437 438 438 439 void platformSyncAllCookies(CompletionHandler<void()>&&); 439 440 void originsWithPersistentCredentials(CompletionHandler<void(Vector<WebCore::SecurityOriginData>)>&&);441 void removeCredentialsWithOrigins(const Vector<WebCore::SecurityOriginData>& origins, CompletionHandler<void()>&&);442 440 443 441 void registerURLSchemeAsSecure(const String&) const; -
trunk/Source/WebKit/NetworkProcess/NetworkProcess.messages.in
r247162 r247270 39 39 40 40 ClearCachedCredentials() 41 ClearPermanentCredentialsForProtectionSpace(WebCore::ProtectionSpace protectionSpace) -> () Async 41 42 42 43 AddWebsiteDataStore(struct WebKit::WebsiteDataStoreParameters websiteDataStoreParameters); … … 169 170 SetAdClickAttributionConversionURLForTesting(PAL::SessionID sessionID, URL url) -> () Async 170 171 MarkAdClickAttributionsAsExpiredForTesting(PAL::SessionID sessionID) -> () Async 171 OriginsWithPersistentCredentials() -> (Vector<WebCore::SecurityOriginData> origins) Async172 RemoveCredentialsWithOrigins(Vector<WebCore::SecurityOriginData> origins) -> () Async173 172 GetLocalStorageOriginDetails(PAL::SessionID sessionID) -> (Vector<WebKit::LocalStorageDatabaseTracker::OriginDetails> details) Async 174 173 } -
trunk/Source/WebKit/NetworkProcess/cocoa/NetworkProcessCocoa.mm
r247162 r247270 213 213 } 214 214 215 void NetworkProcess::originsWithPersistentCredentials(CompletionHandler<void(Vector<WebCore::SecurityOriginData>)>&& completionHandler)216 {217 completionHandler(WebCore::CredentialStorage::originsWithPersistentCredentials());218 }219 220 void NetworkProcess::removeCredentialsWithOrigins(const Vector<WebCore::SecurityOriginData>& origins, CompletionHandler<void()>&& completionHandler)221 {222 for (auto& origin : origins) {223 auto allCredentials = [[NSURLCredentialStorage sharedCredentialStorage] allCredentials];224 for (NSURLProtectionSpace* space in allCredentials) {225 if (origin.protocol == String(space.protocol)226 && origin.host == String(space.host)227 && origin.port228 && *origin.port == space.port) {229 auto credentials = allCredentials[space];230 for (NSString* user in credentials) {231 auto credential = credentials[user];232 [[NSURLCredentialStorage sharedCredentialStorage] removeCredential:credential forProtectionSpace:space];233 }234 }235 }236 }237 completionHandler();238 }239 240 215 #if PLATFORM(MAC) 241 216 void NetworkProcess::setSharedHTTPCookieStorage(const Vector<uint8_t>& identifier) -
trunk/Source/WebKit/UIProcess/API/Cocoa/WKProcessPool.mm
r246807 r247270 632 632 } 633 633 634 - (void)_clearPermanentCredentialsForProtectionSpace:(NSURLProtectionSpace *)protectionSpace completionHandler:(void(^)())completionHandler 635 { 636 _processPool->clearPermanentCredentialsForProtectionSpace(WebCore::ProtectionSpace(protectionSpace), [completionHandler = makeBlockPtr(completionHandler)] { 637 completionHandler(); 638 }); 639 } 640 634 641 @end -
trunk/Source/WebKit/UIProcess/API/Cocoa/WKProcessPoolPrivate.h
r245294 r247270 121 121 - (void)_getActivePagesOriginsInWebProcessForTesting:(pid_t)pid completionHandler:(void(^)(NSArray<NSString *> *))completionHandler WK_API_AVAILABLE(macos(10.14.4), ios(12.2)); 122 122 - (BOOL)_networkProcessHasEntitlementForTesting:(NSString *)entitlement WK_API_AVAILABLE(macos(10.14.4), ios(12.2)); 123 - (void)_clearPermanentCredentialsForProtectionSpace:(NSURLProtectionSpace *)protectionSpace completionHandler:(void(^)(void))completionHandler WK_API_AVAILABLE(macos(WK_MAC_TBA), ios(WK_IOS_TBA)); 123 124 124 125 @property (nonatomic, getter=_isCookieStoragePartitioningEnabled, setter=_setCookieStoragePartitioningEnabled:) BOOL _cookieStoragePartitioningEnabled WK_API_DEPRECATED("Partitioned cookies are no longer supported", macos(10.12.3, 10.14.4), ios(10.3, 12.2)); -
trunk/Source/WebKit/UIProcess/WebProcessPool.cpp
r246955 r247270 1745 1745 } 1746 1746 1747 void WebProcessPool::clearPermanentCredentialsForProtectionSpace(WebCore::ProtectionSpace&& protectionSpace, CompletionHandler<void()>&& completionHandler) 1748 { 1749 if (m_networkProcess) 1750 m_networkProcess->sendWithAsyncReply(Messages::NetworkProcess::ClearPermanentCredentialsForProtectionSpace(protectionSpace), WTFMove(completionHandler)); 1751 } 1752 1747 1753 void WebProcessPool::terminateNetworkProcess() 1748 1754 { -
trunk/Source/WebKit/UIProcess/WebProcessPool.h
r247058 r247270 311 311 312 312 void clearCachedCredentials(); 313 void clearPermanentCredentialsForProtectionSpace(WebCore::ProtectionSpace&&, CompletionHandler<void()>&&); 313 314 void terminateNetworkProcess(); 314 315 void sendNetworkProcessWillSuspendImminently(); -
trunk/Source/WebKit/UIProcess/WebsiteData/WebsiteDataStore.cpp
r247162 r247270 521 521 } 522 522 523 #if PLATFORM(COCOA)524 if (dataTypes.contains(WebsiteDataType::Credentials) && isPersistent()) {525 for (auto& processPool : processPools()) {526 if (!processPool->networkProcess())527 continue;528 529 callbackAggregator->addPendingCallback();530 WTF::CompletionHandler<void(Vector<WebCore::SecurityOriginData>&&)> completionHandler = [callbackAggregator](Vector<WebCore::SecurityOriginData>&& origins) mutable {531 WebsiteData websiteData;532 for (auto& origin : origins)533 websiteData.entries.append(WebsiteData::Entry { origin, WebsiteDataType::Credentials, 0 });534 callbackAggregator->removePendingCallback(WTFMove(websiteData));535 };536 processPool->networkProcess()->sendWithAsyncReply(Messages::NetworkProcess::OriginsWithPersistentCredentials(), WTFMove(completionHandler));537 }538 }539 #endif540 541 523 #if ENABLE(NETSCAPE_PLUGIN_API) 542 524 if (dataTypes.contains(WebsiteDataType::PlugInData) && isPersistent()) { … … 645 627 processAccessType = std::max(processAccessType, ProcessAccessType::OnlyIfLaunched); 646 628 647 if (dataTypes.contains(WebsiteDataType::Credentials))648 processAccessType = std::max(processAccessType, ProcessAccessType::OnlyIfLaunched);649 650 629 return processAccessType; 651 630 } … … 1094 1073 } 1095 1074 1096 if (dataTypes.contains(WebsiteDataType::Credentials) && isPersistent()) {1097 for (auto& processPool : processPools()) {1098 if (!processPool->networkProcess())1099 continue;1100 1101 callbackAggregator->addPendingCallback();1102 WTF::CompletionHandler<void()> completionHandler = [callbackAggregator]() mutable {1103 callbackAggregator->removePendingCallback();1104 };1105 processPool->networkProcess()->sendWithAsyncReply(Messages::NetworkProcess::RemoveCredentialsWithOrigins(origins), WTFMove(completionHandler));1106 }1107 }1108 1109 1075 #if ENABLE(NETSCAPE_PLUGIN_API) 1110 1076 if (dataTypes.contains(WebsiteDataType::PlugInData) && isPersistent()) { -
trunk/Tools/ChangeLog
r247269 r247270 1 2019-07-09 Sihui Liu <sihui_liu@apple.com> 2 3 Only allow fetching and removing session credentials from WebsiteDataStore 4 https://bugs.webkit.org/show_bug.cgi?id=199385 5 <rdar://problem/52622080> 6 7 Reviewed by Alex Christensen. 8 9 removeDataOfTypes will no longer remove persistent credentials. We should clear persistent credentials using 10 the new SPI after each test that creates persistent credentials, otherwise the later tests may use credentials 11 left by previous tests and didReceiveAuthenticationChallenge will not be invoked. 12 13 * TestWebKitAPI/Tests/WebKitCocoa/Challenge.mm: 14 (TEST): 15 * TestWebKitAPI/Tests/WebKitCocoa/WKWebsiteDatastore.mm: 16 (TestWebKitAPI::TEST): 17 1 18 2019-07-09 Alex Christensen <achristensen@webkit.org> 2 19 -
trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/Challenge.mm
r246605 r247270 104 104 105 105 Util::run(&navigationFinished); 106 107 // Clear persistent credentials created by this test. 108 NSURLProtectionSpace *protectionSpace = [[[NSURLProtectionSpace alloc] initWithHost:@"127.0.0.1" port:server.port() protocol:NSURLProtectionSpaceHTTP realm:@"testrealm" authenticationMethod:NSURLAuthenticationMethodHTTPBasic] autorelease]; 109 __block bool removedCredential = false; 110 [[webView configuration].processPool _clearPermanentCredentialsForProtectionSpace:protectionSpace completionHandler:^{ 111 removedCredential = true; 112 }]; 113 Util::run(&removedCredential); 106 114 } 107 115 … … 199 207 Util::run(&navigationFinished); 200 208 EXPECT_TRUE(receivedSecondChallenge); 201 209 210 // Clear persistent credentials created by this test. 211 NSURLProtectionSpace *protectionSpace = [[[NSURLProtectionSpace alloc] initWithHost:@"127.0.0.1" port:server.port() protocol:NSURLProtectionSpaceHTTP realm:@"testrealm" authenticationMethod:NSURLAuthenticationMethodHTTPBasic] autorelease]; 202 212 __block bool removedCredential = false; 203 WKWebsiteDataStore *websiteDataStore = [webView configuration].websiteDataStore; 204 [websiteDataStore fetchDataRecordsOfTypes:[NSSet setWithObject:_WKWebsiteDataTypeCredentials] completionHandler:^(NSArray<WKWebsiteDataRecord *> *dataRecords) { 205 [websiteDataStore removeDataOfTypes:[NSSet setWithObject:_WKWebsiteDataTypeCredentials] forDataRecords:dataRecords completionHandler:^(void) { 206 removedCredential = true; 207 }]; 213 [[webView configuration].processPool _clearPermanentCredentialsForProtectionSpace:protectionSpace completionHandler:^{ 214 removedCredential = true; 208 215 }]; 209 216 Util::run(&removedCredential); -
trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/WKWebsiteDatastore.mm
r247162 r247270 93 93 readyToContinue = false; 94 94 [[WKWebsiteDataStore defaultDataStore] fetchDataRecordsOfTypes:[WKWebsiteDataStore _allWebsiteDataTypesIncludingPrivate] completionHandler:^(NSArray<WKWebsiteDataRecord *> *dataRecords) { 95 ASSERT_EQ(0u, dataRecords.count);95 EXPECT_EQ(0u, dataRecords.count); 96 96 readyToContinue = true; 97 97 }]; … … 140 140 { 141 141 TCPServer server(TCPServer::respondWithChallengeThenOK); 142 142 143 143 usePersistentCredentialStorage = true; 144 144 auto websiteDataStore = [WKWebsiteDataStore defaultDataStore]; … … 152 152 [websiteDataStore fetchDataRecordsOfTypes:[NSSet setWithObject:_WKWebsiteDataTypeCredentials] completionHandler:^(NSArray<WKWebsiteDataRecord *> *dataRecords) { 153 153 int credentialCount = dataRecords.count; 154 ASSERT_GT(credentialCount, 0); 155 bool foundExpectedRecord = false; 156 for (WKWebsiteDataRecord *record in dataRecords) { 157 auto name = [record displayName]; 158 if ([name isEqualToString:@"127.0.0.1"]) { 159 foundExpectedRecord = true; 160 break; 161 } 162 } 163 EXPECT_TRUE(foundExpectedRecord); 164 done = true; 165 }]; 166 TestWebKitAPI::Util::run(&done); 167 154 EXPECT_EQ(credentialCount, 0); 155 done = true; 156 }]; 157 TestWebKitAPI::Util::run(&done); 158 159 // Clear persistent credentials created by this test. 160 NSURLProtectionSpace *protectionSpace = [[[NSURLProtectionSpace alloc] initWithHost:@"127.0.0.1" port:server.port() protocol:NSURLProtectionSpaceHTTP realm:@"testrealm" authenticationMethod:NSURLAuthenticationMethodHTTPBasic] autorelease]; 168 161 __block bool removedCredential = false; 169 [websiteDataStore fetchDataRecordsOfTypes:[NSSet setWithObject:_WKWebsiteDataTypeCredentials] completionHandler:^(NSArray<WKWebsiteDataRecord *> *dataRecords) { 170 [websiteDataStore removeDataOfTypes:[NSSet setWithObject:_WKWebsiteDataTypeCredentials] forDataRecords:dataRecords completionHandler:^(void) { 171 removedCredential = true; 172 }]; 173 }]; 174 TestWebKitAPI::Util::run(&removedCredential); 175 } 176 177 TEST(WKWebsiteDataStore, RemovePersistentCredentials) 162 [[webView configuration].processPool _clearPermanentCredentialsForProtectionSpace:protectionSpace completionHandler:^{ 163 removedCredential = true; 164 }]; 165 Util::run(&removedCredential); 166 } 167 168 TEST(WKWebsiteDataStore, RemoveNonPersistentCredentials) 178 169 { 179 170 TCPServer server(TCPServer::respondWithChallengeThenOK); 180 171 181 usePersistentCredentialStorage = true; 182 auto websiteDataStore = [WKWebsiteDataStore defaultDataStore]; 172 usePersistentCredentialStorage = false; 173 auto configuration = adoptNS([WKWebViewConfiguration new]); 174 auto websiteDataStore = [WKWebsiteDataStore nonPersistentDataStore]; 175 [configuration setWebsiteDataStore:websiteDataStore]; 183 176 auto navigationDelegate = adoptNS([[NavigationTestDelegate alloc] init]); 184 auto webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) ]);177 auto webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get()]); 185 178 [webView setNavigationDelegate:navigationDelegate.get()]; 186 179 [webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://127.0.0.1:%d/", server.port()]]]]; … … 226 219 } 227 220 228 TEST(WKWebsiteDataStore, RemoveNonPersistentCredentials)229 {230 TCPServer server(TCPServer::respondWithChallengeThenOK);231 232 usePersistentCredentialStorage = false;233 auto configuration = adoptNS([WKWebViewConfiguration new]);234 auto websiteDataStore = [WKWebsiteDataStore nonPersistentDataStore];235 [configuration setWebsiteDataStore:websiteDataStore];236 auto navigationDelegate = adoptNS([[NavigationTestDelegate alloc] init]);237 auto webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get()]);238 [webView setNavigationDelegate:navigationDelegate.get()];239 [webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://127.0.0.1:%d/", server.port()]]]];240 [navigationDelegate waitForDidFinishNavigation];241 242 __block bool done = false;243 __block RetainPtr<WKWebsiteDataRecord> expectedRecord;244 [websiteDataStore fetchDataRecordsOfTypes:[NSSet setWithObject:_WKWebsiteDataTypeCredentials] completionHandler:^(NSArray<WKWebsiteDataRecord *> *dataRecords) {245 int credentialCount = dataRecords.count;246 ASSERT_GT(credentialCount, 0);247 for (WKWebsiteDataRecord *record in dataRecords) {248 auto name = [record displayName];249 if ([name isEqualToString:@"127.0.0.1"]) {250 expectedRecord = record;251 break;252 }253 }254 EXPECT_TRUE(expectedRecord);255 done = true;256 }];257 TestWebKitAPI::Util::run(&done);258 259 done = false;260 [websiteDataStore removeDataOfTypes:[NSSet setWithObject:_WKWebsiteDataTypeCredentials] forDataRecords:[NSArray arrayWithObject:expectedRecord.get()] completionHandler:^(void) {261 done = true;262 }];263 TestWebKitAPI::Util::run(&done);264 265 done = false;266 [websiteDataStore fetchDataRecordsOfTypes:[NSSet setWithObject:_WKWebsiteDataTypeCredentials] completionHandler:^(NSArray<WKWebsiteDataRecord *> *dataRecords) {267 bool foundLocalHostRecord = false;268 for (WKWebsiteDataRecord *record in dataRecords) {269 auto name = [record displayName];270 if ([name isEqualToString:@"127.0.0.1"]) {271 foundLocalHostRecord = true;272 break;273 }274 }275 EXPECT_FALSE(foundLocalHostRecord);276 done = true;277 }];278 TestWebKitAPI::Util::run(&done);279 }280 281 221 TEST(WebKit, SettingNonPersistentDataStorePathsThrowsException) 282 222 {
Note: See TracChangeset
for help on using the changeset viewer.