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