| OLD | NEW |
| 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/files/file_path.h" | 9 #include "base/files/file_path.h" |
| 10 #include "base/files/file_util.h" | 10 #include "base/files/file_util.h" |
| (...skipping 26 matching lines...) Expand all Loading... |
| 37 // 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 |
| 38 // application/pkix-cert per RFC 5280. | 38 // application/pkix-cert per RFC 5280. |
| 39 const char kAiaHeaders[] = "HTTP/1.1 200 OK\0" | 39 const char kAiaHeaders[] = "HTTP/1.1 200 OK\0" |
| 40 "Content-type: application/pkix-cert\0" | 40 "Content-type: application/pkix-cert\0" |
| 41 "\0"; | 41 "\0"; |
| 42 | 42 |
| 43 class AiaResponseHandler : public net::URLRequestInterceptor { | 43 class AiaResponseHandler : public net::URLRequestInterceptor { |
| 44 public: | 44 public: |
| 45 AiaResponseHandler(const std::string& headers, const std::string& cert_data) | 45 AiaResponseHandler(const std::string& headers, const std::string& cert_data) |
| 46 : headers_(headers), cert_data_(cert_data), request_count_(0) {} | 46 : headers_(headers), cert_data_(cert_data), request_count_(0) {} |
| 47 virtual ~AiaResponseHandler() {} | 47 ~AiaResponseHandler() override {} |
| 48 | 48 |
| 49 // net::URLRequestInterceptor implementation: | 49 // net::URLRequestInterceptor implementation: |
| 50 virtual net::URLRequestJob* MaybeInterceptRequest( | 50 net::URLRequestJob* MaybeInterceptRequest( |
| 51 net::URLRequest* request, | 51 net::URLRequest* request, |
| 52 net::NetworkDelegate* network_delegate) const override { | 52 net::NetworkDelegate* network_delegate) const override { |
| 53 ++const_cast<AiaResponseHandler*>(this)->request_count_; | 53 ++const_cast<AiaResponseHandler*>(this)->request_count_; |
| 54 | 54 |
| 55 return new net::URLRequestTestJob( | 55 return new net::URLRequestTestJob( |
| 56 request, network_delegate, headers_, cert_data_, true); | 56 request, network_delegate, headers_, cert_data_, true); |
| 57 } | 57 } |
| 58 | 58 |
| 59 int request_count() const { return request_count_; } | 59 int request_count() const { return request_count_; } |
| 60 | 60 |
| 61 private: | 61 private: |
| 62 std::string headers_; | 62 std::string headers_; |
| 63 std::string cert_data_; | 63 std::string cert_data_; |
| 64 int request_count_; | 64 int request_count_; |
| 65 | 65 |
| 66 DISALLOW_COPY_AND_ASSIGN(AiaResponseHandler); | 66 DISALLOW_COPY_AND_ASSIGN(AiaResponseHandler); |
| 67 }; | 67 }; |
| 68 | 68 |
| 69 } // namespace | 69 } // namespace |
| 70 | 70 |
| 71 class NssHttpTest : public ::testing::Test { | 71 class NssHttpTest : public ::testing::Test { |
| 72 public: | 72 public: |
| 73 NssHttpTest() | 73 NssHttpTest() |
| 74 : context_(false), | 74 : context_(false), |
| 75 handler_(NULL), | 75 handler_(NULL), |
| 76 verify_proc_(new CertVerifyProcNSS), | 76 verify_proc_(new CertVerifyProcNSS), |
| 77 verifier_(new MultiThreadedCertVerifier(verify_proc_.get())) {} | 77 verifier_(new MultiThreadedCertVerifier(verify_proc_.get())) {} |
| 78 virtual ~NssHttpTest() {} | 78 ~NssHttpTest() override {} |
| 79 | 79 |
| 80 virtual void SetUp() { | 80 void SetUp() override { |
| 81 std::string file_contents; | 81 std::string file_contents; |
| 82 ASSERT_TRUE(base::ReadFileToString( | 82 ASSERT_TRUE(base::ReadFileToString( |
| 83 GetTestCertsDirectory().AppendASCII("aia-intermediate.der"), | 83 GetTestCertsDirectory().AppendASCII("aia-intermediate.der"), |
| 84 &file_contents)); | 84 &file_contents)); |
| 85 ASSERT_FALSE(file_contents.empty()); | 85 ASSERT_FALSE(file_contents.empty()); |
| 86 | 86 |
| 87 // Ownership of |handler| is transferred to the URLRequestFilter, but | 87 // Ownership of |handler| is transferred to the URLRequestFilter, but |
| 88 // hold onto the original pointer in order to access |request_count()|. | 88 // hold onto the original pointer in order to access |request_count()|. |
| 89 scoped_ptr<AiaResponseHandler> handler( | 89 scoped_ptr<AiaResponseHandler> handler( |
| 90 new AiaResponseHandler(kAiaHeaders, file_contents)); | 90 new AiaResponseHandler(kAiaHeaders, file_contents)); |
| 91 handler_ = handler.get(); | 91 handler_ = handler.get(); |
| 92 | 92 |
| 93 URLRequestFilter::GetInstance()->AddHostnameInterceptor( | 93 URLRequestFilter::GetInstance()->AddHostnameInterceptor( |
| 94 "http", kAiaHost, handler.Pass()); | 94 "http", kAiaHost, handler.Pass()); |
| 95 | 95 |
| 96 SetURLRequestContextForNSSHttpIO(&context_); | 96 SetURLRequestContextForNSSHttpIO(&context_); |
| 97 EnsureNSSHttpIOInit(); | 97 EnsureNSSHttpIOInit(); |
| 98 } | 98 } |
| 99 | 99 |
| 100 virtual void TearDown() { | 100 void TearDown() override { |
| 101 ShutdownNSSHttpIO(); | 101 ShutdownNSSHttpIO(); |
| 102 | 102 |
| 103 if (handler_) | 103 if (handler_) |
| 104 URLRequestFilter::GetInstance()->RemoveHostnameHandler("http", kAiaHost); | 104 URLRequestFilter::GetInstance()->RemoveHostnameHandler("http", kAiaHost); |
| 105 } | 105 } |
| 106 | 106 |
| 107 CertVerifier* verifier() const { | 107 CertVerifier* verifier() const { |
| 108 return verifier_.get(); | 108 return verifier_.get(); |
| 109 } | 109 } |
| 110 | 110 |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 153 | 153 |
| 154 error = test_callback.WaitForResult(); | 154 error = test_callback.WaitForResult(); |
| 155 | 155 |
| 156 EXPECT_EQ(OK, error); | 156 EXPECT_EQ(OK, error); |
| 157 | 157 |
| 158 // Ensure that NSS made an AIA request for the missing intermediate. | 158 // Ensure that NSS made an AIA request for the missing intermediate. |
| 159 EXPECT_LT(0, request_count()); | 159 EXPECT_LT(0, request_count()); |
| 160 } | 160 } |
| 161 | 161 |
| 162 } // namespace net | 162 } // namespace net |
| OLD | NEW |