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

Unified 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: Changed SimpleTestClock ownership 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chromeos/network/client_cert_resolver.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chromeos/network/client_cert_resolver_unittest.cc
diff --git a/chromeos/network/client_cert_resolver_unittest.cc b/chromeos/network/client_cert_resolver_unittest.cc
index 7f2035b32ba68359f5b1baf6b35ffd7e5d95c807..40060727df5741be51d92c914c7d60e66ea64573 100644
--- a/chromeos/network/client_cert_resolver_unittest.cc
+++ b/chromeos/network/client_cert_resolver_unittest.cc
@@ -11,8 +11,10 @@
#include "base/files/file_path.h"
#include "base/files/file_util.h"
#include "base/json/json_reader.h"
+#include "base/memory/scoped_ptr.h"
#include "base/run_loop.h"
#include "base/strings/stringprintf.h"
+#include "base/test/simple_test_clock.h"
#include "base/values.h"
#include "chromeos/cert_loader.h"
#include "chromeos/dbus/dbus_thread_manager.h"
@@ -50,9 +52,9 @@ class ClientCertResolverTest : public testing::Test,
public:
ClientCertResolverTest()
: network_properties_changed_count_(0),
- service_test_(NULL),
- profile_test_(NULL),
- cert_loader_(NULL) {}
+ service_test_(nullptr),
+ profile_test_(nullptr),
+ cert_loader_(nullptr) {}
~ClientCertResolverTest() override {}
void SetUp() override {
@@ -82,6 +84,7 @@ class ClientCertResolverTest : public testing::Test,
void TearDown() override {
client_cert_resolver_->RemoveObserver(this);
client_cert_resolver_.reset();
+ test_clock_.reset();
managed_config_handler_.reset();
network_config_handler_.reset();
network_profile_handler_.reset();
@@ -138,6 +141,10 @@ class ClientCertResolverTest : public testing::Test,
managed_config_handler_.reset(new ManagedNetworkConfigurationHandlerImpl());
client_cert_resolver_.reset(new ClientCertResolver());
+ test_clock_.reset(new base::SimpleTestClock);
+ test_clock_->SetNow(base::Time::Now());
+ client_cert_resolver_->SetClockForTesting(test_clock_.get());
+
network_profile_handler_->Init();
network_config_handler_->Init(network_state_handler_.get(),
nullptr /* network_device_handler */);
@@ -198,10 +205,10 @@ class ClientCertResolverTest : public testing::Test,
std::string error;
scoped_ptr<base::Value> policy_value = base::JSONReader::ReadAndReturnError(
- kTestPolicy, base::JSON_ALLOW_TRAILING_COMMAS, NULL, &error);
+ kTestPolicy, base::JSON_ALLOW_TRAILING_COMMAS, nullptr, &error);
ASSERT_TRUE(policy_value) << error;
- base::ListValue* policy = NULL;
+ base::ListValue* policy = nullptr;
ASSERT_TRUE(policy_value->GetAsList(&policy));
managed_config_handler_->SetPolicy(
@@ -234,10 +241,10 @@ class ClientCertResolverTest : public testing::Test,
std::string error;
scoped_ptr<base::Value> policy_value = base::JSONReader::ReadAndReturnError(
- policy_json, base::JSON_ALLOW_TRAILING_COMMAS, NULL, &error);
+ policy_json, base::JSON_ALLOW_TRAILING_COMMAS, nullptr, &error);
ASSERT_TRUE(policy_value) << error;
- base::ListValue* policy = NULL;
+ base::ListValue* policy = nullptr;
ASSERT_TRUE(policy_value->GetAsList(&policy));
managed_config_handler_->SetPolicy(
@@ -247,6 +254,11 @@ class ClientCertResolverTest : public testing::Test,
base::DictionaryValue() /* no global network config */);
}
+ void SetWifiState(const std::string& state) {
+ ASSERT_TRUE(service_test_->SetServiceProperty(
+ kWifiStub, shill::kStateProperty, base::StringValue(state)));
+ }
+
void GetClientCertProperties(std::string* pkcs11_id) {
pkcs11_id->clear();
const base::DictionaryValue* properties =
@@ -259,6 +271,7 @@ class ClientCertResolverTest : public testing::Test,
int network_properties_changed_count_;
std::string test_cert_id_;
+ scoped_ptr<base::SimpleTestClock> test_clock_;
scoped_ptr<ClientCertResolver> client_cert_resolver_;
private:
@@ -365,4 +378,34 @@ TEST_F(ClientCertResolverTest, ResolveAfterPolicyApplication) {
EXPECT_EQ(1, network_properties_changed_count_);
}
+TEST_F(ClientCertResolverTest, ExpiringCertificate) {
+ SetupTestCerts(true /* import issuer */);
+ SetupWifi();
+ base::RunLoop().RunUntilIdle();
+
+ SetupNetworkHandlers();
+ SetupPolicyMatchingIssuerPEM();
+ base::RunLoop().RunUntilIdle();
+
+ StartCertLoader();
+ base::RunLoop().RunUntilIdle();
+
+ SetWifiState(shill::kStateOnline);
+ base::RunLoop().RunUntilIdle();
+
+ // Verify that the resolver positively matched the pattern in the policy with
+ // the test client cert and configured the network.
+ std::string pkcs11_id;
+ GetClientCertProperties(&pkcs11_id);
+ EXPECT_EQ(test_cert_id_, pkcs11_id);
+
+ // Verify that, after the certificate expired and the network disconnection
+ // happens, no client certificate was configured.
+ test_clock_->SetNow(base::Time::Max());
+ SetWifiState(shill::kStateOffline);
+ base::RunLoop().RunUntilIdle();
+ GetClientCertProperties(&pkcs11_id);
+ EXPECT_EQ(std::string(), pkcs11_id);
+}
+
} // namespace chromeos
« 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