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

Side by Side Diff: net/url_request/url_request_unittest.cc

Issue 2587243002: Do not do Expect-Staple when OCSPVerifyResult has not been populated (Closed)
Patch Set: sleevi comments; revert to not sending reports on cert errors 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/http/transport_security_state.cc ('k') | no next file » | 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 <memory> 5 #include <memory>
6 #include <utility> 6 #include <utility>
7 7
8 #include "base/memory/ptr_util.h" 8 #include "base/memory/ptr_util.h"
9 #include "base/run_loop.h" 9 #include "base/run_loop.h"
10 #include "build/build_config.h" 10 #include "build/build_config.h"
(...skipping 9601 matching lines...) Expand 10 before | Expand all | Expand 10 after
9612 context.CreateRequest(url, DEFAULT_PRIORITY, &d)); 9612 context.CreateRequest(url, DEFAULT_PRIORITY, &d));
9613 violating_request->Start(); 9613 violating_request->Start();
9614 base::RunLoop().Run(); 9614 base::RunLoop().Run();
9615 9615
9616 // Confirm a report was sent. 9616 // Confirm a report was sent.
9617 EXPECT_FALSE(mock_report_sender.latest_report().empty()); 9617 EXPECT_FALSE(mock_report_sender.latest_report().empty());
9618 EXPECT_EQ(GURL(kExpectStapleReportURI), 9618 EXPECT_EQ(GURL(kExpectStapleReportURI),
9619 mock_report_sender.latest_report_uri()); 9619 mock_report_sender.latest_report_uri());
9620 } 9620 }
9621 9621
9622 // Tests that Expect-Staple reports are not sent for connections on which there
estark 2016/12/21 17:53:12 Just in case this is confusing: In PS #1, this wa
9623 // is a certificate error.
9624 TEST_F(HTTPSOCSPTest, ExpectStapleReportNotSentOnMissingWithCertError) {
9625 EmbeddedTestServer https_test_server(net::EmbeddedTestServer::TYPE_HTTPS);
9626 https_test_server.SetSSLConfig(
9627 net::EmbeddedTestServer::CERT_COMMON_NAME_IS_DOMAIN);
9628 https_test_server.ServeFilesFromSourceDirectory(
9629 base::FilePath(kTestFilePath));
9630 ASSERT_TRUE(https_test_server.Start());
9631
9632 // Set up a MockCertVerifier to report an error for the certificate
9633 // and indicate that there was no stapled OCSP response.
9634 scoped_refptr<X509Certificate> cert = https_test_server.GetCertificate();
9635 ASSERT_TRUE(cert);
9636 MockCertVerifier cert_verifier;
9637 CertVerifyResult verify_result;
9638 verify_result.cert_status = CERT_STATUS_DATE_INVALID;
9639 verify_result.verified_cert = cert;
9640 verify_result.is_issued_by_known_root = true;
9641 verify_result.ocsp_result.response_status = OCSPVerifyResult::MISSING;
9642 cert_verifier.AddResultForCert(cert.get(), verify_result,
9643 ERR_CERT_DATE_INVALID);
9644
9645 // Set up a mock report sender so that the test can check that an
9646 // Expect-Staple report is not sent.
9647 TransportSecurityState transport_security_state;
9648 MockCertificateReportSender mock_report_sender;
9649 transport_security_state.SetReportSender(&mock_report_sender);
9650
9651 TestNetworkDelegate network_delegate;
9652 TestURLRequestContext context(true);
9653
9654 // Force |kExpectStapleStaticHostname| to resolve to |https_test_server|.
9655 MockHostResolver host_resolver;
9656 context.set_host_resolver(&host_resolver);
9657
9658 context.set_transport_security_state(&transport_security_state);
9659 context.set_network_delegate(&network_delegate);
9660 context.set_cert_verifier(&cert_verifier);
9661 context.Init();
9662
9663 // Make a connection to |kExpectStapleStaticHostname|. Because the
9664 // |verify_result| used with the |cert_verifier| will indicate a certificate
9665 // error, an Expect-Staple report should not be sent.
9666 TestDelegate d;
9667 GURL url = https_test_server.GetURL("/");
9668 GURL::Replacements replace_host;
9669 replace_host.SetHostStr(kExpectStapleStaticHostname);
9670 url = url.ReplaceComponents(replace_host);
9671 std::unique_ptr<URLRequest> violating_request(
9672 context.CreateRequest(url, DEFAULT_PRIORITY, &d));
9673 violating_request->Start();
9674 base::RunLoop().Run();
9675
9676 // Confirm a report was not sent.
9677 EXPECT_TRUE(mock_report_sender.latest_report().empty());
9678 EXPECT_EQ(GURL(), mock_report_sender.latest_report_uri());
9679 }
9680
9622 TEST_F(HTTPSOCSPTest, ExpectStapleReportNotSentOnValid) { 9681 TEST_F(HTTPSOCSPTest, ExpectStapleReportNotSentOnValid) {
9623 EmbeddedTestServer https_test_server(net::EmbeddedTestServer::TYPE_HTTPS); 9682 EmbeddedTestServer https_test_server(net::EmbeddedTestServer::TYPE_HTTPS);
9624 https_test_server.SetSSLConfig( 9683 https_test_server.SetSSLConfig(
9625 net::EmbeddedTestServer::CERT_COMMON_NAME_IS_DOMAIN); 9684 net::EmbeddedTestServer::CERT_COMMON_NAME_IS_DOMAIN);
9626 https_test_server.ServeFilesFromSourceDirectory( 9685 https_test_server.ServeFilesFromSourceDirectory(
9627 base::FilePath(kTestFilePath)); 9686 base::FilePath(kTestFilePath));
9628 ASSERT_TRUE(https_test_server.Start()); 9687 ASSERT_TRUE(https_test_server.Start());
9629 9688
9630 // Set up a MockCertVerifier to accept the certificate that the server sends, 9689 // Set up a MockCertVerifier to accept the certificate that the server sends,
9631 // and provide GOOD revocation status. 9690 // and provide GOOD revocation status.
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
9664 std::unique_ptr<URLRequest> ok_request( 9723 std::unique_ptr<URLRequest> ok_request(
9665 context.CreateRequest(url, DEFAULT_PRIORITY, &d)); 9724 context.CreateRequest(url, DEFAULT_PRIORITY, &d));
9666 ok_request->Start(); 9725 ok_request->Start();
9667 base::RunLoop().Run(); 9726 base::RunLoop().Run();
9668 9727
9669 // Check that no report was sent. 9728 // Check that no report was sent.
9670 EXPECT_TRUE(mock_report_sender.latest_report().empty()); 9729 EXPECT_TRUE(mock_report_sender.latest_report().empty());
9671 EXPECT_EQ(GURL(), mock_report_sender.latest_report_uri()); 9730 EXPECT_EQ(GURL(), mock_report_sender.latest_report_uri());
9672 } 9731 }
9673 9732
9733 // Tests that an Expect-Staple report is not sent when OCSP details are not
9734 // checked on the connection.
9735 TEST_F(HTTPSOCSPTest, ExpectStapleReportNotSentOnNotChecked) {
9736 EmbeddedTestServer https_test_server(net::EmbeddedTestServer::TYPE_HTTPS);
9737 https_test_server.SetSSLConfig(
9738 net::EmbeddedTestServer::CERT_COMMON_NAME_IS_DOMAIN);
9739 https_test_server.ServeFilesFromSourceDirectory(
9740 base::FilePath(kTestFilePath));
9741 ASSERT_TRUE(https_test_server.Start());
9742
9743 // Set up a MockCertVerifier to accept the certificate that the server sends,
9744 // and set |ocsp_result| to indicate that OCSP stapling details were not
9745 // checked on the connection.
9746 scoped_refptr<X509Certificate> cert = https_test_server.GetCertificate();
9747 ASSERT_TRUE(cert);
9748 MockCertVerifier cert_verifier;
9749 CertVerifyResult verify_result;
9750 verify_result.verified_cert = cert;
9751 verify_result.is_issued_by_known_root = true;
9752 verify_result.ocsp_result.response_status = OCSPVerifyResult::NOT_CHECKED;
9753 cert_verifier.AddResultForCert(cert.get(), verify_result, OK);
9754
9755 // Set up a mock report sender so that the test can check that an
9756 // Expect-Staple report is not sent.
9757 TransportSecurityState transport_security_state;
9758 MockCertificateReportSender mock_report_sender;
9759 transport_security_state.SetReportSender(&mock_report_sender);
9760
9761 TestNetworkDelegate network_delegate;
9762 TestURLRequestContext context(true);
9763
9764 // Force |kExpectStapleStaticHostname| to resolve to |https_test_server|.
9765 MockHostResolver host_resolver;
9766 context.set_host_resolver(&host_resolver);
9767
9768 context.set_transport_security_state(&transport_security_state);
9769 context.set_network_delegate(&network_delegate);
9770 context.set_cert_verifier(&cert_verifier);
9771 context.Init();
9772
9773 // Make a connection to |kExpectStapleStaticHostname|. Because the
9774 // |verify_result| used with the |cert_verifier| will indicate that OCSP
9775 // stapling details were not checked on the connection, an Expect-Staple
9776 // report should not be sent.
9777 TestDelegate d;
9778 GURL url = https_test_server.GetURL("/");
9779 GURL::Replacements replace_host;
9780 replace_host.SetHostStr(kExpectStapleStaticHostname);
9781 url = url.ReplaceComponents(replace_host);
9782 std::unique_ptr<URLRequest> ok_request(
9783 context.CreateRequest(url, DEFAULT_PRIORITY, &d));
9784 ok_request->Start();
9785 base::RunLoop().Run();
9786
9787 // Check that no report was sent.
9788 EXPECT_TRUE(mock_report_sender.latest_report().empty());
9789 EXPECT_EQ(GURL(), mock_report_sender.latest_report_uri());
9790 }
9791
9674 static const struct OCSPVerifyTestData { 9792 static const struct OCSPVerifyTestData {
9675 std::vector<SpawnedTestServer::SSLOptions::OCSPSingleResponse> ocsp_responses; 9793 std::vector<SpawnedTestServer::SSLOptions::OCSPSingleResponse> ocsp_responses;
9676 SpawnedTestServer::SSLOptions::OCSPProduced ocsp_produced; 9794 SpawnedTestServer::SSLOptions::OCSPProduced ocsp_produced;
9677 OCSPVerifyResult::ResponseStatus response_status; 9795 OCSPVerifyResult::ResponseStatus response_status;
9678 bool has_revocation_status; 9796 bool has_revocation_status;
9679 OCSPRevocationStatus cert_status; 9797 OCSPRevocationStatus cert_status;
9680 } kOCSPVerifyData[] = { 9798 } kOCSPVerifyData[] = {
9681 9799
9682 {{{SpawnedTestServer::SSLOptions::OCSP_OK, 9800 {{{SpawnedTestServer::SSLOptions::OCSP_OK,
9683 SpawnedTestServer::SSLOptions::OCSP_DATE_VALID}}, 9801 SpawnedTestServer::SSLOptions::OCSP_DATE_VALID}},
(...skipping 950 matching lines...) Expand 10 before | Expand all | Expand 10 after
10634 AddTestInterceptor()->set_main_intercept_job(std::move(job)); 10752 AddTestInterceptor()->set_main_intercept_job(std::move(job));
10635 10753
10636 req->Start(); 10754 req->Start();
10637 req->Cancel(); 10755 req->Cancel();
10638 base::RunLoop().RunUntilIdle(); 10756 base::RunLoop().RunUntilIdle();
10639 EXPECT_EQ(ERR_ABORTED, d.request_status()); 10757 EXPECT_EQ(ERR_ABORTED, d.request_status());
10640 EXPECT_EQ(0, d.received_redirect_count()); 10758 EXPECT_EQ(0, d.received_redirect_count());
10641 } 10759 }
10642 10760
10643 } // namespace net 10761 } // namespace net
OLDNEW
« no previous file with comments | « net/http/transport_security_state.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698