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

Side by Side Diff: chromeos/network/client_cert_resolver_unittest.cc

Issue 1443043002: Execute ClientCertResolver on network disconnection. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix problem with AutoConnectHandler test Created 5 years, 1 month 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
« no previous file with comments | « chromeos/network/client_cert_resolver.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "base/bind.h" 9 #include "base/bind.h"
10 #include "base/bind_helpers.h" 10 #include "base/bind_helpers.h"
11 #include "base/files/file_path.h" 11 #include "base/files/file_path.h"
12 #include "base/files/file_util.h" 12 #include "base/files/file_util.h"
13 #include "base/json/json_reader.h" 13 #include "base/json/json_reader.h"
14 #include "base/memory/scoped_ptr.h"
14 #include "base/run_loop.h" 15 #include "base/run_loop.h"
15 #include "base/strings/stringprintf.h" 16 #include "base/strings/stringprintf.h"
17 #include "base/test/simple_test_clock.h"
16 #include "base/values.h" 18 #include "base/values.h"
17 #include "chromeos/cert_loader.h" 19 #include "chromeos/cert_loader.h"
18 #include "chromeos/dbus/dbus_thread_manager.h" 20 #include "chromeos/dbus/dbus_thread_manager.h"
19 #include "chromeos/dbus/shill_manager_client.h" 21 #include "chromeos/dbus/shill_manager_client.h"
20 #include "chromeos/dbus/shill_profile_client.h" 22 #include "chromeos/dbus/shill_profile_client.h"
21 #include "chromeos/dbus/shill_service_client.h" 23 #include "chromeos/dbus/shill_service_client.h"
22 #include "chromeos/network/managed_network_configuration_handler_impl.h" 24 #include "chromeos/network/managed_network_configuration_handler_impl.h"
23 #include "chromeos/network/network_configuration_handler.h" 25 #include "chromeos/network/network_configuration_handler.h"
24 #include "chromeos/network/network_profile_handler.h" 26 #include "chromeos/network/network_profile_handler.h"
25 #include "chromeos/network/network_state_handler.h" 27 #include "chromeos/network/network_state_handler.h"
(...skipping 17 matching lines...) Expand all
43 const char* kUserProfilePath = "user_profile"; 45 const char* kUserProfilePath = "user_profile";
44 const char* kUserHash = "user_hash"; 46 const char* kUserHash = "user_hash";
45 47
46 } // namespace 48 } // namespace
47 49
48 class ClientCertResolverTest : public testing::Test, 50 class ClientCertResolverTest : public testing::Test,
49 public ClientCertResolver::Observer { 51 public ClientCertResolver::Observer {
50 public: 52 public:
51 ClientCertResolverTest() 53 ClientCertResolverTest()
52 : network_properties_changed_count_(0), 54 : network_properties_changed_count_(0),
55 test_clock_(NULL),
stevenjb 2015/11/17 00:45:22 s/NULL/nullptr throughout
emaxx 2015/11/17 12:44:07 Done.
53 service_test_(NULL), 56 service_test_(NULL),
54 profile_test_(NULL), 57 profile_test_(NULL),
55 cert_loader_(NULL) {} 58 cert_loader_(NULL) {}
56 ~ClientCertResolverTest() override {} 59 ~ClientCertResolverTest() override {}
57 60
58 void SetUp() override { 61 void SetUp() override {
59 ASSERT_TRUE(test_nssdb_.is_open()); 62 ASSERT_TRUE(test_nssdb_.is_open());
60 63
61 // Use the same DB for public and private slot. 64 // Use the same DB for public and private slot.
62 test_nsscertdb_.reset(new net::NSSCertDatabaseChromeOS( 65 test_nsscertdb_.reset(new net::NSSCertDatabaseChromeOS(
(...skipping 12 matching lines...) Expand all
75 base::RunLoop().RunUntilIdle(); 78 base::RunLoop().RunUntilIdle();
76 79
77 CertLoader::Initialize(); 80 CertLoader::Initialize();
78 cert_loader_ = CertLoader::Get(); 81 cert_loader_ = CertLoader::Get();
79 CertLoader::ForceHardwareBackedForTesting(); 82 CertLoader::ForceHardwareBackedForTesting();
80 } 83 }
81 84
82 void TearDown() override { 85 void TearDown() override {
83 client_cert_resolver_->RemoveObserver(this); 86 client_cert_resolver_->RemoveObserver(this);
84 client_cert_resolver_.reset(); 87 client_cert_resolver_.reset();
88 test_clock_ = NULL;
85 managed_config_handler_.reset(); 89 managed_config_handler_.reset();
86 network_config_handler_.reset(); 90 network_config_handler_.reset();
87 network_profile_handler_.reset(); 91 network_profile_handler_.reset();
88 network_state_handler_.reset(); 92 network_state_handler_.reset();
89 CertLoader::Shutdown(); 93 CertLoader::Shutdown();
90 DBusThreadManager::Shutdown(); 94 DBusThreadManager::Shutdown();
91 } 95 }
92 96
93 protected: 97 protected:
94 void StartCertLoader() { 98 void StartCertLoader() {
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 ASSERT_TRUE(test_client_cert_.get()); 135 ASSERT_TRUE(test_client_cert_.get());
132 } 136 }
133 137
134 void SetupNetworkHandlers() { 138 void SetupNetworkHandlers() {
135 network_state_handler_.reset(NetworkStateHandler::InitializeForTest()); 139 network_state_handler_.reset(NetworkStateHandler::InitializeForTest());
136 network_profile_handler_.reset(new NetworkProfileHandler()); 140 network_profile_handler_.reset(new NetworkProfileHandler());
137 network_config_handler_.reset(new NetworkConfigurationHandler()); 141 network_config_handler_.reset(new NetworkConfigurationHandler());
138 managed_config_handler_.reset(new ManagedNetworkConfigurationHandlerImpl()); 142 managed_config_handler_.reset(new ManagedNetworkConfigurationHandlerImpl());
139 client_cert_resolver_.reset(new ClientCertResolver()); 143 client_cert_resolver_.reset(new ClientCertResolver());
140 144
145 test_clock_ = new base::SimpleTestClock;
146 test_clock_->SetNow(base::Time::Now());
147 client_cert_resolver_->SetClockForTesting(make_scoped_ptr(test_clock_));
stevenjb 2015/11/17 00:45:22 This is dangerous. client_cert_resolver_ now owns
emaxx 2015/11/17 12:44:07 Implemented a) now. Though this looks pretty simil
stevenjb 2015/11/17 17:53:52 I acknowledge it's a subtle distinction, but I thi
148
141 network_profile_handler_->Init(); 149 network_profile_handler_->Init();
142 network_config_handler_->Init(network_state_handler_.get(), 150 network_config_handler_->Init(network_state_handler_.get(),
143 nullptr /* network_device_handler */); 151 nullptr /* network_device_handler */);
144 managed_config_handler_->Init( 152 managed_config_handler_->Init(
145 network_state_handler_.get(), network_profile_handler_.get(), 153 network_state_handler_.get(), network_profile_handler_.get(),
146 network_config_handler_.get(), nullptr /* network_device_handler */, 154 network_config_handler_.get(), nullptr /* network_device_handler */,
147 nullptr /* prohibited_technologies_handler */); 155 nullptr /* prohibited_technologies_handler */);
148 // 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.
149 base::RunLoop().RunUntilIdle(); 157 base::RunLoop().RunUntilIdle();
150 158
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
240 base::ListValue* policy = NULL; 248 base::ListValue* policy = NULL;
241 ASSERT_TRUE(policy_value->GetAsList(&policy)); 249 ASSERT_TRUE(policy_value->GetAsList(&policy));
242 250
243 managed_config_handler_->SetPolicy( 251 managed_config_handler_->SetPolicy(
244 onc::ONC_SOURCE_USER_POLICY, 252 onc::ONC_SOURCE_USER_POLICY,
245 kUserHash, 253 kUserHash,
246 *policy, 254 *policy,
247 base::DictionaryValue() /* no global network config */); 255 base::DictionaryValue() /* no global network config */);
248 } 256 }
249 257
258 void SetWifiState(const std::string& state) {
259 ASSERT_TRUE(service_test_->SetServiceProperty(
260 kWifiStub, shill::kStateProperty, base::StringValue(state)));
261 }
262
250 void GetClientCertProperties(std::string* pkcs11_id) { 263 void GetClientCertProperties(std::string* pkcs11_id) {
251 pkcs11_id->clear(); 264 pkcs11_id->clear();
252 const base::DictionaryValue* properties = 265 const base::DictionaryValue* properties =
253 service_test_->GetServiceProperties(kWifiStub); 266 service_test_->GetServiceProperties(kWifiStub);
254 if (!properties) 267 if (!properties)
255 return; 268 return;
256 properties->GetStringWithoutPathExpansion(shill::kEapCertIdProperty, 269 properties->GetStringWithoutPathExpansion(shill::kEapCertIdProperty,
257 pkcs11_id); 270 pkcs11_id);
258 } 271 }
259 272
260 int network_properties_changed_count_; 273 int network_properties_changed_count_;
261 std::string test_cert_id_; 274 std::string test_cert_id_;
275 base::SimpleTestClock* test_clock_;
262 scoped_ptr<ClientCertResolver> client_cert_resolver_; 276 scoped_ptr<ClientCertResolver> client_cert_resolver_;
263 277
264 private: 278 private:
265 // ClientCertResolver::Observer: 279 // ClientCertResolver::Observer:
266 void ResolveRequestCompleted(bool network_properties_changed) override { 280 void ResolveRequestCompleted(bool network_properties_changed) override {
267 if (network_properties_changed) 281 if (network_properties_changed)
268 ++network_properties_changed_count_; 282 ++network_properties_changed_count_;
269 } 283 }
270 284
271 ShillServiceClient::TestInterface* service_test_; 285 ShillServiceClient::TestInterface* service_test_;
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
358 base::RunLoop().RunUntilIdle(); 372 base::RunLoop().RunUntilIdle();
359 373
360 // Verify that the resolver positively matched the pattern in the policy with 374 // Verify that the resolver positively matched the pattern in the policy with
361 // the test client cert and configured the network. 375 // the test client cert and configured the network.
362 std::string pkcs11_id; 376 std::string pkcs11_id;
363 GetClientCertProperties(&pkcs11_id); 377 GetClientCertProperties(&pkcs11_id);
364 EXPECT_EQ(test_cert_id_, pkcs11_id); 378 EXPECT_EQ(test_cert_id_, pkcs11_id);
365 EXPECT_EQ(1, network_properties_changed_count_); 379 EXPECT_EQ(1, network_properties_changed_count_);
366 } 380 }
367 381
382 TEST_F(ClientCertResolverTest, ExpiringCertificate) {
383 SetupTestCerts(true /* import issuer */);
384 SetupWifi();
385 base::RunLoop().RunUntilIdle();
386
387 SetupNetworkHandlers();
388 SetupPolicyMatchingIssuerPEM();
389 base::RunLoop().RunUntilIdle();
390
391 StartCertLoader();
392 base::RunLoop().RunUntilIdle();
393
394 SetWifiState(shill::kStateOnline);
395 base::RunLoop().RunUntilIdle();
396
397 // Verify that the resolver positively matched the pattern in the policy with
398 // the test client cert and configured the network.
399 std::string pkcs11_id;
400 GetClientCertProperties(&pkcs11_id);
401 EXPECT_EQ(test_cert_id_, pkcs11_id);
402
403 // Verify that, after the certificate expired and the network disconnection
404 // happens, no client certificate was configured.
405 test_clock_->SetNow(base::Time::Max());
406 SetWifiState(shill::kStateOffline);
407 base::RunLoop().RunUntilIdle();
408 GetClientCertProperties(&pkcs11_id);
409 EXPECT_EQ(std::string(), pkcs11_id);
410 }
411
368 } // namespace chromeos 412 } // namespace chromeos
OLDNEW
« no previous file with comments | « chromeos/network/client_cert_resolver.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698