@@ -26,6 +26,7 @@ class TestHTTPCookieStorage: XCTestCase {
26
26
( " test_cookiesForURLWithMainDocumentURL " , test_cookiesForURLWithMainDocumentURL) ,
27
27
( " test_cookieInXDGSpecPath " , test_cookieInXDGSpecPath) ,
28
28
( " test_descriptionCookie " , test_descriptionCookie) ,
29
+ ( " test_cookieDomainMatching " , test_cookieDomainMatching) ,
29
30
]
30
31
}
31
32
@@ -89,6 +90,11 @@ class TestHTTPCookieStorage: XCTestCase {
89
90
descriptionCookie ( with: . groupContainer( " test " ) )
90
91
}
91
92
93
+ func test_cookieDomainMatching( ) {
94
+ cookieDomainMatching ( with: . shared)
95
+ cookieDomainMatching ( with: . groupContainer( " test " ) )
96
+ }
97
+
92
98
func getStorage( for type: _StorageType ) -> HTTPCookieStorage {
93
99
switch type {
94
100
case . shared:
@@ -272,6 +278,49 @@ class TestHTTPCookieStorage: XCTestCase {
272
278
XCTAssertEqual ( storage. description, " <NSHTTPCookieStorage cookies count: \( cookies1. count) > " )
273
279
}
274
280
281
+ func cookieDomainMatching( with storageType: _StorageType ) {
282
+ let storage = getStorage ( for: storageType)
283
+
284
+ let simpleCookie1 = HTTPCookie ( properties: [ // swift.org domain only
285
+ . name: " TestCookie1 " ,
286
+ . value: " TestValue1 " ,
287
+ . path: " / " ,
288
+ . domain: " swift.org " ,
289
+ ] ) !
290
+
291
+ storage. setCookie ( simpleCookie1)
292
+
293
+ let simpleCookie2 = HTTPCookie ( properties: [ // *.swift.org
294
+ . name: " TestCookie2 " ,
295
+ . value: " TestValue2 " ,
296
+ . path: " / " ,
297
+ . domain: " .SWIFT.org " ,
298
+ ] ) !
299
+
300
+ storage. setCookie ( simpleCookie2)
301
+
302
+ let simpleCookie3 = HTTPCookie ( properties: [ // bugs.swift.org
303
+ . name: " TestCookie3 " ,
304
+ . value: " TestValue3 " ,
305
+ . path: " / " ,
306
+ . domain: " bugs.swift.org " ,
307
+ ] ) !
308
+
309
+ storage. setCookie ( simpleCookie3)
310
+ XCTAssertEqual ( storage. cookies!. count, 3 )
311
+
312
+ let swiftOrgUrl = URL ( string: " https://swift.ORG " ) !
313
+ let ciSwiftOrgUrl = URL ( string: " https://CI.swift.ORG " ) !
314
+ let bugsSwiftOrgUrl = URL ( string: " https://BUGS.swift.org " ) !
315
+ let exampleComUrl = URL ( string: " http://www.example.com " ) !
316
+ let superSwiftOrgUrl = URL ( string: " https://superswift.org " ) !
317
+ XCTAssertEqual ( Set ( storage. cookies ( for: swiftOrgUrl) !) , Set ( [ simpleCookie1, simpleCookie2] ) )
318
+ XCTAssertEqual ( storage. cookies ( for: ciSwiftOrgUrl) !, [ simpleCookie2] )
319
+ XCTAssertEqual ( Set ( storage. cookies ( for: bugsSwiftOrgUrl) !) , Set ( [ simpleCookie2, simpleCookie3] ) )
320
+ XCTAssertEqual ( storage. cookies ( for: exampleComUrl) !, [ ] )
321
+ XCTAssertEqual ( storage. cookies ( for: superSwiftOrgUrl) !, [ ] )
322
+ }
323
+
275
324
func test_cookieInXDGSpecPath( ) {
276
325
#if !os(Android) && !DARWIN_COMPATIBILITY_TESTS
277
326
//Test without setting the environment variable
0 commit comments