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

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

Powered by Google App Engine
This is Rietveld 408576698