| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 "net/tools/quic/quic_spdy_server_stream.h" | 5 #include "net/tools/quic/quic_spdy_server_stream.h" |
| 6 | 6 |
| 7 #include "base/strings/string_number_conversions.h" | 7 #include "base/strings/string_number_conversions.h" |
| 8 #include "base/strings/string_piece.h" | 8 #include "base/strings/string_piece.h" |
| 9 #include "net/quic/quic_connection.h" | 9 #include "net/quic/quic_connection.h" |
| 10 #include "net/quic/quic_protocol.h" | 10 #include "net/quic/quic_protocol.h" |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 110 } | 110 } |
| 111 | 111 |
| 112 ~QuicSpdyServerStreamTest() override { | 112 ~QuicSpdyServerStreamTest() override { |
| 113 QuicInMemoryCachePeer::ResetForTests(); | 113 QuicInMemoryCachePeer::ResetForTests(); |
| 114 } | 114 } |
| 115 | 115 |
| 116 const string& StreamBody() { | 116 const string& StreamBody() { |
| 117 return QuicSpdyServerStreamPeer::body(stream_.get()); | 117 return QuicSpdyServerStreamPeer::body(stream_.get()); |
| 118 } | 118 } |
| 119 | 119 |
| 120 const string& StreamHeadersValue(const string& key) { | 120 StringPiece StreamHeadersValue(const string& key) { |
| 121 return (*stream_->mutable_headers())[key]; | 121 return (*stream_->mutable_headers())[key]; |
| 122 } | 122 } |
| 123 | 123 |
| 124 SpdyHeaderBlock response_headers_; | 124 SpdyHeaderBlock response_headers_; |
| 125 StrictMock<MockConnection>* connection_; | 125 StrictMock<MockConnection>* connection_; |
| 126 StrictMock<MockQuicSpdySession> session_; | 126 StrictMock<MockQuicSpdySession> session_; |
| 127 scoped_ptr<QuicSpdyServerStreamPeer> stream_; | 127 scoped_ptr<QuicSpdyServerStreamPeer> stream_; |
| 128 string headers_string_; | 128 string headers_string_; |
| 129 string body_; | 129 string body_; |
| 130 }; | 130 }; |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 220 EXPECT_CALL(session_, WritevData(_, _, _, _, _, _)).Times(1). | 220 EXPECT_CALL(session_, WritevData(_, _, _, _, _, _)).Times(1). |
| 221 WillOnce(Return(QuicConsumedData(3, true))); | 221 WillOnce(Return(QuicConsumedData(3, true))); |
| 222 | 222 |
| 223 QuicSpdyServerStreamPeer::SendErrorResponse(stream_.get()); | 223 QuicSpdyServerStreamPeer::SendErrorResponse(stream_.get()); |
| 224 EXPECT_TRUE(stream_->read_side_closed()); | 224 EXPECT_TRUE(stream_->read_side_closed()); |
| 225 EXPECT_TRUE(stream_->write_side_closed()); | 225 EXPECT_TRUE(stream_->write_side_closed()); |
| 226 } | 226 } |
| 227 | 227 |
| 228 TEST_P(QuicSpdyServerStreamTest, InvalidMultipleContentLength) { | 228 TEST_P(QuicSpdyServerStreamTest, InvalidMultipleContentLength) { |
| 229 SpdyHeaderBlock request_headers; | 229 SpdyHeaderBlock request_headers; |
| 230 request_headers["content-length"] = "11"; | 230 // \000 is a way to write the null byte when followed by a literal digit. |
| 231 request_headers["content-length"].push_back('\0'); | 231 request_headers["content-length"] = StringPiece("11\00012", 5); |
| 232 request_headers["content-length"].append("12"); | |
| 233 | 232 |
| 234 headers_string_ = | 233 headers_string_ = |
| 235 SpdyUtils::SerializeUncompressedHeaders(request_headers, GetParam()); | 234 SpdyUtils::SerializeUncompressedHeaders(request_headers, GetParam()); |
| 236 | 235 |
| 237 EXPECT_CALL(session_, WritevData(_, _, _, _, _, _)) | 236 EXPECT_CALL(session_, WritevData(_, _, _, _, _, _)) |
| 238 .Times(AnyNumber()) | 237 .Times(AnyNumber()) |
| 239 .WillRepeatedly(Invoke(ConsumeAllData)); | 238 .WillRepeatedly(Invoke(ConsumeAllData)); |
| 240 | 239 |
| 241 stream_->OnStreamHeaders(headers_string_); | 240 stream_->OnStreamHeaders(headers_string_); |
| 242 stream_->OnStreamHeadersComplete(false, headers_string_.size()); | 241 stream_->OnStreamHeadersComplete(false, headers_string_.size()); |
| 243 | 242 |
| 244 EXPECT_TRUE(stream_->read_side_closed()); | 243 EXPECT_TRUE(stream_->read_side_closed()); |
| 245 EXPECT_TRUE(stream_->write_side_closed()); | 244 EXPECT_TRUE(stream_->write_side_closed()); |
| 246 } | 245 } |
| 247 | 246 |
| 248 TEST_P(QuicSpdyServerStreamTest, InvalidLeadingNullContentLength) { | 247 TEST_P(QuicSpdyServerStreamTest, InvalidLeadingNullContentLength) { |
| 249 SpdyHeaderBlock request_headers; | 248 SpdyHeaderBlock request_headers; |
| 250 request_headers["content-length"] = '\0'; | 249 // \000 is a way to write the null byte when followed by a literal digit. |
| 251 request_headers["content-length"].append("12"); | 250 request_headers["content-length"] = StringPiece("\00012", 3); |
| 252 | 251 |
| 253 headers_string_ = | 252 headers_string_ = |
| 254 SpdyUtils::SerializeUncompressedHeaders(request_headers, GetParam()); | 253 SpdyUtils::SerializeUncompressedHeaders(request_headers, GetParam()); |
| 255 | 254 |
| 256 EXPECT_CALL(session_, WritevData(_, _, _, _, _, _)) | 255 EXPECT_CALL(session_, WritevData(_, _, _, _, _, _)) |
| 257 .Times(AnyNumber()) | 256 .Times(AnyNumber()) |
| 258 .WillRepeatedly(Invoke(ConsumeAllData)); | 257 .WillRepeatedly(Invoke(ConsumeAllData)); |
| 259 | 258 |
| 260 stream_->OnStreamHeaders(headers_string_); | 259 stream_->OnStreamHeaders(headers_string_); |
| 261 stream_->OnStreamHeadersComplete(false, headers_string_.size()); | 260 stream_->OnStreamHeadersComplete(false, headers_string_.size()); |
| 262 | 261 |
| 263 EXPECT_TRUE(stream_->read_side_closed()); | 262 EXPECT_TRUE(stream_->read_side_closed()); |
| 264 EXPECT_TRUE(stream_->write_side_closed()); | 263 EXPECT_TRUE(stream_->write_side_closed()); |
| 265 } | 264 } |
| 266 | 265 |
| 267 TEST_P(QuicSpdyServerStreamTest, ValidMultipleContentLength) { | 266 TEST_P(QuicSpdyServerStreamTest, ValidMultipleContentLength) { |
| 268 SpdyHeaderBlock request_headers; | 267 SpdyHeaderBlock request_headers; |
| 269 request_headers["content-length"] = "11"; | 268 // \000 is a way to write the null byte when followed by a literal digit. |
| 270 request_headers["content-length"].push_back('\0'); | 269 request_headers["content-length"] = StringPiece("11\00011", 5); |
| 271 request_headers["content-length"].append("11"); | |
| 272 | 270 |
| 273 headers_string_ = | 271 headers_string_ = |
| 274 SpdyUtils::SerializeUncompressedHeaders(request_headers, GetParam()); | 272 SpdyUtils::SerializeUncompressedHeaders(request_headers, GetParam()); |
| 275 | 273 |
| 276 stream_->OnStreamHeaders(headers_string_); | 274 stream_->OnStreamHeaders(headers_string_); |
| 277 stream_->OnStreamHeadersComplete(false, headers_string_.size()); | 275 stream_->OnStreamHeadersComplete(false, headers_string_.size()); |
| 278 | 276 |
| 279 EXPECT_EQ(11, QuicSpdyServerStreamPeer::content_length(stream_.get())); | 277 EXPECT_EQ(11, QuicSpdyServerStreamPeer::content_length(stream_.get())); |
| 280 EXPECT_FALSE(stream_->read_side_closed()); | 278 EXPECT_FALSE(stream_->read_side_closed()); |
| 281 EXPECT_FALSE(stream_->write_side_closed()); | 279 EXPECT_FALSE(stream_->write_side_closed()); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 308 StringPiece data(arr, arraysize(arr)); | 306 StringPiece data(arr, arraysize(arr)); |
| 309 QuicStreamFrame frame(stream_->id(), true, 0, data); | 307 QuicStreamFrame frame(stream_->id(), true, 0, data); |
| 310 // Verify that we don't crash when we get a invalid headers in stream frame. | 308 // Verify that we don't crash when we get a invalid headers in stream frame. |
| 311 stream_->OnStreamFrame(frame); | 309 stream_->OnStreamFrame(frame); |
| 312 } | 310 } |
| 313 | 311 |
| 314 } // namespace | 312 } // namespace |
| 315 } // namespace test | 313 } // namespace test |
| 316 } // namespace tools | 314 } // namespace tools |
| 317 } // namespace net | 315 } // namespace net |
| OLD | NEW |