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

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

Issue 19269012: Don't persist HPKP if PrivacyMode is enabled. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Changed ChromeResourceDispatcherHostDelegate::OnResponseStarted to use URLRequest::GetHSTSRedirect. Created 7 years, 4 months 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 | Annotate | Revision Log
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 "build/build_config.h" 5 #include "build/build_config.h"
6 6
7 #if defined(OS_WIN) 7 #if defined(OS_WIN)
8 #include <windows.h> 8 #include <windows.h>
9 #include <shlobj.h> 9 #include <shlobj.h>
10 #endif 10 #endif
(...skipping 2010 matching lines...) Expand 10 before | Expand all | Expand 10 after
2021 TestDelegate d; 2021 TestDelegate d;
2022 network_delegate.set_cookie_options(TestNetworkDelegate::NO_GET_COOKIES); 2022 network_delegate.set_cookie_options(TestNetworkDelegate::NO_GET_COOKIES);
2023 URLRequest req( 2023 URLRequest req(
2024 test_server.GetURL("echoheader?Cookie"), &d, &default_context_); 2024 test_server.GetURL("echoheader?Cookie"), &d, &default_context_);
2025 req.Start(); 2025 req.Start();
2026 base::MessageLoop::current()->Run(); 2026 base::MessageLoop::current()->Run();
2027 2027
2028 EXPECT_TRUE(d.data_received().find("Cookie: CookieToNotSend=1") 2028 EXPECT_TRUE(d.data_received().find("Cookie: CookieToNotSend=1")
2029 == std::string::npos); 2029 == std::string::npos);
2030 2030
2031 EXPECT_EQ(1, network_delegate.blocked_get_cookies_count()); 2031 EXPECT_EQ(2, network_delegate.blocked_get_cookies_count());
2032 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); 2032 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count());
2033 } 2033 }
2034 } 2034 }
2035 2035
2036 TEST_F(URLRequestTest, DoNotSaveCookies_ViaPolicy) { 2036 TEST_F(URLRequestTest, DoNotSaveCookies_ViaPolicy) {
2037 LocalHttpTestServer test_server; 2037 LocalHttpTestServer test_server;
2038 ASSERT_TRUE(test_server.Start()); 2038 ASSERT_TRUE(test_server.Start());
2039 2039
2040 // Set up a cookie. 2040 // Set up a cookie.
2041 { 2041 {
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
2152 TestDelegate d; 2152 TestDelegate d;
2153 network_delegate.set_cookie_options(TestNetworkDelegate::NO_GET_COOKIES); 2153 network_delegate.set_cookie_options(TestNetworkDelegate::NO_GET_COOKIES);
2154 URLRequest req( 2154 URLRequest req(
2155 test_server.GetURL("echoheader?Cookie"), &d, &default_context_); 2155 test_server.GetURL("echoheader?Cookie"), &d, &default_context_);
2156 req.Start(); 2156 req.Start();
2157 base::MessageLoop::current()->Run(); 2157 base::MessageLoop::current()->Run();
2158 2158
2159 EXPECT_TRUE(d.data_received().find("Cookie: CookieToNotSend=1") 2159 EXPECT_TRUE(d.data_received().find("Cookie: CookieToNotSend=1")
2160 == std::string::npos); 2160 == std::string::npos);
2161 2161
2162 EXPECT_EQ(1, network_delegate.blocked_get_cookies_count()); 2162 EXPECT_EQ(2, network_delegate.blocked_get_cookies_count());
2163 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); 2163 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count());
2164 } 2164 }
2165 } 2165 }
2166 2166
2167 TEST_F(URLRequestTest, DoNotSaveCookies_ViaPolicy_Async) { 2167 TEST_F(URLRequestTest, DoNotSaveCookies_ViaPolicy_Async) {
2168 LocalHttpTestServer test_server; 2168 LocalHttpTestServer test_server;
2169 ASSERT_TRUE(test_server.Start()); 2169 ASSERT_TRUE(test_server.Start());
2170 2170
2171 // Set up a cookie. 2171 // Set up a cookie.
2172 { 2172 {
(...skipping 1747 matching lines...) Expand 10 before | Expand all | Expand 10 after
3920 &d, 3920 &d,
3921 &default_context_); 3921 &default_context_);
3922 request.Start(); 3922 request.Start();
3923 base::MessageLoop::current()->Run(); 3923 base::MessageLoop::current()->Run();
3924 3924
3925 TransportSecurityState* security_state = 3925 TransportSecurityState* security_state =
3926 default_context_.transport_security_state(); 3926 default_context_.transport_security_state();
3927 bool sni_available = true; 3927 bool sni_available = true;
3928 TransportSecurityState::DomainState domain_state; 3928 TransportSecurityState::DomainState domain_state;
3929 EXPECT_TRUE(security_state->GetDomainState( 3929 EXPECT_TRUE(security_state->GetDomainState(
3930 SpawnedTestServer::kLocalhost, sni_available, &domain_state)); 3930 SpawnedTestServer::kLocalhost, sni_available, true, &domain_state));
3931 EXPECT_EQ(TransportSecurityState::DomainState::MODE_FORCE_HTTPS, 3931 EXPECT_EQ(TransportSecurityState::DomainState::MODE_FORCE_HTTPS,
3932 domain_state.upgrade_mode); 3932 domain_state.upgrade_mode);
3933 EXPECT_TRUE(domain_state.sts_include_subdomains); 3933 EXPECT_TRUE(domain_state.sts_include_subdomains);
3934 EXPECT_FALSE(domain_state.pkp_include_subdomains);
3935 #if defined(OS_ANDROID) 3934 #if defined(OS_ANDROID)
3936 // Android's CertVerifyProc does not (yet) handle pins. 3935 // Android's CertVerifyProc does not (yet) handle pins.
3937 #else 3936 #else
3938 EXPECT_FALSE(domain_state.HasPublicKeyPins()); 3937 EXPECT_FALSE(domain_state.HasPublicKeyPins());
3939 #endif 3938 #endif
3940 } 3939 }
3941 3940
3942 // Android's CertVerifyProc does not (yet) handle pins. Therefore, it will 3941 // Android's CertVerifyProc does not (yet) handle pins. Therefore, it will
3943 // reject HPKP headers, and a test setting only HPKP headers will fail (no 3942 // reject HPKP headers, and a test setting only HPKP headers will fail (no
3944 // DomainState present because header rejected). 3943 // DomainState present because header rejected).
(...skipping 19 matching lines...) Expand all
3964 &d, 3963 &d,
3965 &default_context_); 3964 &default_context_);
3966 request.Start(); 3965 request.Start();
3967 base::MessageLoop::current()->Run(); 3966 base::MessageLoop::current()->Run();
3968 3967
3969 TransportSecurityState* security_state = 3968 TransportSecurityState* security_state =
3970 default_context_.transport_security_state(); 3969 default_context_.transport_security_state();
3971 bool sni_available = true; 3970 bool sni_available = true;
3972 TransportSecurityState::DomainState domain_state; 3971 TransportSecurityState::DomainState domain_state;
3973 EXPECT_TRUE(security_state->GetDomainState( 3972 EXPECT_TRUE(security_state->GetDomainState(
3974 SpawnedTestServer::kLocalhost, sni_available, &domain_state)); 3973 SpawnedTestServer::kLocalhost, sni_available, true, &domain_state));
3975 EXPECT_EQ(TransportSecurityState::DomainState::MODE_DEFAULT, 3974 EXPECT_EQ(TransportSecurityState::DomainState::MODE_DEFAULT,
3976 domain_state.upgrade_mode); 3975 domain_state.upgrade_mode);
3977 EXPECT_FALSE(domain_state.sts_include_subdomains); 3976 EXPECT_FALSE(domain_state.sts_include_subdomains);
3978 EXPECT_FALSE(domain_state.pkp_include_subdomains); 3977 EXPECT_FALSE(domain_state.pkp_include_subdomains);
3979 EXPECT_TRUE(domain_state.HasPublicKeyPins()); 3978 EXPECT_TRUE(domain_state.HasPublicKeyPins());
3979
3980 EXPECT_NE(domain_state.upgrade_expiry, 3980 EXPECT_NE(domain_state.upgrade_expiry,
3981 domain_state.dynamic_spki_hashes_expiry); 3981 domain_state.dynamic_spki_hashes_expiry);
3982 } 3982 }
3983 3983
3984 // Android's CertVerifyProc does not (yet) handle pins. Therefore, it will
3985 // reject HPKP headers, and a test setting only HPKP headers will fail (no
3986 // DomainState present because header rejected).
3987 #if defined(OS_ANDROID)
3988 #define MAYBE_ProcessPKP_PrivacyMode DISABLED_ProcessPKP_PrivacyMode
3989 #else
3990 #define MAYBE_ProcessPKP_PrivacyMode ProcessPKP_PrivacyMode
3991 #endif
3992 // Tests that DynamicDomainState is not added if cookies are not set.
3993 TEST_F(URLRequestTestHTTP, ProcessPKP_PrivacyMode) {
3994 SpawnedTestServer::SSLOptions ssl_options;
3995 SpawnedTestServer https_test_server(
3996 SpawnedTestServer::TYPE_HTTPS,
3997 ssl_options,
3998 base::FilePath(FILE_PATH_LITERAL("net/data/url_request_unittest")));
3999 ASSERT_TRUE(https_test_server.Start());
4000
4001 default_network_delegate_.set_cookie_options(
4002 TestNetworkDelegate::NO_SET_COOKIE);
4003 TestDelegate d;
4004 URLRequest request(https_test_server.GetURL("files/hpkp-headers.html"),
4005 &d,
4006 &default_context_);
4007 request.Start();
4008 base::MessageLoop::current()->Run();
4009
4010 TransportSecurityState* security_state =
4011 default_context_.transport_security_state();
4012 bool sni_available = true;
4013 TransportSecurityState::DomainState domain_state;
4014 EXPECT_FALSE(security_state->GetDomainState(
4015 SpawnedTestServer::kLocalhost, sni_available, true, &domain_state));
4016 }
4017
3984 TEST_F(URLRequestTestHTTP, ProcessSTSOnce) { 4018 TEST_F(URLRequestTestHTTP, ProcessSTSOnce) {
3985 SpawnedTestServer::SSLOptions ssl_options; 4019 SpawnedTestServer::SSLOptions ssl_options;
3986 SpawnedTestServer https_test_server( 4020 SpawnedTestServer https_test_server(
3987 SpawnedTestServer::TYPE_HTTPS, 4021 SpawnedTestServer::TYPE_HTTPS,
3988 ssl_options, 4022 ssl_options,
3989 base::FilePath(FILE_PATH_LITERAL("net/data/url_request_unittest"))); 4023 base::FilePath(FILE_PATH_LITERAL("net/data/url_request_unittest")));
3990 ASSERT_TRUE(https_test_server.Start()); 4024 ASSERT_TRUE(https_test_server.Start());
3991 4025
3992 TestDelegate d; 4026 TestDelegate d;
3993 URLRequest request( 4027 URLRequest request(
3994 https_test_server.GetURL("files/hsts-multiple-headers.html"), 4028 https_test_server.GetURL("files/hsts-multiple-headers.html"),
3995 &d, 4029 &d,
3996 &default_context_); 4030 &default_context_);
3997 request.Start(); 4031 request.Start();
3998 base::MessageLoop::current()->Run(); 4032 base::MessageLoop::current()->Run();
3999 4033
4000 // We should have set parameters from the first header, not the second. 4034 // We should have set parameters from the first header, not the second.
4001 TransportSecurityState* security_state = 4035 TransportSecurityState* security_state =
4002 default_context_.transport_security_state(); 4036 default_context_.transport_security_state();
4003 bool sni_available = true; 4037 bool sni_available = true;
4004 TransportSecurityState::DomainState domain_state; 4038 TransportSecurityState::DomainState domain_state;
4005 EXPECT_TRUE(security_state->GetDomainState( 4039 EXPECT_TRUE(security_state->GetDomainState(
4006 SpawnedTestServer::kLocalhost, sni_available, &domain_state)); 4040 SpawnedTestServer::kLocalhost, sni_available, true, &domain_state));
4007 EXPECT_EQ(TransportSecurityState::DomainState::MODE_FORCE_HTTPS, 4041 EXPECT_EQ(TransportSecurityState::DomainState::MODE_FORCE_HTTPS,
4008 domain_state.upgrade_mode); 4042 domain_state.upgrade_mode);
4009 EXPECT_FALSE(domain_state.sts_include_subdomains); 4043 EXPECT_FALSE(domain_state.sts_include_subdomains);
4010 EXPECT_FALSE(domain_state.pkp_include_subdomains); 4044 EXPECT_FALSE(domain_state.pkp_include_subdomains);
4011 } 4045 }
4012 4046
4013 TEST_F(URLRequestTestHTTP, ProcessSTSAndPKP) { 4047 TEST_F(URLRequestTestHTTP, ProcessSTSAndPKP) {
4014 SpawnedTestServer::SSLOptions ssl_options; 4048 SpawnedTestServer::SSLOptions ssl_options;
4015 SpawnedTestServer https_test_server( 4049 SpawnedTestServer https_test_server(
4016 SpawnedTestServer::TYPE_HTTPS, 4050 SpawnedTestServer::TYPE_HTTPS,
4017 ssl_options, 4051 ssl_options,
4018 base::FilePath(FILE_PATH_LITERAL("net/data/url_request_unittest"))); 4052 base::FilePath(FILE_PATH_LITERAL("net/data/url_request_unittest")));
4019 ASSERT_TRUE(https_test_server.Start()); 4053 ASSERT_TRUE(https_test_server.Start());
4020 4054
4021 TestDelegate d; 4055 TestDelegate d;
4022 URLRequest request( 4056 URLRequest request(
4023 https_test_server.GetURL("files/hsts-and-hpkp-headers.html"), 4057 https_test_server.GetURL("files/hsts-and-hpkp-headers.html"),
4024 &d, 4058 &d,
4025 &default_context_); 4059 &default_context_);
4026 request.Start(); 4060 request.Start();
4027 base::MessageLoop::current()->Run(); 4061 base::MessageLoop::current()->Run();
4028 4062
4029 // We should have set parameters from the first header, not the second. 4063 // We should have set parameters from the first header, not the second.
4030 TransportSecurityState* security_state = 4064 TransportSecurityState* security_state =
4031 default_context_.transport_security_state(); 4065 default_context_.transport_security_state();
4032 bool sni_available = true; 4066 bool sni_available = true;
4033 TransportSecurityState::DomainState domain_state; 4067 TransportSecurityState::DomainState domain_state;
4034 EXPECT_TRUE(security_state->GetDomainState( 4068 EXPECT_TRUE(security_state->GetDomainState(
4035 SpawnedTestServer::kLocalhost, sni_available, &domain_state)); 4069 SpawnedTestServer::kLocalhost, sni_available, true, &domain_state));
4036 EXPECT_EQ(TransportSecurityState::DomainState::MODE_FORCE_HTTPS, 4070 EXPECT_EQ(TransportSecurityState::DomainState::MODE_FORCE_HTTPS,
4037 domain_state.upgrade_mode); 4071 domain_state.upgrade_mode);
4038 #if defined(OS_ANDROID) 4072 #if defined(OS_ANDROID)
4039 // Android's CertVerifyProc does not (yet) handle pins. 4073 // Android's CertVerifyProc does not (yet) handle pins.
4040 #else 4074 #else
4041 EXPECT_TRUE(domain_state.HasPublicKeyPins()); 4075 EXPECT_TRUE(domain_state.HasPublicKeyPins());
4042 #endif 4076 #endif
4043 EXPECT_NE(domain_state.upgrade_expiry, 4077 EXPECT_NE(domain_state.upgrade_expiry,
4044 domain_state.dynamic_spki_hashes_expiry); 4078 domain_state.dynamic_spki_hashes_expiry);
4045 4079
(...skipping 20 matching lines...) Expand all
4066 &d, 4100 &d,
4067 &default_context_); 4101 &default_context_);
4068 request.Start(); 4102 request.Start();
4069 base::MessageLoop::current()->Run(); 4103 base::MessageLoop::current()->Run();
4070 4104
4071 TransportSecurityState* security_state = 4105 TransportSecurityState* security_state =
4072 default_context_.transport_security_state(); 4106 default_context_.transport_security_state();
4073 bool sni_available = true; 4107 bool sni_available = true;
4074 TransportSecurityState::DomainState domain_state; 4108 TransportSecurityState::DomainState domain_state;
4075 EXPECT_TRUE(security_state->GetDomainState( 4109 EXPECT_TRUE(security_state->GetDomainState(
4076 SpawnedTestServer::kLocalhost, sni_available, &domain_state)); 4110 SpawnedTestServer::kLocalhost, sni_available, true, &domain_state));
4077 EXPECT_EQ(TransportSecurityState::DomainState::MODE_FORCE_HTTPS, 4111 EXPECT_EQ(TransportSecurityState::DomainState::MODE_FORCE_HTTPS,
4078 domain_state.upgrade_mode); 4112 domain_state.upgrade_mode);
4079 #if defined(OS_ANDROID) 4113 #if defined(OS_ANDROID)
4080 // Android's CertVerifyProc does not (yet) handle pins. 4114 // Android's CertVerifyProc does not (yet) handle pins.
4081 #else 4115 #else
4082 EXPECT_TRUE(domain_state.HasPublicKeyPins()); 4116 EXPECT_TRUE(domain_state.HasPublicKeyPins());
4083 #endif 4117 #endif
4084 EXPECT_NE(domain_state.upgrade_expiry, 4118 EXPECT_NE(domain_state.upgrade_expiry,
4085 domain_state.dynamic_spki_hashes_expiry); 4119 domain_state.dynamic_spki_hashes_expiry);
4086 4120
(...skipping 975 matching lines...) Expand 10 before | Expand all | Expand 10 after
5062 // MockHostResolver in order to direct www.google.com to the testserver. 5096 // MockHostResolver in order to direct www.google.com to the testserver.
5063 // By default, MockHostResolver maps all hosts to 127.0.0.1. 5097 // By default, MockHostResolver maps all hosts to 127.0.0.1.
5064 5098
5065 MockHostResolver host_resolver; 5099 MockHostResolver host_resolver;
5066 TestNetworkDelegate network_delegate; // Must outlive URLRequest. 5100 TestNetworkDelegate network_delegate; // Must outlive URLRequest.
5067 TestURLRequestContext context(true); 5101 TestURLRequestContext context(true);
5068 context.set_network_delegate(&network_delegate); 5102 context.set_network_delegate(&network_delegate);
5069 context.set_host_resolver(&host_resolver); 5103 context.set_host_resolver(&host_resolver);
5070 TransportSecurityState transport_security_state; 5104 TransportSecurityState transport_security_state;
5071 TransportSecurityState::DomainState domain_state; 5105 TransportSecurityState::DomainState domain_state;
5072 EXPECT_TRUE(transport_security_state.GetDomainState("www.google.com", true, 5106 EXPECT_TRUE(transport_security_state.GetDomainState(
5073 &domain_state)); 5107 "www.google.com", true, true, &domain_state));
5074 context.set_transport_security_state(&transport_security_state); 5108 context.set_transport_security_state(&transport_security_state);
5075 context.Init(); 5109 context.Init();
5076 5110
5077 TestDelegate d; 5111 TestDelegate d;
5078 URLRequest r(GURL(base::StringPrintf("https://www.google.com:%d", 5112 URLRequest r(GURL(base::StringPrintf("https://www.google.com:%d",
5079 test_server.host_port_pair().port())), 5113 test_server.host_port_pair().port())),
5080 &d, 5114 &d,
5081 &context); 5115 &context);
5082 5116
5083 r.Start(); 5117 r.Start();
5084 EXPECT_TRUE(r.is_pending()); 5118 EXPECT_TRUE(r.is_pending());
5085 5119
5086 base::MessageLoop::current()->Run(); 5120 base::MessageLoop::current()->Run();
5087 5121
5088 EXPECT_EQ(1, d.response_started_count()); 5122 EXPECT_EQ(1, d.response_started_count());
5089 EXPECT_FALSE(d.received_data_before_response()); 5123 EXPECT_FALSE(d.received_data_before_response());
5090 EXPECT_TRUE(d.have_certificate_errors()); 5124 EXPECT_TRUE(d.have_certificate_errors());
5091 EXPECT_TRUE(d.certificate_errors_are_fatal()); 5125 EXPECT_TRUE(d.certificate_errors_are_fatal());
5092 5126
5093 // Get a fresh copy of the state, and check that it hasn't been updated. 5127 // Get a fresh copy of the state, and check that it hasn't been updated.
5094 TransportSecurityState::DomainState new_domain_state; 5128 TransportSecurityState::DomainState new_domain_state;
5095 EXPECT_TRUE(transport_security_state.GetDomainState("www.google.com", true, 5129 EXPECT_TRUE(transport_security_state.GetDomainState(
5096 &new_domain_state)); 5130 "www.google.com", true, true, &new_domain_state));
5097 EXPECT_EQ(new_domain_state.upgrade_mode, domain_state.upgrade_mode); 5131 EXPECT_EQ(new_domain_state.upgrade_mode, domain_state.upgrade_mode);
5098 EXPECT_EQ(new_domain_state.sts_include_subdomains, 5132 EXPECT_EQ(new_domain_state.sts_include_subdomains,
5099 domain_state.sts_include_subdomains); 5133 domain_state.sts_include_subdomains);
5100 EXPECT_EQ(new_domain_state.pkp_include_subdomains, 5134 EXPECT_EQ(new_domain_state.pkp_include_subdomains,
5101 domain_state.pkp_include_subdomains); 5135 domain_state.pkp_include_subdomains);
5102 EXPECT_TRUE(FingerprintsEqual(new_domain_state.static_spki_hashes, 5136 EXPECT_TRUE(FingerprintsEqual(new_domain_state.static_spki_hashes,
5103 domain_state.static_spki_hashes)); 5137 domain_state.static_spki_hashes));
5104 EXPECT_TRUE(FingerprintsEqual(new_domain_state.dynamic_spki_hashes, 5138 EXPECT_TRUE(FingerprintsEqual(new_domain_state.dynamic_spki_hashes,
5105 domain_state.dynamic_spki_hashes)); 5139 domain_state.dynamic_spki_hashes));
5106 EXPECT_TRUE(FingerprintsEqual(new_domain_state.bad_static_spki_hashes, 5140 EXPECT_TRUE(FingerprintsEqual(new_domain_state.bad_static_spki_hashes,
(...skipping 1005 matching lines...) Expand 10 before | Expand all | Expand 10 after
6112 6146
6113 EXPECT_FALSE(r.is_pending()); 6147 EXPECT_FALSE(r.is_pending());
6114 EXPECT_EQ(1, d->response_started_count()); 6148 EXPECT_EQ(1, d->response_started_count());
6115 EXPECT_FALSE(d->received_data_before_response()); 6149 EXPECT_FALSE(d->received_data_before_response());
6116 EXPECT_EQ(d->bytes_received(), static_cast<int>(file_size)); 6150 EXPECT_EQ(d->bytes_received(), static_cast<int>(file_size));
6117 } 6151 }
6118 } 6152 }
6119 #endif // !defined(DISABLE_FTP_SUPPORT) 6153 #endif // !defined(DISABLE_FTP_SUPPORT)
6120 6154
6121 } // namespace net 6155 } // namespace net
OLDNEW
« net/socket_stream/socket_stream_job.cc ('K') | « net/url_request/url_request_test_util.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698