| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 | 5 |
| 6 #include "base/callback.h" | 6 #include "base/callback.h" |
| 7 #include "base/files/file_path.h" | 7 #include "base/files/file_path.h" |
| 8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
| 9 #include "base/run_loop.h" | 9 #include "base/run_loop.h" |
| 10 #include "base/values.h" | 10 #include "base/values.h" |
| (...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 239 SetPolicy(onc::ONC_SOURCE_USER_POLICY, _, _)); | 239 SetPolicy(onc::ONC_SOURCE_USER_POLICY, _, _)); |
| 240 EXPECT_CALL(*certificate_importer_, ImportCertificates(_, _, _)) | 240 EXPECT_CALL(*certificate_importer_, ImportCertificates(_, _, _)) |
| 241 .WillRepeatedly(SetCertificateList(cert_list)); | 241 .WillRepeatedly(SetCertificateList(cert_list)); |
| 242 | 242 |
| 243 UserNetworkConfigurationUpdater* updater = | 243 UserNetworkConfigurationUpdater* updater = |
| 244 CreateNetworkConfigurationUpdaterForUserPolicy( | 244 CreateNetworkConfigurationUpdaterForUserPolicy( |
| 245 false /* do not allow trusted certs from policy */); | 245 false /* do not allow trusted certs from policy */); |
| 246 | 246 |
| 247 // Certificates with the "Web" trust flag set should not be forwarded to the | 247 // Certificates with the "Web" trust flag set should not be forwarded to the |
| 248 // trust provider. | 248 // trust provider. |
| 249 policy::PolicyCertVerifier cert_verifier(( | 249 policy::PolicyCertVerifier cert_verifier; |
| 250 base::Closure() /* no policy cert trusted callback */)); | |
| 251 updater->SetPolicyCertVerifier(&cert_verifier); | 250 updater->SetPolicyCertVerifier(&cert_verifier); |
| 252 base::RunLoop().RunUntilIdle(); | 251 base::RunLoop().RunUntilIdle(); |
| 253 EXPECT_TRUE(cert_verifier.GetAdditionalTrustAnchors().empty()); | 252 EXPECT_TRUE(cert_verifier.GetAdditionalTrustAnchors().empty()); |
| 254 | 253 |
| 255 // |cert_verifier| must outlive the updater. | 254 // |cert_verifier| must outlive the updater. |
| 256 network_configuration_updater_.reset(); | 255 network_configuration_updater_.reset(); |
| 256 cert_verifier.ShutdownOnUIThread(); |
| 257 } | 257 } |
| 258 | 258 |
| 259 TEST_F(NetworkConfigurationUpdaterTest, AllowTrustedCertificatesFromPolicy) { | 259 TEST_F(NetworkConfigurationUpdaterTest, AllowTrustedCertificatesFromPolicy) { |
| 260 net::CertificateList cert_list; | 260 net::CertificateList cert_list; |
| 261 cert_list = | 261 cert_list = |
| 262 net::CreateCertificateListFromFile(net::GetTestCertsDirectory(), | 262 net::CreateCertificateListFromFile(net::GetTestCertsDirectory(), |
| 263 "ok_cert.pem", | 263 "ok_cert.pem", |
| 264 net::X509Certificate::FORMAT_AUTO); | 264 net::X509Certificate::FORMAT_AUTO); |
| 265 ASSERT_EQ(1u, cert_list.size()); | 265 ASSERT_EQ(1u, cert_list.size()); |
| 266 | 266 |
| 267 EXPECT_CALL(network_config_handler_, | 267 EXPECT_CALL(network_config_handler_, |
| 268 SetPolicy(onc::ONC_SOURCE_USER_POLICY, _, _)); | 268 SetPolicy(onc::ONC_SOURCE_USER_POLICY, _, _)); |
| 269 EXPECT_CALL(*certificate_importer_, | 269 EXPECT_CALL(*certificate_importer_, |
| 270 ImportCertificates(_, onc::ONC_SOURCE_USER_POLICY, _)) | 270 ImportCertificates(_, onc::ONC_SOURCE_USER_POLICY, _)) |
| 271 .WillRepeatedly(SetCertificateList(cert_list)); | 271 .WillRepeatedly(SetCertificateList(cert_list)); |
| 272 | 272 |
| 273 UserNetworkConfigurationUpdater* updater = | 273 UserNetworkConfigurationUpdater* updater = |
| 274 CreateNetworkConfigurationUpdaterForUserPolicy( | 274 CreateNetworkConfigurationUpdaterForUserPolicy( |
| 275 true /* allow trusted certs from policy */); | 275 true /* allow trusted certs from policy */); |
| 276 | 276 |
| 277 // Certificates with the "Web" trust flag set should be forwarded to the | 277 // Certificates with the "Web" trust flag set should be forwarded to the |
| 278 // trust provider. | 278 // trust provider. |
| 279 policy::PolicyCertVerifier cert_verifier(( | 279 policy::PolicyCertVerifier cert_verifier; |
| 280 base::Closure() /* no policy cert trusted callback */)); | |
| 281 updater->SetPolicyCertVerifier(&cert_verifier); | 280 updater->SetPolicyCertVerifier(&cert_verifier); |
| 282 base::RunLoop().RunUntilIdle(); | 281 base::RunLoop().RunUntilIdle(); |
| 283 EXPECT_EQ(1u, cert_verifier.GetAdditionalTrustAnchors().size()); | 282 EXPECT_EQ(1u, cert_verifier.GetAdditionalTrustAnchors().size()); |
| 284 | 283 |
| 285 // |cert_verifier| must outlive the updater. | 284 // |cert_verifier| must outlive the updater. |
| 286 network_configuration_updater_.reset(); | 285 network_configuration_updater_.reset(); |
| 286 cert_verifier.ShutdownOnUIThread(); |
| 287 } | 287 } |
| 288 | 288 |
| 289 class NetworkConfigurationUpdaterTestWithParam | 289 class NetworkConfigurationUpdaterTestWithParam |
| 290 : public NetworkConfigurationUpdaterTest, | 290 : public NetworkConfigurationUpdaterTest, |
| 291 public testing::WithParamInterface<const char*> { | 291 public testing::WithParamInterface<const char*> { |
| 292 protected: | 292 protected: |
| 293 // Returns the currently tested ONC source. | 293 // Returns the currently tested ONC source. |
| 294 onc::ONCSource CurrentONCSource() { | 294 onc::ONCSource CurrentONCSource() { |
| 295 if (GetParam() == key::kOpenNetworkConfiguration) | 295 if (GetParam() == key::kOpenNetworkConfiguration) |
| 296 return onc::ONC_SOURCE_USER_POLICY; | 296 return onc::ONC_SOURCE_USER_POLICY; |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 370 policy.Erase(GetParam()); | 370 policy.Erase(GetParam()); |
| 371 UpdateProviderPolicy(policy); | 371 UpdateProviderPolicy(policy); |
| 372 } | 372 } |
| 373 | 373 |
| 374 INSTANTIATE_TEST_CASE_P(NetworkConfigurationUpdaterTestWithParamInstance, | 374 INSTANTIATE_TEST_CASE_P(NetworkConfigurationUpdaterTestWithParamInstance, |
| 375 NetworkConfigurationUpdaterTestWithParam, | 375 NetworkConfigurationUpdaterTestWithParam, |
| 376 testing::Values(key::kDeviceOpenNetworkConfiguration, | 376 testing::Values(key::kDeviceOpenNetworkConfiguration, |
| 377 key::kOpenNetworkConfiguration)); | 377 key::kOpenNetworkConfiguration)); |
| 378 | 378 |
| 379 } // namespace policy | 379 } // namespace policy |
| OLD | NEW |