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

Side by Side Diff: net/ocsp/nss_ocsp_unittest.cc

Issue 300693005: Make URLRequestFilter use URLRequestInterceptors. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix merge Created 6 years, 6 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 (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 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 "net/ocsp/nss_ocsp.h" 5 #include "net/ocsp/nss_ocsp.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/file_util.h" 9 #include "base/file_util.h"
10 #include "base/files/file_path.h" 10 #include "base/files/file_path.h"
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "base/memory/ref_counted.h" 12 #include "base/memory/ref_counted.h"
13 #include "net/base/net_errors.h" 13 #include "net/base/net_errors.h"
14 #include "net/base/test_completion_callback.h" 14 #include "net/base/test_completion_callback.h"
15 #include "net/base/test_data_directory.h" 15 #include "net/base/test_data_directory.h"
16 #include "net/cert/cert_status_flags.h" 16 #include "net/cert/cert_status_flags.h"
17 #include "net/cert/cert_verifier.h" 17 #include "net/cert/cert_verifier.h"
18 #include "net/cert/cert_verify_proc.h" 18 #include "net/cert/cert_verify_proc.h"
19 #include "net/cert/cert_verify_proc_nss.h" 19 #include "net/cert/cert_verify_proc_nss.h"
20 #include "net/cert/cert_verify_result.h" 20 #include "net/cert/cert_verify_result.h"
21 #include "net/cert/multi_threaded_cert_verifier.h" 21 #include "net/cert/multi_threaded_cert_verifier.h"
22 #include "net/cert/test_root_certs.h" 22 #include "net/cert/test_root_certs.h"
23 #include "net/cert/x509_certificate.h" 23 #include "net/cert/x509_certificate.h"
24 #include "net/test/cert_test_util.h" 24 #include "net/test/cert_test_util.h"
25 #include "net/url_request/url_request_filter.h" 25 #include "net/url_request/url_request_filter.h"
26 #include "net/url_request/url_request_interceptor.h"
26 #include "net/url_request/url_request_test_job.h" 27 #include "net/url_request/url_request_test_job.h"
27 #include "net/url_request/url_request_test_util.h" 28 #include "net/url_request/url_request_test_util.h"
28 #include "testing/gtest/include/gtest/gtest.h" 29 #include "testing/gtest/include/gtest/gtest.h"
29 30
30 namespace net { 31 namespace net {
31 32
32 namespace { 33 namespace {
33 34
34 // Matches the caIssuers hostname from the generated certificate. 35 // Matches the caIssuers hostname from the generated certificate.
35 const char kAiaHost[] = "aia-test.invalid"; 36 const char kAiaHost[] = "aia-test.invalid";
36 // Returning a single DER-encoded cert, so the mime-type must be 37 // Returning a single DER-encoded cert, so the mime-type must be
37 // application/pkix-cert per RFC 5280. 38 // application/pkix-cert per RFC 5280.
38 const char kAiaHeaders[] = "HTTP/1.1 200 OK\0" 39 const char kAiaHeaders[] = "HTTP/1.1 200 OK\0"
39 "Content-type: application/pkix-cert\0" 40 "Content-type: application/pkix-cert\0"
40 "\0"; 41 "\0";
41 42
42 class AiaResponseHandler : public net::URLRequestJobFactory::ProtocolHandler { 43 class AiaResponseHandler : public net::URLRequestInterceptor {
43 public: 44 public:
44 AiaResponseHandler(const std::string& headers, const std::string& cert_data) 45 AiaResponseHandler(const std::string& headers, const std::string& cert_data)
45 : headers_(headers), cert_data_(cert_data), request_count_(0) {} 46 : headers_(headers), cert_data_(cert_data), request_count_(0) {}
46 virtual ~AiaResponseHandler() {} 47 virtual ~AiaResponseHandler() {}
47 48
48 // net::URLRequestJobFactory::ProtocolHandler implementation: 49 // net::URLRequestInterceptor implementation:
49 virtual net::URLRequestJob* MaybeCreateJob( 50 virtual net::URLRequestJob* MaybeInterceptRequest(
50 net::URLRequest* request, 51 net::URLRequest* request,
51 net::NetworkDelegate* network_delegate) const OVERRIDE { 52 net::NetworkDelegate* network_delegate) const OVERRIDE {
52 ++const_cast<AiaResponseHandler*>(this)->request_count_; 53 ++const_cast<AiaResponseHandler*>(this)->request_count_;
53 54
54 return new net::URLRequestTestJob( 55 return new net::URLRequestTestJob(
55 request, network_delegate, headers_, cert_data_, true); 56 request, network_delegate, headers_, cert_data_, true);
56 } 57 }
57 58
58 int request_count() const { return request_count_; } 59 int request_count() const { return request_count_; }
59 60
(...skipping 22 matching lines...) Expand all
82 GetTestCertsDirectory().AppendASCII("aia-intermediate.der"), 83 GetTestCertsDirectory().AppendASCII("aia-intermediate.der"),
83 &file_contents)); 84 &file_contents));
84 ASSERT_FALSE(file_contents.empty()); 85 ASSERT_FALSE(file_contents.empty());
85 86
86 // Ownership of |handler| is transferred to the URLRequestFilter, but 87 // Ownership of |handler| is transferred to the URLRequestFilter, but
87 // hold onto the original pointer in order to access |request_count()|. 88 // hold onto the original pointer in order to access |request_count()|.
88 scoped_ptr<AiaResponseHandler> handler( 89 scoped_ptr<AiaResponseHandler> handler(
89 new AiaResponseHandler(kAiaHeaders, file_contents)); 90 new AiaResponseHandler(kAiaHeaders, file_contents));
90 handler_ = handler.get(); 91 handler_ = handler.get();
91 92
92 URLRequestFilter::GetInstance()->AddHostnameProtocolHandler( 93 URLRequestFilter::GetInstance()->AddHostnameInterceptor(
93 "http", 94 "http",
94 kAiaHost, 95 kAiaHost,
95 handler.PassAs<URLRequestJobFactory::ProtocolHandler>()); 96 handler.PassAs<URLRequestInterceptor>());
96 97
97 SetURLRequestContextForNSSHttpIO(&context_); 98 SetURLRequestContextForNSSHttpIO(&context_);
98 EnsureNSSHttpIOInit(); 99 EnsureNSSHttpIOInit();
99 } 100 }
100 101
101 virtual void TearDown() { 102 virtual void TearDown() {
102 ShutdownNSSHttpIO(); 103 ShutdownNSSHttpIO();
103 104
104 if (handler_) 105 if (handler_)
105 URLRequestFilter::GetInstance()->RemoveHostnameHandler("http", kAiaHost); 106 URLRequestFilter::GetInstance()->RemoveHostnameHandler("http", kAiaHost);
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 155
155 error = test_callback.WaitForResult(); 156 error = test_callback.WaitForResult();
156 157
157 EXPECT_EQ(OK, error); 158 EXPECT_EQ(OK, error);
158 159
159 // Ensure that NSS made an AIA request for the missing intermediate. 160 // Ensure that NSS made an AIA request for the missing intermediate.
160 EXPECT_LT(0, request_count()); 161 EXPECT_LT(0, request_count());
161 } 162 }
162 163
163 } // namespace net 164 } // namespace net
OLDNEW
« no previous file with comments | « content/test/net/url_request_prepackaged_interceptor.cc ('k') | net/url_request/url_request_filter.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698