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 #include "chromeos/network/client_cert_resolver.h" | 4 #include "chromeos/network/client_cert_resolver.h" |
5 | 5 |
6 #include <cert.h> | 6 #include <cert.h> |
7 #include <pk11pub.h> | 7 #include <pk11pub.h> |
8 | 8 |
9 #include <memory> | 9 #include <memory> |
10 | 10 |
11 #include "base/bind.h" | 11 #include "base/bind.h" |
12 #include "base/bind_helpers.h" | 12 #include "base/bind_helpers.h" |
13 #include "base/files/file_path.h" | 13 #include "base/files/file_path.h" |
14 #include "base/files/file_util.h" | 14 #include "base/files/file_util.h" |
15 #include "base/json/json_reader.h" | 15 #include "base/json/json_reader.h" |
16 #include "base/macros.h" | 16 #include "base/macros.h" |
17 #include "base/run_loop.h" | 17 #include "base/run_loop.h" |
18 #include "base/strings/stringprintf.h" | 18 #include "base/strings/stringprintf.h" |
19 #include "base/test/scoped_task_scheduler.h" | |
19 #include "base/test/simple_test_clock.h" | 20 #include "base/test/simple_test_clock.h" |
20 #include "base/values.h" | 21 #include "base/values.h" |
21 #include "chromeos/cert_loader.h" | 22 #include "chromeos/cert_loader.h" |
22 #include "chromeos/dbus/dbus_thread_manager.h" | 23 #include "chromeos/dbus/dbus_thread_manager.h" |
23 #include "chromeos/dbus/shill_manager_client.h" | 24 #include "chromeos/dbus/shill_manager_client.h" |
24 #include "chromeos/dbus/shill_profile_client.h" | 25 #include "chromeos/dbus/shill_profile_client.h" |
25 #include "chromeos/dbus/shill_service_client.h" | 26 #include "chromeos/dbus/shill_service_client.h" |
26 #include "chromeos/network/managed_network_configuration_handler_impl.h" | 27 #include "chromeos/network/managed_network_configuration_handler_impl.h" |
27 #include "chromeos/network/network_configuration_handler.h" | 28 #include "chromeos/network/network_configuration_handler.h" |
28 #include "chromeos/network/network_profile_handler.h" | 29 #include "chromeos/network/network_profile_handler.h" |
(...skipping 20 matching lines...) Expand all Loading... | |
49 | 50 |
50 } // namespace | 51 } // namespace |
51 | 52 |
52 class ClientCertResolverTest : public testing::Test, | 53 class ClientCertResolverTest : public testing::Test, |
53 public ClientCertResolver::Observer { | 54 public ClientCertResolver::Observer { |
54 public: | 55 public: |
55 ClientCertResolverTest() | 56 ClientCertResolverTest() |
56 : network_properties_changed_count_(0), | 57 : network_properties_changed_count_(0), |
57 service_test_(nullptr), | 58 service_test_(nullptr), |
58 profile_test_(nullptr), | 59 profile_test_(nullptr), |
59 cert_loader_(nullptr) {} | 60 cert_loader_(nullptr), |
61 scoped_task_scheduler_(&message_loop_) {} | |
60 ~ClientCertResolverTest() override {} | 62 ~ClientCertResolverTest() override {} |
61 | 63 |
62 void SetUp() override { | 64 void SetUp() override { |
63 ASSERT_TRUE(test_nssdb_.is_open()); | 65 ASSERT_TRUE(test_nssdb_.is_open()); |
64 | 66 |
65 // Use the same DB for public and private slot. | 67 // Use the same DB for public and private slot. |
66 test_nsscertdb_.reset(new net::NSSCertDatabaseChromeOS( | 68 test_nsscertdb_.reset(new net::NSSCertDatabaseChromeOS( |
67 crypto::ScopedPK11Slot(PK11_ReferenceSlot(test_nssdb_.slot())), | 69 crypto::ScopedPK11Slot(PK11_ReferenceSlot(test_nssdb_.slot())), |
68 crypto::ScopedPK11Slot(PK11_ReferenceSlot(test_nssdb_.slot())))); | 70 crypto::ScopedPK11Slot(PK11_ReferenceSlot(test_nssdb_.slot())))); |
69 test_nsscertdb_->SetSlowTaskRunnerForTest(message_loop_.task_runner()); | |
70 | 71 |
71 DBusThreadManager::Initialize(); | 72 DBusThreadManager::Initialize(); |
72 service_test_ = | 73 service_test_ = |
73 DBusThreadManager::Get()->GetShillServiceClient()->GetTestInterface(); | 74 DBusThreadManager::Get()->GetShillServiceClient()->GetTestInterface(); |
74 profile_test_ = | 75 profile_test_ = |
75 DBusThreadManager::Get()->GetShillProfileClient()->GetTestInterface(); | 76 DBusThreadManager::Get()->GetShillProfileClient()->GetTestInterface(); |
76 profile_test_->AddProfile(kUserProfilePath, kUserHash); | 77 profile_test_->AddProfile(kUserProfilePath, kUserHash); |
77 base::RunLoop().RunUntilIdle(); | 78 base::RunLoop().RunUntilIdle(); |
78 service_test_->ClearServices(); | 79 service_test_->ClearServices(); |
79 base::RunLoop().RunUntilIdle(); | 80 base::RunLoop().RunUntilIdle(); |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
152 network_state_handler_.get(), network_profile_handler_.get(), | 153 network_state_handler_.get(), network_profile_handler_.get(), |
153 network_config_handler_.get(), nullptr /* network_device_handler */, | 154 network_config_handler_.get(), nullptr /* network_device_handler */, |
154 nullptr /* prohibited_technologies_handler */); | 155 nullptr /* prohibited_technologies_handler */); |
155 // Run all notifications before starting the cert loader to reduce run time. | 156 // Run all notifications before starting the cert loader to reduce run time. |
156 base::RunLoop().RunUntilIdle(); | 157 base::RunLoop().RunUntilIdle(); |
157 | 158 |
158 client_cert_resolver_->Init(network_state_handler_.get(), | 159 client_cert_resolver_->Init(network_state_handler_.get(), |
159 managed_config_handler_.get()); | 160 managed_config_handler_.get()); |
160 client_cert_resolver_->AddObserver(this); | 161 client_cert_resolver_->AddObserver(this); |
161 client_cert_resolver_->SetSlowTaskRunnerForTest( | 162 client_cert_resolver_->SetSlowTaskRunnerForTest( |
162 message_loop_.task_runner()); | 163 message_loop_.task_runner()); |
stevenjb
2017/02/03 18:01:04
And here?
fdoray
2017/02/03 19:23:06
Same answer.
| |
163 } | 164 } |
164 | 165 |
165 void SetupWifi() { | 166 void SetupWifi() { |
166 service_test_->SetServiceProperties(kWifiStub, | 167 service_test_->SetServiceProperties(kWifiStub, |
167 kWifiStub, | 168 kWifiStub, |
168 kWifiSSID, | 169 kWifiSSID, |
169 shill::kTypeWifi, | 170 shill::kTypeWifi, |
170 shill::kStateOnline, | 171 shill::kStateOnline, |
171 true /* visible */); | 172 true /* visible */); |
172 // Set an arbitrary cert id, so that we can check afterwards whether we | 173 // Set an arbitrary cert id, so that we can check afterwards whether we |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
286 | 287 |
287 ShillServiceClient::TestInterface* service_test_; | 288 ShillServiceClient::TestInterface* service_test_; |
288 ShillProfileClient::TestInterface* profile_test_; | 289 ShillProfileClient::TestInterface* profile_test_; |
289 CertLoader* cert_loader_; | 290 CertLoader* cert_loader_; |
290 std::unique_ptr<NetworkStateHandler> network_state_handler_; | 291 std::unique_ptr<NetworkStateHandler> network_state_handler_; |
291 std::unique_ptr<NetworkProfileHandler> network_profile_handler_; | 292 std::unique_ptr<NetworkProfileHandler> network_profile_handler_; |
292 std::unique_ptr<NetworkConfigurationHandler> network_config_handler_; | 293 std::unique_ptr<NetworkConfigurationHandler> network_config_handler_; |
293 std::unique_ptr<ManagedNetworkConfigurationHandlerImpl> | 294 std::unique_ptr<ManagedNetworkConfigurationHandlerImpl> |
294 managed_config_handler_; | 295 managed_config_handler_; |
295 base::MessageLoop message_loop_; | 296 base::MessageLoop message_loop_; |
297 base::test::ScopedTaskScheduler scoped_task_scheduler_; | |
296 scoped_refptr<net::X509Certificate> test_client_cert_; | 298 scoped_refptr<net::X509Certificate> test_client_cert_; |
297 std::string test_ca_cert_pem_; | 299 std::string test_ca_cert_pem_; |
298 crypto::ScopedTestNSSDB test_nssdb_; | 300 crypto::ScopedTestNSSDB test_nssdb_; |
299 std::unique_ptr<net::NSSCertDatabaseChromeOS> test_nsscertdb_; | 301 std::unique_ptr<net::NSSCertDatabaseChromeOS> test_nsscertdb_; |
300 | 302 |
301 DISALLOW_COPY_AND_ASSIGN(ClientCertResolverTest); | 303 DISALLOW_COPY_AND_ASSIGN(ClientCertResolverTest); |
302 }; | 304 }; |
303 | 305 |
304 TEST_F(ClientCertResolverTest, NoMatchingCertificates) { | 306 TEST_F(ClientCertResolverTest, NoMatchingCertificates) { |
305 SetupTestCerts("client_1", false /* do not import the issuer */); | 307 SetupTestCerts("client_1", false /* do not import the issuer */); |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
437 // substituted into the shill service entry. | 439 // substituted into the shill service entry. |
438 SetupPolicyMatchingIssuerPEM("upn-${CERT_SAN_UPN}-suffix"); | 440 SetupPolicyMatchingIssuerPEM("upn-${CERT_SAN_UPN}-suffix"); |
439 base::RunLoop().RunUntilIdle(); | 441 base::RunLoop().RunUntilIdle(); |
440 | 442 |
441 GetServiceProperty(shill::kEapIdentityProperty, &identity); | 443 GetServiceProperty(shill::kEapIdentityProperty, &identity); |
442 EXPECT_EQ("upn-santest@ad.corp.example.com-suffix", identity); | 444 EXPECT_EQ("upn-santest@ad.corp.example.com-suffix", identity); |
443 EXPECT_EQ(2, network_properties_changed_count_); | 445 EXPECT_EQ(2, network_properties_changed_count_); |
444 } | 446 } |
445 | 447 |
446 } // namespace chromeos | 448 } // namespace chromeos |
OLD | NEW |