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,
const base::Feature
WebSocketBasicHandshakeStream::kWebSocketHandshakeReuseConnection{
"WebSocketHandshakeReuseConnection", base::FEATURE_DISABLED_BY_DEFAULT};
"WebSocketHandshakeReuseConnection", base::FEATURE_ENABLED_BY_DEFAULT};
WebSocketBasicHandshakeStream::WebSocketBasicHandshakeStream(
std::unique_ptr<ClientSocketHandle> connection,
......
......@@ -426,28 +426,24 @@ INSTANTIATE_TEST_CASE_P(,
// send the authenticated request on.
class CommonAuthTestHelper {
public:
CommonAuthTestHelper() : reads1_(), writes1_(), reads2_(), writes2_() {}
CommonAuthTestHelper() : reads_(), writes_() {}
std::unique_ptr<SequencedSocketData> BuildSocketData1(
const std::string& response) {
std::unique_ptr<SequencedSocketData> BuildAuthSocketData(
std::string response1,
std::string request2,
std::string response2) {
request1_ =
WebSocketStandardRequest("/", "www.example.org", Origin(), "", "");
writes1_[0] = MockWrite(SYNCHRONOUS, 0, request1_.c_str());
response1_ = response;
reads1_[0] = MockRead(SYNCHRONOUS, 1, response1_.c_str());
reads1_[1] = MockRead(SYNCHRONOUS, OK, 2); // Close connection
return BuildSocketData(reads1_, writes1_);
}
std::unique_ptr<SequencedSocketData> BuildSocketData2(
const std::string& request,
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_);
response1_ = std::move(response1);
request2_ = std::move(request2);
response2_ = std::move(response2);
writes_[0] = MockWrite(SYNCHRONOUS, 0, request1_.c_str());
reads_[0] = MockRead(SYNCHRONOUS, 1, response1_.c_str());
writes_[1] = MockWrite(SYNCHRONOUS, 2, request2_.c_str());
reads_[1] = MockRead(SYNCHRONOUS, 3, response2_.c_str());
reads_[2] = MockRead(SYNCHRONOUS, OK, 4); // Close connection
return BuildSocketData(reads_, writes_);
}
private:
......@@ -457,10 +453,8 @@ class CommonAuthTestHelper {
std::string request2_;
std::string response1_;
std::string response2_;
MockRead reads1_[2];
MockWrite writes1_[1];
MockRead reads2_[1];
MockWrite writes2_[1];
MockRead reads_[3];
MockWrite writes_[2];
DISALLOW_COPY_AND_ASSIGN(CommonAuthTestHelper);
};
......@@ -471,12 +465,11 @@ class WebSocketStreamCreateBasicAuthTest : public WebSocketStreamCreateTest {
void CreateAndConnectAuthHandshake(base::StringPiece url,
base::StringPiece base64_user_pass,
base::StringPiece response2) {
AddRawExpectations(helper_.BuildSocketData1(kUnauthorizedResponse));
CreateAndConnectRawExpectations(
url, NoSubProtocols(), HttpRequestHeaders(),
helper_.BuildSocketData2(RequestExpectation(base64_user_pass),
response2.as_string()));
helper_.BuildAuthSocketData(kUnauthorizedResponse,
RequestExpectation(base64_user_pass),
response2.as_string()));
}
static std::string RequestExpectation(base::StringPiece base64_user_pass) {
......@@ -1479,10 +1472,6 @@ TEST_P(WebSocketStreamCreateBasicAuthTest, FailureIncorrectPasswordInUrl) {
}
TEST_P(WebSocketStreamCreateBasicAuthTest, SuccessfulConnectionReuse) {
base::test::ScopedFeatureList scoped_feature_list;
scoped_feature_list.InitAndEnableFeature(
WebSocketBasicHandshakeStream ::kWebSocketHandshakeReuseConnection);
std::string request1 =
WebSocketStandardRequest("/", "www.example.org", Origin(), "", "");
std::string response1 = kUnauthorizedResponse;
......@@ -1528,8 +1517,11 @@ TEST_P(WebSocketStreamCreateBasicAuthTest, OnAuthRequiredCancelAuth) {
}
TEST_P(WebSocketStreamCreateBasicAuthTest, OnAuthRequiredSetAuth) {
CreateAndConnectCustomResponse("ws://www.example.org/", NoSubProtocols(), {},
{}, kUnauthorizedResponse);
CreateAndConnectRawExpectations(
"ws://www.example.org/", NoSubProtocols(), HttpRequestHeaders(),
helper_.BuildAuthSocketData(kUnauthorizedResponse,
RequestExpectation("Zm9vOmJheg=="),
WebSocketStandardResponse(std::string())));
EXPECT_FALSE(request_info_);
EXPECT_FALSE(response_info_);
......@@ -1543,12 +1535,6 @@ TEST_P(WebSocketStreamCreateBasicAuthTest, OnAuthRequiredSetAuth) {
base::ASCIIToUTF16("baz"));
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();
EXPECT_TRUE(stream_);
EXPECT_FALSE(has_failed());
......@@ -1558,13 +1544,11 @@ TEST_P(WebSocketStreamCreateBasicAuthTest, OnAuthRequiredSetAuth) {
// 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.
TEST_P(WebSocketStreamCreateDigestAuthTest, DigestPasswordInUrl) {
AddRawExpectations(helper_.BuildSocketData1(kUnauthorizedResponse));
CreateAndConnectRawExpectations(
"ws://FooBar:pass@www.example.org/", NoSubProtocols(),
HttpRequestHeaders(),
helper_.BuildSocketData2(kAuthorizedRequest,
WebSocketStandardResponse(std::string())));
helper_.BuildAuthSocketData(kUnauthorizedResponse, kAuthorizedRequest,
WebSocketStandardResponse(std::string())));
WaitUntilConnectDone();
EXPECT_FALSE(has_failed());
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