Commit 6612adc3 authored by Adam Rice's avatar Adam Rice Committed by Commit Bot

Ship WebSocket auth connection reuse

This will permit Windows authentication to work with WebSockets. See
Intent to Ship thread:
https://groups.google.com/a/chromium.org/d/msg/blink-dev/kEtUcy7W0fU/dTyvzUy0BgAJ

Turn on the WebSocketHandshakeReuseConnection feature by default.

Test coverage for the old behaviour has been removed; since the flag
itself will be removed in the next version, this seems acceptable.

BUG=423609

Change-Id: I1373b7b4adcfe695f56a174a7fed2a3bd67ad56b
Reviewed-on: https://chromium-review.googlesource.com/c/1283349Reviewed-by: default avatarYutaka Hirano <yhirano@chromium.org>
Commit-Queue: Adam Rice <ricea@chromium.org>
Cr-Commit-Position: refs/heads/master@{#600045}
parent 2419220c
...@@ -161,7 +161,7 @@ bool ValidateConnection(const HttpResponseHeaders* headers, ...@@ -161,7 +161,7 @@ bool ValidateConnection(const HttpResponseHeaders* headers,
const base::Feature const base::Feature
WebSocketBasicHandshakeStream::kWebSocketHandshakeReuseConnection{ WebSocketBasicHandshakeStream::kWebSocketHandshakeReuseConnection{
"WebSocketHandshakeReuseConnection", base::FEATURE_DISABLED_BY_DEFAULT}; "WebSocketHandshakeReuseConnection", base::FEATURE_ENABLED_BY_DEFAULT};
WebSocketBasicHandshakeStream::WebSocketBasicHandshakeStream( WebSocketBasicHandshakeStream::WebSocketBasicHandshakeStream(
std::unique_ptr<ClientSocketHandle> connection, std::unique_ptr<ClientSocketHandle> connection,
......
...@@ -426,28 +426,24 @@ INSTANTIATE_TEST_CASE_P(, ...@@ -426,28 +426,24 @@ INSTANTIATE_TEST_CASE_P(,
// send the authenticated request on. // send the authenticated request on.
class CommonAuthTestHelper { class CommonAuthTestHelper {
public: public:
CommonAuthTestHelper() : reads1_(), writes1_(), reads2_(), writes2_() {} CommonAuthTestHelper() : reads_(), writes_() {}
std::unique_ptr<SequencedSocketData> BuildSocketData1( std::unique_ptr<SequencedSocketData> BuildAuthSocketData(
const std::string& response) { std::string response1,
std::string request2,
std::string response2) {
request1_ = request1_ =
WebSocketStandardRequest("/", "www.example.org", Origin(), "", ""); WebSocketStandardRequest("/", "www.example.org", Origin(), "", "");
writes1_[0] = MockWrite(SYNCHRONOUS, 0, request1_.c_str()); response1_ = std::move(response1);
response1_ = response; request2_ = std::move(request2);
reads1_[0] = MockRead(SYNCHRONOUS, 1, response1_.c_str()); response2_ = std::move(response2);
reads1_[1] = MockRead(SYNCHRONOUS, OK, 2); // Close connection writes_[0] = MockWrite(SYNCHRONOUS, 0, request1_.c_str());
reads_[0] = MockRead(SYNCHRONOUS, 1, response1_.c_str());
return BuildSocketData(reads1_, writes1_); writes_[1] = MockWrite(SYNCHRONOUS, 2, request2_.c_str());
} reads_[1] = MockRead(SYNCHRONOUS, 3, response2_.c_str());
reads_[2] = MockRead(SYNCHRONOUS, OK, 4); // Close connection
std::unique_ptr<SequencedSocketData> BuildSocketData2(
const std::string& request, return BuildSocketData(reads_, writes_);
const std::string& response) {
request2_ = request;
response2_ = response;
writes2_[0] = MockWrite(SYNCHRONOUS, 0, request2_.c_str());
reads2_[0] = MockRead(SYNCHRONOUS, 1, response2_.c_str());
return BuildSocketData(reads2_, writes2_);
} }
private: private:
...@@ -457,10 +453,8 @@ class CommonAuthTestHelper { ...@@ -457,10 +453,8 @@ class CommonAuthTestHelper {
std::string request2_; std::string request2_;
std::string response1_; std::string response1_;
std::string response2_; std::string response2_;
MockRead reads1_[2]; MockRead reads_[3];
MockWrite writes1_[1]; MockWrite writes_[2];
MockRead reads2_[1];
MockWrite writes2_[1];
DISALLOW_COPY_AND_ASSIGN(CommonAuthTestHelper); DISALLOW_COPY_AND_ASSIGN(CommonAuthTestHelper);
}; };
...@@ -471,12 +465,11 @@ class WebSocketStreamCreateBasicAuthTest : public WebSocketStreamCreateTest { ...@@ -471,12 +465,11 @@ class WebSocketStreamCreateBasicAuthTest : public WebSocketStreamCreateTest {
void CreateAndConnectAuthHandshake(base::StringPiece url, void CreateAndConnectAuthHandshake(base::StringPiece url,
base::StringPiece base64_user_pass, base::StringPiece base64_user_pass,
base::StringPiece response2) { base::StringPiece response2) {
AddRawExpectations(helper_.BuildSocketData1(kUnauthorizedResponse));
CreateAndConnectRawExpectations( CreateAndConnectRawExpectations(
url, NoSubProtocols(), HttpRequestHeaders(), url, NoSubProtocols(), HttpRequestHeaders(),
helper_.BuildSocketData2(RequestExpectation(base64_user_pass), helper_.BuildAuthSocketData(kUnauthorizedResponse,
response2.as_string())); RequestExpectation(base64_user_pass),
response2.as_string()));
} }
static std::string RequestExpectation(base::StringPiece base64_user_pass) { static std::string RequestExpectation(base::StringPiece base64_user_pass) {
...@@ -1479,10 +1472,6 @@ TEST_P(WebSocketStreamCreateBasicAuthTest, FailureIncorrectPasswordInUrl) { ...@@ -1479,10 +1472,6 @@ TEST_P(WebSocketStreamCreateBasicAuthTest, FailureIncorrectPasswordInUrl) {
} }
TEST_P(WebSocketStreamCreateBasicAuthTest, SuccessfulConnectionReuse) { TEST_P(WebSocketStreamCreateBasicAuthTest, SuccessfulConnectionReuse) {
base::test::ScopedFeatureList scoped_feature_list;
scoped_feature_list.InitAndEnableFeature(
WebSocketBasicHandshakeStream ::kWebSocketHandshakeReuseConnection);
std::string request1 = std::string request1 =
WebSocketStandardRequest("/", "www.example.org", Origin(), "", ""); WebSocketStandardRequest("/", "www.example.org", Origin(), "", "");
std::string response1 = kUnauthorizedResponse; std::string response1 = kUnauthorizedResponse;
...@@ -1528,8 +1517,11 @@ TEST_P(WebSocketStreamCreateBasicAuthTest, OnAuthRequiredCancelAuth) { ...@@ -1528,8 +1517,11 @@ TEST_P(WebSocketStreamCreateBasicAuthTest, OnAuthRequiredCancelAuth) {
} }
TEST_P(WebSocketStreamCreateBasicAuthTest, OnAuthRequiredSetAuth) { TEST_P(WebSocketStreamCreateBasicAuthTest, OnAuthRequiredSetAuth) {
CreateAndConnectCustomResponse("ws://www.example.org/", NoSubProtocols(), {}, CreateAndConnectRawExpectations(
{}, kUnauthorizedResponse); "ws://www.example.org/", NoSubProtocols(), HttpRequestHeaders(),
helper_.BuildAuthSocketData(kUnauthorizedResponse,
RequestExpectation("Zm9vOmJheg=="),
WebSocketStandardResponse(std::string())));
EXPECT_FALSE(request_info_); EXPECT_FALSE(request_info_);
EXPECT_FALSE(response_info_); EXPECT_FALSE(response_info_);
...@@ -1543,12 +1535,6 @@ TEST_P(WebSocketStreamCreateBasicAuthTest, OnAuthRequiredSetAuth) { ...@@ -1543,12 +1535,6 @@ TEST_P(WebSocketStreamCreateBasicAuthTest, OnAuthRequiredSetAuth) {
base::ASCIIToUTF16("baz")); base::ASCIIToUTF16("baz"));
std::move(on_auth_required_callback_).Run(&credentials); std::move(on_auth_required_callback_).Run(&credentials);
// As we are re-establishing the connection with additional credentials,
// add new expectations.
AddRawExpectations(
helper_.BuildSocketData2(RequestExpectation("Zm9vOmJheg=="),
WebSocketStandardResponse(std::string())));
WaitUntilConnectDone(); WaitUntilConnectDone();
EXPECT_TRUE(stream_); EXPECT_TRUE(stream_);
EXPECT_FALSE(has_failed()); EXPECT_FALSE(has_failed());
...@@ -1558,13 +1544,11 @@ TEST_P(WebSocketStreamCreateBasicAuthTest, OnAuthRequiredSetAuth) { ...@@ -1558,13 +1544,11 @@ TEST_P(WebSocketStreamCreateBasicAuthTest, OnAuthRequiredSetAuth) {
// generally assume that whatever works for Basic auth will also work for // generally assume that whatever works for Basic auth will also work for
// Digest. There's just one test here, to confirm that it works at all. // Digest. There's just one test here, to confirm that it works at all.
TEST_P(WebSocketStreamCreateDigestAuthTest, DigestPasswordInUrl) { TEST_P(WebSocketStreamCreateDigestAuthTest, DigestPasswordInUrl) {
AddRawExpectations(helper_.BuildSocketData1(kUnauthorizedResponse));
CreateAndConnectRawExpectations( CreateAndConnectRawExpectations(
"ws://FooBar:pass@www.example.org/", NoSubProtocols(), "ws://FooBar:pass@www.example.org/", NoSubProtocols(),
HttpRequestHeaders(), HttpRequestHeaders(),
helper_.BuildSocketData2(kAuthorizedRequest, helper_.BuildAuthSocketData(kUnauthorizedResponse, kAuthorizedRequest,
WebSocketStandardResponse(std::string()))); WebSocketStandardResponse(std::string())));
WaitUntilConnectDone(); WaitUntilConnectDone();
EXPECT_FALSE(has_failed()); EXPECT_FALSE(has_failed());
EXPECT_TRUE(stream_); EXPECT_TRUE(stream_);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment