| OLD | NEW |
| 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 5915 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5926 https_test_server.GetURL("/hsts-headers.html"), DEFAULT_PRIORITY, &d)); | 5926 https_test_server.GetURL("/hsts-headers.html"), DEFAULT_PRIORITY, &d)); |
| 5927 request->Start(); | 5927 request->Start(); |
| 5928 base::RunLoop().Run(); | 5928 base::RunLoop().Run(); |
| 5929 TransportSecurityState* security_state = | 5929 TransportSecurityState* security_state = |
| 5930 default_context_.transport_security_state(); | 5930 default_context_.transport_security_state(); |
| 5931 TransportSecurityState::STSState sts_state; | 5931 TransportSecurityState::STSState sts_state; |
| 5932 EXPECT_FALSE( | 5932 EXPECT_FALSE( |
| 5933 security_state->GetDynamicSTSState(test_server_hostname, &sts_state)); | 5933 security_state->GetDynamicSTSState(test_server_hostname, &sts_state)); |
| 5934 } | 5934 } |
| 5935 | 5935 |
| 5936 // Android's CertVerifyProc does not (yet) handle pins. Therefore, it will | |
| 5937 // reject HPKP headers, and a test setting only HPKP headers will fail (no | |
| 5938 // PKPState present because header rejected). | |
| 5939 #if defined(OS_ANDROID) | |
| 5940 #define MAYBE_ProcessPKP DISABLED_ProcessPKP | |
| 5941 #define MAYBE_ProcessPKPAndSendReport DISABLED_ProcessPKPAndSendReport | |
| 5942 #define MAYBE_ProcessPKPReportOnly DISABLED_ProcessPKPReportOnly | |
| 5943 #define MAYBE_ProcessPKPReportOnlyWithNoViolation \ | |
| 5944 DISABLED_ProcessPKPReportOnlyWithNoViolation | |
| 5945 #else | |
| 5946 #define MAYBE_ProcessPKP ProcessPKP | |
| 5947 #define MAYBE_ProcessPKPAndSendReport ProcessPKPAndSendReport | |
| 5948 #define MAYBE_ProcessPKPReportOnly ProcessPKPReportOnly | |
| 5949 #define MAYBE_ProcessPKPReportOnlyWithNoViolation \ | |
| 5950 ProcessPKPReportOnlyWithNoViolation | |
| 5951 #endif | |
| 5952 | |
| 5953 namespace { | 5936 namespace { |
| 5954 const char kExpectCTStaticHostname[] = "preloaded-expect-ct.badssl.com"; | 5937 const char kExpectCTStaticHostname[] = "preloaded-expect-ct.badssl.com"; |
| 5955 const char kHPKPReportUri[] = "https://hpkp-report.test"; | 5938 const char kHPKPReportUri[] = "https://hpkp-report.test"; |
| 5956 } // namespace | 5939 } // namespace |
| 5957 | 5940 |
| 5958 // Tests that enabling HPKP on a domain does not affect the HSTS | 5941 // Tests that enabling HPKP on a domain does not affect the HSTS |
| 5959 // validity/expiration. | 5942 // validity/expiration. |
| 5960 TEST_F(URLRequestTestHTTP, MAYBE_ProcessPKP) { | 5943 TEST_F(URLRequestTestHTTP, ProcessPKP) { |
| 5961 GURL report_uri(kHPKPReportUri); | 5944 GURL report_uri(kHPKPReportUri); |
| 5962 EmbeddedTestServer https_test_server(net::EmbeddedTestServer::TYPE_HTTPS); | 5945 EmbeddedTestServer https_test_server(net::EmbeddedTestServer::TYPE_HTTPS); |
| 5963 https_test_server.SetSSLConfig( | 5946 https_test_server.SetSSLConfig( |
| 5964 net::EmbeddedTestServer::CERT_COMMON_NAME_IS_DOMAIN); | 5947 net::EmbeddedTestServer::CERT_COMMON_NAME_IS_DOMAIN); |
| 5965 https_test_server.ServeFilesFromSourceDirectory( | 5948 https_test_server.ServeFilesFromSourceDirectory( |
| 5966 base::FilePath(kTestFilePath)); | 5949 base::FilePath(kTestFilePath)); |
| 5967 ASSERT_TRUE(https_test_server.Start()); | 5950 ASSERT_TRUE(https_test_server.Start()); |
| 5968 | 5951 |
| 5969 std::string test_server_hostname = https_test_server.GetURL("/").host(); | 5952 std::string test_server_hostname = https_test_server.GetURL("/").host(); |
| 5970 | 5953 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 5984 EXPECT_EQ(TransportSecurityState::STSState::MODE_DEFAULT, | 5967 EXPECT_EQ(TransportSecurityState::STSState::MODE_DEFAULT, |
| 5985 sts_state.upgrade_mode); | 5968 sts_state.upgrade_mode); |
| 5986 EXPECT_FALSE(sts_state.include_subdomains); | 5969 EXPECT_FALSE(sts_state.include_subdomains); |
| 5987 EXPECT_FALSE(pkp_state.include_subdomains); | 5970 EXPECT_FALSE(pkp_state.include_subdomains); |
| 5988 EXPECT_TRUE(pkp_state.HasPublicKeyPins()); | 5971 EXPECT_TRUE(pkp_state.HasPublicKeyPins()); |
| 5989 EXPECT_EQ(report_uri, pkp_state.report_uri); | 5972 EXPECT_EQ(report_uri, pkp_state.report_uri); |
| 5990 EXPECT_NE(sts_state.expiry, pkp_state.expiry); | 5973 EXPECT_NE(sts_state.expiry, pkp_state.expiry); |
| 5991 } | 5974 } |
| 5992 | 5975 |
| 5993 // Tests that reports get sent on HPKP violations when a report-uri is set. | 5976 // Tests that reports get sent on HPKP violations when a report-uri is set. |
| 5994 TEST_F(URLRequestTestHTTP, MAYBE_ProcessPKPAndSendReport) { | 5977 TEST_F(URLRequestTestHTTP, ProcessPKPAndSendReport) { |
| 5995 GURL report_uri(kHPKPReportUri); | 5978 GURL report_uri(kHPKPReportUri); |
| 5996 EmbeddedTestServer https_test_server(net::EmbeddedTestServer::TYPE_HTTPS); | 5979 EmbeddedTestServer https_test_server(net::EmbeddedTestServer::TYPE_HTTPS); |
| 5997 https_test_server.SetSSLConfig( | 5980 https_test_server.SetSSLConfig( |
| 5998 net::EmbeddedTestServer::CERT_COMMON_NAME_IS_DOMAIN); | 5981 net::EmbeddedTestServer::CERT_COMMON_NAME_IS_DOMAIN); |
| 5999 https_test_server.ServeFilesFromSourceDirectory( | 5982 https_test_server.ServeFilesFromSourceDirectory( |
| 6000 base::FilePath(kTestFilePath)); | 5983 base::FilePath(kTestFilePath)); |
| 6001 ASSERT_TRUE(https_test_server.Start()); | 5984 ASSERT_TRUE(https_test_server.Start()); |
| 6002 | 5985 |
| 6003 std::string test_server_hostname = https_test_server.GetURL("/").host(); | 5986 std::string test_server_hostname = https_test_server.GetURL("/").host(); |
| 6004 | 5987 |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6062 ASSERT_TRUE(value->IsType(base::Value::TYPE_DICTIONARY)); | 6045 ASSERT_TRUE(value->IsType(base::Value::TYPE_DICTIONARY)); |
| 6063 base::DictionaryValue* report_dict; | 6046 base::DictionaryValue* report_dict; |
| 6064 ASSERT_TRUE(value->GetAsDictionary(&report_dict)); | 6047 ASSERT_TRUE(value->GetAsDictionary(&report_dict)); |
| 6065 std::string report_hostname; | 6048 std::string report_hostname; |
| 6066 EXPECT_TRUE(report_dict->GetString("hostname", &report_hostname)); | 6049 EXPECT_TRUE(report_dict->GetString("hostname", &report_hostname)); |
| 6067 EXPECT_EQ(test_server_hostname, report_hostname); | 6050 EXPECT_EQ(test_server_hostname, report_hostname); |
| 6068 } | 6051 } |
| 6069 | 6052 |
| 6070 // Tests that reports get sent on requests with | 6053 // Tests that reports get sent on requests with |
| 6071 // Public-Key-Pins-Report-Only headers. | 6054 // Public-Key-Pins-Report-Only headers. |
| 6072 TEST_F(URLRequestTestHTTP, MAYBE_ProcessPKPReportOnly) { | 6055 TEST_F(URLRequestTestHTTP, ProcessPKPReportOnly) { |
| 6073 GURL report_uri(kHPKPReportUri); | 6056 GURL report_uri(kHPKPReportUri); |
| 6074 EmbeddedTestServer https_test_server(net::EmbeddedTestServer::TYPE_HTTPS); | 6057 EmbeddedTestServer https_test_server(net::EmbeddedTestServer::TYPE_HTTPS); |
| 6075 https_test_server.SetSSLConfig( | 6058 https_test_server.SetSSLConfig( |
| 6076 net::EmbeddedTestServer::CERT_COMMON_NAME_IS_DOMAIN); | 6059 net::EmbeddedTestServer::CERT_COMMON_NAME_IS_DOMAIN); |
| 6077 https_test_server.ServeFilesFromSourceDirectory( | 6060 https_test_server.ServeFilesFromSourceDirectory( |
| 6078 base::FilePath(kTestFilePath)); | 6061 base::FilePath(kTestFilePath)); |
| 6079 ASSERT_TRUE(https_test_server.Start()); | 6062 ASSERT_TRUE(https_test_server.Start()); |
| 6080 | 6063 |
| 6081 std::string test_server_hostname = https_test_server.GetURL("/").host(); | 6064 std::string test_server_hostname = https_test_server.GetURL("/").host(); |
| 6082 | 6065 |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6125 ASSERT_TRUE(value->IsType(base::Value::TYPE_DICTIONARY)); | 6108 ASSERT_TRUE(value->IsType(base::Value::TYPE_DICTIONARY)); |
| 6126 base::DictionaryValue* report_dict; | 6109 base::DictionaryValue* report_dict; |
| 6127 ASSERT_TRUE(value->GetAsDictionary(&report_dict)); | 6110 ASSERT_TRUE(value->GetAsDictionary(&report_dict)); |
| 6128 std::string report_hostname; | 6111 std::string report_hostname; |
| 6129 EXPECT_TRUE(report_dict->GetString("hostname", &report_hostname)); | 6112 EXPECT_TRUE(report_dict->GetString("hostname", &report_hostname)); |
| 6130 EXPECT_EQ(test_server_hostname, report_hostname); | 6113 EXPECT_EQ(test_server_hostname, report_hostname); |
| 6131 } | 6114 } |
| 6132 | 6115 |
| 6133 // Tests that reports do not get sent on requests with | 6116 // Tests that reports do not get sent on requests with |
| 6134 // Public-Key-Pins-Report-Only headers that don't have pin violations. | 6117 // Public-Key-Pins-Report-Only headers that don't have pin violations. |
| 6135 TEST_F(URLRequestTestHTTP, MAYBE_ProcessPKPReportOnlyWithNoViolation) { | 6118 TEST_F(URLRequestTestHTTP, ProcessPKPReportOnlyWithNoViolation) { |
| 6136 GURL report_uri(kHPKPReportUri); | 6119 GURL report_uri(kHPKPReportUri); |
| 6137 EmbeddedTestServer https_test_server(net::EmbeddedTestServer::TYPE_HTTPS); | 6120 EmbeddedTestServer https_test_server(net::EmbeddedTestServer::TYPE_HTTPS); |
| 6138 https_test_server.SetSSLConfig( | 6121 https_test_server.SetSSLConfig( |
| 6139 net::EmbeddedTestServer::CERT_COMMON_NAME_IS_DOMAIN); | 6122 net::EmbeddedTestServer::CERT_COMMON_NAME_IS_DOMAIN); |
| 6140 https_test_server.ServeFilesFromSourceDirectory( | 6123 https_test_server.ServeFilesFromSourceDirectory( |
| 6141 base::FilePath(kTestFilePath)); | 6124 base::FilePath(kTestFilePath)); |
| 6142 ASSERT_TRUE(https_test_server.Start()); | 6125 ASSERT_TRUE(https_test_server.Start()); |
| 6143 | 6126 |
| 6144 std::string test_server_hostname = https_test_server.GetURL("/").host(); | 6127 std::string test_server_hostname = https_test_server.GetURL("/").host(); |
| 6145 | 6128 |
| (...skipping 3711 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 9857 AddTestInterceptor()->set_main_intercept_job(std::move(job)); | 9840 AddTestInterceptor()->set_main_intercept_job(std::move(job)); |
| 9858 | 9841 |
| 9859 req->Start(); | 9842 req->Start(); |
| 9860 req->Cancel(); | 9843 req->Cancel(); |
| 9861 base::RunLoop().RunUntilIdle(); | 9844 base::RunLoop().RunUntilIdle(); |
| 9862 EXPECT_EQ(URLRequestStatus::CANCELED, req->status().status()); | 9845 EXPECT_EQ(URLRequestStatus::CANCELED, req->status().status()); |
| 9863 EXPECT_EQ(0, d.received_redirect_count()); | 9846 EXPECT_EQ(0, d.received_redirect_count()); |
| 9864 } | 9847 } |
| 9865 | 9848 |
| 9866 } // namespace net | 9849 } // namespace net |
| OLD | NEW |