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() { |
| 58 // Ideally, we'd open a test DB for each test case, and close it |
| 59 // again, removing the temp dir, but unfortunately, there's a |
| 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 |
57 virtual void SetUp() { | 69 virtual void SetUp() { |
58 ASSERT_TRUE(test_nssdb_.is_open()); | |
59 | |
60 slot_ = net::NSSCertDatabase::GetInstance()->GetPublicModule(); | 70 slot_ = net::NSSCertDatabase::GetInstance()->GetPublicModule(); |
61 | 71 |
62 // Don't run the test if the setup failed. | 72 // Don't run the test if the setup failed. |
63 ASSERT_TRUE(slot_->os_module_handle()); | 73 ASSERT_TRUE(slot_->os_module_handle()); |
64 | 74 |
65 // Test db should be empty at start of test. | 75 // Test db should be empty at start of test. |
66 EXPECT_EQ(0U, ListCertsInSlot(slot_->os_module_handle()).size()); | 76 EXPECT_EQ(0U, ListCertsInSlot(slot_->os_module_handle()).size()); |
67 } | 77 } |
68 | 78 |
69 virtual void TearDown() { | 79 virtual void TearDown() { |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
120 bool ok = true; | 130 bool ok = true; |
121 net::CertificateList certs = ListCertsInSlot(slot); | 131 net::CertificateList certs = ListCertsInSlot(slot); |
122 for (size_t i = 0; i < certs.size(); ++i) { | 132 for (size_t i = 0; i < certs.size(); ++i) { |
123 if (!net::NSSCertDatabase::GetInstance()->DeleteCertAndKey(certs[i])) | 133 if (!net::NSSCertDatabase::GetInstance()->DeleteCertAndKey(certs[i])) |
124 ok = false; | 134 ok = false; |
125 } | 135 } |
126 return ok; | 136 return ok; |
127 } | 137 } |
128 | 138 |
129 ScopedStubCrosEnabler stub_cros_enabler_; | 139 ScopedStubCrosEnabler stub_cros_enabler_; |
130 crypto::ScopedTestNSSDB test_nssdb_; | |
131 }; | 140 }; |
132 | 141 |
133 const base::Value* OncNetworkParserTest::GetExpectedProperty( | 142 const base::Value* OncNetworkParserTest::GetExpectedProperty( |
134 const Network* network, | 143 const Network* network, |
135 PropertyIndex index, | 144 PropertyIndex index, |
136 base::Value::Type expected_type) { | 145 base::Value::Type expected_type) { |
137 const base::Value* value; | 146 const base::Value* value; |
138 if (!network->GetProperty(index, &value)) { | 147 if (!network->GetProperty(index, &value)) { |
139 ADD_FAILURE() << "Property " << index << " does not exist"; | 148 ADD_FAILURE() << "Property " << index << " does not exist"; |
140 return NULL; | 149 return NULL; |
(...skipping 823 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
964 EXPECT_EQ(1, parser.GetNetworkConfigsSize()); | 973 EXPECT_EQ(1, parser.GetNetworkConfigsSize()); |
965 EXPECT_EQ(0, parser.GetCertificatesSize()); | 974 EXPECT_EQ(0, parser.GetCertificatesSize()); |
966 bool marked_for_removal = false; | 975 bool marked_for_removal = false; |
967 scoped_ptr<Network> network(parser.ParseNetwork(0, &marked_for_removal)); | 976 scoped_ptr<Network> network(parser.ParseNetwork(0, &marked_for_removal)); |
968 | 977 |
969 EXPECT_TRUE(marked_for_removal); | 978 EXPECT_TRUE(marked_for_removal); |
970 EXPECT_EQ("{485d6076-dd44-6b6d-69787465725f5045}", network->unique_id()); | 979 EXPECT_EQ("{485d6076-dd44-6b6d-69787465725f5045}", network->unique_id()); |
971 } | 980 } |
972 | 981 |
973 } // namespace chromeos | 982 } // namespace chromeos |
OLD | NEW |