Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(84)

Side by Side Diff: net/websockets/websocket_stream_cookie_test.cc

Issue 2102993002: Fix WebSocket to set first party for cookies (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Update testRunner calls to setBlockThirdPartyCookies() Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « net/websockets/websocket_stream.cc ('k') | net/websockets/websocket_stream_create_test_base.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <string> 5 #include <string>
6 6
7 #include "base/callback_forward.h" 7 #include "base/callback_forward.h"
8 #include "base/memory/ptr_util.h" 8 #include "base/memory/ptr_util.h"
9 #include "base/memory/weak_ptr.h" 9 #include "base/memory/weak_ptr.h"
10 #include "base/message_loop/message_loop.h" 10 #include "base/message_loop/message_loop.h"
(...skipping 14 matching lines...) Expand all
25 25
26 using ::testing::TestWithParam; 26 using ::testing::TestWithParam;
27 using ::testing::ValuesIn; 27 using ::testing::ValuesIn;
28 28
29 const char kNoCookieHeader[] = ""; 29 const char kNoCookieHeader[] = "";
30 30
31 class TestBase : public WebSocketStreamCreateTestBase { 31 class TestBase : public WebSocketStreamCreateTestBase {
32 public: 32 public:
33 void CreateAndConnect(const GURL& url, 33 void CreateAndConnect(const GURL& url,
34 const url::Origin& origin, 34 const url::Origin& origin,
35 const GURL& first_party_for_cookies,
35 const std::string& cookie_header, 36 const std::string& cookie_header,
36 const std::string& response_body) { 37 const std::string& response_body) {
37 // We assume cookie_header ends with CRLF if not empty, as 38 // We assume cookie_header ends with CRLF if not empty, as
38 // WebSocketStandardRequestWithCookies requires. Use AddCRLFIfNotEmpty 39 // WebSocketStandardRequestWithCookies requires. Use AddCRLFIfNotEmpty
39 // in a call site. 40 // in a call site.
40 CHECK(cookie_header.empty() || 41 CHECK(cookie_header.empty() ||
41 base::EndsWith(cookie_header, "\r\n", base::CompareCase::SENSITIVE)); 42 base::EndsWith(cookie_header, "\r\n", base::CompareCase::SENSITIVE));
42 43
43 url_request_context_host_.SetExpectations( 44 url_request_context_host_.SetExpectations(
44 WebSocketStandardRequestWithCookies(url.path(), url.host(), origin, 45 WebSocketStandardRequestWithCookies(url.path(), url.host(), origin,
45 cookie_header, std::string(), 46 cookie_header, std::string(),
46 std::string()), 47 std::string()),
47 response_body); 48 response_body);
48 CreateAndConnectStream(url.spec(), NoSubProtocols(), origin, "", nullptr); 49 CreateAndConnectStream(url, NoSubProtocols(), origin,
50 first_party_for_cookies, "", nullptr);
49 } 51 }
50 52
51 std::string AddCRLFIfNotEmpty(const std::string& s) { 53 std::string AddCRLFIfNotEmpty(const std::string& s) {
52 return s.empty() ? s : s + "\r\n"; 54 return s.empty() ? s : s + "\r\n";
53 } 55 }
54 }; 56 };
55 57
56 struct ClientUseCookieParameter { 58 struct ClientUseCookieParameter {
57 // The URL for the WebSocket connection. 59 // The URL for the WebSocket connection.
58 const char* const url; 60 const char* const url;
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 TEST_P(WebSocketStreamClientUseCookieTest, ClientUseCookie) { 123 TEST_P(WebSocketStreamClientUseCookieTest, ClientUseCookie) {
122 // For wss tests. 124 // For wss tests.
123 ssl_data_.push_back(base::WrapUnique(new SSLSocketDataProvider(ASYNC, OK))); 125 ssl_data_.push_back(base::WrapUnique(new SSLSocketDataProvider(ASYNC, OK)));
124 126
125 CookieStore* store = 127 CookieStore* store =
126 url_request_context_host_.GetURLRequestContext()->cookie_store(); 128 url_request_context_host_.GetURLRequestContext()->cookie_store();
127 129
128 const GURL url(GetParam().url); 130 const GURL url(GetParam().url);
129 const GURL cookie_url(GetParam().cookie_url); 131 const GURL cookie_url(GetParam().cookie_url);
130 const url::Origin origin(GURL("http://www.example.com")); 132 const url::Origin origin(GURL("http://www.example.com"));
133 const GURL first_party_for_cookies("http://www.example.com/");
131 const std::string cookie_line(GetParam().cookie_line); 134 const std::string cookie_line(GetParam().cookie_line);
132 const std::string cookie_header(AddCRLFIfNotEmpty(GetParam().cookie_header)); 135 const std::string cookie_header(AddCRLFIfNotEmpty(GetParam().cookie_header));
133 136
134 bool is_called = false; 137 bool is_called = false;
135 bool set_cookie_result = false; 138 bool set_cookie_result = false;
136 base::WeakPtrFactory<bool> weak_is_called(&is_called); 139 base::WeakPtrFactory<bool> weak_is_called(&is_called);
137 base::WeakPtrFactory<bool> weak_set_cookie_result(&set_cookie_result); 140 base::WeakPtrFactory<bool> weak_set_cookie_result(&set_cookie_result);
138 141
139 base::RunLoop run_loop; 142 base::RunLoop run_loop;
140 store->SetCookieWithOptionsAsync( 143 store->SetCookieWithOptionsAsync(
141 cookie_url, cookie_line, CookieOptions(), 144 cookie_url, cookie_line, CookieOptions(),
142 base::Bind(&SetCookieHelperFunction, run_loop.QuitClosure(), 145 base::Bind(&SetCookieHelperFunction, run_loop.QuitClosure(),
143 weak_is_called.GetWeakPtr(), 146 weak_is_called.GetWeakPtr(),
144 weak_set_cookie_result.GetWeakPtr())); 147 weak_set_cookie_result.GetWeakPtr()));
145 run_loop.Run(); 148 run_loop.Run();
146 ASSERT_TRUE(is_called); 149 ASSERT_TRUE(is_called);
147 ASSERT_TRUE(set_cookie_result); 150 ASSERT_TRUE(set_cookie_result);
148 151
149 CreateAndConnect(url, origin, cookie_header, WebSocketStandardResponse("")); 152 CreateAndConnect(url, origin, first_party_for_cookies, cookie_header,
153 WebSocketStandardResponse(""));
150 WaitUntilConnectDone(); 154 WaitUntilConnectDone();
151 EXPECT_FALSE(has_failed()); 155 EXPECT_FALSE(has_failed());
152 } 156 }
153 157
154 TEST_P(WebSocketStreamServerSetCookieTest, ServerSetCookie) { 158 TEST_P(WebSocketStreamServerSetCookieTest, ServerSetCookie) {
155 // For wss tests. 159 // For wss tests.
156 ssl_data_.push_back(base::WrapUnique(new SSLSocketDataProvider(ASYNC, OK))); 160 ssl_data_.push_back(base::WrapUnique(new SSLSocketDataProvider(ASYNC, OK)));
157 161
158 const GURL url(GetParam().url); 162 const GURL url(GetParam().url);
159 const GURL cookie_url(GetParam().cookie_url); 163 const GURL cookie_url(GetParam().cookie_url);
160 const url::Origin origin(GURL("http://www.example.com")); 164 const url::Origin origin(GURL("http://www.example.com"));
165 const GURL first_party_for_cookies("http://www.example.com/");
161 const std::string cookie_line(GetParam().cookie_line); 166 const std::string cookie_line(GetParam().cookie_line);
162 const std::string cookie_header(AddCRLFIfNotEmpty(GetParam().cookie_header)); 167 const std::string cookie_header(AddCRLFIfNotEmpty(GetParam().cookie_header));
163 168
164 const std::string response = base::StringPrintf( 169 const std::string response = base::StringPrintf(
165 "HTTP/1.1 101 Switching Protocols\r\n" 170 "HTTP/1.1 101 Switching Protocols\r\n"
166 "Upgrade: websocket\r\n" 171 "Upgrade: websocket\r\n"
167 "Connection: Upgrade\r\n" 172 "Connection: Upgrade\r\n"
168 "%s" 173 "%s"
169 "Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r\n" 174 "Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r\n"
170 "\r\n", 175 "\r\n",
171 cookie_header.c_str()); 176 cookie_header.c_str());
172 177
173 CookieStore* store = 178 CookieStore* store =
174 url_request_context_host_.GetURLRequestContext()->cookie_store(); 179 url_request_context_host_.GetURLRequestContext()->cookie_store();
175 180
176 CreateAndConnect(url, origin, "", response); 181 CreateAndConnect(url, origin, first_party_for_cookies, "", response);
177 WaitUntilConnectDone(); 182 WaitUntilConnectDone();
178 EXPECT_FALSE(has_failed()); 183 EXPECT_FALSE(has_failed());
179 184
180 bool is_called = false; 185 bool is_called = false;
181 std::string get_cookies_result; 186 std::string get_cookies_result;
182 base::WeakPtrFactory<bool> weak_is_called(&is_called); 187 base::WeakPtrFactory<bool> weak_is_called(&is_called);
183 base::WeakPtrFactory<std::string> weak_get_cookies_result( 188 base::WeakPtrFactory<std::string> weak_get_cookies_result(
184 &get_cookies_result); 189 &get_cookies_result);
185 base::RunLoop run_loop; 190 base::RunLoop run_loop;
186 store->GetCookiesWithOptionsAsync( 191 store->GetCookiesWithOptionsAsync(
(...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after
498 "", 503 "",
499 "Set-Cookie: test-cookie"}, 504 "Set-Cookie: test-cookie"},
500 }; 505 };
501 506
502 INSTANTIATE_TEST_CASE_P(WebSocketStreamServerSetCookieTest, 507 INSTANTIATE_TEST_CASE_P(WebSocketStreamServerSetCookieTest,
503 WebSocketStreamServerSetCookieTest, 508 WebSocketStreamServerSetCookieTest,
504 ValuesIn(kServerSetCookieParameters)); 509 ValuesIn(kServerSetCookieParameters));
505 510
506 } // namespace 511 } // namespace
507 } // namespace net 512 } // namespace net
OLDNEW
« no previous file with comments | « net/websockets/websocket_stream.cc ('k') | net/websockets/websocket_stream_create_test_base.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698