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

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

Issue 2109503009: Refactor net tests to use GMock matchers for checking net::Error results (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Revert changes to contents.txt files Created 4 years, 5 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
« no previous file with comments | « net/cert/nss_cert_database_unittest.cc ('k') | net/cert_net/cert_net_fetcher_impl_unittest.cc » ('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 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/cert/cert_status_flags.h" 8 #include "net/cert/cert_status_flags.h"
9 #include "net/cert/cert_verify_proc.h" 9 #include "net/cert/cert_verify_proc.h"
10 #include "net/cert/cert_verify_result.h" 10 #include "net/cert/cert_verify_result.h"
11 #include "net/cert/test_root_certs.h" 11 #include "net/cert/test_root_certs.h"
12 #include "net/cert/x509_certificate.h" 12 #include "net/cert/x509_certificate.h"
13 #include "net/test/cert_test_util.h" 13 #include "net/test/cert_test_util.h"
14 #include "net/test/gtest_util.h"
14 #include "net/test/test_data_directory.h" 15 #include "net/test/test_data_directory.h"
16 #include "testing/gmock/include/gmock/gmock.h"
15 #include "testing/gtest/include/gtest/gtest.h" 17 #include "testing/gtest/include/gtest/gtest.h"
16 18
17 #if defined(USE_NSS_CERTS) 19 #if defined(USE_NSS_CERTS)
18 #include <nss.h> 20 #include <nss.h>
19 #endif 21 #endif
20 22
23 using net::test::IsOk;
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 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 EXPECT_TRUE(test_roots->AddFromFile( 102 EXPECT_TRUE(test_roots->AddFromFile(
99 GetTestCertsDirectory().AppendASCII(kRootCertificateFile))); 103 GetTestCertsDirectory().AppendASCII(kRootCertificateFile)));
100 EXPECT_FALSE(test_roots->IsEmpty()); 104 EXPECT_FALSE(test_roots->IsEmpty());
101 105
102 // Test that the certificate verification now succeeds, because the 106 // Test that the certificate verification now succeeds, because the
103 // TestRootCerts is successfully imbuing trust. 107 // TestRootCerts is successfully imbuing trust.
104 CertVerifyResult good_verify_result; 108 CertVerifyResult good_verify_result;
105 int good_status = 109 int good_status =
106 verify_proc->Verify(test_cert.get(), "127.0.0.1", std::string(), flags, 110 verify_proc->Verify(test_cert.get(), "127.0.0.1", std::string(), flags,
107 NULL, CertificateList(), &good_verify_result); 111 NULL, CertificateList(), &good_verify_result);
108 EXPECT_EQ(OK, good_status); 112 EXPECT_THAT(good_status, IsOk());
109 EXPECT_EQ(0u, good_verify_result.cert_status); 113 EXPECT_EQ(0u, good_verify_result.cert_status);
110 114
111 test_roots->Clear(); 115 test_roots->Clear();
112 EXPECT_TRUE(test_roots->IsEmpty()); 116 EXPECT_TRUE(test_roots->IsEmpty());
113 117
114 // Ensure that when the TestRootCerts is cleared, the trust settings 118 // Ensure that when the TestRootCerts is cleared, the trust settings
115 // revert to their original state, and don't linger. If trust status 119 // revert to their original state, and don't linger. If trust status
116 // lingers, it will likely break other tests in net_unittests. 120 // lingers, it will likely break other tests in net_unittests.
117 CertVerifyResult restored_verify_result; 121 CertVerifyResult restored_verify_result;
118 int restored_status = 122 int restored_status =
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 EXPECT_FALSE(test_roots->Contains(root_cert_1->os_cert_handle())); 161 EXPECT_FALSE(test_roots->Contains(root_cert_1->os_cert_handle()));
158 EXPECT_FALSE(test_roots->Contains(root_cert_2->os_cert_handle())); 162 EXPECT_FALSE(test_roots->Contains(root_cert_2->os_cert_handle()));
159 } 163 }
160 #endif 164 #endif
161 165
162 // TODO(rsleevi): Add tests for revocation checking via CRLs, ensuring that 166 // TODO(rsleevi): Add tests for revocation checking via CRLs, ensuring that
163 // TestRootCerts properly injects itself into the validation process. See 167 // TestRootCerts properly injects itself into the validation process. See
164 // http://crbug.com/63958 168 // http://crbug.com/63958
165 169
166 } // namespace net 170 } // namespace net
OLDNEW
« no previous file with comments | « net/cert/nss_cert_database_unittest.cc ('k') | net/cert_net/cert_net_fetcher_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698