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

Side by Side Diff: chromeos/network/onc/onc_certificate_importer_unittest.cc

Issue 11299236: This moves the ONC parsing code into chromeos/network/onc (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix unit tests Created 8 years 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chromeos/network/onc/onc_certificate_importer.cc ('k') | chromeos/network/onc/onc_constants.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/network_settings/onc_certificate_importer.h" 5 #include "chromeos/network/onc/onc_certificate_importer.h"
6 6
7 #include <cert.h> 7 #include <cert.h>
8 #include <certdb.h>
8 #include <keyhi.h> 9 #include <keyhi.h>
9 #include <pk11pub.h> 10 #include <pk11pub.h>
10 #include <string> 11 #include <string>
11 12
12 #include "base/logging.h" 13 #include "base/logging.h"
13 #include "base/string_number_conversions.h" 14 #include "base/string_number_conversions.h"
14 #include "base/values.h" 15 #include "base/values.h"
15 #include "chrome/browser/chromeos/cros/onc_constants.h" 16 #include "chromeos/network/onc/onc_constants.h"
16 #include "chrome/browser/chromeos/network_settings/onc_test_utils.h" 17 #include "chromeos/network/onc/onc_test_utils.h"
17 #include "chrome/common/net/x509_certificate_model.h"
18 #include "crypto/nss_util.h" 18 #include "crypto/nss_util.h"
19 #include "net/base/cert_type.h" 19 #include "net/base/cert_type.h"
20 #include "net/base/crypto_module.h" 20 #include "net/base/crypto_module.h"
21 #include "net/base/nss_cert_database.h" 21 #include "net/base/nss_cert_database.h"
22 #include "net/base/x509_certificate.h" 22 #include "net/base/x509_certificate.h"
23 #include "testing/gtest/include/gtest/gtest.h" 23 #include "testing/gtest/include/gtest/gtest.h"
24 24
25 namespace {
26
27 net::CertType GetCertType(const net::X509Certificate* cert) {
28 DCHECK(cert);
29 return x509_certificate_model::GetType(cert->os_cert_handle());
30 }
31
32 } // namespace
33
34 namespace chromeos { 25 namespace chromeos {
35 namespace onc { 26 namespace onc {
36 27
28 #if defined(USE_NSS)
29 // In NSS 3.13, CERTDB_VALID_PEER was renamed CERTDB_TERMINAL_RECORD. So we use
30 // the new name of the macro.
31 #if !defined(CERTDB_TERMINAL_RECORD)
32 #define CERTDB_TERMINAL_RECORD CERTDB_VALID_PEER
33 #endif
34
35 net::CertType GetCertType(net::X509Certificate::OSCertHandle cert) {
36 CERTCertTrust trust = {0};
37 CERT_GetCertTrust(cert, &trust);
38
39 unsigned all_flags = trust.sslFlags | trust.emailFlags |
40 trust.objectSigningFlags;
41
42 if (cert->nickname && (all_flags & CERTDB_USER))
43 return net::USER_CERT;
44 if ((all_flags & CERTDB_VALID_CA) || CERT_IsCACert(cert, NULL))
45 return net::CA_CERT;
46 // TODO(mattm): http://crbug.com/128633.
47 if (trust.sslFlags & CERTDB_TERMINAL_RECORD)
48 return net::SERVER_CERT;
49 return net::UNKNOWN_CERT;
50 }
51 #else
52 net::CertType GetCertType(net::X509Certificate::OSCertHandle cert) {
53 NOTIMPLEMENTED();
54 return net::UNKNOWN_CERT;
55 }
56 #endif // USE_NSS
57
37 class ONCCertificateImporterTest : public testing::Test { 58 class ONCCertificateImporterTest : public testing::Test {
38 public: 59 public:
39 virtual void SetUp() { 60 virtual void SetUp() {
40 ASSERT_TRUE(test_nssdb_.is_open()); 61 ASSERT_TRUE(test_nssdb_.is_open());
41 62
42 slot_ = net::NSSCertDatabase::GetInstance()->GetPublicModule(); 63 slot_ = net::NSSCertDatabase::GetInstance()->GetPublicModule();
43 64
44 // Don't run the test if the setup failed. 65 // Don't run the test if the setup failed.
45 ASSERT_TRUE(slot_->os_module_handle()); 66 ASSERT_TRUE(slot_->os_module_handle());
46 67
(...skipping 14 matching lines...) Expand all
61 std::string* guid) { 82 std::string* guid) {
62 scoped_ptr<base::DictionaryValue> onc = 83 scoped_ptr<base::DictionaryValue> onc =
63 test_utils::ReadTestDictionary(filename); 84 test_utils::ReadTestDictionary(filename);
64 base::ListValue* certificates; 85 base::ListValue* certificates;
65 onc->GetListWithoutPathExpansion(kCertificates, &certificates); 86 onc->GetListWithoutPathExpansion(kCertificates, &certificates);
66 87
67 base::DictionaryValue* certificate; 88 base::DictionaryValue* certificate;
68 certificates->GetDictionary(0, &certificate); 89 certificates->GetDictionary(0, &certificate);
69 certificate->GetStringWithoutPathExpansion(kGUID, guid); 90 certificate->GetStringWithoutPathExpansion(kGUID, guid);
70 91
71 CertificateImporter importer(NetworkUIData::ONC_SOURCE_USER_IMPORT, 92 CertificateImporter importer(ONC_SOURCE_USER_IMPORT,
72 false /* don't allow webtrust */); 93 false /* don't allow web trust */);
73 std::string error; 94 EXPECT_EQ(CertificateImporter::IMPORT_OK,
74 EXPECT_TRUE(importer.ParseAndStoreCertificates(*certificates, &error)); 95 importer.ParseAndStoreCertificates(*certificates));
75 EXPECT_TRUE(error.empty());
76 96
77 net::CertificateList result_list; 97 net::CertificateList result_list;
78 CertificateImporter::ListCertsWithNickname(*guid, &result_list); 98 CertificateImporter::ListCertsWithNickname(*guid, &result_list);
79 ASSERT_EQ(1ul, result_list.size()); 99 ASSERT_EQ(1ul, result_list.size());
80 EXPECT_EQ(expected_type, GetCertType(result_list[0].get())); 100 EXPECT_EQ(expected_type, GetCertType(result_list[0]->os_cert_handle()));
81 } 101 }
82 102
83 scoped_refptr<net::CryptoModule> slot_; 103 scoped_refptr<net::CryptoModule> slot_;
84 104
85 private: 105 private:
86 net::CertificateList ListCertsInSlot(PK11SlotInfo* slot) { 106 net::CertificateList ListCertsInSlot(PK11SlotInfo* slot) {
87 net::CertificateList result; 107 net::CertificateList result;
88 CERTCertList* cert_list = PK11_ListCertsInSlot(slot); 108 CERTCertList* cert_list = PK11_ListCertsInSlot(slot);
89 for (CERTCertListNode* node = CERT_LIST_HEAD(cert_list); 109 for (CERTCertListNode* node = CERT_LIST_HEAD(cert_list);
90 !CERT_LIST_END(node, cert_list); 110 !CERT_LIST_END(node, cert_list);
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
232 std::make_pair(net::SERVER_CERT, 252 std::make_pair(net::SERVER_CERT,
233 std::make_pair("certificate-server.onc", 253 std::make_pair("certificate-server.onc",
234 "certificate-server-update.onc")), 254 "certificate-server-update.onc")),
235 std::make_pair( 255 std::make_pair(
236 net::CA_CERT, 256 net::CA_CERT,
237 std::make_pair("certificate-web-authority.onc", 257 std::make_pair("certificate-web-authority.onc",
238 "certificate-web-authority-update.onc")))); 258 "certificate-web-authority-update.onc"))));
239 259
240 } // namespace onc 260 } // namespace onc
241 } // namespace chromeos 261 } // namespace chromeos
OLDNEW
« no previous file with comments | « chromeos/network/onc/onc_certificate_importer.cc ('k') | chromeos/network/onc/onc_constants.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698