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

Side by Side Diff: net/cert/caching_cert_verifier_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/base/upload_file_element_reader_unittest.cc ('k') | net/cert/cert_verify_proc_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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 "net/cert/caching_cert_verifier.h" 5 #include "net/cert/caching_cert_verifier.h"
6 6
7 #include <memory> 7 #include <memory>
8 8
9 #include "base/files/file_path.h" 9 #include "base/files/file_path.h"
10 #include "base/memory/ptr_util.h" 10 #include "base/memory/ptr_util.h"
11 #include "base/memory/ref_counted.h" 11 #include "base/memory/ref_counted.h"
12 #include "net/base/net_errors.h" 12 #include "net/base/net_errors.h"
13 #include "net/base/test_completion_callback.h" 13 #include "net/base/test_completion_callback.h"
14 #include "net/cert/cert_verifier.h" 14 #include "net/cert/cert_verifier.h"
15 #include "net/cert/cert_verify_result.h" 15 #include "net/cert/cert_verify_result.h"
16 #include "net/cert/mock_cert_verifier.h" 16 #include "net/cert/mock_cert_verifier.h"
17 #include "net/cert/x509_certificate.h" 17 #include "net/cert/x509_certificate.h"
18 #include "net/log/net_log.h" 18 #include "net/log/net_log.h"
19 #include "net/test/cert_test_util.h" 19 #include "net/test/cert_test_util.h"
20 #include "net/test/gtest_util.h"
20 #include "net/test/test_data_directory.h" 21 #include "net/test/test_data_directory.h"
21 #include "testing/gmock/include/gmock/gmock.h" 22 #include "testing/gmock/include/gmock/gmock.h"
22 #include "testing/gtest/include/gtest/gtest.h" 23 #include "testing/gtest/include/gtest/gtest.h"
23 24
25 using net::test::IsError;
26 using net::test::IsOk;
27
24 using testing::_; 28 using testing::_;
25 using testing::Mock; 29 using testing::Mock;
26 using testing::Return; 30 using testing::Return;
27 using testing::ReturnRef; 31 using testing::ReturnRef;
28 32
29 namespace net { 33 namespace net {
30 34
31 namespace { 35 namespace {
32 36
33 class MockCacheVisitor : public CachingCertVerifier::CacheVisitor { 37 class MockCacheVisitor : public CachingCertVerifier::CacheVisitor {
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
181 ASSERT_EQ(0u, verifier_.cache_hits()); 185 ASSERT_EQ(0u, verifier_.cache_hits());
182 ASSERT_EQ(1u, verifier_.GetCacheSize()); 186 ASSERT_EQ(1u, verifier_.GetCacheSize());
183 187
184 TestCompletionCallback callback; 188 TestCompletionCallback callback;
185 std::unique_ptr<CertVerifier::Request> request; 189 std::unique_ptr<CertVerifier::Request> request;
186 190
187 CertVerifyResult cached_result; 191 CertVerifyResult cached_result;
188 int error = callback.GetResult( 192 int error = callback.GetResult(
189 verifier_.Verify(params, nullptr, &cached_result, callback.callback(), 193 verifier_.Verify(params, nullptr, &cached_result, callback.callback(),
190 &request, BoundNetLog())); 194 &request, BoundNetLog()));
191 ASSERT_EQ(ERR_CERT_WEAK_KEY, error); 195 ASSERT_THAT(error, IsError(ERR_CERT_WEAK_KEY));
192 EXPECT_TRUE(cached_result.has_md2); 196 EXPECT_TRUE(cached_result.has_md2);
193 EXPECT_FALSE(cached_result.is_issued_by_known_root); 197 EXPECT_FALSE(cached_result.is_issued_by_known_root);
194 198
195 ASSERT_EQ(1u, verifier_.requests()); 199 ASSERT_EQ(1u, verifier_.requests());
196 ASSERT_EQ(1u, verifier_.cache_hits()); 200 ASSERT_EQ(1u, verifier_.cache_hits());
197 ASSERT_EQ(1u, verifier_.GetCacheSize()); 201 ASSERT_EQ(1u, verifier_.GetCacheSize());
198 202
199 // But it should not be fine to replace it with an existing entry, even 203 // But it should not be fine to replace it with an existing entry, even
200 // if that entry is 'newer'. 204 // if that entry is 'newer'.
201 EXPECT_FALSE(verifier_.AddEntry(params, OK, result_2, 205 EXPECT_FALSE(verifier_.AddEntry(params, OK, result_2,
202 now + base::TimeDelta::FromMinutes(1))); 206 now + base::TimeDelta::FromMinutes(1)));
203 207
204 error = callback.GetResult(verifier_.Verify(params, nullptr, &cached_result, 208 error = callback.GetResult(verifier_.Verify(params, nullptr, &cached_result,
205 callback.callback(), &request, 209 callback.callback(), &request,
206 BoundNetLog())); 210 BoundNetLog()));
207 ASSERT_EQ(ERR_CERT_WEAK_KEY, error); 211 ASSERT_THAT(error, IsError(ERR_CERT_WEAK_KEY));
208 EXPECT_TRUE(cached_result.has_md2); 212 EXPECT_TRUE(cached_result.has_md2);
209 EXPECT_FALSE(cached_result.is_issued_by_known_root); 213 EXPECT_FALSE(cached_result.is_issued_by_known_root);
210 214
211 ASSERT_EQ(2u, verifier_.requests()); 215 ASSERT_EQ(2u, verifier_.requests());
212 ASSERT_EQ(2u, verifier_.cache_hits()); 216 ASSERT_EQ(2u, verifier_.cache_hits());
213 ASSERT_EQ(1u, verifier_.GetCacheSize()); 217 ASSERT_EQ(1u, verifier_.GetCacheSize());
214 } 218 }
215 219
216 // Tests the same server certificate with different intermediate CA 220 // Tests the same server certificate with different intermediate CA
217 // certificates. These should be treated as different certificate chains even 221 // certificates. These should be treated as different certificate chains even
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
263 CertVerifier::RequestParams(cert_chain2, "www.example.com", 0, 267 CertVerifier::RequestParams(cert_chain2, "www.example.com", 0,
264 std::string(), CertificateList()), 268 std::string(), CertificateList()),
265 nullptr, &verify_result, callback.callback(), &request, BoundNetLog())); 269 nullptr, &verify_result, callback.callback(), &request, BoundNetLog()));
266 ASSERT_TRUE(IsCertificateError(error)); 270 ASSERT_TRUE(IsCertificateError(error));
267 ASSERT_EQ(2u, verifier_.requests()); 271 ASSERT_EQ(2u, verifier_.requests());
268 ASSERT_EQ(0u, verifier_.cache_hits()); 272 ASSERT_EQ(0u, verifier_.cache_hits());
269 ASSERT_EQ(2u, verifier_.GetCacheSize()); 273 ASSERT_EQ(2u, verifier_.GetCacheSize());
270 } 274 }
271 275
272 } // namespace net 276 } // namespace net
OLDNEW
« no previous file with comments | « net/base/upload_file_element_reader_unittest.cc ('k') | net/cert/cert_verify_proc_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698