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

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

Issue 24251011: Revert 224269 "Don't persist HPKP if PrivacyMode is enabled." (Closed) Base URL: svn://svn.chromium.org/chrome/
Patch Set: 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(2, network_delegate.blocked_get_cookies_count()); 2034 EXPECT_EQ(1, 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(2, network_delegate.blocked_get_cookies_count()); 2165 EXPECT_EQ(1, 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, true, &domain_state)); 3933 SpawnedTestServer::kLocalhost, sni_available, &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);
3937 #if defined(OS_ANDROID) 3938 #if defined(OS_ANDROID)
3938 // Android's CertVerifyProc does not (yet) handle pins. 3939 // Android's CertVerifyProc does not (yet) handle pins.
3939 #else 3940 #else
3940 EXPECT_FALSE(domain_state.HasPublicKeyPins()); 3941 EXPECT_FALSE(domain_state.HasPublicKeyPins());
3941 #endif 3942 #endif
3942 } 3943 }
3943 3944
3944 // Android's CertVerifyProc does not (yet) handle pins. Therefore, it will 3945 // Android's CertVerifyProc does not (yet) handle pins. Therefore, it will
3945 // reject HPKP headers, and a test setting only HPKP headers will fail (no 3946 // reject HPKP headers, and a test setting only HPKP headers will fail (no
3946 // DomainState present because header rejected). 3947 // DomainState present because header rejected).
(...skipping 19 matching lines...) Expand all
3966 &d, 3967 &d,
3967 &default_context_); 3968 &default_context_);
3968 request.Start(); 3969 request.Start();
3969 base::RunLoop().Run(); 3970 base::RunLoop().Run();
3970 3971
3971 TransportSecurityState* security_state = 3972 TransportSecurityState* security_state =
3972 default_context_.transport_security_state(); 3973 default_context_.transport_security_state();
3973 bool sni_available = true; 3974 bool sni_available = true;
3974 TransportSecurityState::DomainState domain_state; 3975 TransportSecurityState::DomainState domain_state;
3975 EXPECT_TRUE(security_state->GetDomainState( 3976 EXPECT_TRUE(security_state->GetDomainState(
3976 SpawnedTestServer::kLocalhost, sni_available, true, &domain_state)); 3977 SpawnedTestServer::kLocalhost, sni_available, &domain_state));
3977 EXPECT_EQ(TransportSecurityState::DomainState::MODE_DEFAULT, 3978 EXPECT_EQ(TransportSecurityState::DomainState::MODE_DEFAULT,
3978 domain_state.upgrade_mode); 3979 domain_state.upgrade_mode);
3979 EXPECT_FALSE(domain_state.sts_include_subdomains); 3980 EXPECT_FALSE(domain_state.sts_include_subdomains);
3980 EXPECT_FALSE(domain_state.pkp_include_subdomains); 3981 EXPECT_FALSE(domain_state.pkp_include_subdomains);
3981 EXPECT_TRUE(domain_state.HasPublicKeyPins()); 3982 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
4021 TEST_F(URLRequestTestHTTP, ProcessSTSOnce) { 3987 TEST_F(URLRequestTestHTTP, ProcessSTSOnce) {
4022 SpawnedTestServer::SSLOptions ssl_options; 3988 SpawnedTestServer::SSLOptions ssl_options;
4023 SpawnedTestServer https_test_server( 3989 SpawnedTestServer https_test_server(
4024 SpawnedTestServer::TYPE_HTTPS, 3990 SpawnedTestServer::TYPE_HTTPS,
4025 ssl_options, 3991 ssl_options,
4026 base::FilePath(FILE_PATH_LITERAL("net/data/url_request_unittest"))); 3992 base::FilePath(FILE_PATH_LITERAL("net/data/url_request_unittest")));
4027 ASSERT_TRUE(https_test_server.Start()); 3993 ASSERT_TRUE(https_test_server.Start());
4028 3994
4029 TestDelegate d; 3995 TestDelegate d;
4030 URLRequest request( 3996 URLRequest request(
4031 https_test_server.GetURL("files/hsts-multiple-headers.html"), 3997 https_test_server.GetURL("files/hsts-multiple-headers.html"),
4032 &d, 3998 &d,
4033 &default_context_); 3999 &default_context_);
4034 request.Start(); 4000 request.Start();
4035 base::RunLoop().Run(); 4001 base::RunLoop().Run();
4036 4002
4037 // We should have set parameters from the first header, not the second. 4003 // We should have set parameters from the first header, not the second.
4038 TransportSecurityState* security_state = 4004 TransportSecurityState* security_state =
4039 default_context_.transport_security_state(); 4005 default_context_.transport_security_state();
4040 bool sni_available = true; 4006 bool sni_available = true;
4041 TransportSecurityState::DomainState domain_state; 4007 TransportSecurityState::DomainState domain_state;
4042 EXPECT_TRUE(security_state->GetDomainState( 4008 EXPECT_TRUE(security_state->GetDomainState(
4043 SpawnedTestServer::kLocalhost, sni_available, true, &domain_state)); 4009 SpawnedTestServer::kLocalhost, sni_available, &domain_state));
4044 EXPECT_EQ(TransportSecurityState::DomainState::MODE_FORCE_HTTPS, 4010 EXPECT_EQ(TransportSecurityState::DomainState::MODE_FORCE_HTTPS,
4045 domain_state.upgrade_mode); 4011 domain_state.upgrade_mode);
4046 EXPECT_FALSE(domain_state.sts_include_subdomains); 4012 EXPECT_FALSE(domain_state.sts_include_subdomains);
4047 EXPECT_FALSE(domain_state.pkp_include_subdomains); 4013 EXPECT_FALSE(domain_state.pkp_include_subdomains);
4048 } 4014 }
4049 4015
4050 TEST_F(URLRequestTestHTTP, ProcessSTSAndPKP) { 4016 TEST_F(URLRequestTestHTTP, ProcessSTSAndPKP) {
4051 SpawnedTestServer::SSLOptions ssl_options; 4017 SpawnedTestServer::SSLOptions ssl_options;
4052 SpawnedTestServer https_test_server( 4018 SpawnedTestServer https_test_server(
4053 SpawnedTestServer::TYPE_HTTPS, 4019 SpawnedTestServer::TYPE_HTTPS,
4054 ssl_options, 4020 ssl_options,
4055 base::FilePath(FILE_PATH_LITERAL("net/data/url_request_unittest"))); 4021 base::FilePath(FILE_PATH_LITERAL("net/data/url_request_unittest")));
4056 ASSERT_TRUE(https_test_server.Start()); 4022 ASSERT_TRUE(https_test_server.Start());
4057 4023
4058 TestDelegate d; 4024 TestDelegate d;
4059 URLRequest request( 4025 URLRequest request(
4060 https_test_server.GetURL("files/hsts-and-hpkp-headers.html"), 4026 https_test_server.GetURL("files/hsts-and-hpkp-headers.html"),
4061 &d, 4027 &d,
4062 &default_context_); 4028 &default_context_);
4063 request.Start(); 4029 request.Start();
4064 base::RunLoop().Run(); 4030 base::RunLoop().Run();
4065 4031
4066 // We should have set parameters from the first header, not the second. 4032 // We should have set parameters from the first header, not the second.
4067 TransportSecurityState* security_state = 4033 TransportSecurityState* security_state =
4068 default_context_.transport_security_state(); 4034 default_context_.transport_security_state();
4069 bool sni_available = true; 4035 bool sni_available = true;
4070 TransportSecurityState::DomainState domain_state; 4036 TransportSecurityState::DomainState domain_state;
4071 EXPECT_TRUE(security_state->GetDomainState( 4037 EXPECT_TRUE(security_state->GetDomainState(
4072 SpawnedTestServer::kLocalhost, sni_available, true, &domain_state)); 4038 SpawnedTestServer::kLocalhost, sni_available, &domain_state));
4073 EXPECT_EQ(TransportSecurityState::DomainState::MODE_FORCE_HTTPS, 4039 EXPECT_EQ(TransportSecurityState::DomainState::MODE_FORCE_HTTPS,
4074 domain_state.upgrade_mode); 4040 domain_state.upgrade_mode);
4075 #if defined(OS_ANDROID) 4041 #if defined(OS_ANDROID)
4076 // Android's CertVerifyProc does not (yet) handle pins. 4042 // Android's CertVerifyProc does not (yet) handle pins.
4077 #else 4043 #else
4078 EXPECT_TRUE(domain_state.HasPublicKeyPins()); 4044 EXPECT_TRUE(domain_state.HasPublicKeyPins());
4079 #endif 4045 #endif
4080 EXPECT_NE(domain_state.upgrade_expiry, 4046 EXPECT_NE(domain_state.upgrade_expiry,
4081 domain_state.dynamic_spki_hashes_expiry); 4047 domain_state.dynamic_spki_hashes_expiry);
4082 4048
(...skipping 20 matching lines...) Expand all
4103 &d, 4069 &d,
4104 &default_context_); 4070 &default_context_);
4105 request.Start(); 4071 request.Start();
4106 base::RunLoop().Run(); 4072 base::RunLoop().Run();
4107 4073
4108 TransportSecurityState* security_state = 4074 TransportSecurityState* security_state =
4109 default_context_.transport_security_state(); 4075 default_context_.transport_security_state();
4110 bool sni_available = true; 4076 bool sni_available = true;
4111 TransportSecurityState::DomainState domain_state; 4077 TransportSecurityState::DomainState domain_state;
4112 EXPECT_TRUE(security_state->GetDomainState( 4078 EXPECT_TRUE(security_state->GetDomainState(
4113 SpawnedTestServer::kLocalhost, sni_available, true, &domain_state)); 4079 SpawnedTestServer::kLocalhost, sni_available, &domain_state));
4114 EXPECT_EQ(TransportSecurityState::DomainState::MODE_FORCE_HTTPS, 4080 EXPECT_EQ(TransportSecurityState::DomainState::MODE_FORCE_HTTPS,
4115 domain_state.upgrade_mode); 4081 domain_state.upgrade_mode);
4116 #if defined(OS_ANDROID) 4082 #if defined(OS_ANDROID)
4117 // Android's CertVerifyProc does not (yet) handle pins. 4083 // Android's CertVerifyProc does not (yet) handle pins.
4118 #else 4084 #else
4119 EXPECT_TRUE(domain_state.HasPublicKeyPins()); 4085 EXPECT_TRUE(domain_state.HasPublicKeyPins());
4120 #endif 4086 #endif
4121 EXPECT_NE(domain_state.upgrade_expiry, 4087 EXPECT_NE(domain_state.upgrade_expiry,
4122 domain_state.dynamic_spki_hashes_expiry); 4088 domain_state.dynamic_spki_hashes_expiry);
4123 4089
(...skipping 988 matching lines...) Expand 10 before | Expand all | Expand 10 after
5112 // MockHostResolver in order to direct www.google.com to the testserver. 5078 // MockHostResolver in order to direct www.google.com to the testserver.
5113 // By default, MockHostResolver maps all hosts to 127.0.0.1. 5079 // By default, MockHostResolver maps all hosts to 127.0.0.1.
5114 5080
5115 MockHostResolver host_resolver; 5081 MockHostResolver host_resolver;
5116 TestNetworkDelegate network_delegate; // Must outlive URLRequest. 5082 TestNetworkDelegate network_delegate; // Must outlive URLRequest.
5117 TestURLRequestContext context(true); 5083 TestURLRequestContext context(true);
5118 context.set_network_delegate(&network_delegate); 5084 context.set_network_delegate(&network_delegate);
5119 context.set_host_resolver(&host_resolver); 5085 context.set_host_resolver(&host_resolver);
5120 TransportSecurityState transport_security_state; 5086 TransportSecurityState transport_security_state;
5121 TransportSecurityState::DomainState domain_state; 5087 TransportSecurityState::DomainState domain_state;
5122 EXPECT_TRUE(transport_security_state.GetDomainState( 5088 EXPECT_TRUE(transport_security_state.GetDomainState("www.google.com", true,
5123 "www.google.com", true, true, &domain_state)); 5089 &domain_state));
5124 context.set_transport_security_state(&transport_security_state); 5090 context.set_transport_security_state(&transport_security_state);
5125 context.Init(); 5091 context.Init();
5126 5092
5127 TestDelegate d; 5093 TestDelegate d;
5128 URLRequest r(GURL(base::StringPrintf("https://www.google.com:%d", 5094 URLRequest r(GURL(base::StringPrintf("https://www.google.com:%d",
5129 test_server.host_port_pair().port())), 5095 test_server.host_port_pair().port())),
5130 &d, 5096 &d,
5131 &context); 5097 &context);
5132 5098
5133 r.Start(); 5099 r.Start();
5134 EXPECT_TRUE(r.is_pending()); 5100 EXPECT_TRUE(r.is_pending());
5135 5101
5136 base::RunLoop().Run(); 5102 base::RunLoop().Run();
5137 5103
5138 EXPECT_EQ(1, d.response_started_count()); 5104 EXPECT_EQ(1, d.response_started_count());
5139 EXPECT_FALSE(d.received_data_before_response()); 5105 EXPECT_FALSE(d.received_data_before_response());
5140 EXPECT_TRUE(d.have_certificate_errors()); 5106 EXPECT_TRUE(d.have_certificate_errors());
5141 EXPECT_TRUE(d.certificate_errors_are_fatal()); 5107 EXPECT_TRUE(d.certificate_errors_are_fatal());
5142 5108
5143 // Get a fresh copy of the state, and check that it hasn't been updated. 5109 // Get a fresh copy of the state, and check that it hasn't been updated.
5144 TransportSecurityState::DomainState new_domain_state; 5110 TransportSecurityState::DomainState new_domain_state;
5145 EXPECT_TRUE(transport_security_state.GetDomainState( 5111 EXPECT_TRUE(transport_security_state.GetDomainState("www.google.com", true,
5146 "www.google.com", true, true, &new_domain_state)); 5112 &new_domain_state));
5147 EXPECT_EQ(new_domain_state.upgrade_mode, domain_state.upgrade_mode); 5113 EXPECT_EQ(new_domain_state.upgrade_mode, domain_state.upgrade_mode);
5148 EXPECT_EQ(new_domain_state.sts_include_subdomains, 5114 EXPECT_EQ(new_domain_state.sts_include_subdomains,
5149 domain_state.sts_include_subdomains); 5115 domain_state.sts_include_subdomains);
5150 EXPECT_EQ(new_domain_state.pkp_include_subdomains, 5116 EXPECT_EQ(new_domain_state.pkp_include_subdomains,
5151 domain_state.pkp_include_subdomains); 5117 domain_state.pkp_include_subdomains);
5152 EXPECT_TRUE(FingerprintsEqual(new_domain_state.static_spki_hashes, 5118 EXPECT_TRUE(FingerprintsEqual(new_domain_state.static_spki_hashes,
5153 domain_state.static_spki_hashes)); 5119 domain_state.static_spki_hashes));
5154 EXPECT_TRUE(FingerprintsEqual(new_domain_state.dynamic_spki_hashes, 5120 EXPECT_TRUE(FingerprintsEqual(new_domain_state.dynamic_spki_hashes,
5155 domain_state.dynamic_spki_hashes)); 5121 domain_state.dynamic_spki_hashes));
5156 EXPECT_TRUE(FingerprintsEqual(new_domain_state.bad_static_spki_hashes, 5122 EXPECT_TRUE(FingerprintsEqual(new_domain_state.bad_static_spki_hashes,
(...skipping 1163 matching lines...) Expand 10 before | Expand all | Expand 10 after
6320 6286
6321 EXPECT_FALSE(r.is_pending()); 6287 EXPECT_FALSE(r.is_pending());
6322 EXPECT_EQ(1, d->response_started_count()); 6288 EXPECT_EQ(1, d->response_started_count());
6323 EXPECT_FALSE(d->received_data_before_response()); 6289 EXPECT_FALSE(d->received_data_before_response());
6324 EXPECT_EQ(d->bytes_received(), static_cast<int>(file_size)); 6290 EXPECT_EQ(d->bytes_received(), static_cast<int>(file_size));
6325 } 6291 }
6326 } 6292 }
6327 #endif // !defined(DISABLE_FTP_SUPPORT) 6293 #endif // !defined(DISABLE_FTP_SUPPORT)
6328 6294
6329 } // namespace net 6295 } // namespace net
OLDNEW
« no previous file with comments | « trunk/src/net/url_request/url_request_test_util.h ('k') | trunk/src/net/websockets/websocket_job.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698