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 "chrome/browser/chromeos/cros/onc_network_parser.h" | 5 #include "chrome/browser/chromeos/cros/onc_network_parser.h" |
6 | 6 |
7 #include <cert.h> | 7 #include <cert.h> |
8 #include <keyhi.h> | 8 #include <keyhi.h> |
9 #include <pk11pub.h> | 9 #include <pk11pub.h> |
10 | 10 |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
47 | 47 |
48 net::CertType GetCertType(const net::X509Certificate* cert) { | 48 net::CertType GetCertType(const net::X509Certificate* cert) { |
49 DCHECK(cert); | 49 DCHECK(cert); |
50 return x509_certificate_model::GetType(cert->os_cert_handle()); | 50 return x509_certificate_model::GetType(cert->os_cert_handle()); |
51 } | 51 } |
52 | 52 |
53 } // namespace | 53 } // namespace |
54 | 54 |
55 class OncNetworkParserTest : public testing::Test { | 55 class OncNetworkParserTest : public testing::Test { |
56 public: | 56 public: |
57 static void SetUpTestCase() { | 57 virtual void SetUp() { |
58 // Ideally, we'd open a test DB for each test case, and close it | 58 test_nssdb_.reset(new crypto::ScopedTestNSSDB()); |
59 // again, removing the temp dir, but unfortunately, there's a | 59 ASSERT_TRUE(test_nssdb_->is_open()); |
60 // bug in NSS that prevents this from working, so we just open | |
61 // it once, and empty it for each test case. Here's the bug: | |
62 // https://bugzilla.mozilla.org/show_bug.cgi?id=588269 | |
63 ASSERT_TRUE(crypto::OpenTestNSSDB()); | |
64 // There is no matching TearDownTestCase call to close the test NSS DB | |
65 // because that would leave NSS in a potentially broken state for further | |
66 // tests, due to https://bugzilla.mozilla.org/show_bug.cgi?id=588269 | |
67 } | |
68 | 60 |
69 virtual void SetUp() { | |
70 slot_ = net::NSSCertDatabase::GetInstance()->GetPublicModule(); | 61 slot_ = net::NSSCertDatabase::GetInstance()->GetPublicModule(); |
71 | 62 |
72 // Don't run the test if the setup failed. | 63 // Don't run the test if the setup failed. |
73 ASSERT_TRUE(slot_->os_module_handle()); | 64 ASSERT_TRUE(slot_->os_module_handle()); |
74 | 65 |
75 // Test db should be empty at start of test. | 66 // Test db should be empty at start of test. |
76 EXPECT_EQ(0U, ListCertsInSlot(slot_->os_module_handle()).size()); | 67 EXPECT_EQ(0U, ListCertsInSlot(slot_->os_module_handle()).size()); |
77 } | 68 } |
78 | 69 |
79 virtual void TearDown() { | 70 virtual void TearDown() { |
80 EXPECT_TRUE(CleanupSlotContents(slot_->os_module_handle())); | 71 EXPECT_TRUE(CleanupSlotContents(slot_->os_module_handle())); |
81 EXPECT_EQ(0U, ListCertsInSlot(slot_->os_module_handle()).size()); | 72 EXPECT_EQ(0U, ListCertsInSlot(slot_->os_module_handle()).size()); |
73 test_nssdb_.reset(); | |
82 } | 74 } |
83 | 75 |
84 virtual void GetTestData(const std::string& filename, std::string* contents) { | 76 virtual void GetTestData(const std::string& filename, std::string* contents) { |
85 FilePath path; | 77 FilePath path; |
86 std::string error; | 78 std::string error; |
87 PathService::Get(chrome::DIR_TEST_DATA, &path); | 79 PathService::Get(chrome::DIR_TEST_DATA, &path); |
88 path = path.AppendASCII("chromeos").AppendASCII("cros").Append(filename); | 80 path = path.AppendASCII("chromeos").AppendASCII("cros").Append(filename); |
89 ASSERT_TRUE(contents != NULL); | 81 ASSERT_TRUE(contents != NULL); |
90 ASSERT_TRUE(file_util::PathExists(path)) | 82 ASSERT_TRUE(file_util::PathExists(path)) |
91 << "Couldn't find test data file " << path.value(); | 83 << "Couldn't find test data file " << path.value(); |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
130 bool ok = true; | 122 bool ok = true; |
131 net::CertificateList certs = ListCertsInSlot(slot); | 123 net::CertificateList certs = ListCertsInSlot(slot); |
132 for (size_t i = 0; i < certs.size(); ++i) { | 124 for (size_t i = 0; i < certs.size(); ++i) { |
133 if (!net::NSSCertDatabase::GetInstance()->DeleteCertAndKey(certs[i])) | 125 if (!net::NSSCertDatabase::GetInstance()->DeleteCertAndKey(certs[i])) |
134 ok = false; | 126 ok = false; |
135 } | 127 } |
136 return ok; | 128 return ok; |
137 } | 129 } |
138 | 130 |
139 ScopedStubCrosEnabler stub_cros_enabler_; | 131 ScopedStubCrosEnabler stub_cros_enabler_; |
132 scoped_ptr<crypto::ScopedTestNSSDB> test_nssdb_; | |
Ryan Sleevi
2012/10/16 18:19:02
Doesn't need to be a scoped_ptr here - GTest creat
Takashi Toyoshima
2012/10/17 04:58:53
Done.
| |
140 }; | 133 }; |
141 | 134 |
142 const base::Value* OncNetworkParserTest::GetExpectedProperty( | 135 const base::Value* OncNetworkParserTest::GetExpectedProperty( |
143 const Network* network, | 136 const Network* network, |
144 PropertyIndex index, | 137 PropertyIndex index, |
145 base::Value::Type expected_type) { | 138 base::Value::Type expected_type) { |
146 const base::Value* value; | 139 const base::Value* value; |
147 if (!network->GetProperty(index, &value)) { | 140 if (!network->GetProperty(index, &value)) { |
148 ADD_FAILURE() << "Property " << index << " does not exist"; | 141 ADD_FAILURE() << "Property " << index << " does not exist"; |
149 return NULL; | 142 return NULL; |
(...skipping 823 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
973 EXPECT_EQ(1, parser.GetNetworkConfigsSize()); | 966 EXPECT_EQ(1, parser.GetNetworkConfigsSize()); |
974 EXPECT_EQ(0, parser.GetCertificatesSize()); | 967 EXPECT_EQ(0, parser.GetCertificatesSize()); |
975 bool marked_for_removal = false; | 968 bool marked_for_removal = false; |
976 scoped_ptr<Network> network(parser.ParseNetwork(0, &marked_for_removal)); | 969 scoped_ptr<Network> network(parser.ParseNetwork(0, &marked_for_removal)); |
977 | 970 |
978 EXPECT_TRUE(marked_for_removal); | 971 EXPECT_TRUE(marked_for_removal); |
979 EXPECT_EQ("{485d6076-dd44-6b6d-69787465725f5045}", network->unique_id()); | 972 EXPECT_EQ("{485d6076-dd44-6b6d-69787465725f5045}", network->unique_id()); |
980 } | 973 } |
981 | 974 |
982 } // namespace chromeos | 975 } // namespace chromeos |
OLD | NEW |