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

Side by Side Diff: net/spdy/spdy_network_transaction_unittest.cc

Issue 2526003002: Disallow multiple HEADERS frames on pushed streams. (Closed)
Patch Set: Rename enum, enum entry, and member. Created 4 years 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/spdy/spdy_http_stream.cc ('k') | net/spdy/spdy_proxy_client_socket.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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 <cmath> 5 #include <cmath>
6 #include <memory> 6 #include <memory>
7 #include <string> 7 #include <string>
8 #include <utility> 8 #include <utility>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 4560 matching lines...) Expand 10 before | Expand all | Expand 10 after
4571 4571
4572 // Read the final EOF (which will close the session) 4572 // Read the final EOF (which will close the session)
4573 data.Resume(); 4573 data.Resume();
4574 base::RunLoop().RunUntilIdle(); 4574 base::RunLoop().RunUntilIdle();
4575 4575
4576 // Verify that we consumed all test data. 4576 // Verify that we consumed all test data.
4577 EXPECT_TRUE(data.AllReadDataConsumed()); 4577 EXPECT_TRUE(data.AllReadDataConsumed());
4578 EXPECT_TRUE(data.AllWriteDataConsumed()); 4578 EXPECT_TRUE(data.AllWriteDataConsumed());
4579 } 4579 }
4580 4580
4581 // TODO(baranovich): HTTP 2 does not allow multiple HEADERS frames
4582 TEST_F(SpdyNetworkTransactionTest, ServerPushWithTwoHeaderFrames) {
4583 // We push a stream and attempt to claim it before the headers come down.
4584 SpdySerializedFrame stream1_syn(
4585 spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST, true));
4586 MockWrite writes[] = {
4587 CreateMockWrite(stream1_syn, 0, SYNCHRONOUS),
4588 };
4589
4590 SpdySerializedFrame stream1_reply(
4591 spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1));
4592
4593 SpdyHeaderBlock initial_headers;
4594 spdy_util_.AddUrlToHeaderBlock(GetDefaultUrlWithPath("/foo.dat"),
4595 &initial_headers);
4596 SpdySerializedFrame stream2_syn(spdy_util_.ConstructInitialSpdyPushFrame(
4597 std::move(initial_headers), 2, 1));
4598
4599 SpdySerializedFrame stream1_body(spdy_util_.ConstructSpdyDataFrame(1, true));
4600
4601 SpdyHeaderBlock middle_headers;
4602 middle_headers["hello"] = "bye";
4603 SpdySerializedFrame stream2_headers1(spdy_util_.ConstructSpdyResponseHeaders(
4604 2, std::move(middle_headers), false));
4605
4606 SpdyHeaderBlock late_headers;
4607 late_headers[spdy_util_.GetStatusKey()] = "200";
4608 SpdySerializedFrame stream2_headers2(spdy_util_.ConstructSpdyResponseHeaders(
4609 2, std::move(late_headers), false));
4610
4611 const char kPushedData[] = "pushed";
4612 SpdySerializedFrame stream2_body(spdy_util_.ConstructSpdyDataFrame(
4613 2, kPushedData, strlen(kPushedData), true));
4614
4615 MockRead reads[] = {
4616 CreateMockRead(stream1_reply, 1), CreateMockRead(stream2_syn, 2),
4617 CreateMockRead(stream1_body, 3), MockRead(ASYNC, ERR_IO_PENDING, 4),
4618 CreateMockRead(stream2_headers1, 5),
4619 // This is needed to work around https://crbug.com/571102.
4620 MockRead(ASYNC, ERR_IO_PENDING, 6), CreateMockRead(stream2_headers2, 7),
4621 CreateMockRead(stream2_body, 8), MockRead(ASYNC, ERR_IO_PENDING, 9),
4622 MockRead(ASYNC, 0, 10), // EOF
4623 };
4624
4625 HttpResponseInfo response;
4626 HttpResponseInfo response2;
4627 std::string expected_push_result("pushed");
4628 SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes));
4629
4630 NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY,
4631 NetLogWithSource(), NULL);
4632 helper.AddData(&data);
4633 helper.RunPreTestSetup();
4634
4635 HttpNetworkTransaction* trans = helper.trans();
4636
4637 // Start the transaction.
4638 TestCompletionCallback callback;
4639 int rv = trans->Start(&CreateGetRequest(), callback.callback(),
4640 NetLogWithSource());
4641 EXPECT_THAT(rv, IsError(ERR_IO_PENDING));
4642 // Run until we've received the primary HEADERS, the pushed HEADERS,
4643 // the first HEADERS frame, and the body of the primary stream, but before
4644 // we've received the final HEADERS for the pushed stream.
4645 data.RunUntilPaused();
4646 EXPECT_EQ(0, callback.WaitForResult());
4647
4648 // Request the pushed path. At this point, we've received the push, but the
4649 // headers are not yet complete.
4650 HttpNetworkTransaction trans2(DEFAULT_PRIORITY, helper.session());
4651 rv = trans2.Start(&CreateGetPushRequest(), callback.callback(),
4652 NetLogWithSource());
4653 EXPECT_THAT(rv, IsError(ERR_IO_PENDING));
4654 data.Resume();
4655 data.RunUntilPaused();
4656 base::RunLoop().RunUntilIdle();
4657 // This is needed to work around https://crbug.com/571102.
4658 data.Resume();
4659 data.RunUntilPaused();
4660 base::RunLoop().RunUntilIdle();
4661
4662 // Read the server push body.
4663 std::string result2;
4664 ReadResult(&trans2, &result2);
4665 // Read the response body.
4666 std::string result;
4667 ReadResult(trans, &result);
4668
4669 // Verify that the received push data is same as the expected push data.
4670 EXPECT_EQ(expected_push_result, result2);
4671
4672 // Verify the response headers.
4673 // Copy the response info, because trans goes away.
4674 response = *trans->GetResponseInfo();
4675 response2 = *trans2.GetResponseInfo();
4676
4677 VerifyStreamsClosed(helper);
4678
4679 // Verify the response headers.
4680 EXPECT_TRUE(response.headers);
4681 EXPECT_EQ("HTTP/1.1 200", response.headers->GetStatusLine());
4682
4683 // Verify the pushed stream.
4684 EXPECT_TRUE(response2.headers);
4685 EXPECT_EQ("HTTP/1.1 200", response2.headers->GetStatusLine());
4686
4687 // Verify we got all the headers from all header blocks.
4688 EXPECT_TRUE(response2.headers->HasHeaderValue("hello", "bye"));
4689 EXPECT_TRUE(response2.headers->HasHeaderValue("status", "200"));
4690
4691 // Read the final EOF (which will close the session)
4692 data.Resume();
4693 base::RunLoop().RunUntilIdle();
4694
4695 // Verify that we consumed all test data.
4696 EXPECT_TRUE(data.AllReadDataConsumed());
4697 EXPECT_TRUE(data.AllWriteDataConsumed());
4698 }
4699
4700 TEST_F(SpdyNetworkTransactionTest, ServerPushWithNoStatusHeaderFrames) {
4701 // We push a stream and attempt to claim it before the headers come down.
4702 SpdySerializedFrame stream1_syn(
4703 spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST, true));
4704 MockWrite writes[] = {
4705 CreateMockWrite(stream1_syn, 0, SYNCHRONOUS),
4706 };
4707
4708 SpdySerializedFrame stream1_reply(
4709 spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1));
4710
4711 SpdyHeaderBlock initial_headers;
4712 spdy_util_.AddUrlToHeaderBlock(GetDefaultUrlWithPath("/foo.dat"),
4713 &initial_headers);
4714 SpdySerializedFrame stream2_syn(spdy_util_.ConstructInitialSpdyPushFrame(
4715 std::move(initial_headers), 2, 1));
4716
4717 SpdySerializedFrame stream1_body(spdy_util_.ConstructSpdyDataFrame(1, true));
4718
4719 SpdyHeaderBlock middle_headers;
4720 middle_headers["hello"] = "bye";
4721 SpdySerializedFrame stream2_headers1(spdy_util_.ConstructSpdyResponseHeaders(
4722 2, std::move(middle_headers), false));
4723
4724 const char kPushedData[] = "pushed";
4725 SpdySerializedFrame stream2_body(spdy_util_.ConstructSpdyDataFrame(
4726 2, kPushedData, strlen(kPushedData), true));
4727
4728 MockRead reads[] = {
4729 CreateMockRead(stream1_reply, 1), CreateMockRead(stream2_syn, 2),
4730 CreateMockRead(stream1_body, 3), MockRead(ASYNC, ERR_IO_PENDING, 4),
4731 CreateMockRead(stream2_headers1, 5), CreateMockRead(stream2_body, 6),
4732 MockRead(ASYNC, ERR_IO_PENDING, 7), MockRead(ASYNC, 0, 8), // EOF
4733 };
4734
4735 SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes));
4736
4737 NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY,
4738 NetLogWithSource(), NULL);
4739 helper.AddData(&data);
4740 helper.RunPreTestSetup();
4741
4742 HttpNetworkTransaction* trans = helper.trans();
4743
4744 // Start the transaction.
4745 TestCompletionCallback callback;
4746 int rv = trans->Start(&CreateGetRequest(), callback.callback(),
4747 NetLogWithSource());
4748 EXPECT_THAT(rv, IsError(ERR_IO_PENDING));
4749 // Run until we've received the primary HEADERS, the pushed HEADERS,
4750 // the first HEADERS frame, and the body of the primary stream, but before
4751 // we've received the final HEADERS for the pushed stream.
4752 data.RunUntilPaused();
4753 EXPECT_EQ(0, callback.WaitForResult());
4754
4755 // Request the pushed path. At this point, we've received the push, but the
4756 // headers are not yet complete.
4757 HttpNetworkTransaction trans2(DEFAULT_PRIORITY, helper.session());
4758 rv = trans2.Start(&CreateGetPushRequest(), callback.callback(),
4759 NetLogWithSource());
4760 EXPECT_THAT(rv, IsError(ERR_IO_PENDING));
4761 data.Resume();
4762 data.RunUntilPaused();
4763 base::RunLoop().RunUntilIdle();
4764
4765 // Read the server push body.
4766 std::string result2;
4767 ReadResult(&trans2, &result2);
4768 // Read the response body.
4769 std::string result;
4770 ReadResult(trans, &result);
4771 EXPECT_EQ("hello!", result);
4772
4773 // Verify that we haven't received any push data.
4774 EXPECT_EQ("", result2);
4775
4776 // Verify the response headers.
4777 // Copy the response info, because trans goes away.
4778 HttpResponseInfo response = *trans->GetResponseInfo();
4779
4780 VerifyStreamsClosed(helper);
4781
4782 // Verify the response headers.
4783 EXPECT_TRUE(response.headers);
4784 EXPECT_EQ("HTTP/1.1 200", response.headers->GetStatusLine());
4785
4786 // Read the final EOF (which will close the session).
4787 data.Resume();
4788 base::RunLoop().RunUntilIdle();
4789
4790 // Verify that we consumed all test data.
4791 EXPECT_TRUE(data.AllReadDataConsumed());
4792 EXPECT_TRUE(data.AllWriteDataConsumed());
4793 }
4794
4795 TEST_F(SpdyNetworkTransactionTest, ResponseHeadersTwice) { 4581 TEST_F(SpdyNetworkTransactionTest, ResponseHeadersTwice) {
4796 SpdySerializedFrame req( 4582 SpdySerializedFrame req(
4797 spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST, true)); 4583 spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST, true));
4798 SpdySerializedFrame rst( 4584 SpdySerializedFrame rst(
4799 spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_PROTOCOL_ERROR)); 4585 spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_PROTOCOL_ERROR));
4800 MockWrite writes[] = { 4586 MockWrite writes[] = {
4801 CreateMockWrite(req, 0), CreateMockWrite(rst, 4), 4587 CreateMockWrite(req, 0), CreateMockWrite(rst, 4),
4802 }; 4588 };
4803 4589
4804 SpdySerializedFrame stream1_reply( 4590 SpdySerializedFrame stream1_reply(
(...skipping 1604 matching lines...) Expand 10 before | Expand all | Expand 10 after
6409 TEST_F(SpdyNetworkTransactionTLSUsageCheckTest, TLSCipherSuiteSucky) { 6195 TEST_F(SpdyNetworkTransactionTLSUsageCheckTest, TLSCipherSuiteSucky) {
6410 std::unique_ptr<SSLSocketDataProvider> ssl_provider( 6196 std::unique_ptr<SSLSocketDataProvider> ssl_provider(
6411 new SSLSocketDataProvider(ASYNC, OK)); 6197 new SSLSocketDataProvider(ASYNC, OK));
6412 // Set to TLS_RSA_WITH_NULL_MD5 6198 // Set to TLS_RSA_WITH_NULL_MD5
6413 SSLConnectionStatusSetCipherSuite(0x1, &ssl_provider->connection_status); 6199 SSLConnectionStatusSetCipherSuite(0x1, &ssl_provider->connection_status);
6414 6200
6415 RunTLSUsageCheckTest(std::move(ssl_provider)); 6201 RunTLSUsageCheckTest(std::move(ssl_provider));
6416 } 6202 }
6417 6203
6418 } // namespace net 6204 } // namespace net
OLDNEW
« no previous file with comments | « net/spdy/spdy_http_stream.cc ('k') | net/spdy/spdy_proxy_client_socket.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698