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

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: Disable URLRequestTestHTTP.ProcessPKP_PrivacyMode in chrome_frame_net_tests. Created 7 years, 3 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 2013 matching lines...) Expand 10 before | Expand all | Expand 10 after
2024 TestDelegate d; 2024 TestDelegate d;
2025 network_delegate.set_cookie_options(TestNetworkDelegate::NO_GET_COOKIES); 2025 network_delegate.set_cookie_options(TestNetworkDelegate::NO_GET_COOKIES);
2026 URLRequest req( 2026 URLRequest req(
2027 test_server.GetURL("echoheader?Cookie"), &d, &default_context_); 2027 test_server.GetURL("echoheader?Cookie"), &d, &default_context_);
2028 req.Start(); 2028 req.Start();
2029 base::RunLoop().Run(); 2029 base::RunLoop().Run();
2030 2030
2031 EXPECT_TRUE(d.data_received().find("Cookie: CookieToNotSend=1") 2031 EXPECT_TRUE(d.data_received().find("Cookie: CookieToNotSend=1")
2032 == std::string::npos); 2032 == std::string::npos);
2033 2033
2034 EXPECT_EQ(1, network_delegate.blocked_get_cookies_count()); 2034 EXPECT_EQ(2, network_delegate.blocked_get_cookies_count());
2035 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); 2035 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count());
2036 } 2036 }
2037 } 2037 }
2038 2038
2039 TEST_F(URLRequestTest, DoNotSaveCookies_ViaPolicy) { 2039 TEST_F(URLRequestTest, DoNotSaveCookies_ViaPolicy) {
2040 LocalHttpTestServer test_server; 2040 LocalHttpTestServer test_server;
2041 ASSERT_TRUE(test_server.Start()); 2041 ASSERT_TRUE(test_server.Start());
2042 2042
2043 // Set up a cookie. 2043 // Set up a cookie.
2044 { 2044 {
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
2155 TestDelegate d; 2155 TestDelegate d;
2156 network_delegate.set_cookie_options(TestNetworkDelegate::NO_GET_COOKIES); 2156 network_delegate.set_cookie_options(TestNetworkDelegate::NO_GET_COOKIES);
2157 URLRequest req( 2157 URLRequest req(
2158 test_server.GetURL("echoheader?Cookie"), &d, &default_context_); 2158 test_server.GetURL("echoheader?Cookie"), &d, &default_context_);
2159 req.Start(); 2159 req.Start();
2160 base::RunLoop().Run(); 2160 base::RunLoop().Run();
2161 2161
2162 EXPECT_TRUE(d.data_received().find("Cookie: CookieToNotSend=1") 2162 EXPECT_TRUE(d.data_received().find("Cookie: CookieToNotSend=1")
2163 == std::string::npos); 2163 == std::string::npos);
2164 2164
2165 EXPECT_EQ(1, network_delegate.blocked_get_cookies_count()); 2165 EXPECT_EQ(2, network_delegate.blocked_get_cookies_count());
2166 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); 2166 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count());
2167 } 2167 }
2168 } 2168 }
2169 2169
2170 TEST_F(URLRequestTest, DoNotSaveCookies_ViaPolicy_Async) { 2170 TEST_F(URLRequestTest, DoNotSaveCookies_ViaPolicy_Async) {
2171 LocalHttpTestServer test_server; 2171 LocalHttpTestServer test_server;
2172 ASSERT_TRUE(test_server.Start()); 2172 ASSERT_TRUE(test_server.Start());
2173 2173
2174 // Set up a cookie. 2174 // Set up a cookie.
2175 { 2175 {
(...skipping 1747 matching lines...) Expand 10 before | Expand all | Expand 10 after
3923 &d, 3923 &d,
3924 &default_context_); 3924 &default_context_);
3925 request.Start(); 3925 request.Start();
3926 base::RunLoop().Run(); 3926 base::RunLoop().Run();
3927 3927
3928 TransportSecurityState* security_state = 3928 TransportSecurityState* security_state =
3929 default_context_.transport_security_state(); 3929 default_context_.transport_security_state();
3930 bool sni_available = true; 3930 bool sni_available = true;
3931 TransportSecurityState::DomainState domain_state; 3931 TransportSecurityState::DomainState domain_state;
3932 EXPECT_TRUE(security_state->GetDomainState( 3932 EXPECT_TRUE(security_state->GetDomainState(
3933 SpawnedTestServer::kLocalhost, sni_available, &domain_state)); 3933 SpawnedTestServer::kLocalhost, sni_available, true, &domain_state));
3934 EXPECT_EQ(TransportSecurityState::DomainState::MODE_FORCE_HTTPS, 3934 EXPECT_EQ(TransportSecurityState::DomainState::MODE_FORCE_HTTPS,
3935 domain_state.upgrade_mode); 3935 domain_state.upgrade_mode);
3936 EXPECT_TRUE(domain_state.sts_include_subdomains); 3936 EXPECT_TRUE(domain_state.sts_include_subdomains);
3937 EXPECT_FALSE(domain_state.pkp_include_subdomains);
3938 #if defined(OS_ANDROID) 3937 #if defined(OS_ANDROID)
3939 // Android's CertVerifyProc does not (yet) handle pins. 3938 // Android's CertVerifyProc does not (yet) handle pins.
3940 #else 3939 #else
3941 EXPECT_FALSE(domain_state.HasPublicKeyPins()); 3940 EXPECT_FALSE(domain_state.HasPublicKeyPins());
3942 #endif 3941 #endif
3943 } 3942 }
3944 3943
3945 // Android's CertVerifyProc does not (yet) handle pins. Therefore, it will 3944 // Android's CertVerifyProc does not (yet) handle pins. Therefore, it will
3946 // reject HPKP headers, and a test setting only HPKP headers will fail (no 3945 // reject HPKP headers, and a test setting only HPKP headers will fail (no
3947 // DomainState present because header rejected). 3946 // DomainState present because header rejected).
(...skipping 19 matching lines...) Expand all
3967 &d, 3966 &d,
3968 &default_context_); 3967 &default_context_);
3969 request.Start(); 3968 request.Start();
3970 base::RunLoop().Run(); 3969 base::RunLoop().Run();
3971 3970
3972 TransportSecurityState* security_state = 3971 TransportSecurityState* security_state =
3973 default_context_.transport_security_state(); 3972 default_context_.transport_security_state();
3974 bool sni_available = true; 3973 bool sni_available = true;
3975 TransportSecurityState::DomainState domain_state; 3974 TransportSecurityState::DomainState domain_state;
3976 EXPECT_TRUE(security_state->GetDomainState( 3975 EXPECT_TRUE(security_state->GetDomainState(
3977 SpawnedTestServer::kLocalhost, sni_available, &domain_state)); 3976 SpawnedTestServer::kLocalhost, sni_available, true, &domain_state));
3978 EXPECT_EQ(TransportSecurityState::DomainState::MODE_DEFAULT, 3977 EXPECT_EQ(TransportSecurityState::DomainState::MODE_DEFAULT,
3979 domain_state.upgrade_mode); 3978 domain_state.upgrade_mode);
3980 EXPECT_FALSE(domain_state.sts_include_subdomains); 3979 EXPECT_FALSE(domain_state.sts_include_subdomains);
3981 EXPECT_FALSE(domain_state.pkp_include_subdomains); 3980 EXPECT_FALSE(domain_state.pkp_include_subdomains);
3982 EXPECT_TRUE(domain_state.HasPublicKeyPins()); 3981 EXPECT_TRUE(domain_state.HasPublicKeyPins());
3982
3983 EXPECT_NE(domain_state.upgrade_expiry, 3983 EXPECT_NE(domain_state.upgrade_expiry,
3984 domain_state.dynamic_spki_hashes_expiry); 3984 domain_state.dynamic_spki_hashes_expiry);
3985 } 3985 }
3986 3986
3987 // Android's CertVerifyProc does not (yet) handle pins. Therefore, it will
3988 // reject HPKP headers, and a test setting only HPKP headers will fail (no
3989 // DomainState present because header rejected).
3990 #if defined(OS_ANDROID)
3991 #define MAYBE_ProcessPKP_PrivacyMode DISABLED_ProcessPKP_PrivacyMode
3992 #else
3993 #define MAYBE_ProcessPKP_PrivacyMode ProcessPKP_PrivacyMode
3994 #endif
3995 // Tests that DynamicDomainState is not added if cookies are not set.
3996 TEST_F(URLRequestTestHTTP, ProcessPKP_PrivacyMode) {
3997 SpawnedTestServer::SSLOptions ssl_options;
3998 SpawnedTestServer https_test_server(
3999 SpawnedTestServer::TYPE_HTTPS,
4000 ssl_options,
4001 base::FilePath(FILE_PATH_LITERAL("net/data/url_request_unittest")));
4002 ASSERT_TRUE(https_test_server.Start());
4003
4004 default_network_delegate_.set_cookie_options(
4005 TestNetworkDelegate::NO_SET_COOKIE);
4006 TestDelegate d;
4007 URLRequest request(https_test_server.GetURL("files/hpkp-headers.html"),
4008 &d,
4009 &default_context_);
4010 request.Start();
4011 base::MessageLoop::current()->Run();
4012
4013 TransportSecurityState* security_state =
4014 default_context_.transport_security_state();
4015 bool sni_available = true;
4016 TransportSecurityState::DomainState domain_state;
4017 EXPECT_FALSE(security_state->GetDomainState(
4018 SpawnedTestServer::kLocalhost, sni_available, true, &domain_state));
4019 }
4020
3987 TEST_F(URLRequestTestHTTP, ProcessSTSOnce) { 4021 TEST_F(URLRequestTestHTTP, ProcessSTSOnce) {
3988 SpawnedTestServer::SSLOptions ssl_options; 4022 SpawnedTestServer::SSLOptions ssl_options;
3989 SpawnedTestServer https_test_server( 4023 SpawnedTestServer https_test_server(
3990 SpawnedTestServer::TYPE_HTTPS, 4024 SpawnedTestServer::TYPE_HTTPS,
3991 ssl_options, 4025 ssl_options,
3992 base::FilePath(FILE_PATH_LITERAL("net/data/url_request_unittest"))); 4026 base::FilePath(FILE_PATH_LITERAL("net/data/url_request_unittest")));
3993 ASSERT_TRUE(https_test_server.Start()); 4027 ASSERT_TRUE(https_test_server.Start());
3994 4028
3995 TestDelegate d; 4029 TestDelegate d;
3996 URLRequest request( 4030 URLRequest request(
3997 https_test_server.GetURL("files/hsts-multiple-headers.html"), 4031 https_test_server.GetURL("files/hsts-multiple-headers.html"),
3998 &d, 4032 &d,
3999 &default_context_); 4033 &default_context_);
4000 request.Start(); 4034 request.Start();
4001 base::RunLoop().Run(); 4035 base::RunLoop().Run();
4002 4036
4003 // We should have set parameters from the first header, not the second. 4037 // We should have set parameters from the first header, not the second.
4004 TransportSecurityState* security_state = 4038 TransportSecurityState* security_state =
4005 default_context_.transport_security_state(); 4039 default_context_.transport_security_state();
4006 bool sni_available = true; 4040 bool sni_available = true;
4007 TransportSecurityState::DomainState domain_state; 4041 TransportSecurityState::DomainState domain_state;
4008 EXPECT_TRUE(security_state->GetDomainState( 4042 EXPECT_TRUE(security_state->GetDomainState(
4009 SpawnedTestServer::kLocalhost, sni_available, &domain_state)); 4043 SpawnedTestServer::kLocalhost, sni_available, true, &domain_state));
4010 EXPECT_EQ(TransportSecurityState::DomainState::MODE_FORCE_HTTPS, 4044 EXPECT_EQ(TransportSecurityState::DomainState::MODE_FORCE_HTTPS,
4011 domain_state.upgrade_mode); 4045 domain_state.upgrade_mode);
4012 EXPECT_FALSE(domain_state.sts_include_subdomains); 4046 EXPECT_FALSE(domain_state.sts_include_subdomains);
4013 EXPECT_FALSE(domain_state.pkp_include_subdomains); 4047 EXPECT_FALSE(domain_state.pkp_include_subdomains);
4014 } 4048 }
4015 4049
4016 TEST_F(URLRequestTestHTTP, ProcessSTSAndPKP) { 4050 TEST_F(URLRequestTestHTTP, ProcessSTSAndPKP) {
4017 SpawnedTestServer::SSLOptions ssl_options; 4051 SpawnedTestServer::SSLOptions ssl_options;
4018 SpawnedTestServer https_test_server( 4052 SpawnedTestServer https_test_server(
4019 SpawnedTestServer::TYPE_HTTPS, 4053 SpawnedTestServer::TYPE_HTTPS,
4020 ssl_options, 4054 ssl_options,
4021 base::FilePath(FILE_PATH_LITERAL("net/data/url_request_unittest"))); 4055 base::FilePath(FILE_PATH_LITERAL("net/data/url_request_unittest")));
4022 ASSERT_TRUE(https_test_server.Start()); 4056 ASSERT_TRUE(https_test_server.Start());
4023 4057
4024 TestDelegate d; 4058 TestDelegate d;
4025 URLRequest request( 4059 URLRequest request(
4026 https_test_server.GetURL("files/hsts-and-hpkp-headers.html"), 4060 https_test_server.GetURL("files/hsts-and-hpkp-headers.html"),
4027 &d, 4061 &d,
4028 &default_context_); 4062 &default_context_);
4029 request.Start(); 4063 request.Start();
4030 base::RunLoop().Run(); 4064 base::RunLoop().Run();
4031 4065
4032 // We should have set parameters from the first header, not the second. 4066 // We should have set parameters from the first header, not the second.
4033 TransportSecurityState* security_state = 4067 TransportSecurityState* security_state =
4034 default_context_.transport_security_state(); 4068 default_context_.transport_security_state();
4035 bool sni_available = true; 4069 bool sni_available = true;
4036 TransportSecurityState::DomainState domain_state; 4070 TransportSecurityState::DomainState domain_state;
4037 EXPECT_TRUE(security_state->GetDomainState( 4071 EXPECT_TRUE(security_state->GetDomainState(
4038 SpawnedTestServer::kLocalhost, sni_available, &domain_state)); 4072 SpawnedTestServer::kLocalhost, sni_available, true, &domain_state));
4039 EXPECT_EQ(TransportSecurityState::DomainState::MODE_FORCE_HTTPS, 4073 EXPECT_EQ(TransportSecurityState::DomainState::MODE_FORCE_HTTPS,
4040 domain_state.upgrade_mode); 4074 domain_state.upgrade_mode);
4041 #if defined(OS_ANDROID) 4075 #if defined(OS_ANDROID)
4042 // Android's CertVerifyProc does not (yet) handle pins. 4076 // Android's CertVerifyProc does not (yet) handle pins.
4043 #else 4077 #else
4044 EXPECT_TRUE(domain_state.HasPublicKeyPins()); 4078 EXPECT_TRUE(domain_state.HasPublicKeyPins());
4045 #endif 4079 #endif
4046 EXPECT_NE(domain_state.upgrade_expiry, 4080 EXPECT_NE(domain_state.upgrade_expiry,
4047 domain_state.dynamic_spki_hashes_expiry); 4081 domain_state.dynamic_spki_hashes_expiry);
4048 4082
(...skipping 20 matching lines...) Expand all
4069 &d, 4103 &d,
4070 &default_context_); 4104 &default_context_);
4071 request.Start(); 4105 request.Start();
4072 base::RunLoop().Run(); 4106 base::RunLoop().Run();
4073 4107
4074 TransportSecurityState* security_state = 4108 TransportSecurityState* security_state =
4075 default_context_.transport_security_state(); 4109 default_context_.transport_security_state();
4076 bool sni_available = true; 4110 bool sni_available = true;
4077 TransportSecurityState::DomainState domain_state; 4111 TransportSecurityState::DomainState domain_state;
4078 EXPECT_TRUE(security_state->GetDomainState( 4112 EXPECT_TRUE(security_state->GetDomainState(
4079 SpawnedTestServer::kLocalhost, sni_available, &domain_state)); 4113 SpawnedTestServer::kLocalhost, sni_available, true, &domain_state));
4080 EXPECT_EQ(TransportSecurityState::DomainState::MODE_FORCE_HTTPS, 4114 EXPECT_EQ(TransportSecurityState::DomainState::MODE_FORCE_HTTPS,
4081 domain_state.upgrade_mode); 4115 domain_state.upgrade_mode);
4082 #if defined(OS_ANDROID) 4116 #if defined(OS_ANDROID)
4083 // Android's CertVerifyProc does not (yet) handle pins. 4117 // Android's CertVerifyProc does not (yet) handle pins.
4084 #else 4118 #else
4085 EXPECT_TRUE(domain_state.HasPublicKeyPins()); 4119 EXPECT_TRUE(domain_state.HasPublicKeyPins());
4086 #endif 4120 #endif
4087 EXPECT_NE(domain_state.upgrade_expiry, 4121 EXPECT_NE(domain_state.upgrade_expiry,
4088 domain_state.dynamic_spki_hashes_expiry); 4122 domain_state.dynamic_spki_hashes_expiry);
4089 4123
(...skipping 988 matching lines...) Expand 10 before | Expand all | Expand 10 after
5078 // MockHostResolver in order to direct www.google.com to the testserver. 5112 // MockHostResolver in order to direct www.google.com to the testserver.
5079 // By default, MockHostResolver maps all hosts to 127.0.0.1. 5113 // By default, MockHostResolver maps all hosts to 127.0.0.1.
5080 5114
5081 MockHostResolver host_resolver; 5115 MockHostResolver host_resolver;
5082 TestNetworkDelegate network_delegate; // Must outlive URLRequest. 5116 TestNetworkDelegate network_delegate; // Must outlive URLRequest.
5083 TestURLRequestContext context(true); 5117 TestURLRequestContext context(true);
5084 context.set_network_delegate(&network_delegate); 5118 context.set_network_delegate(&network_delegate);
5085 context.set_host_resolver(&host_resolver); 5119 context.set_host_resolver(&host_resolver);
5086 TransportSecurityState transport_security_state; 5120 TransportSecurityState transport_security_state;
5087 TransportSecurityState::DomainState domain_state; 5121 TransportSecurityState::DomainState domain_state;
5088 EXPECT_TRUE(transport_security_state.GetDomainState("www.google.com", true, 5122 EXPECT_TRUE(transport_security_state.GetDomainState(
5089 &domain_state)); 5123 "www.google.com", true, true, &domain_state));
5090 context.set_transport_security_state(&transport_security_state); 5124 context.set_transport_security_state(&transport_security_state);
5091 context.Init(); 5125 context.Init();
5092 5126
5093 TestDelegate d; 5127 TestDelegate d;
5094 URLRequest r(GURL(base::StringPrintf("https://www.google.com:%d", 5128 URLRequest r(GURL(base::StringPrintf("https://www.google.com:%d",
5095 test_server.host_port_pair().port())), 5129 test_server.host_port_pair().port())),
5096 &d, 5130 &d,
5097 &context); 5131 &context);
5098 5132
5099 r.Start(); 5133 r.Start();
5100 EXPECT_TRUE(r.is_pending()); 5134 EXPECT_TRUE(r.is_pending());
5101 5135
5102 base::RunLoop().Run(); 5136 base::RunLoop().Run();
5103 5137
5104 EXPECT_EQ(1, d.response_started_count()); 5138 EXPECT_EQ(1, d.response_started_count());
5105 EXPECT_FALSE(d.received_data_before_response()); 5139 EXPECT_FALSE(d.received_data_before_response());
5106 EXPECT_TRUE(d.have_certificate_errors()); 5140 EXPECT_TRUE(d.have_certificate_errors());
5107 EXPECT_TRUE(d.certificate_errors_are_fatal()); 5141 EXPECT_TRUE(d.certificate_errors_are_fatal());
5108 5142
5109 // Get a fresh copy of the state, and check that it hasn't been updated. 5143 // Get a fresh copy of the state, and check that it hasn't been updated.
5110 TransportSecurityState::DomainState new_domain_state; 5144 TransportSecurityState::DomainState new_domain_state;
5111 EXPECT_TRUE(transport_security_state.GetDomainState("www.google.com", true, 5145 EXPECT_TRUE(transport_security_state.GetDomainState(
5112 &new_domain_state)); 5146 "www.google.com", true, true, &new_domain_state));
5113 EXPECT_EQ(new_domain_state.upgrade_mode, domain_state.upgrade_mode); 5147 EXPECT_EQ(new_domain_state.upgrade_mode, domain_state.upgrade_mode);
5114 EXPECT_EQ(new_domain_state.sts_include_subdomains, 5148 EXPECT_EQ(new_domain_state.sts_include_subdomains,
5115 domain_state.sts_include_subdomains); 5149 domain_state.sts_include_subdomains);
5116 EXPECT_EQ(new_domain_state.pkp_include_subdomains, 5150 EXPECT_EQ(new_domain_state.pkp_include_subdomains,
5117 domain_state.pkp_include_subdomains); 5151 domain_state.pkp_include_subdomains);
5118 EXPECT_TRUE(FingerprintsEqual(new_domain_state.static_spki_hashes, 5152 EXPECT_TRUE(FingerprintsEqual(new_domain_state.static_spki_hashes,
5119 domain_state.static_spki_hashes)); 5153 domain_state.static_spki_hashes));
5120 EXPECT_TRUE(FingerprintsEqual(new_domain_state.dynamic_spki_hashes, 5154 EXPECT_TRUE(FingerprintsEqual(new_domain_state.dynamic_spki_hashes,
5121 domain_state.dynamic_spki_hashes)); 5155 domain_state.dynamic_spki_hashes));
5122 EXPECT_TRUE(FingerprintsEqual(new_domain_state.bad_static_spki_hashes, 5156 EXPECT_TRUE(FingerprintsEqual(new_domain_state.bad_static_spki_hashes,
(...skipping 1163 matching lines...) Expand 10 before | Expand all | Expand 10 after
6286 6320
6287 EXPECT_FALSE(r.is_pending()); 6321 EXPECT_FALSE(r.is_pending());
6288 EXPECT_EQ(1, d->response_started_count()); 6322 EXPECT_EQ(1, d->response_started_count());
6289 EXPECT_FALSE(d->received_data_before_response()); 6323 EXPECT_FALSE(d->received_data_before_response());
6290 EXPECT_EQ(d->bytes_received(), static_cast<int>(file_size)); 6324 EXPECT_EQ(d->bytes_received(), static_cast<int>(file_size));
6291 } 6325 }
6292 } 6326 }
6293 #endif // !defined(DISABLE_FTP_SUPPORT) 6327 #endif // !defined(DISABLE_FTP_SUPPORT)
6294 6328
6295 } // namespace net 6329 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698