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

Side by Side Diff: chrome/common/net/x509_certificate_model_unittest.cc

Issue 288053003: x509_certificate_model_openssl: implement GetCertNameOrNickname, GetTitle (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: exclude unittest on android too Created 6 years, 7 months 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 | « chrome/common/net/x509_certificate_model_openssl.cc ('k') | no next file » | 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/common/net/x509_certificate_model.h" 5 #include "chrome/common/net/x509_certificate_model.h"
6 6
7 #include "base/files/file_path.h" 7 #include "base/files/file_path.h"
8 #include "base/path_service.h" 8 #include "base/path_service.h"
9 #include "net/base/test_data_directory.h" 9 #include "net/base/test_data_directory.h"
10 #include "net/test/cert_test_util.h" 10 #include "net/test/cert_test_util.h"
11 #include "testing/gtest/include/gtest/gtest.h" 11 #include "testing/gtest/include/gtest/gtest.h"
12 12
13 #if defined(USE_NSS) 13 #if defined(USE_NSS)
14 #include "net/cert/nss_cert_database.h" 14 #include "net/cert/nss_cert_database.h"
15 #endif 15 #endif
16 16
17 TEST(X509CertificateModelTest, GetCertNameOrNicknameAndGetTitle) {
18 scoped_refptr<net::X509Certificate> cert(
19 net::ImportCertFromFile(net::GetTestCertsDirectory(),
20 "root_ca_cert.pem"));
21 ASSERT_TRUE(cert.get());
22 EXPECT_EQ(
23 "Test Root CA",
24 x509_certificate_model::GetCertNameOrNickname(cert->os_cert_handle()));
25
26 scoped_refptr<net::X509Certificate> punycode_cert(
27 net::ImportCertFromFile(net::GetTestCertsDirectory(),
28 "punycodetest.der"));
29 ASSERT_TRUE(punycode_cert.get());
30 EXPECT_EQ("xn--wgv71a119e.com (日本語.com)",
31 x509_certificate_model::GetCertNameOrNickname(
32 punycode_cert->os_cert_handle()));
33
34 scoped_refptr<net::X509Certificate> no_cn_cert(
35 net::ImportCertFromFile(net::GetTestCertsDirectory(),
36 "no_subject_common_name_cert.pem"));
37 ASSERT_TRUE(no_cn_cert.get());
38 #if defined(USE_OPENSSL)
39 EXPECT_EQ("emailAddress=wtc@google.com",
40 x509_certificate_model::GetCertNameOrNickname(
41 no_cn_cert->os_cert_handle()));
42 #else
43 // Temp cert has no nickname.
44 EXPECT_EQ("",
45 x509_certificate_model::GetCertNameOrNickname(
46 no_cn_cert->os_cert_handle()));
47 #endif
48
49 EXPECT_EQ("xn--wgv71a119e.com",
50 x509_certificate_model::GetTitle(
51 punycode_cert->os_cert_handle()));
52
53 #if defined(USE_OPENSSL)
54 EXPECT_EQ("emailAddress=wtc@google.com",
55 x509_certificate_model::GetTitle(
56 no_cn_cert->os_cert_handle()));
57 #else
58 EXPECT_EQ("E=wtc@google.com",
59 x509_certificate_model::GetTitle(
60 no_cn_cert->os_cert_handle()));
61 #endif
62
63 scoped_refptr<net::X509Certificate> no_cn_cert2(net::ImportCertFromFile(
64 net::GetTestCertsDirectory(), "ct-test-embedded-cert.pem"));
65 ASSERT_TRUE(no_cn_cert2.get());
66 EXPECT_EQ("L=Erw Wen,ST=Wales,O=Certificate Transparency,C=GB",
67 x509_certificate_model::GetTitle(no_cn_cert2->os_cert_handle()));
68 }
69
17 TEST(X509CertificateModelTest, GetTypeCA) { 70 TEST(X509CertificateModelTest, GetTypeCA) {
18 scoped_refptr<net::X509Certificate> cert( 71 scoped_refptr<net::X509Certificate> cert(
19 net::ImportCertFromFile(net::GetTestCertsDirectory(), 72 net::ImportCertFromFile(net::GetTestCertsDirectory(),
20 "root_ca_cert.pem")); 73 "root_ca_cert.pem"));
21 ASSERT_TRUE(cert.get()); 74 ASSERT_TRUE(cert.get());
22 75
23 #if defined(USE_OPENSSL) 76 #if defined(USE_OPENSSL)
24 // Remove this when OpenSSL build implements the necessary functions. 77 // Remove this when OpenSSL build implements the necessary functions.
25 EXPECT_EQ(net::OTHER_CERT, 78 EXPECT_EQ(net::OTHER_CERT,
26 x509_certificate_model::GetType(cert->os_cert_handle())); 79 x509_certificate_model::GetType(cert->os_cert_handle()));
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 // An X.509 v1 certificate with the version field omitted should get 129 // An X.509 v1 certificate with the version field omitted should get
77 // the default value v1. 130 // the default value v1.
78 TEST(X509CertificateModelTest, GetVersionOmitted) { 131 TEST(X509CertificateModelTest, GetVersionOmitted) {
79 scoped_refptr<net::X509Certificate> cert( 132 scoped_refptr<net::X509Certificate> cert(
80 net::ImportCertFromFile(net::GetTestCertsDirectory(), 133 net::ImportCertFromFile(net::GetTestCertsDirectory(),
81 "ndn.ca.crt")); 134 "ndn.ca.crt"));
82 ASSERT_TRUE(cert.get()); 135 ASSERT_TRUE(cert.get());
83 136
84 EXPECT_EQ("1", x509_certificate_model::GetVersion(cert->os_cert_handle())); 137 EXPECT_EQ("1", x509_certificate_model::GetVersion(cert->os_cert_handle()));
85 } 138 }
OLDNEW
« no previous file with comments | « chrome/common/net/x509_certificate_model_openssl.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698