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

Side by Side Diff: net/cert/test_root_certs_unittest.cc

Issue 137553004: NSS Cros multiprofile: trust roots added by a profile shouldn't apply to other profiles. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: update ProfileIOData comment Created 6 years, 10 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
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "base/files/file_path.h" 5 #include "base/files/file_path.h"
6 #include "build/build_config.h" 6 #include "build/build_config.h"
7 #include "net/base/net_errors.h" 7 #include "net/base/net_errors.h"
8 #include "net/base/test_data_directory.h" 8 #include "net/base/test_data_directory.h"
9 #include "net/cert/cert_status_flags.h" 9 #include "net/cert/cert_status_flags.h"
10 #include "net/cert/cert_verify_proc.h" 10 #include "net/cert/cert_verify_proc.h"
11 #include "net/cert/cert_verify_result.h" 11 #include "net/cert/cert_verify_result.h"
12 #include "net/cert/test_root_certs.h" 12 #include "net/cert/test_root_certs.h"
13 #include "net/cert/x509_certificate.h" 13 #include "net/cert/x509_certificate.h"
14 #include "net/test/cert_test_util.h" 14 #include "net/test/cert_test_util.h"
15 #include "testing/gtest/include/gtest/gtest.h" 15 #include "testing/gtest/include/gtest/gtest.h"
16 16
17 #if defined(USE_NSS) || defined(OS_IOS) 17 #if defined(USE_NSS) || defined(OS_IOS)
18 #include <nss.h> 18 #include <nss.h>
19 #endif 19 #endif
20 20
21 #if defined(OS_IOS)
22 #include "net/cert/x509_util_ios.h"
23 #endif
24
21 namespace net { 25 namespace net {
22 26
23 namespace { 27 namespace {
24 28
25 // The local test root certificate. 29 // The local test root certificate.
26 const char kRootCertificateFile[] = "root_ca_cert.pem"; 30 const char kRootCertificateFile[] = "root_ca_cert.pem";
27 // A certificate issued by the local test root for 127.0.0.1. 31 // A certificate issued by the local test root for 127.0.0.1.
28 const char kGoodCertificateFile[] = "ok_cert.pem"; 32 const char kGoodCertificateFile[] = "ok_cert.pem";
29 33
30 } // namespace 34 } // namespace
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 NULL, 132 NULL,
129 CertificateList(), 133 CertificateList(),
130 &restored_verify_result); 134 &restored_verify_result);
131 EXPECT_NE(OK, restored_status); 135 EXPECT_NE(OK, restored_status);
132 EXPECT_NE(0u, 136 EXPECT_NE(0u,
133 restored_verify_result.cert_status & CERT_STATUS_AUTHORITY_INVALID); 137 restored_verify_result.cert_status & CERT_STATUS_AUTHORITY_INVALID);
134 EXPECT_EQ(bad_status, restored_status); 138 EXPECT_EQ(bad_status, restored_status);
135 EXPECT_EQ(bad_verify_result.cert_status, restored_verify_result.cert_status); 139 EXPECT_EQ(bad_verify_result.cert_status, restored_verify_result.cert_status);
136 } 140 }
137 141
142 #if defined(USE_NSS) || defined(OS_IOS) || \
143 (defined(USE_OPENSSL) && !defined(OS_ANDROID))
144 TEST(TestRootCertsTest, Contains) {
145 // Another test root certificate.
146 const char kRootCertificateFile2[] = "2048-rsa-root.pem";
147
148 TestRootCerts* test_roots = TestRootCerts::GetInstance();
149 ASSERT_NE(static_cast<TestRootCerts*>(NULL), test_roots);
150
151 scoped_refptr<X509Certificate> root_cert_1 =
152 ImportCertFromFile(GetTestCertsDirectory(), kRootCertificateFile);
153 ASSERT_NE(static_cast<X509Certificate*>(NULL), root_cert_1.get());
154
155 scoped_refptr<X509Certificate> root_cert_2 =
156 ImportCertFromFile(GetTestCertsDirectory(), kRootCertificateFile2);
157 ASSERT_NE(static_cast<X509Certificate*>(NULL), root_cert_2.get());
158
159 #if defined(OS_IOS)
160 x509_util_ios::NSSCertificate nss_certificate_1(
161 root_cert_1->os_cert_handle());
162 x509_util_ios::NSSCertificate nss_certificate_2(
163 root_cert_2->os_cert_handle());
164 CERTCertificate* handle_1 = nss_certificate_1.cert_handle();
165 CERTCertificate* handle_2 = nss_certificate_2.cert_handle();
166 #else
167 X509Certificate::OSCertHandle handle_1 = root_cert_1->os_cert_handle();
168 X509Certificate::OSCertHandle handle_2 = root_cert_2->os_cert_handle();
169 #endif
170
171 EXPECT_FALSE(test_roots->Contains(handle_1));
172 EXPECT_FALSE(test_roots->Contains(handle_2));
173
174 EXPECT_TRUE(test_roots->Add(root_cert_1.get()));
175 EXPECT_TRUE(test_roots->Contains(handle_1));
176 EXPECT_FALSE(test_roots->Contains(handle_2));
177
178 EXPECT_TRUE(test_roots->Add(root_cert_2.get()));
179 EXPECT_TRUE(test_roots->Contains(handle_1));
180 EXPECT_TRUE(test_roots->Contains(handle_2));
181
182 test_roots->Clear();
183 EXPECT_FALSE(test_roots->Contains(handle_1));
184 EXPECT_FALSE(test_roots->Contains(handle_2));
185 }
186 #endif
187
138 // TODO(rsleevi): Add tests for revocation checking via CRLs, ensuring that 188 // TODO(rsleevi): Add tests for revocation checking via CRLs, ensuring that
139 // TestRootCerts properly injects itself into the validation process. See 189 // TestRootCerts properly injects itself into the validation process. See
140 // http://crbug.com/63958 190 // http://crbug.com/63958
141 191
142 } // namespace net 192 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698