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/cert_net/nss_ocsp.h" | 5 #include "net/cert_net/nss_ocsp.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
81 | 81 |
82 void SetUp() override { | 82 void SetUp() override { |
83 std::string file_contents; | 83 std::string file_contents; |
84 ASSERT_TRUE(base::ReadFileToString( | 84 ASSERT_TRUE(base::ReadFileToString( |
85 GetTestCertsDirectory().AppendASCII("aia-intermediate.der"), | 85 GetTestCertsDirectory().AppendASCII("aia-intermediate.der"), |
86 &file_contents)); | 86 &file_contents)); |
87 ASSERT_FALSE(file_contents.empty()); | 87 ASSERT_FALSE(file_contents.empty()); |
88 | 88 |
89 // Ownership of |handler| is transferred to the URLRequestFilter, but | 89 // Ownership of |handler| is transferred to the URLRequestFilter, but |
90 // hold onto the original pointer in order to access |request_count()|. | 90 // hold onto the original pointer in order to access |request_count()|. |
91 scoped_ptr<AiaResponseHandler> handler( | 91 std::unique_ptr<AiaResponseHandler> handler( |
92 new AiaResponseHandler(kAiaHeaders, file_contents)); | 92 new AiaResponseHandler(kAiaHeaders, file_contents)); |
93 handler_ = handler.get(); | 93 handler_ = handler.get(); |
94 | 94 |
95 URLRequestFilter::GetInstance()->AddHostnameInterceptor("http", kAiaHost, | 95 URLRequestFilter::GetInstance()->AddHostnameInterceptor("http", kAiaHost, |
96 std::move(handler)); | 96 std::move(handler)); |
97 | 97 |
98 SetURLRequestContextForNSSHttpIO(&context_); | 98 SetURLRequestContextForNSSHttpIO(&context_); |
99 EnsureNSSHttpIOInit(); | 99 EnsureNSSHttpIOInit(); |
100 } | 100 } |
101 | 101 |
(...skipping 12 matching lines...) Expand all Loading... |
114 return handler_->request_count(); | 114 return handler_->request_count(); |
115 } | 115 } |
116 | 116 |
117 protected: | 117 protected: |
118 const CertificateList empty_cert_list_; | 118 const CertificateList empty_cert_list_; |
119 | 119 |
120 private: | 120 private: |
121 TestURLRequestContext context_; | 121 TestURLRequestContext context_; |
122 AiaResponseHandler* handler_; | 122 AiaResponseHandler* handler_; |
123 scoped_refptr<CertVerifyProc> verify_proc_; | 123 scoped_refptr<CertVerifyProc> verify_proc_; |
124 scoped_ptr<CertVerifier> verifier_; | 124 std::unique_ptr<CertVerifier> verifier_; |
125 }; | 125 }; |
126 | 126 |
127 // Tests that when using NSS to verify certificates, and IO is enabled, | 127 // Tests that when using NSS to verify certificates, and IO is enabled, |
128 // that a request to fetch missing intermediate certificates is | 128 // that a request to fetch missing intermediate certificates is |
129 // made successfully. | 129 // made successfully. |
130 TEST_F(NssHttpTest, TestAia) { | 130 TEST_F(NssHttpTest, TestAia) { |
131 scoped_refptr<X509Certificate> test_cert( | 131 scoped_refptr<X509Certificate> test_cert( |
132 ImportCertFromFile(GetTestCertsDirectory(), "aia-cert.pem")); | 132 ImportCertFromFile(GetTestCertsDirectory(), "aia-cert.pem")); |
133 ASSERT_TRUE(test_cert.get()); | 133 ASSERT_TRUE(test_cert.get()); |
134 | 134 |
135 scoped_refptr<X509Certificate> test_root( | 135 scoped_refptr<X509Certificate> test_root( |
136 ImportCertFromFile(GetTestCertsDirectory(), "aia-root.pem")); | 136 ImportCertFromFile(GetTestCertsDirectory(), "aia-root.pem")); |
137 ASSERT_TRUE(test_root.get()); | 137 ASSERT_TRUE(test_root.get()); |
138 | 138 |
139 ScopedTestRoot scoped_root(test_root.get()); | 139 ScopedTestRoot scoped_root(test_root.get()); |
140 | 140 |
141 CertVerifyResult verify_result; | 141 CertVerifyResult verify_result; |
142 TestCompletionCallback test_callback; | 142 TestCompletionCallback test_callback; |
143 scoped_ptr<CertVerifier::Request> request; | 143 std::unique_ptr<CertVerifier::Request> request; |
144 | 144 |
145 int flags = CertVerifier::VERIFY_CERT_IO_ENABLED; | 145 int flags = CertVerifier::VERIFY_CERT_IO_ENABLED; |
146 int error = verifier()->Verify( | 146 int error = verifier()->Verify( |
147 test_cert.get(), "aia-host.invalid", std::string(), flags, NULL, | 147 test_cert.get(), "aia-host.invalid", std::string(), flags, NULL, |
148 &verify_result, test_callback.callback(), &request, BoundNetLog()); | 148 &verify_result, test_callback.callback(), &request, BoundNetLog()); |
149 ASSERT_EQ(ERR_IO_PENDING, error); | 149 ASSERT_EQ(ERR_IO_PENDING, error); |
150 | 150 |
151 error = test_callback.WaitForResult(); | 151 error = test_callback.WaitForResult(); |
152 | 152 |
153 EXPECT_EQ(OK, error); | 153 EXPECT_EQ(OK, error); |
154 | 154 |
155 // Ensure that NSS made an AIA request for the missing intermediate. | 155 // Ensure that NSS made an AIA request for the missing intermediate. |
156 EXPECT_LT(0, request_count()); | 156 EXPECT_LT(0, request_count()); |
157 } | 157 } |
158 | 158 |
159 } // namespace net | 159 } // namespace net |
OLD | NEW |