| OLD | NEW |
| 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 <cert.h> | 5 #include <cert.h> |
| 6 #include <pk11pub.h> | 6 #include <pk11pub.h> |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/at_exit.h" | 11 #include "base/at_exit.h" |
| 12 #include "base/callback.h" | 12 #include "base/callback.h" |
| 13 #include "base/file_util.h" | 13 #include "base/file_util.h" |
| 14 #include "base/files/scoped_temp_dir.h" | 14 #include "base/files/scoped_temp_dir.h" |
| 15 #include "base/json/json_reader.h" | 15 #include "base/json/json_reader.h" |
| 16 #include "base/lazy_instance.h" | 16 #include "base/lazy_instance.h" |
| 17 #include "base/path_service.h" | 17 #include "base/path_service.h" |
| 18 #include "chrome/browser/chromeos/cros/cros_library.h" | 18 #include "chrome/browser/chromeos/cros/cros_library.h" |
| 19 #include "chrome/browser/chromeos/cros/network_library.h" | 19 #include "chrome/browser/chromeos/cros/network_library.h" |
| 20 #include "chrome/browser/chromeos/cros/onc_constants.h" | |
| 21 #include "chrome/browser/chromeos/cros/onc_network_parser.h" | 20 #include "chrome/browser/chromeos/cros/onc_network_parser.h" |
| 22 #include "chrome/browser/chromeos/network_settings/onc_certificate_importer.h" | |
| 23 #include "chrome/browser/chromeos/network_settings/onc_utils.h" | |
| 24 #include "chrome/common/chrome_paths.h" | 21 #include "chrome/common/chrome_paths.h" |
| 22 #include "chromeos/network/onc/onc_certificate_importer.h" |
| 23 #include "chromeos/network/onc/onc_constants.h" |
| 24 #include "chromeos/network/onc/onc_utils.h" |
| 25 #include "crypto/nss_util.h" | 25 #include "crypto/nss_util.h" |
| 26 #include "net/base/crypto_module.h" | 26 #include "net/base/crypto_module.h" |
| 27 #include "net/base/nss_cert_database.h" | 27 #include "net/base/nss_cert_database.h" |
| 28 #include "net/base/x509_certificate.h" | 28 #include "net/base/x509_certificate.h" |
| 29 #include "testing/gmock/include/gmock/gmock.h" | 29 #include "testing/gmock/include/gmock/gmock.h" |
| 30 #include "testing/gtest/include/gtest/gtest.h" | 30 #include "testing/gtest/include/gtest/gtest.h" |
| 31 | 31 |
| 32 using ::testing::Return; | 32 using ::testing::Return; |
| 33 | 33 |
| 34 namespace chromeos { | 34 namespace chromeos { |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 149 virtual void TearDown() { | 149 virtual void TearDown() { |
| 150 cros_ = NULL; | 150 cros_ = NULL; |
| 151 EXPECT_TRUE(CleanupSlotContents(slot_->os_module_handle())); | 151 EXPECT_TRUE(CleanupSlotContents(slot_->os_module_handle())); |
| 152 EXPECT_EQ(0U, ListCertsInSlot(slot_->os_module_handle()).size()); | 152 EXPECT_EQ(0U, ListCertsInSlot(slot_->os_module_handle()).size()); |
| 153 } | 153 } |
| 154 | 154 |
| 155 virtual void GetTestData(const std::string& filename, | 155 virtual void GetTestData(const std::string& filename, |
| 156 scoped_ptr<base::ListValue>* certificates, | 156 scoped_ptr<base::ListValue>* certificates, |
| 157 scoped_ptr<base::ListValue>* network_configs) { | 157 scoped_ptr<base::ListValue>* network_configs) { |
| 158 FilePath path; | 158 FilePath path; |
| 159 std::string error; | |
| 160 PathService::Get(chrome::DIR_TEST_DATA, &path); | 159 PathService::Get(chrome::DIR_TEST_DATA, &path); |
| 161 path = path.AppendASCII("chromeos").AppendASCII("cros").Append(filename); | 160 path = path.AppendASCII("chromeos").AppendASCII("cros").Append(filename); |
| 162 ASSERT_TRUE(file_util::PathExists(path)) | 161 ASSERT_TRUE(file_util::PathExists(path)) |
| 163 << "Couldn't find test data file " << path.value(); | 162 << "Couldn't find test data file " << path.value(); |
| 164 std::string contents; | 163 std::string contents; |
| 165 ASSERT_TRUE(file_util::ReadFileToString(path, &contents)) | 164 ASSERT_TRUE(file_util::ReadFileToString(path, &contents)) |
| 166 << "Unable to read test data file " << path.value(); | 165 << "Unable to read test data file " << path.value(); |
| 167 | 166 |
| 168 scoped_ptr<base::DictionaryValue> root = | 167 scoped_ptr<base::DictionaryValue> root = |
| 169 onc::ReadDictionaryFromJson(contents, &error); | 168 onc::ReadDictionaryFromJson(contents); |
| 170 CHECK(root.get() != NULL) << "ONC is not a valid json dictionary: " | 169 CHECK(root.get() != NULL) << "ONC is not a valid JSON dictionary."; |
| 171 << error; | |
| 172 | 170 |
| 173 base::ListValue* certificates_ptr; | 171 base::ListValue* certificates_ptr; |
| 174 CHECK(root->GetListWithoutPathExpansion(onc::kCertificates, | 172 CHECK(root->GetListWithoutPathExpansion(onc::kCertificates, |
| 175 &certificates_ptr)); | 173 &certificates_ptr)); |
| 176 certificates->reset(certificates_ptr->DeepCopy()); | 174 certificates->reset(certificates_ptr->DeepCopy()); |
| 177 | 175 |
| 178 base::ListValue* network_configs_ptr; | 176 base::ListValue* network_configs_ptr; |
| 179 CHECK(root->GetListWithoutPathExpansion(onc::kNetworkConfigurations, | 177 CHECK(root->GetListWithoutPathExpansion(onc::kNetworkConfigurations, |
| 180 &network_configs_ptr)); | 178 &network_configs_ptr)); |
| 181 network_configs->reset(network_configs_ptr->DeepCopy()); | 179 network_configs->reset(network_configs_ptr->DeepCopy()); |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 297 cros_->ConnectToWifiNetwork(wifi1); | 295 cros_->ConnectToWifiNetwork(wifi1); |
| 298 EXPECT_TRUE(wifi1->connected()); | 296 EXPECT_TRUE(wifi1->connected()); |
| 299 } | 297 } |
| 300 | 298 |
| 301 TEST_F(NetworkLibraryStubTest, NetworkConnectOncWifi) { | 299 TEST_F(NetworkLibraryStubTest, NetworkConnectOncWifi) { |
| 302 // Import a wireless network via loading an ONC file. | 300 // Import a wireless network via loading an ONC file. |
| 303 scoped_ptr<base::ListValue> network_configs; | 301 scoped_ptr<base::ListValue> network_configs; |
| 304 scoped_ptr<base::ListValue> certificates; | 302 scoped_ptr<base::ListValue> certificates; |
| 305 GetTestData("cert-pattern.onc", &certificates, &network_configs); | 303 GetTestData("cert-pattern.onc", &certificates, &network_configs); |
| 306 | 304 |
| 307 onc::CertificateImporter importer(NetworkUIData::ONC_SOURCE_USER_IMPORT, | 305 onc::CertificateImporter importer(onc::ONC_SOURCE_USER_IMPORT, |
| 308 false /* don't allow webtrust */); | 306 false /* don't allow webtrust */); |
| 309 EXPECT_TRUE(importer.ParseAndStoreCertificates(*certificates, NULL)); | 307 EXPECT_EQ(onc::CertificateImporter::IMPORT_OK, |
| 308 importer.ParseAndStoreCertificates(*certificates)); |
| 310 | 309 |
| 311 OncNetworkParser parser(*network_configs, | 310 OncNetworkParser parser(*network_configs, |
| 312 NetworkUIData::ONC_SOURCE_USER_IMPORT); | 311 onc::ONC_SOURCE_USER_IMPORT); |
| 313 ASSERT_TRUE(parser.parse_error().empty()); | 312 ASSERT_TRUE(parser.parse_error().empty()); |
| 314 EXPECT_EQ(1, parser.GetNetworkConfigsSize()); | 313 EXPECT_EQ(1, parser.GetNetworkConfigsSize()); |
| 315 scoped_ptr<Network> network(parser.ParseNetwork(0, NULL)); | 314 scoped_ptr<Network> network(parser.ParseNetwork(0, NULL)); |
| 316 ASSERT_TRUE(network.get()); | 315 ASSERT_TRUE(network.get()); |
| 317 EXPECT_EQ(CLIENT_CERT_TYPE_PATTERN, network->client_cert_type()); | 316 EXPECT_EQ(CLIENT_CERT_TYPE_PATTERN, network->client_cert_type()); |
| 318 | 317 |
| 319 StubEnrollmentDelegate* enrollment_delegate = new StubEnrollmentDelegate(); | 318 StubEnrollmentDelegate* enrollment_delegate = new StubEnrollmentDelegate(); |
| 320 | 319 |
| 321 network->SetEnrollmentDelegate(enrollment_delegate); | 320 network->SetEnrollmentDelegate(enrollment_delegate); |
| 322 EXPECT_FALSE(enrollment_delegate->did_enroll); | 321 EXPECT_FALSE(enrollment_delegate->did_enroll); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 333 EXPECT_TRUE(enrollment_delegate->did_enroll); | 332 EXPECT_TRUE(enrollment_delegate->did_enroll); |
| 334 EXPECT_TRUE(enrollment_delegate->correct_args); | 333 EXPECT_TRUE(enrollment_delegate->correct_args); |
| 335 } | 334 } |
| 336 | 335 |
| 337 TEST_F(NetworkLibraryStubTest, NetworkConnectOncVPN) { | 336 TEST_F(NetworkLibraryStubTest, NetworkConnectOncVPN) { |
| 338 // Import a wireless network via loading an ONC file. | 337 // Import a wireless network via loading an ONC file. |
| 339 scoped_ptr<base::ListValue> network_configs; | 338 scoped_ptr<base::ListValue> network_configs; |
| 340 scoped_ptr<base::ListValue> certificates; | 339 scoped_ptr<base::ListValue> certificates; |
| 341 GetTestData("cert-pattern-vpn.onc", &certificates, &network_configs); | 340 GetTestData("cert-pattern-vpn.onc", &certificates, &network_configs); |
| 342 | 341 |
| 343 onc::CertificateImporter importer(NetworkUIData::ONC_SOURCE_USER_IMPORT, | 342 onc::CertificateImporter importer(onc::ONC_SOURCE_USER_IMPORT, |
| 344 false /* don't allow webtrust */); | 343 false /* don't allow webtrust */); |
| 345 EXPECT_TRUE(importer.ParseAndStoreCertificates(*certificates, NULL)); | 344 EXPECT_EQ(onc::CertificateImporter::IMPORT_OK, |
| 345 importer.ParseAndStoreCertificates(*certificates)); |
| 346 | 346 |
| 347 OncNetworkParser parser(*network_configs, | 347 OncNetworkParser parser(*network_configs, |
| 348 NetworkUIData::ONC_SOURCE_USER_IMPORT); | 348 onc::ONC_SOURCE_USER_IMPORT); |
| 349 ASSERT_TRUE(parser.parse_error().empty()); | 349 ASSERT_TRUE(parser.parse_error().empty()); |
| 350 EXPECT_EQ(1, parser.GetNetworkConfigsSize()); | 350 EXPECT_EQ(1, parser.GetNetworkConfigsSize()); |
| 351 scoped_ptr<Network> network(parser.ParseNetwork(0, NULL)); | 351 scoped_ptr<Network> network(parser.ParseNetwork(0, NULL)); |
| 352 ASSERT_TRUE(network.get()); | 352 ASSERT_TRUE(network.get()); |
| 353 EXPECT_EQ(CLIENT_CERT_TYPE_PATTERN, network->client_cert_type()); | 353 EXPECT_EQ(CLIENT_CERT_TYPE_PATTERN, network->client_cert_type()); |
| 354 | 354 |
| 355 StubEnrollmentDelegate* enrollment_delegate = new StubEnrollmentDelegate(); | 355 StubEnrollmentDelegate* enrollment_delegate = new StubEnrollmentDelegate(); |
| 356 | 356 |
| 357 network->SetEnrollmentDelegate(enrollment_delegate); | 357 network->SetEnrollmentDelegate(enrollment_delegate); |
| 358 EXPECT_FALSE(enrollment_delegate->did_enroll); | 358 EXPECT_FALSE(enrollment_delegate->did_enroll); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 385 | 385 |
| 386 // TODO(stevenjb): Test network profiles. | 386 // TODO(stevenjb): Test network profiles. |
| 387 | 387 |
| 388 // TODO(stevenjb): Test network devices. | 388 // TODO(stevenjb): Test network devices. |
| 389 | 389 |
| 390 // TODO(stevenjb): Test data plans. | 390 // TODO(stevenjb): Test data plans. |
| 391 | 391 |
| 392 // TODO(stevenjb): Test monitor network / device. | 392 // TODO(stevenjb): Test monitor network / device. |
| 393 | 393 |
| 394 } // namespace chromeos | 394 } // namespace chromeos |
| OLD | NEW |