summaryrefslogtreecommitdiffstats
path: root/net/spdy/spdy_proxy_client_socket_unittest.cc
diff options
context:
space:
mode:
Diffstat (limited to 'net/spdy/spdy_proxy_client_socket_unittest.cc')
-rw-r--r--net/spdy/spdy_proxy_client_socket_unittest.cc74
1 files changed, 72 insertions, 2 deletions
diff --git a/net/spdy/spdy_proxy_client_socket_unittest.cc b/net/spdy/spdy_proxy_client_socket_unittest.cc
index 323b6db..89aba7e 100644
--- a/net/spdy/spdy_proxy_client_socket_unittest.cc
+++ b/net/spdy/spdy_proxy_client_socket_unittest.cc
@@ -66,6 +66,7 @@ class SpdyProxyClientSocketTest : public PlatformTest {
spdy::SpdyFrame* ConstructConnectAuthRequestFrame();
spdy::SpdyFrame* ConstructConnectReplyFrame();
spdy::SpdyFrame* ConstructConnectAuthReplyFrame();
+ spdy::SpdyFrame* ConstructNtlmAuthReplyFrame();
spdy::SpdyFrame* ConstructConnectErrorReplyFrame();
spdy::SpdyFrame* ConstructBodyFrame(const char* data, int length);
scoped_refptr<IOBufferWithSize> CreateBuffer(const char* data, int size);
@@ -387,6 +388,26 @@ spdy::SpdyFrame* SpdyProxyClientSocketTest::ConstructConnectAuthReplyFrame() {
arraysize(kStandardReplyHeaders));
}
+// Constructs a SPDY SYN_REPLY frame to match the SPDY CONNECT which
+// requires Proxy Authentication using NTLM.
+spdy::SpdyFrame* SpdyProxyClientSocketTest::ConstructNtlmAuthReplyFrame() {
+ const char* const kStandardReplyHeaders[] = {
+ "status", "407 Proxy Authentication Required",
+ "version", "HTTP/1.1",
+ "proxy-authenticate", "NTLM",
+ };
+
+ return ConstructSpdyControlFrame(NULL,
+ 0,
+ false,
+ kStreamId,
+ LOWEST,
+ spdy::SYN_REPLY,
+ spdy::CONTROL_FLAG_NONE,
+ kStandardReplyHeaders,
+ arraysize(kStandardReplyHeaders));
+}
+
// Constructs a SPDY SYN_REPLY frame with an HTTP 500 error.
spdy::SpdyFrame* SpdyProxyClientSocketTest::ConstructConnectErrorReplyFrame() {
const char* const kStandardReplyHeaders[] = {
@@ -433,6 +454,23 @@ TEST_F(SpdyProxyClientSocketTest, ConnectSendsCorrectRequest) {
AssertConnectionEstablished();
}
+TEST_F(SpdyProxyClientSocketTest, ConnectWithUnsupportedAuth) {
+ scoped_ptr<spdy::SpdyFrame> conn(ConstructConnectRequestFrame());
+ MockWrite writes[] = {
+ CreateMockWrite(*conn, 0, false),
+ };
+
+ scoped_ptr<spdy::SpdyFrame> resp(ConstructNtlmAuthReplyFrame());
+ MockRead reads[] = {
+ CreateMockRead(*resp, 1, true),
+ MockRead(true, 0, 3), // EOF
+ };
+
+ Initialize(reads, arraysize(reads), writes, arraysize(writes));
+
+ AssertConnectFails(ERR_TUNNEL_CONNECTION_FAILED);
+}
+
TEST_F(SpdyProxyClientSocketTest, ConnectWithAuthRequested) {
scoped_ptr<spdy::SpdyFrame> conn(ConstructConnectRequestFrame());
MockWrite writes[] = {
@@ -447,7 +485,7 @@ TEST_F(SpdyProxyClientSocketTest, ConnectWithAuthRequested) {
Initialize(reads, arraysize(reads), writes, arraysize(writes));
- AssertConnectFails(ERR_TUNNEL_CONNECTION_FAILED);
+ AssertConnectFails(ERR_PROXY_AUTH_REQUESTED);
const HttpResponseInfo* response = sock_->GetConnectResponseInfo();
ASSERT_TRUE(response != NULL);
@@ -476,6 +514,38 @@ TEST_F(SpdyProxyClientSocketTest, ConnectWithAuthCredentials) {
AssertConnectionEstablished();
}
+TEST_F(SpdyProxyClientSocketTest, ConnectWithAuthRestart) {
+ scoped_ptr<spdy::SpdyFrame> conn(ConstructConnectRequestFrame());
+ scoped_ptr<spdy::SpdyFrame> auth(ConstructConnectAuthRequestFrame());
+ MockWrite writes[] = {
+ CreateMockWrite(*conn, 0, false),
+ };
+
+ scoped_ptr<spdy::SpdyFrame> resp(ConstructConnectAuthReplyFrame());
+ scoped_ptr<spdy::SpdyFrame> auth_resp(ConstructConnectReplyFrame());
+ MockRead reads[] = {
+ CreateMockRead(*resp, 1, true),
+ MockRead(true, 0, 3), // EOF
+ };
+
+ Initialize(reads, arraysize(reads), writes, arraysize(writes));
+
+ AssertConnectFails(ERR_PROXY_AUTH_REQUESTED);
+
+ const HttpResponseInfo* response = sock_->GetConnectResponseInfo();
+ ASSERT_TRUE(response != NULL);
+ ASSERT_EQ(407, response->headers->response_code());
+ ASSERT_EQ("Proxy Authentication Required",
+ response->headers->GetStatusText());
+
+ AddAuthToCache();
+
+ ASSERT_EQ(OK, sock_->RestartWithAuth(&read_callback_));
+ // A SpdyProxyClientSocket sits on a single SPDY stream which can
+ // only be used for a single request/response.
+ ASSERT_FALSE(sock_->IsConnectedAndIdle());
+}
+
TEST_F(SpdyProxyClientSocketTest, ConnectFails) {
scoped_ptr<spdy::SpdyFrame> conn(ConstructConnectRequestFrame());
MockWrite writes[] = {
@@ -821,7 +891,7 @@ TEST_F(SpdyProxyClientSocketTest, ReadAuthResponseBody) {
Initialize(reads, arraysize(reads), writes, arraysize(writes));
- AssertConnectFails(ERR_TUNNEL_CONNECTION_FAILED);
+ AssertConnectFails(ERR_PROXY_AUTH_REQUESTED);
Run(2); // SpdySession consumes the next two reads and sends then to
// sock_ to be buffered.