yhirano | 01a5d66 | 2015-02-12 04:33:06 | [diff] [blame] | 1 | // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include <string> |
Victor Costan | 8587494 | 2018-02-28 04:11:44 | [diff] [blame] | 6 | #include <utility> |
yhirano | 01a5d66 | 2015-02-12 04:33:06 | [diff] [blame] | 7 | |
Sebastien Marchand | 6d0558fd | 2019-01-25 16:49:37 | [diff] [blame] | 8 | #include "base/bind.h" |
yhirano | 01a5d66 | 2015-02-12 04:33:06 | [diff] [blame] | 9 | #include "base/callback_forward.h" |
| 10 | #include "base/memory/weak_ptr.h" |
yhirano | 01a5d66 | 2015-02-12 04:33:06 | [diff] [blame] | 11 | #include "base/run_loop.h" |
| 12 | #include "base/strings/string_util.h" |
| 13 | #include "base/strings/stringprintf.h" |
gab | f767595f | 2016-05-11 18:50:35 | [diff] [blame] | 14 | #include "base/threading/thread_task_runner_handle.h" |
Victor Costan | 8587494 | 2018-02-28 04:11:44 | [diff] [blame] | 15 | #include "net/cookies/canonical_cookie.h" |
| 16 | #include "net/cookies/canonical_cookie_test_helpers.h" |
yhirano | 01a5d66 | 2015-02-12 04:33:06 | [diff] [blame] | 17 | #include "net/cookies/cookie_store.h" |
Yutaka Hirano | 2f65eec | 2018-05-23 01:58:22 | [diff] [blame] | 18 | #include "net/http/http_request_headers.h" |
yhirano | 01a5d66 | 2015-02-12 04:33:06 | [diff] [blame] | 19 | #include "net/socket/socket_test_util.h" |
| 20 | #include "net/websockets/websocket_stream_create_test_base.h" |
| 21 | #include "net/websockets/websocket_test_util.h" |
Victor Costan | 8587494 | 2018-02-28 04:11:44 | [diff] [blame] | 22 | #include "testing/gmock/include/gmock/gmock.h" |
yhirano | 01a5d66 | 2015-02-12 04:33:06 | [diff] [blame] | 23 | #include "testing/gtest/include/gtest/gtest.h" |
| 24 | #include "url/gurl.h" |
mkwst | 4997ce8 | 2015-07-25 12:00:05 | [diff] [blame] | 25 | #include "url/origin.h" |
yhirano | 01a5d66 | 2015-02-12 04:33:06 | [diff] [blame] | 26 | |
| 27 | namespace net { |
| 28 | namespace { |
| 29 | |
| 30 | using ::testing::TestWithParam; |
| 31 | using ::testing::ValuesIn; |
| 32 | |
| 33 | const char kNoCookieHeader[] = ""; |
| 34 | |
| 35 | class TestBase : public WebSocketStreamCreateTestBase { |
| 36 | public: |
| 37 | void CreateAndConnect(const GURL& url, |
mkwst | 4997ce8 | 2015-07-25 12:00:05 | [diff] [blame] | 38 | const url::Origin& origin, |
Mike West | b85da8ed | 2017-08-10 14:16:46 | [diff] [blame] | 39 | const GURL& site_for_cookies, |
yhirano | 01a5d66 | 2015-02-12 04:33:06 | [diff] [blame] | 40 | const std::string& cookie_header, |
| 41 | const std::string& response_body) { |
| 42 | // We assume cookie_header ends with CRLF if not empty, as |
| 43 | // WebSocketStandardRequestWithCookies requires. Use AddCRLFIfNotEmpty |
| 44 | // in a call site. |
brettw | a7ff1b29 | 2015-07-16 17:49:29 | [diff] [blame] | 45 | CHECK(cookie_header.empty() || |
| 46 | base::EndsWith(cookie_header, "\r\n", base::CompareCase::SENSITIVE)); |
yhirano | 01a5d66 | 2015-02-12 04:33:06 | [diff] [blame] | 47 | |
| 48 | url_request_context_host_.SetExpectations( |
| 49 | WebSocketStandardRequestWithCookies(url.path(), url.host(), origin, |
allada | cef397d | 2016-06-29 17:52:23 | [diff] [blame] | 50 | cookie_header, std::string(), |
| 51 | std::string()), |
yhirano | 01a5d66 | 2015-02-12 04:33:06 | [diff] [blame] | 52 | response_body); |
Yutaka Hirano | 2f65eec | 2018-05-23 01:58:22 | [diff] [blame] | 53 | CreateAndConnectStream(url, NoSubProtocols(), origin, site_for_cookies, |
| 54 | HttpRequestHeaders(), nullptr); |
yhirano | 01a5d66 | 2015-02-12 04:33:06 | [diff] [blame] | 55 | } |
| 56 | |
| 57 | std::string AddCRLFIfNotEmpty(const std::string& s) { |
| 58 | return s.empty() ? s : s + "\r\n"; |
| 59 | } |
| 60 | }; |
| 61 | |
| 62 | struct ClientUseCookieParameter { |
| 63 | // The URL for the WebSocket connection. |
| 64 | const char* const url; |
| 65 | // The URL for the previously set cookies. |
| 66 | const char* const cookie_url; |
| 67 | // The previously set cookies contents. |
| 68 | const char* const cookie_line; |
| 69 | // The Cookie: HTTP header expected to appear in the WS request. An empty |
| 70 | // string means there is no Cookie: header. |
| 71 | const char* const cookie_header; |
| 72 | }; |
| 73 | |
| 74 | class WebSocketStreamClientUseCookieTest |
| 75 | : public TestBase, |
| 76 | public TestWithParam<ClientUseCookieParameter> { |
| 77 | public: |
| 78 | ~WebSocketStreamClientUseCookieTest() override { |
| 79 | // Permit any endpoint locks to be released. |
| 80 | stream_request_.reset(); |
| 81 | stream_.reset(); |
| 82 | base::RunLoop().RunUntilIdle(); |
| 83 | } |
| 84 | |
| 85 | static void SetCookieHelperFunction(const base::Closure& task, |
| 86 | base::WeakPtr<bool> weak_is_called, |
| 87 | base::WeakPtr<bool> weak_result, |
| 88 | bool success) { |
| 89 | *weak_is_called = true; |
| 90 | *weak_result = success; |
| 91 | base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, task); |
| 92 | } |
| 93 | }; |
| 94 | |
| 95 | struct ServerSetCookieParameter { |
| 96 | // The URL for the WebSocket connection. |
| 97 | const char* const url; |
| 98 | // The URL used to query cookies after the response received. |
| 99 | const char* const cookie_url; |
| 100 | // The cookies expected to appear for |cookie_url| inquiry. |
| 101 | const char* const cookie_line; |
| 102 | // The Set-Cookie: HTTP header attached to the response. |
| 103 | const char* const cookie_header; |
| 104 | }; |
| 105 | |
| 106 | class WebSocketStreamServerSetCookieTest |
| 107 | : public TestBase, |
| 108 | public TestWithParam<ServerSetCookieParameter> { |
| 109 | public: |
| 110 | ~WebSocketStreamServerSetCookieTest() override { |
| 111 | // Permit any endpoint locks to be released. |
| 112 | stream_request_.reset(); |
| 113 | stream_.reset(); |
| 114 | base::RunLoop().RunUntilIdle(); |
| 115 | } |
| 116 | |
Aaron Tagliaboschi | a4c64b5 | 2019-01-25 03:28:49 | [diff] [blame] | 117 | static void GetCookieListHelperFunction( |
| 118 | base::OnceClosure task, |
| 119 | base::WeakPtr<bool> weak_is_called, |
| 120 | base::WeakPtr<CookieList> weak_result, |
| 121 | const CookieList& cookie_list, |
| 122 | const CookieStatusList& excluded_cookies) { |
yhirano | 01a5d66 | 2015-02-12 04:33:06 | [diff] [blame] | 123 | *weak_is_called = true; |
Victor Costan | 8587494 | 2018-02-28 04:11:44 | [diff] [blame] | 124 | *weak_result = cookie_list; |
| 125 | base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, std::move(task)); |
yhirano | 01a5d66 | 2015-02-12 04:33:06 | [diff] [blame] | 126 | } |
| 127 | }; |
| 128 | |
| 129 | TEST_P(WebSocketStreamClientUseCookieTest, ClientUseCookie) { |
| 130 | // For wss tests. |
Bence Béky | 63842f0 | 2018-03-05 13:48:21 | [diff] [blame] | 131 | url_request_context_host_.AddSSLSocketDataProvider( |
| 132 | std::make_unique<SSLSocketDataProvider>(ASYNC, OK)); |
yhirano | 01a5d66 | 2015-02-12 04:33:06 | [diff] [blame] | 133 | |
| 134 | CookieStore* store = |
| 135 | url_request_context_host_.GetURLRequestContext()->cookie_store(); |
| 136 | |
| 137 | const GURL url(GetParam().url); |
| 138 | const GURL cookie_url(GetParam().cookie_url); |
Daniel Cheng | 88186bd5 | 2017-10-20 08:14:46 | [diff] [blame] | 139 | const url::Origin origin = |
| 140 | url::Origin::Create(GURL("http://www.example.com")); |
Mike West | b85da8ed | 2017-08-10 14:16:46 | [diff] [blame] | 141 | const GURL site_for_cookies("http://www.example.com/"); |
yhirano | 01a5d66 | 2015-02-12 04:33:06 | [diff] [blame] | 142 | const std::string cookie_line(GetParam().cookie_line); |
| 143 | const std::string cookie_header(AddCRLFIfNotEmpty(GetParam().cookie_header)); |
| 144 | |
| 145 | bool is_called = false; |
| 146 | bool set_cookie_result = false; |
| 147 | base::WeakPtrFactory<bool> weak_is_called(&is_called); |
| 148 | base::WeakPtrFactory<bool> weak_set_cookie_result(&set_cookie_result); |
| 149 | |
| 150 | base::RunLoop run_loop; |
| 151 | store->SetCookieWithOptionsAsync( |
| 152 | cookie_url, cookie_line, CookieOptions(), |
| 153 | base::Bind(&SetCookieHelperFunction, run_loop.QuitClosure(), |
| 154 | weak_is_called.GetWeakPtr(), |
| 155 | weak_set_cookie_result.GetWeakPtr())); |
| 156 | run_loop.Run(); |
| 157 | ASSERT_TRUE(is_called); |
| 158 | ASSERT_TRUE(set_cookie_result); |
| 159 | |
Mike West | b85da8ed | 2017-08-10 14:16:46 | [diff] [blame] | 160 | CreateAndConnect(url, origin, site_for_cookies, cookie_header, |
tyoshino | 8572d57 | 2016-07-13 06:29:48 | [diff] [blame] | 161 | WebSocketStandardResponse("")); |
yhirano | 01a5d66 | 2015-02-12 04:33:06 | [diff] [blame] | 162 | WaitUntilConnectDone(); |
| 163 | EXPECT_FALSE(has_failed()); |
| 164 | } |
| 165 | |
| 166 | TEST_P(WebSocketStreamServerSetCookieTest, ServerSetCookie) { |
| 167 | // For wss tests. |
Bence Béky | 63842f0 | 2018-03-05 13:48:21 | [diff] [blame] | 168 | url_request_context_host_.AddSSLSocketDataProvider( |
| 169 | std::make_unique<SSLSocketDataProvider>(ASYNC, OK)); |
yhirano | 01a5d66 | 2015-02-12 04:33:06 | [diff] [blame] | 170 | |
| 171 | const GURL url(GetParam().url); |
| 172 | const GURL cookie_url(GetParam().cookie_url); |
Daniel Cheng | 88186bd5 | 2017-10-20 08:14:46 | [diff] [blame] | 173 | const url::Origin origin = |
| 174 | url::Origin::Create(GURL("http://www.example.com")); |
Mike West | b85da8ed | 2017-08-10 14:16:46 | [diff] [blame] | 175 | const GURL site_for_cookies("http://www.example.com/"); |
yhirano | 01a5d66 | 2015-02-12 04:33:06 | [diff] [blame] | 176 | const std::string cookie_line(GetParam().cookie_line); |
| 177 | const std::string cookie_header(AddCRLFIfNotEmpty(GetParam().cookie_header)); |
| 178 | |
| 179 | const std::string response = base::StringPrintf( |
| 180 | "HTTP/1.1 101 Switching Protocols\r\n" |
| 181 | "Upgrade: websocket\r\n" |
| 182 | "Connection: Upgrade\r\n" |
| 183 | "%s" |
| 184 | "Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r\n" |
| 185 | "\r\n", |
| 186 | cookie_header.c_str()); |
| 187 | |
| 188 | CookieStore* store = |
| 189 | url_request_context_host_.GetURLRequestContext()->cookie_store(); |
| 190 | |
Mike West | b85da8ed | 2017-08-10 14:16:46 | [diff] [blame] | 191 | CreateAndConnect(url, origin, site_for_cookies, "", response); |
yhirano | 01a5d66 | 2015-02-12 04:33:06 | [diff] [blame] | 192 | WaitUntilConnectDone(); |
| 193 | EXPECT_FALSE(has_failed()); |
| 194 | |
| 195 | bool is_called = false; |
Victor Costan | 8587494 | 2018-02-28 04:11:44 | [diff] [blame] | 196 | CookieList get_cookie_list_result; |
yhirano | 01a5d66 | 2015-02-12 04:33:06 | [diff] [blame] | 197 | base::WeakPtrFactory<bool> weak_is_called(&is_called); |
Victor Costan | 8587494 | 2018-02-28 04:11:44 | [diff] [blame] | 198 | base::WeakPtrFactory<CookieList> weak_get_cookie_list_result( |
| 199 | &get_cookie_list_result); |
yhirano | 01a5d66 | 2015-02-12 04:33:06 | [diff] [blame] | 200 | base::RunLoop run_loop; |
Victor Costan | 8587494 | 2018-02-28 04:11:44 | [diff] [blame] | 201 | store->GetCookieListWithOptionsAsync( |
yhirano | 01a5d66 | 2015-02-12 04:33:06 | [diff] [blame] | 202 | cookie_url, CookieOptions(), |
Victor Costan | 8587494 | 2018-02-28 04:11:44 | [diff] [blame] | 203 | base::BindOnce(&GetCookieListHelperFunction, run_loop.QuitClosure(), |
| 204 | weak_is_called.GetWeakPtr(), |
| 205 | weak_get_cookie_list_result.GetWeakPtr())); |
yhirano | 01a5d66 | 2015-02-12 04:33:06 | [diff] [blame] | 206 | run_loop.Run(); |
| 207 | EXPECT_TRUE(is_called); |
Victor Costan | 8587494 | 2018-02-28 04:11:44 | [diff] [blame] | 208 | EXPECT_THAT(get_cookie_list_result, MatchesCookieLine(cookie_line)); |
yhirano | 01a5d66 | 2015-02-12 04:33:06 | [diff] [blame] | 209 | } |
| 210 | |
| 211 | // Test parameters definitions follow... |
| 212 | |
| 213 | const ClientUseCookieParameter kClientUseCookieParameters[] = { |
| 214 | // Non-secure cookies for ws |
| 215 | {"ws://www.example.com", |
| 216 | "http://www.example.com", |
| 217 | "test-cookie", |
| 218 | "Cookie: test-cookie"}, |
| 219 | |
| 220 | {"ws://www.example.com", |
| 221 | "https://www.example.com", |
| 222 | "test-cookie", |
| 223 | "Cookie: test-cookie"}, |
| 224 | |
| 225 | {"ws://www.example.com", |
| 226 | "ws://www.example.com", |
| 227 | "test-cookie", |
| 228 | "Cookie: test-cookie"}, |
| 229 | |
| 230 | {"ws://www.example.com", |
| 231 | "wss://www.example.com", |
| 232 | "test-cookie", |
| 233 | "Cookie: test-cookie"}, |
| 234 | |
| 235 | // Non-secure cookies for wss |
| 236 | {"wss://www.example.com", |
| 237 | "http://www.example.com", |
| 238 | "test-cookie", |
| 239 | "Cookie: test-cookie"}, |
| 240 | |
| 241 | {"wss://www.example.com", |
| 242 | "https://www.example.com", |
| 243 | "test-cookie", |
| 244 | "Cookie: test-cookie"}, |
| 245 | |
| 246 | {"wss://www.example.com", |
| 247 | "ws://www.example.com", |
| 248 | "test-cookie", |
| 249 | "Cookie: test-cookie"}, |
| 250 | |
| 251 | {"wss://www.example.com", |
| 252 | "wss://www.example.com", |
| 253 | "test-cookie", |
| 254 | "Cookie: test-cookie"}, |
| 255 | |
| 256 | // Secure-cookies for ws |
| 257 | {"ws://www.example.com", |
| 258 | "https://www.example.com", |
| 259 | "test-cookie; secure", |
| 260 | kNoCookieHeader}, |
| 261 | |
| 262 | {"ws://www.example.com", |
| 263 | "wss://www.example.com", |
| 264 | "test-cookie; secure", |
| 265 | kNoCookieHeader}, |
| 266 | |
| 267 | // Secure-cookies for wss |
| 268 | {"wss://www.example.com", |
| 269 | "https://www.example.com", |
| 270 | "test-cookie; secure", |
| 271 | "Cookie: test-cookie"}, |
| 272 | |
| 273 | {"wss://www.example.com", |
| 274 | "wss://www.example.com", |
| 275 | "test-cookie; secure", |
| 276 | "Cookie: test-cookie"}, |
| 277 | |
| 278 | // Non-secure cookies for ws (sharing domain) |
| 279 | {"ws://www.example.com", |
| 280 | "http://www2.example.com", |
| 281 | "test-cookie; Domain=example.com", |
| 282 | "Cookie: test-cookie"}, |
| 283 | |
| 284 | {"ws://www.example.com", |
| 285 | "https://www2.example.com", |
| 286 | "test-cookie; Domain=example.com", |
| 287 | "Cookie: test-cookie"}, |
| 288 | |
| 289 | {"ws://www.example.com", |
| 290 | "ws://www2.example.com", |
| 291 | "test-cookie; Domain=example.com", |
| 292 | "Cookie: test-cookie"}, |
| 293 | |
| 294 | {"ws://www.example.com", |
| 295 | "wss://www2.example.com", |
| 296 | "test-cookie; Domain=example.com", |
| 297 | "Cookie: test-cookie"}, |
| 298 | |
| 299 | // Non-secure cookies for wss (sharing domain) |
| 300 | {"wss://www.example.com", |
| 301 | "http://www2.example.com", |
| 302 | "test-cookie; Domain=example.com", |
| 303 | "Cookie: test-cookie"}, |
| 304 | |
| 305 | {"wss://www.example.com", |
| 306 | "https://www2.example.com", |
| 307 | "test-cookie; Domain=example.com", |
| 308 | "Cookie: test-cookie"}, |
| 309 | |
| 310 | {"wss://www.example.com", |
| 311 | "ws://www2.example.com", |
| 312 | "test-cookie; Domain=example.com", |
| 313 | "Cookie: test-cookie"}, |
| 314 | |
| 315 | {"wss://www.example.com", |
| 316 | "wss://www2.example.com", |
| 317 | "test-cookie; Domain=example.com", |
| 318 | "Cookie: test-cookie"}, |
| 319 | |
| 320 | // Secure-cookies for ws (sharing domain) |
| 321 | {"ws://www.example.com", |
| 322 | "https://www2.example.com", |
| 323 | "test-cookie; Domain=example.com; secure", |
| 324 | kNoCookieHeader}, |
| 325 | |
| 326 | {"ws://www.example.com", |
| 327 | "wss://www2.example.com", |
| 328 | "test-cookie; Domain=example.com; secure", |
| 329 | kNoCookieHeader}, |
| 330 | |
| 331 | // Secure-cookies for wss (sharing domain) |
| 332 | {"wss://www.example.com", |
| 333 | "https://www2.example.com", |
| 334 | "test-cookie; Domain=example.com; secure", |
| 335 | "Cookie: test-cookie"}, |
| 336 | |
| 337 | {"wss://www.example.com", |
| 338 | "wss://www2.example.com", |
| 339 | "test-cookie; Domain=example.com; secure", |
| 340 | "Cookie: test-cookie"}, |
| 341 | |
| 342 | // Non-matching cookies for ws |
| 343 | {"ws://www.example.com", |
| 344 | "http://www2.example.com", |
| 345 | "test-cookie", |
| 346 | kNoCookieHeader}, |
| 347 | |
| 348 | {"ws://www.example.com", |
| 349 | "https://www2.example.com", |
| 350 | "test-cookie", |
| 351 | kNoCookieHeader}, |
| 352 | |
| 353 | {"ws://www.example.com", |
| 354 | "ws://www2.example.com", |
| 355 | "test-cookie", |
| 356 | kNoCookieHeader}, |
| 357 | |
| 358 | {"ws://www.example.com", |
| 359 | "wss://www2.example.com", |
| 360 | "test-cookie", |
| 361 | kNoCookieHeader}, |
| 362 | |
| 363 | // Non-matching cookies for wss |
| 364 | {"wss://www.example.com", |
| 365 | "http://www2.example.com", |
| 366 | "test-cookie", |
| 367 | kNoCookieHeader}, |
| 368 | |
| 369 | {"wss://www.example.com", |
| 370 | "https://www2.example.com", |
| 371 | "test-cookie", |
| 372 | kNoCookieHeader}, |
| 373 | |
| 374 | {"wss://www.example.com", |
| 375 | "ws://www2.example.com", |
| 376 | "test-cookie", |
| 377 | kNoCookieHeader}, |
| 378 | |
| 379 | {"wss://www.example.com", |
| 380 | "wss://www2.example.com", |
| 381 | "test-cookie", |
| 382 | kNoCookieHeader}, |
| 383 | }; |
| 384 | |
| 385 | INSTANTIATE_TEST_CASE_P(WebSocketStreamClientUseCookieTest, |
| 386 | WebSocketStreamClientUseCookieTest, |
| 387 | ValuesIn(kClientUseCookieParameters)); |
| 388 | |
| 389 | const ServerSetCookieParameter kServerSetCookieParameters[] = { |
| 390 | // Cookies coming from ws |
| 391 | {"ws://www.example.com", |
| 392 | "http://www.example.com", |
| 393 | "test-cookie", |
| 394 | "Set-Cookie: test-cookie"}, |
| 395 | |
| 396 | {"ws://www.example.com", |
| 397 | "https://www.example.com", |
| 398 | "test-cookie", |
| 399 | "Set-Cookie: test-cookie"}, |
| 400 | |
| 401 | {"ws://www.example.com", |
| 402 | "ws://www.example.com", |
| 403 | "test-cookie", |
| 404 | "Set-Cookie: test-cookie"}, |
| 405 | |
| 406 | {"ws://www.example.com", |
| 407 | "wss://www.example.com", |
| 408 | "test-cookie", |
| 409 | "Set-Cookie: test-cookie"}, |
| 410 | |
| 411 | // Cookies coming from wss |
| 412 | {"wss://www.example.com", |
| 413 | "http://www.example.com", |
| 414 | "test-cookie", |
| 415 | "Set-Cookie: test-cookie"}, |
| 416 | |
| 417 | {"wss://www.example.com", |
| 418 | "https://www.example.com", |
| 419 | "test-cookie", |
| 420 | "Set-Cookie: test-cookie"}, |
| 421 | |
| 422 | {"wss://www.example.com", |
| 423 | "ws://www.example.com", |
| 424 | "test-cookie", |
| 425 | "Set-Cookie: test-cookie"}, |
| 426 | |
| 427 | {"wss://www.example.com", |
| 428 | "wss://www.example.com", |
| 429 | "test-cookie", |
| 430 | "Set-Cookie: test-cookie"}, |
| 431 | |
| 432 | // cookies coming from ws (sharing domain) |
| 433 | {"ws://www.example.com", |
| 434 | "http://www2.example.com", |
| 435 | "test-cookie", |
| 436 | "Set-Cookie: test-cookie; Domain=example.com"}, |
| 437 | |
| 438 | {"ws://www.example.com", |
| 439 | "https://www2.example.com", |
| 440 | "test-cookie", |
| 441 | "Set-Cookie: test-cookie; Domain=example.com"}, |
| 442 | |
| 443 | {"ws://www.example.com", |
| 444 | "ws://www2.example.com", |
| 445 | "test-cookie", |
| 446 | "Set-Cookie: test-cookie; Domain=example.com"}, |
| 447 | |
| 448 | {"ws://www.example.com", |
| 449 | "wss://www2.example.com", |
| 450 | "test-cookie", |
| 451 | "Set-Cookie: test-cookie; Domain=example.com"}, |
| 452 | |
| 453 | // cookies coming from wss (sharing domain) |
| 454 | {"wss://www.example.com", |
| 455 | "http://www2.example.com", |
| 456 | "test-cookie", |
| 457 | "Set-Cookie: test-cookie; Domain=example.com"}, |
| 458 | |
| 459 | {"wss://www.example.com", |
| 460 | "https://www2.example.com", |
| 461 | "test-cookie", |
| 462 | "Set-Cookie: test-cookie; Domain=example.com"}, |
| 463 | |
| 464 | {"wss://www.example.com", |
| 465 | "ws://www2.example.com", |
| 466 | "test-cookie", |
| 467 | "Set-Cookie: test-cookie; Domain=example.com"}, |
| 468 | |
| 469 | {"wss://www.example.com", |
| 470 | "wss://www2.example.com", |
| 471 | "test-cookie", |
| 472 | "Set-Cookie: test-cookie; Domain=example.com"}, |
| 473 | |
| 474 | // Non-matching cookies coming from ws |
| 475 | {"ws://www.example.com", |
| 476 | "http://www2.example.com", |
| 477 | "", |
| 478 | "Set-Cookie: test-cookie"}, |
| 479 | |
| 480 | {"ws://www.example.com", |
| 481 | "https://www2.example.com", |
| 482 | "", |
| 483 | "Set-Cookie: test-cookie"}, |
| 484 | |
| 485 | {"ws://www.example.com", |
| 486 | "ws://www2.example.com", |
| 487 | "", |
| 488 | "Set-Cookie: test-cookie"}, |
| 489 | |
| 490 | {"ws://www.example.com", |
| 491 | "wss://www2.example.com", |
| 492 | "", |
| 493 | "Set-Cookie: test-cookie"}, |
| 494 | |
| 495 | // Non-matching cookies coming from wss |
| 496 | {"wss://www.example.com", |
| 497 | "http://www2.example.com", |
| 498 | "", |
| 499 | "Set-Cookie: test-cookie"}, |
| 500 | |
| 501 | {"wss://www.example.com", |
| 502 | "https://www2.example.com", |
| 503 | "", |
| 504 | "Set-Cookie: test-cookie"}, |
| 505 | |
| 506 | {"wss://www.example.com", |
| 507 | "ws://www2.example.com", |
| 508 | "", |
| 509 | "Set-Cookie: test-cookie"}, |
| 510 | |
| 511 | {"wss://www.example.com", |
| 512 | "wss://www2.example.com", |
| 513 | "", |
| 514 | "Set-Cookie: test-cookie"}, |
| 515 | }; |
| 516 | |
| 517 | INSTANTIATE_TEST_CASE_P(WebSocketStreamServerSetCookieTest, |
| 518 | WebSocketStreamServerSetCookieTest, |
| 519 | ValuesIn(kServerSetCookieParameters)); |
| 520 | |
| 521 | } // namespace |
| 522 | } // namespace net |