Avi Drissman | 6459548 | 2022-09-14 20:52:29 | [diff] [blame] | 1 | // Copyright 2015 The Chromium Authors |
yhirano | 01a5d66 | 2015-02-12 04:33:06 | [diff] [blame] | 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 | |
Avi Drissman | 41c4a41 | 2023-01-11 22:45:37 | [diff] [blame^] | 8 | #include "base/functional/bind.h" |
yhirano | 01a5d66 | 2015-02-12 04:33:06 | [diff] [blame] | 9 | #include "base/memory/weak_ptr.h" |
yhirano | 01a5d66 | 2015-02-12 04:33:06 | [diff] [blame] | 10 | #include "base/run_loop.h" |
| 11 | #include "base/strings/string_util.h" |
| 12 | #include "base/strings/stringprintf.h" |
Sean Maher | 5b9af51f | 2022-11-21 15:32:47 | [diff] [blame] | 13 | #include "base/task/single_thread_task_runner.h" |
Matt Menke | 29a538d | 2020-04-29 16:12:17 | [diff] [blame] | 14 | #include "net/base/isolation_info.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" |
Ayu Ishii | f3966ca | 2020-07-08 17:35:12 | [diff] [blame] | 17 | #include "net/cookies/cookie_access_result.h" |
yhirano | 01a5d66 | 2015-02-12 04:33:06 | [diff] [blame] | 18 | #include "net/cookies/cookie_store.h" |
Lily Chen | f068a76 | 2019-08-21 21:10:50 | [diff] [blame] | 19 | #include "net/cookies/cookie_util.h" |
Yutaka Hirano | 2f65eec | 2018-05-23 01:58:22 | [diff] [blame] | 20 | #include "net/http/http_request_headers.h" |
yhirano | 01a5d66 | 2015-02-12 04:33:06 | [diff] [blame] | 21 | #include "net/socket/socket_test_util.h" |
| 22 | #include "net/websockets/websocket_stream_create_test_base.h" |
| 23 | #include "net/websockets/websocket_test_util.h" |
Victor Costan | 8587494 | 2018-02-28 04:11:44 | [diff] [blame] | 24 | #include "testing/gmock/include/gmock/gmock.h" |
yhirano | 01a5d66 | 2015-02-12 04:33:06 | [diff] [blame] | 25 | #include "testing/gtest/include/gtest/gtest.h" |
| 26 | #include "url/gurl.h" |
mkwst | 4997ce8 | 2015-07-25 12:00:05 | [diff] [blame] | 27 | #include "url/origin.h" |
yhirano | 01a5d66 | 2015-02-12 04:33:06 | [diff] [blame] | 28 | |
| 29 | namespace net { |
| 30 | namespace { |
| 31 | |
| 32 | using ::testing::TestWithParam; |
| 33 | using ::testing::ValuesIn; |
| 34 | |
Yoichi Osato | ef37ee4 | 2022-03-08 04:56:32 | [diff] [blame] | 35 | const WebSocketExtraHeaders kNoCookieHeader = {}; |
yhirano | 01a5d66 | 2015-02-12 04:33:06 | [diff] [blame] | 36 | |
| 37 | class TestBase : public WebSocketStreamCreateTestBase { |
| 38 | public: |
| 39 | void CreateAndConnect(const GURL& url, |
mkwst | 4997ce8 | 2015-07-25 12:00:05 | [diff] [blame] | 40 | const url::Origin& origin, |
Maks Orlovich | 8be0e25 | 2019-12-09 18:35:49 | [diff] [blame] | 41 | const SiteForCookies& site_for_cookies, |
Matt Menke | 29a538d | 2020-04-29 16:12:17 | [diff] [blame] | 42 | const IsolationInfo& isolation_info, |
Yoichi Osato | ef37ee4 | 2022-03-08 04:56:32 | [diff] [blame] | 43 | const WebSocketExtraHeaders& cookie_header, |
yhirano | 01a5d66 | 2015-02-12 04:33:06 | [diff] [blame] | 44 | const std::string& response_body) { |
yhirano | 01a5d66 | 2015-02-12 04:33:06 | [diff] [blame] | 45 | url_request_context_host_.SetExpectations( |
Yoichi Osato | effb00c1 | 2022-02-24 06:55:35 | [diff] [blame] | 46 | WebSocketStandardRequestWithCookies( |
| 47 | url.path(), url.host(), origin, cookie_header, |
| 48 | /*send_additional_request_headers=*/{}, /*extra_headers=*/{}), |
yhirano | 01a5d66 | 2015-02-12 04:33:06 | [diff] [blame] | 49 | response_body); |
Yutaka Hirano | 2f65eec | 2018-05-23 01:58:22 | [diff] [blame] | 50 | CreateAndConnectStream(url, NoSubProtocols(), origin, site_for_cookies, |
Matt Menke | 29a538d | 2020-04-29 16:12:17 | [diff] [blame] | 51 | isolation_info, HttpRequestHeaders(), nullptr); |
yhirano | 01a5d66 | 2015-02-12 04:33:06 | [diff] [blame] | 52 | } |
yhirano | 01a5d66 | 2015-02-12 04:33:06 | [diff] [blame] | 53 | }; |
| 54 | |
| 55 | struct ClientUseCookieParameter { |
| 56 | // The URL for the WebSocket connection. |
| 57 | const char* const url; |
| 58 | // The URL for the previously set cookies. |
| 59 | const char* const cookie_url; |
| 60 | // The previously set cookies contents. |
| 61 | const char* const cookie_line; |
Yoichi Osato | ef37ee4 | 2022-03-08 04:56:32 | [diff] [blame] | 62 | // The Cookie: HTTP header expected to appear in the WS request. |
| 63 | const WebSocketExtraHeaders cookie_header; |
yhirano | 01a5d66 | 2015-02-12 04:33:06 | [diff] [blame] | 64 | }; |
| 65 | |
| 66 | class WebSocketStreamClientUseCookieTest |
| 67 | : public TestBase, |
| 68 | public TestWithParam<ClientUseCookieParameter> { |
| 69 | public: |
| 70 | ~WebSocketStreamClientUseCookieTest() override { |
| 71 | // Permit any endpoint locks to be released. |
| 72 | stream_request_.reset(); |
| 73 | stream_.reset(); |
| 74 | base::RunLoop().RunUntilIdle(); |
| 75 | } |
| 76 | |
Jihwan Marc Kim | 3e132f1 | 2020-05-20 17:33:19 | [diff] [blame] | 77 | static void SetCookieHelperFunction(const base::RepeatingClosure& task, |
| 78 | base::WeakPtr<bool> weak_is_called, |
| 79 | base::WeakPtr<bool> weak_result, |
Ayu Ishii | f3966ca | 2020-07-08 17:35:12 | [diff] [blame] | 80 | CookieAccessResult access_result) { |
yhirano | 01a5d66 | 2015-02-12 04:33:06 | [diff] [blame] | 81 | *weak_is_called = true; |
Ayu Ishii | f3966ca | 2020-07-08 17:35:12 | [diff] [blame] | 82 | *weak_result = access_result.status.IsInclude(); |
Sean Maher | 5b9af51f | 2022-11-21 15:32:47 | [diff] [blame] | 83 | base::SingleThreadTaskRunner::GetCurrentDefault()->PostTask(FROM_HERE, |
| 84 | task); |
yhirano | 01a5d66 | 2015-02-12 04:33:06 | [diff] [blame] | 85 | } |
| 86 | }; |
| 87 | |
| 88 | struct ServerSetCookieParameter { |
| 89 | // The URL for the WebSocket connection. |
| 90 | const char* const url; |
| 91 | // The URL used to query cookies after the response received. |
| 92 | const char* const cookie_url; |
| 93 | // The cookies expected to appear for |cookie_url| inquiry. |
| 94 | const char* const cookie_line; |
| 95 | // The Set-Cookie: HTTP header attached to the response. |
Yoichi Osato | ef37ee4 | 2022-03-08 04:56:32 | [diff] [blame] | 96 | const WebSocketExtraHeaders cookie_header; |
yhirano | 01a5d66 | 2015-02-12 04:33:06 | [diff] [blame] | 97 | }; |
| 98 | |
| 99 | class WebSocketStreamServerSetCookieTest |
| 100 | : public TestBase, |
| 101 | public TestWithParam<ServerSetCookieParameter> { |
| 102 | public: |
| 103 | ~WebSocketStreamServerSetCookieTest() override { |
| 104 | // Permit any endpoint locks to be released. |
| 105 | stream_request_.reset(); |
| 106 | stream_.reset(); |
| 107 | base::RunLoop().RunUntilIdle(); |
| 108 | } |
| 109 | |
Aaron Tagliaboschi | a4c64b5 | 2019-01-25 03:28:49 | [diff] [blame] | 110 | static void GetCookieListHelperFunction( |
| 111 | base::OnceClosure task, |
| 112 | base::WeakPtr<bool> weak_is_called, |
| 113 | base::WeakPtr<CookieList> weak_result, |
Ayu Ishii | bc6fdb0a | 2020-06-08 22:59:19 | [diff] [blame] | 114 | const CookieAccessResultList& cookie_list, |
| 115 | const CookieAccessResultList& excluded_cookies) { |
yhirano | 01a5d66 | 2015-02-12 04:33:06 | [diff] [blame] | 116 | *weak_is_called = true; |
Ayu Ishii | bc6fdb0a | 2020-06-08 22:59:19 | [diff] [blame] | 117 | *weak_result = cookie_util::StripAccessResults(cookie_list); |
Sean Maher | 5b9af51f | 2022-11-21 15:32:47 | [diff] [blame] | 118 | base::SingleThreadTaskRunner::GetCurrentDefault()->PostTask( |
| 119 | FROM_HERE, std::move(task)); |
yhirano | 01a5d66 | 2015-02-12 04:33:06 | [diff] [blame] | 120 | } |
| 121 | }; |
| 122 | |
| 123 | TEST_P(WebSocketStreamClientUseCookieTest, ClientUseCookie) { |
| 124 | // For wss tests. |
Bence Béky | 63842f0 | 2018-03-05 13:48:21 | [diff] [blame] | 125 | url_request_context_host_.AddSSLSocketDataProvider( |
| 126 | std::make_unique<SSLSocketDataProvider>(ASYNC, OK)); |
yhirano | 01a5d66 | 2015-02-12 04:33:06 | [diff] [blame] | 127 | |
| 128 | CookieStore* store = |
| 129 | url_request_context_host_.GetURLRequestContext()->cookie_store(); |
| 130 | |
| 131 | const GURL url(GetParam().url); |
| 132 | const GURL cookie_url(GetParam().cookie_url); |
Steven Bingler | 9b8d9f0 | 2021-03-15 20:30:58 | [diff] [blame] | 133 | const url::Origin origin = url::Origin::Create(GURL(GetParam().url)); |
Maks Orlovich | 8be0e25 | 2019-12-09 18:35:49 | [diff] [blame] | 134 | const SiteForCookies site_for_cookies = SiteForCookies::FromOrigin(origin); |
Matt Menke | 29a538d | 2020-04-29 16:12:17 | [diff] [blame] | 135 | const IsolationInfo isolation_info = |
shivanigithub | 4e78015f59 | 2020-10-21 13:26:23 | [diff] [blame] | 136 | IsolationInfo::Create(IsolationInfo::RequestType::kOther, origin, origin, |
| 137 | SiteForCookies::FromOrigin(origin)); |
yhirano | 01a5d66 | 2015-02-12 04:33:06 | [diff] [blame] | 138 | const std::string cookie_line(GetParam().cookie_line); |
yhirano | 01a5d66 | 2015-02-12 04:33:06 | [diff] [blame] | 139 | |
| 140 | bool is_called = false; |
| 141 | bool set_cookie_result = false; |
| 142 | base::WeakPtrFactory<bool> weak_is_called(&is_called); |
| 143 | base::WeakPtrFactory<bool> weak_set_cookie_result(&set_cookie_result); |
| 144 | |
| 145 | base::RunLoop run_loop; |
Lily Chen | 0f208ea | 2019-08-08 23:37:53 | [diff] [blame] | 146 | auto cookie = |
| 147 | CanonicalCookie::Create(cookie_url, cookie_line, base::Time::Now(), |
Dylan Cutler | f4a802b | 2021-08-03 16:38:54 | [diff] [blame] | 148 | absl::nullopt /* server_time */, |
| 149 | absl::nullopt /* cookie_partition_key */); |
Lily Chen | 0f208ea | 2019-08-08 23:37:53 | [diff] [blame] | 150 | store->SetCanonicalCookieAsync( |
Lily Chen | 96f29a13 | 2020-04-15 17:59:36 | [diff] [blame] | 151 | std::move(cookie), cookie_url, net::CookieOptions::MakeAllInclusive(), |
Yannic Bonenberger | 782a2860 | 2019-09-03 10:36:52 | [diff] [blame] | 152 | base::BindOnce(&SetCookieHelperFunction, run_loop.QuitClosure(), |
| 153 | weak_is_called.GetWeakPtr(), |
| 154 | weak_set_cookie_result.GetWeakPtr())); |
yhirano | 01a5d66 | 2015-02-12 04:33:06 | [diff] [blame] | 155 | run_loop.Run(); |
| 156 | ASSERT_TRUE(is_called); |
| 157 | ASSERT_TRUE(set_cookie_result); |
| 158 | |
Yoichi Osato | ef37ee4 | 2022-03-08 04:56:32 | [diff] [blame] | 159 | CreateAndConnect(url, origin, site_for_cookies, isolation_info, |
| 160 | GetParam().cookie_header, WebSocketStandardResponse("")); |
yhirano | 01a5d66 | 2015-02-12 04:33:06 | [diff] [blame] | 161 | WaitUntilConnectDone(); |
| 162 | EXPECT_FALSE(has_failed()); |
| 163 | } |
| 164 | |
| 165 | TEST_P(WebSocketStreamServerSetCookieTest, ServerSetCookie) { |
| 166 | // For wss tests. |
Bence Béky | 63842f0 | 2018-03-05 13:48:21 | [diff] [blame] | 167 | url_request_context_host_.AddSSLSocketDataProvider( |
| 168 | std::make_unique<SSLSocketDataProvider>(ASYNC, OK)); |
yhirano | 01a5d66 | 2015-02-12 04:33:06 | [diff] [blame] | 169 | |
| 170 | const GURL url(GetParam().url); |
| 171 | const GURL cookie_url(GetParam().cookie_url); |
Steven Bingler | 9b8d9f0 | 2021-03-15 20:30:58 | [diff] [blame] | 172 | const url::Origin origin = url::Origin::Create(GURL(GetParam().url)); |
Maks Orlovich | 8be0e25 | 2019-12-09 18:35:49 | [diff] [blame] | 173 | const SiteForCookies site_for_cookies = SiteForCookies::FromOrigin(origin); |
Matt Menke | 29a538d | 2020-04-29 16:12:17 | [diff] [blame] | 174 | const IsolationInfo isolation_info = |
shivanigithub | 4e78015f59 | 2020-10-21 13:26:23 | [diff] [blame] | 175 | IsolationInfo::Create(IsolationInfo::RequestType::kOther, origin, origin, |
| 176 | SiteForCookies::FromOrigin(origin)); |
yhirano | 01a5d66 | 2015-02-12 04:33:06 | [diff] [blame] | 177 | const std::string cookie_line(GetParam().cookie_line); |
Yoichi Osato | ef37ee4 | 2022-03-08 04:56:32 | [diff] [blame] | 178 | HttpRequestHeaders headers; |
| 179 | for (const auto& [key, value] : GetParam().cookie_header) |
| 180 | headers.SetHeader(key, value); |
| 181 | std::string cookie_header(headers.ToString()); |
yhirano | 01a5d66 | 2015-02-12 04:33:06 | [diff] [blame] | 182 | const std::string response = base::StringPrintf( |
| 183 | "HTTP/1.1 101 Switching Protocols\r\n" |
| 184 | "Upgrade: websocket\r\n" |
| 185 | "Connection: Upgrade\r\n" |
yhirano | 01a5d66 | 2015-02-12 04:33:06 | [diff] [blame] | 186 | "Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r\n" |
Yoichi Osato | ef37ee4 | 2022-03-08 04:56:32 | [diff] [blame] | 187 | "%s", |
yhirano | 01a5d66 | 2015-02-12 04:33:06 | [diff] [blame] | 188 | cookie_header.c_str()); |
yhirano | 01a5d66 | 2015-02-12 04:33:06 | [diff] [blame] | 189 | CookieStore* store = |
| 190 | url_request_context_host_.GetURLRequestContext()->cookie_store(); |
| 191 | |
Yoichi Osato | ef37ee4 | 2022-03-08 04:56:32 | [diff] [blame] | 192 | CreateAndConnect(url, origin, site_for_cookies, isolation_info, |
| 193 | /*cookie_header=*/{}, response); |
yhirano | 01a5d66 | 2015-02-12 04:33:06 | [diff] [blame] | 194 | WaitUntilConnectDone(); |
Yoichi Osato | ef37ee4 | 2022-03-08 04:56:32 | [diff] [blame] | 195 | EXPECT_FALSE(has_failed()) << failure_message(); |
yhirano | 01a5d66 | 2015-02-12 04:33:06 | [diff] [blame] | 196 | |
| 197 | bool is_called = false; |
Victor Costan | 8587494 | 2018-02-28 04:11:44 | [diff] [blame] | 198 | CookieList get_cookie_list_result; |
yhirano | 01a5d66 | 2015-02-12 04:33:06 | [diff] [blame] | 199 | base::WeakPtrFactory<bool> weak_is_called(&is_called); |
Victor Costan | 8587494 | 2018-02-28 04:11:44 | [diff] [blame] | 200 | base::WeakPtrFactory<CookieList> weak_get_cookie_list_result( |
| 201 | &get_cookie_list_result); |
yhirano | 01a5d66 | 2015-02-12 04:33:06 | [diff] [blame] | 202 | base::RunLoop run_loop; |
Victor Costan | 8587494 | 2018-02-28 04:11:44 | [diff] [blame] | 203 | store->GetCookieListWithOptionsAsync( |
Maks Orlovich | fc69c6f | 2019-10-22 15:58:54 | [diff] [blame] | 204 | cookie_url, net::CookieOptions::MakeAllInclusive(), |
Aykut Bulut | 244341e | 2021-12-09 15:57:25 | [diff] [blame] | 205 | CookiePartitionKeyCollection(), |
Victor Costan | 8587494 | 2018-02-28 04:11:44 | [diff] [blame] | 206 | base::BindOnce(&GetCookieListHelperFunction, run_loop.QuitClosure(), |
| 207 | weak_is_called.GetWeakPtr(), |
| 208 | weak_get_cookie_list_result.GetWeakPtr())); |
yhirano | 01a5d66 | 2015-02-12 04:33:06 | [diff] [blame] | 209 | run_loop.Run(); |
| 210 | EXPECT_TRUE(is_called); |
Victor Costan | 8587494 | 2018-02-28 04:11:44 | [diff] [blame] | 211 | EXPECT_THAT(get_cookie_list_result, MatchesCookieLine(cookie_line)); |
yhirano | 01a5d66 | 2015-02-12 04:33:06 | [diff] [blame] | 212 | } |
| 213 | |
| 214 | // Test parameters definitions follow... |
| 215 | |
| 216 | const ClientUseCookieParameter kClientUseCookieParameters[] = { |
| 217 | // Non-secure cookies for ws |
| 218 | {"ws://www.example.com", |
| 219 | "http://www.example.com", |
| 220 | "test-cookie", |
Yoichi Osato | ef37ee4 | 2022-03-08 04:56:32 | [diff] [blame] | 221 | {{"Cookie", "test-cookie"}}}, |
yhirano | 01a5d66 | 2015-02-12 04:33:06 | [diff] [blame] | 222 | |
| 223 | {"ws://www.example.com", |
| 224 | "https://www.example.com", |
| 225 | "test-cookie", |
Yoichi Osato | ef37ee4 | 2022-03-08 04:56:32 | [diff] [blame] | 226 | {{"Cookie", "test-cookie"}}}, |
yhirano | 01a5d66 | 2015-02-12 04:33:06 | [diff] [blame] | 227 | |
| 228 | {"ws://www.example.com", |
| 229 | "ws://www.example.com", |
| 230 | "test-cookie", |
Yoichi Osato | ef37ee4 | 2022-03-08 04:56:32 | [diff] [blame] | 231 | {{"Cookie", "test-cookie"}}}, |
yhirano | 01a5d66 | 2015-02-12 04:33:06 | [diff] [blame] | 232 | |
| 233 | {"ws://www.example.com", |
| 234 | "wss://www.example.com", |
| 235 | "test-cookie", |
Yoichi Osato | ef37ee4 | 2022-03-08 04:56:32 | [diff] [blame] | 236 | {{"Cookie", "test-cookie"}}}, |
yhirano | 01a5d66 | 2015-02-12 04:33:06 | [diff] [blame] | 237 | |
| 238 | // Non-secure cookies for wss |
| 239 | {"wss://www.example.com", |
| 240 | "http://www.example.com", |
| 241 | "test-cookie", |
Yoichi Osato | ef37ee4 | 2022-03-08 04:56:32 | [diff] [blame] | 242 | {{"Cookie", "test-cookie"}}}, |
yhirano | 01a5d66 | 2015-02-12 04:33:06 | [diff] [blame] | 243 | |
| 244 | {"wss://www.example.com", |
| 245 | "https://www.example.com", |
| 246 | "test-cookie", |
Yoichi Osato | ef37ee4 | 2022-03-08 04:56:32 | [diff] [blame] | 247 | {{"Cookie", "test-cookie"}}}, |
yhirano | 01a5d66 | 2015-02-12 04:33:06 | [diff] [blame] | 248 | |
| 249 | {"wss://www.example.com", |
| 250 | "ws://www.example.com", |
| 251 | "test-cookie", |
Yoichi Osato | ef37ee4 | 2022-03-08 04:56:32 | [diff] [blame] | 252 | {{"Cookie", "test-cookie"}}}, |
yhirano | 01a5d66 | 2015-02-12 04:33:06 | [diff] [blame] | 253 | |
| 254 | {"wss://www.example.com", |
| 255 | "wss://www.example.com", |
| 256 | "test-cookie", |
Yoichi Osato | ef37ee4 | 2022-03-08 04:56:32 | [diff] [blame] | 257 | {{"Cookie", "test-cookie"}}}, |
yhirano | 01a5d66 | 2015-02-12 04:33:06 | [diff] [blame] | 258 | |
| 259 | // Secure-cookies for ws |
Yoichi Osato | ef37ee4 | 2022-03-08 04:56:32 | [diff] [blame] | 260 | {"ws://www.example.com", "https://www.example.com", "test-cookie; secure", |
yhirano | 01a5d66 | 2015-02-12 04:33:06 | [diff] [blame] | 261 | kNoCookieHeader}, |
| 262 | |
Yoichi Osato | ef37ee4 | 2022-03-08 04:56:32 | [diff] [blame] | 263 | {"ws://www.example.com", "wss://www.example.com", "test-cookie; secure", |
yhirano | 01a5d66 | 2015-02-12 04:33:06 | [diff] [blame] | 264 | kNoCookieHeader}, |
| 265 | |
| 266 | // Secure-cookies for wss |
| 267 | {"wss://www.example.com", |
| 268 | "https://www.example.com", |
| 269 | "test-cookie; secure", |
Yoichi Osato | ef37ee4 | 2022-03-08 04:56:32 | [diff] [blame] | 270 | {{"Cookie", "test-cookie"}}}, |
yhirano | 01a5d66 | 2015-02-12 04:33:06 | [diff] [blame] | 271 | |
| 272 | {"wss://www.example.com", |
| 273 | "wss://www.example.com", |
| 274 | "test-cookie; secure", |
Yoichi Osato | ef37ee4 | 2022-03-08 04:56:32 | [diff] [blame] | 275 | {{"Cookie", "test-cookie"}}}, |
yhirano | 01a5d66 | 2015-02-12 04:33:06 | [diff] [blame] | 276 | |
| 277 | // Non-secure cookies for ws (sharing domain) |
| 278 | {"ws://www.example.com", |
| 279 | "http://www2.example.com", |
| 280 | "test-cookie; Domain=example.com", |
Yoichi Osato | ef37ee4 | 2022-03-08 04:56:32 | [diff] [blame] | 281 | {{"Cookie", "test-cookie"}}}, |
yhirano | 01a5d66 | 2015-02-12 04:33:06 | [diff] [blame] | 282 | |
| 283 | {"ws://www.example.com", |
| 284 | "https://www2.example.com", |
| 285 | "test-cookie; Domain=example.com", |
Yoichi Osato | ef37ee4 | 2022-03-08 04:56:32 | [diff] [blame] | 286 | {{"Cookie", "test-cookie"}}}, |
yhirano | 01a5d66 | 2015-02-12 04:33:06 | [diff] [blame] | 287 | |
| 288 | {"ws://www.example.com", |
| 289 | "ws://www2.example.com", |
| 290 | "test-cookie; Domain=example.com", |
Yoichi Osato | ef37ee4 | 2022-03-08 04:56:32 | [diff] [blame] | 291 | {{"Cookie", "test-cookie"}}}, |
yhirano | 01a5d66 | 2015-02-12 04:33:06 | [diff] [blame] | 292 | |
| 293 | {"ws://www.example.com", |
| 294 | "wss://www2.example.com", |
| 295 | "test-cookie; Domain=example.com", |
Yoichi Osato | ef37ee4 | 2022-03-08 04:56:32 | [diff] [blame] | 296 | {{"Cookie", "test-cookie"}}}, |
yhirano | 01a5d66 | 2015-02-12 04:33:06 | [diff] [blame] | 297 | |
| 298 | // Non-secure cookies for wss (sharing domain) |
| 299 | {"wss://www.example.com", |
| 300 | "http://www2.example.com", |
| 301 | "test-cookie; Domain=example.com", |
Yoichi Osato | ef37ee4 | 2022-03-08 04:56:32 | [diff] [blame] | 302 | {{"Cookie", "test-cookie"}}}, |
yhirano | 01a5d66 | 2015-02-12 04:33:06 | [diff] [blame] | 303 | |
| 304 | {"wss://www.example.com", |
| 305 | "https://www2.example.com", |
| 306 | "test-cookie; Domain=example.com", |
Yoichi Osato | ef37ee4 | 2022-03-08 04:56:32 | [diff] [blame] | 307 | {{"Cookie", "test-cookie"}}}, |
yhirano | 01a5d66 | 2015-02-12 04:33:06 | [diff] [blame] | 308 | |
| 309 | {"wss://www.example.com", |
| 310 | "ws://www2.example.com", |
| 311 | "test-cookie; Domain=example.com", |
Yoichi Osato | ef37ee4 | 2022-03-08 04:56:32 | [diff] [blame] | 312 | {{"Cookie", "test-cookie"}}}, |
yhirano | 01a5d66 | 2015-02-12 04:33:06 | [diff] [blame] | 313 | |
| 314 | {"wss://www.example.com", |
| 315 | "wss://www2.example.com", |
| 316 | "test-cookie; Domain=example.com", |
Yoichi Osato | ef37ee4 | 2022-03-08 04:56:32 | [diff] [blame] | 317 | {{"Cookie", "test-cookie"}}}, |
yhirano | 01a5d66 | 2015-02-12 04:33:06 | [diff] [blame] | 318 | |
| 319 | // Secure-cookies for ws (sharing domain) |
Yoichi Osato | ef37ee4 | 2022-03-08 04:56:32 | [diff] [blame] | 320 | {"ws://www.example.com", "https://www2.example.com", |
| 321 | "test-cookie; Domain=example.com; secure", kNoCookieHeader}, |
yhirano | 01a5d66 | 2015-02-12 04:33:06 | [diff] [blame] | 322 | |
Yoichi Osato | ef37ee4 | 2022-03-08 04:56:32 | [diff] [blame] | 323 | {"ws://www.example.com", "wss://www2.example.com", |
| 324 | "test-cookie; Domain=example.com; secure", kNoCookieHeader}, |
yhirano | 01a5d66 | 2015-02-12 04:33:06 | [diff] [blame] | 325 | |
| 326 | // Secure-cookies for wss (sharing domain) |
| 327 | {"wss://www.example.com", |
| 328 | "https://www2.example.com", |
| 329 | "test-cookie; Domain=example.com; secure", |
Yoichi Osato | ef37ee4 | 2022-03-08 04:56:32 | [diff] [blame] | 330 | {{"Cookie", "test-cookie"}}}, |
yhirano | 01a5d66 | 2015-02-12 04:33:06 | [diff] [blame] | 331 | |
| 332 | {"wss://www.example.com", |
| 333 | "wss://www2.example.com", |
| 334 | "test-cookie; Domain=example.com; secure", |
Yoichi Osato | ef37ee4 | 2022-03-08 04:56:32 | [diff] [blame] | 335 | {{"Cookie", "test-cookie"}}}, |
yhirano | 01a5d66 | 2015-02-12 04:33:06 | [diff] [blame] | 336 | |
| 337 | // Non-matching cookies for ws |
Yoichi Osato | ef37ee4 | 2022-03-08 04:56:32 | [diff] [blame] | 338 | {"ws://www.example.com", "http://www2.example.com", "test-cookie", |
yhirano | 01a5d66 | 2015-02-12 04:33:06 | [diff] [blame] | 339 | kNoCookieHeader}, |
| 340 | |
Yoichi Osato | ef37ee4 | 2022-03-08 04:56:32 | [diff] [blame] | 341 | {"ws://www.example.com", "https://www2.example.com", "test-cookie", |
yhirano | 01a5d66 | 2015-02-12 04:33:06 | [diff] [blame] | 342 | kNoCookieHeader}, |
| 343 | |
Yoichi Osato | ef37ee4 | 2022-03-08 04:56:32 | [diff] [blame] | 344 | {"ws://www.example.com", "ws://www2.example.com", "test-cookie", |
yhirano | 01a5d66 | 2015-02-12 04:33:06 | [diff] [blame] | 345 | kNoCookieHeader}, |
| 346 | |
Yoichi Osato | ef37ee4 | 2022-03-08 04:56:32 | [diff] [blame] | 347 | {"ws://www.example.com", "wss://www2.example.com", "test-cookie", |
yhirano | 01a5d66 | 2015-02-12 04:33:06 | [diff] [blame] | 348 | kNoCookieHeader}, |
| 349 | |
| 350 | // Non-matching cookies for wss |
Yoichi Osato | ef37ee4 | 2022-03-08 04:56:32 | [diff] [blame] | 351 | {"wss://www.example.com", "http://www2.example.com", "test-cookie", |
yhirano | 01a5d66 | 2015-02-12 04:33:06 | [diff] [blame] | 352 | kNoCookieHeader}, |
| 353 | |
Yoichi Osato | ef37ee4 | 2022-03-08 04:56:32 | [diff] [blame] | 354 | {"wss://www.example.com", "https://www2.example.com", "test-cookie", |
yhirano | 01a5d66 | 2015-02-12 04:33:06 | [diff] [blame] | 355 | kNoCookieHeader}, |
| 356 | |
Yoichi Osato | ef37ee4 | 2022-03-08 04:56:32 | [diff] [blame] | 357 | {"wss://www.example.com", "ws://www2.example.com", "test-cookie", |
yhirano | 01a5d66 | 2015-02-12 04:33:06 | [diff] [blame] | 358 | kNoCookieHeader}, |
| 359 | |
Yoichi Osato | ef37ee4 | 2022-03-08 04:56:32 | [diff] [blame] | 360 | {"wss://www.example.com", "wss://www2.example.com", "test-cookie", |
yhirano | 01a5d66 | 2015-02-12 04:33:06 | [diff] [blame] | 361 | kNoCookieHeader}, |
| 362 | }; |
| 363 | |
Victor Costan | 2309ea0 | 2019-02-13 21:35:47 | [diff] [blame] | 364 | INSTANTIATE_TEST_SUITE_P(WebSocketStreamClientUseCookieTest, |
| 365 | WebSocketStreamClientUseCookieTest, |
| 366 | ValuesIn(kClientUseCookieParameters)); |
yhirano | 01a5d66 | 2015-02-12 04:33:06 | [diff] [blame] | 367 | |
| 368 | const ServerSetCookieParameter kServerSetCookieParameters[] = { |
| 369 | // Cookies coming from ws |
| 370 | {"ws://www.example.com", |
| 371 | "http://www.example.com", |
| 372 | "test-cookie", |
Yoichi Osato | ef37ee4 | 2022-03-08 04:56:32 | [diff] [blame] | 373 | {{"Set-Cookie", "test-cookie"}}}, |
yhirano | 01a5d66 | 2015-02-12 04:33:06 | [diff] [blame] | 374 | |
| 375 | {"ws://www.example.com", |
| 376 | "https://www.example.com", |
| 377 | "test-cookie", |
Yoichi Osato | ef37ee4 | 2022-03-08 04:56:32 | [diff] [blame] | 378 | {{"Set-Cookie", "test-cookie"}}}, |
yhirano | 01a5d66 | 2015-02-12 04:33:06 | [diff] [blame] | 379 | |
| 380 | {"ws://www.example.com", |
| 381 | "ws://www.example.com", |
| 382 | "test-cookie", |
Yoichi Osato | ef37ee4 | 2022-03-08 04:56:32 | [diff] [blame] | 383 | {{"Set-Cookie", "test-cookie"}}}, |
yhirano | 01a5d66 | 2015-02-12 04:33:06 | [diff] [blame] | 384 | |
| 385 | {"ws://www.example.com", |
| 386 | "wss://www.example.com", |
| 387 | "test-cookie", |
Yoichi Osato | ef37ee4 | 2022-03-08 04:56:32 | [diff] [blame] | 388 | {{"Set-Cookie", "test-cookie"}}}, |
yhirano | 01a5d66 | 2015-02-12 04:33:06 | [diff] [blame] | 389 | |
| 390 | // Cookies coming from wss |
| 391 | {"wss://www.example.com", |
| 392 | "http://www.example.com", |
| 393 | "test-cookie", |
Yoichi Osato | ef37ee4 | 2022-03-08 04:56:32 | [diff] [blame] | 394 | {{"Set-Cookie", "test-cookie"}}}, |
yhirano | 01a5d66 | 2015-02-12 04:33:06 | [diff] [blame] | 395 | |
| 396 | {"wss://www.example.com", |
| 397 | "https://www.example.com", |
| 398 | "test-cookie", |
Yoichi Osato | ef37ee4 | 2022-03-08 04:56:32 | [diff] [blame] | 399 | {{"Set-Cookie", "test-cookie"}}}, |
yhirano | 01a5d66 | 2015-02-12 04:33:06 | [diff] [blame] | 400 | |
| 401 | {"wss://www.example.com", |
| 402 | "ws://www.example.com", |
| 403 | "test-cookie", |
Yoichi Osato | ef37ee4 | 2022-03-08 04:56:32 | [diff] [blame] | 404 | {{"Set-Cookie", "test-cookie"}}}, |
yhirano | 01a5d66 | 2015-02-12 04:33:06 | [diff] [blame] | 405 | |
| 406 | {"wss://www.example.com", |
| 407 | "wss://www.example.com", |
| 408 | "test-cookie", |
Yoichi Osato | ef37ee4 | 2022-03-08 04:56:32 | [diff] [blame] | 409 | {{"Set-Cookie", "test-cookie"}}}, |
yhirano | 01a5d66 | 2015-02-12 04:33:06 | [diff] [blame] | 410 | |
| 411 | // cookies coming from ws (sharing domain) |
| 412 | {"ws://www.example.com", |
| 413 | "http://www2.example.com", |
| 414 | "test-cookie", |
Yoichi Osato | ef37ee4 | 2022-03-08 04:56:32 | [diff] [blame] | 415 | {{"Set-Cookie", "test-cookie; Domain=example.com"}}}, |
yhirano | 01a5d66 | 2015-02-12 04:33:06 | [diff] [blame] | 416 | |
| 417 | {"ws://www.example.com", |
| 418 | "https://www2.example.com", |
| 419 | "test-cookie", |
Yoichi Osato | ef37ee4 | 2022-03-08 04:56:32 | [diff] [blame] | 420 | {{"Set-Cookie", "test-cookie; Domain=example.com"}}}, |
yhirano | 01a5d66 | 2015-02-12 04:33:06 | [diff] [blame] | 421 | |
| 422 | {"ws://www.example.com", |
| 423 | "ws://www2.example.com", |
| 424 | "test-cookie", |
Yoichi Osato | ef37ee4 | 2022-03-08 04:56:32 | [diff] [blame] | 425 | {{"Set-Cookie", "test-cookie; Domain=example.com"}}}, |
yhirano | 01a5d66 | 2015-02-12 04:33:06 | [diff] [blame] | 426 | |
| 427 | {"ws://www.example.com", |
| 428 | "wss://www2.example.com", |
| 429 | "test-cookie", |
Yoichi Osato | ef37ee4 | 2022-03-08 04:56:32 | [diff] [blame] | 430 | {{"Set-Cookie", "test-cookie; Domain=example.com"}}}, |
yhirano | 01a5d66 | 2015-02-12 04:33:06 | [diff] [blame] | 431 | |
| 432 | // cookies coming from wss (sharing domain) |
| 433 | {"wss://www.example.com", |
| 434 | "http://www2.example.com", |
| 435 | "test-cookie", |
Yoichi Osato | ef37ee4 | 2022-03-08 04:56:32 | [diff] [blame] | 436 | {{"Set-Cookie", "test-cookie; Domain=example.com"}}}, |
yhirano | 01a5d66 | 2015-02-12 04:33:06 | [diff] [blame] | 437 | |
| 438 | {"wss://www.example.com", |
| 439 | "https://www2.example.com", |
| 440 | "test-cookie", |
Yoichi Osato | ef37ee4 | 2022-03-08 04:56:32 | [diff] [blame] | 441 | {{"Set-Cookie", "test-cookie; Domain=example.com"}}}, |
yhirano | 01a5d66 | 2015-02-12 04:33:06 | [diff] [blame] | 442 | |
| 443 | {"wss://www.example.com", |
| 444 | "ws://www2.example.com", |
| 445 | "test-cookie", |
Yoichi Osato | ef37ee4 | 2022-03-08 04:56:32 | [diff] [blame] | 446 | {{"Set-Cookie", "test-cookie; Domain=example.com"}}}, |
yhirano | 01a5d66 | 2015-02-12 04:33:06 | [diff] [blame] | 447 | |
| 448 | {"wss://www.example.com", |
| 449 | "wss://www2.example.com", |
| 450 | "test-cookie", |
Yoichi Osato | ef37ee4 | 2022-03-08 04:56:32 | [diff] [blame] | 451 | {{"Set-Cookie", "test-cookie; Domain=example.com"}}}, |
yhirano | 01a5d66 | 2015-02-12 04:33:06 | [diff] [blame] | 452 | |
| 453 | // Non-matching cookies coming from ws |
| 454 | {"ws://www.example.com", |
| 455 | "http://www2.example.com", |
| 456 | "", |
Yoichi Osato | ef37ee4 | 2022-03-08 04:56:32 | [diff] [blame] | 457 | {{"Set-Cookie", "test-cookie"}}}, |
yhirano | 01a5d66 | 2015-02-12 04:33:06 | [diff] [blame] | 458 | |
| 459 | {"ws://www.example.com", |
| 460 | "https://www2.example.com", |
| 461 | "", |
Yoichi Osato | ef37ee4 | 2022-03-08 04:56:32 | [diff] [blame] | 462 | {{"Set-Cookie", "test-cookie"}}}, |
yhirano | 01a5d66 | 2015-02-12 04:33:06 | [diff] [blame] | 463 | |
| 464 | {"ws://www.example.com", |
| 465 | "ws://www2.example.com", |
| 466 | "", |
Yoichi Osato | ef37ee4 | 2022-03-08 04:56:32 | [diff] [blame] | 467 | {{"Set-Cookie", "test-cookie"}}}, |
yhirano | 01a5d66 | 2015-02-12 04:33:06 | [diff] [blame] | 468 | |
| 469 | {"ws://www.example.com", |
| 470 | "wss://www2.example.com", |
| 471 | "", |
Yoichi Osato | ef37ee4 | 2022-03-08 04:56:32 | [diff] [blame] | 472 | {{"Set-Cookie", "test-cookie"}}}, |
yhirano | 01a5d66 | 2015-02-12 04:33:06 | [diff] [blame] | 473 | |
| 474 | // Non-matching cookies coming from wss |
| 475 | {"wss://www.example.com", |
| 476 | "http://www2.example.com", |
| 477 | "", |
Yoichi Osato | ef37ee4 | 2022-03-08 04:56:32 | [diff] [blame] | 478 | {{"Set-Cookie", "test-cookie"}}}, |
yhirano | 01a5d66 | 2015-02-12 04:33:06 | [diff] [blame] | 479 | |
| 480 | {"wss://www.example.com", |
| 481 | "https://www2.example.com", |
| 482 | "", |
Yoichi Osato | ef37ee4 | 2022-03-08 04:56:32 | [diff] [blame] | 483 | {{"Set-Cookie", "test-cookie"}}}, |
yhirano | 01a5d66 | 2015-02-12 04:33:06 | [diff] [blame] | 484 | |
| 485 | {"wss://www.example.com", |
| 486 | "ws://www2.example.com", |
| 487 | "", |
Yoichi Osato | ef37ee4 | 2022-03-08 04:56:32 | [diff] [blame] | 488 | {{"Set-Cookie", "test-cookie"}}}, |
yhirano | 01a5d66 | 2015-02-12 04:33:06 | [diff] [blame] | 489 | |
| 490 | {"wss://www.example.com", |
| 491 | "wss://www2.example.com", |
| 492 | "", |
Yoichi Osato | ef37ee4 | 2022-03-08 04:56:32 | [diff] [blame] | 493 | {{"Set-Cookie", "test-cookie"}}}, |
yhirano | 01a5d66 | 2015-02-12 04:33:06 | [diff] [blame] | 494 | }; |
| 495 | |
Victor Costan | 2309ea0 | 2019-02-13 21:35:47 | [diff] [blame] | 496 | INSTANTIATE_TEST_SUITE_P(WebSocketStreamServerSetCookieTest, |
| 497 | WebSocketStreamServerSetCookieTest, |
| 498 | ValuesIn(kServerSetCookieParameters)); |
yhirano | 01a5d66 | 2015-02-12 04:33:06 | [diff] [blame] | 499 | |
| 500 | } // namespace |
| 501 | } // namespace net |