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

Side by Side Diff: net/cert/internal/cert_issuer_source_aia_unittest.cc

Issue 2595723002: Allow CertNetFetcher to be shutdown from the network thread (Closed)
Patch Set: fix AIA tests Created 3 years, 11 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
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/internal/cert_issuer_source_aia.h" 5 #include "net/cert/internal/cert_issuer_source_aia.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/memory/ptr_util.h" 8 #include "base/memory/ptr_util.h"
9 #include "net/cert/cert_net_fetcher.h" 9 #include "net/cert/cert_net_fetcher.h"
10 #include "net/cert/internal/cert_errors.h" 10 #include "net/cert/internal/cert_errors.h"
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 std::vector<uint8_t> CertDataVector(const ParsedCertificate* cert) { 56 std::vector<uint8_t> CertDataVector(const ParsedCertificate* cert) {
57 std::vector<uint8_t> data( 57 std::vector<uint8_t> data(
58 cert->der_cert().UnsafeData(), 58 cert->der_cert().UnsafeData(),
59 cert->der_cert().UnsafeData() + cert->der_cert().Length()); 59 cert->der_cert().UnsafeData() + cert->der_cert().Length());
60 return data; 60 return data;
61 } 61 }
62 62
63 // MockCertNetFetcher is an implementation of CertNetFetcher for testing. 63 // MockCertNetFetcher is an implementation of CertNetFetcher for testing.
64 class MockCertNetFetcher : public CertNetFetcher { 64 class MockCertNetFetcher : public CertNetFetcher {
65 public: 65 public:
66 MockCertNetFetcher() {}
67 MOCK_METHOD0(Shutdown, void());
66 MOCK_METHOD3(FetchCaIssuers, 68 MOCK_METHOD3(FetchCaIssuers,
67 std::unique_ptr<Request>(const GURL& url, 69 std::unique_ptr<Request>(const GURL& url,
68 int timeout_milliseconds, 70 int timeout_milliseconds,
69 int max_response_bytes)); 71 int max_response_bytes));
70 MOCK_METHOD3(FetchCrl, 72 MOCK_METHOD3(FetchCrl,
71 std::unique_ptr<Request>(const GURL& url, 73 std::unique_ptr<Request>(const GURL& url,
72 int timeout_milliseconds, 74 int timeout_milliseconds,
73 int max_response_bytes)); 75 int max_response_bytes));
74 76
75 MOCK_METHOD3(FetchOcsp, 77 MOCK_METHOD3(FetchOcsp,
76 std::unique_ptr<Request>(const GURL& url, 78 std::unique_ptr<Request>(const GURL& url,
77 int timeout_milliseconds, 79 int timeout_milliseconds,
78 int max_response_bytes)); 80 int max_response_bytes));
81
82 protected:
83 ~MockCertNetFetcher() override {}
79 }; 84 };
80 85
81 // MockCertNetFetcherRequest gives back the indicated error and bytes. 86 // MockCertNetFetcherRequest gives back the indicated error and bytes.
82 class MockCertNetFetcherRequest : public CertNetFetcher::Request { 87 class MockCertNetFetcherRequest : public CertNetFetcher::Request {
83 public: 88 public:
84 MockCertNetFetcherRequest(Error error, std::vector<uint8_t> bytes) 89 MockCertNetFetcherRequest(Error error, std::vector<uint8_t> bytes)
85 : error_(error), bytes_(std::move(bytes)) {} 90 : error_(error), bytes_(std::move(bytes)) {}
86 91
87 void WaitForResult(Error* error, std::vector<uint8_t>* bytes) override { 92 void WaitForResult(Error* error, std::vector<uint8_t>* bytes) override {
88 DCHECK(!did_consume_result_); 93 DCHECK(!did_consume_result_);
(...skipping 20 matching lines...) Expand all
109 const std::vector<uint8_t>& bytes) { 114 const std::vector<uint8_t>& bytes) {
110 return base::MakeUnique<MockCertNetFetcherRequest>(OK, bytes); 115 return base::MakeUnique<MockCertNetFetcherRequest>(OK, bytes);
111 } 116 }
112 117
113 // CertIssuerSourceAia does not return results for SyncGetIssuersOf. 118 // CertIssuerSourceAia does not return results for SyncGetIssuersOf.
114 TEST(CertIssuerSourceAiaTest, NoSyncResults) { 119 TEST(CertIssuerSourceAiaTest, NoSyncResults) {
115 scoped_refptr<ParsedCertificate> cert; 120 scoped_refptr<ParsedCertificate> cert;
116 ASSERT_TRUE(ReadTestCert("target_two_aia.pem", &cert)); 121 ASSERT_TRUE(ReadTestCert("target_two_aia.pem", &cert));
117 122
118 // No methods on |mock_fetcher| should be called. 123 // No methods on |mock_fetcher| should be called.
119 StrictMock<MockCertNetFetcher> mock_fetcher; 124 scoped_refptr<StrictMock<MockCertNetFetcher>> mock_fetcher(
eroman 2017/01/11 01:56:59 nit: make_scoped_refptr() ?
estark 2017/01/12 01:06:30 Done.
120 CertIssuerSourceAia aia_source(&mock_fetcher); 125 new StrictMock<MockCertNetFetcher>());
126 CertIssuerSourceAia aia_source(mock_fetcher);
121 ParsedCertificateList issuers; 127 ParsedCertificateList issuers;
122 aia_source.SyncGetIssuersOf(cert.get(), &issuers); 128 aia_source.SyncGetIssuersOf(cert.get(), &issuers);
123 EXPECT_EQ(0U, issuers.size()); 129 EXPECT_EQ(0U, issuers.size());
124 } 130 }
125 131
126 // If the AuthorityInfoAccess extension is not present, AsyncGetIssuersOf should 132 // If the AuthorityInfoAccess extension is not present, AsyncGetIssuersOf should
127 // synchronously indicate no results. 133 // synchronously indicate no results.
128 TEST(CertIssuerSourceAiaTest, NoAia) { 134 TEST(CertIssuerSourceAiaTest, NoAia) {
129 scoped_refptr<ParsedCertificate> cert; 135 scoped_refptr<ParsedCertificate> cert;
130 ASSERT_TRUE(ReadTestCert("target_no_aia.pem", &cert)); 136 ASSERT_TRUE(ReadTestCert("target_no_aia.pem", &cert));
131 137
132 // No methods on |mock_fetcher| should be called. 138 // No methods on |mock_fetcher| should be called.
133 StrictMock<MockCertNetFetcher> mock_fetcher; 139 scoped_refptr<StrictMock<MockCertNetFetcher>> mock_fetcher(
134 CertIssuerSourceAia aia_source(&mock_fetcher); 140 new StrictMock<MockCertNetFetcher>());
141 CertIssuerSourceAia aia_source(mock_fetcher);
135 std::unique_ptr<CertIssuerSource::Request> request; 142 std::unique_ptr<CertIssuerSource::Request> request;
136 aia_source.AsyncGetIssuersOf(cert.get(), &request); 143 aia_source.AsyncGetIssuersOf(cert.get(), &request);
137 EXPECT_EQ(nullptr, request); 144 EXPECT_EQ(nullptr, request);
138 } 145 }
139 146
140 // If the AuthorityInfoAccess extension only contains non-HTTP URIs, 147 // If the AuthorityInfoAccess extension only contains non-HTTP URIs,
141 // AsyncGetIssuersOf should create a Request object. The URL scheme check is 148 // AsyncGetIssuersOf should create a Request object. The URL scheme check is
142 // part of the specific CertNetFetcher implementation, this tests that we handle 149 // part of the specific CertNetFetcher implementation, this tests that we handle
143 // ERR_DISALLOWED_URL_SCHEME properly. If FetchCaIssuers is modified to fail 150 // ERR_DISALLOWED_URL_SCHEME properly. If FetchCaIssuers is modified to fail
144 // synchronously in that case, this test will be more interesting. 151 // synchronously in that case, this test will be more interesting.
145 TEST(CertIssuerSourceAiaTest, FileAia) { 152 TEST(CertIssuerSourceAiaTest, FileAia) {
146 scoped_refptr<ParsedCertificate> cert; 153 scoped_refptr<ParsedCertificate> cert;
147 ASSERT_TRUE(ReadTestCert("target_file_aia.pem", &cert)); 154 ASSERT_TRUE(ReadTestCert("target_file_aia.pem", &cert));
148 155
149 StrictMock<MockCertNetFetcher> mock_fetcher; 156 scoped_refptr<StrictMock<MockCertNetFetcher>> mock_fetcher(
150 EXPECT_CALL(mock_fetcher, FetchCaIssuers(GURL("file:///dev/null"), _, _)) 157 new StrictMock<MockCertNetFetcher>());
158 EXPECT_CALL(*mock_fetcher.get(),
eroman 2017/01/11 01:56:59 nit: I don't believe the .get() is needed here --
estark 2017/01/12 01:06:30 Done.
159 FetchCaIssuers(GURL("file:///dev/null"), _, _))
151 .WillOnce(Return(ByMove(CreateMockRequest(ERR_DISALLOWED_URL_SCHEME)))); 160 .WillOnce(Return(ByMove(CreateMockRequest(ERR_DISALLOWED_URL_SCHEME))));
152 161
153 CertIssuerSourceAia aia_source(&mock_fetcher); 162 CertIssuerSourceAia aia_source(mock_fetcher);
154 std::unique_ptr<CertIssuerSource::Request> cert_source_request; 163 std::unique_ptr<CertIssuerSource::Request> cert_source_request;
155 aia_source.AsyncGetIssuersOf(cert.get(), &cert_source_request); 164 aia_source.AsyncGetIssuersOf(cert.get(), &cert_source_request);
156 ASSERT_NE(nullptr, cert_source_request); 165 ASSERT_NE(nullptr, cert_source_request);
157 166
158 // No results. 167 // No results.
159 ParsedCertificateList result_certs; 168 ParsedCertificateList result_certs;
160 cert_source_request->GetNext(&result_certs); 169 cert_source_request->GetNext(&result_certs);
161 EXPECT_TRUE(result_certs.empty()); 170 EXPECT_TRUE(result_certs.empty());
162 } 171 }
163 172
164 // If the AuthorityInfoAccess extension contains an invalid URL, 173 // If the AuthorityInfoAccess extension contains an invalid URL,
165 // AsyncGetIssuersOf should synchronously indicate no results. 174 // AsyncGetIssuersOf should synchronously indicate no results.
166 TEST(CertIssuerSourceAiaTest, OneInvalidURL) { 175 TEST(CertIssuerSourceAiaTest, OneInvalidURL) {
167 scoped_refptr<ParsedCertificate> cert; 176 scoped_refptr<ParsedCertificate> cert;
168 ASSERT_TRUE(ReadTestCert("target_invalid_url_aia.pem", &cert)); 177 ASSERT_TRUE(ReadTestCert("target_invalid_url_aia.pem", &cert));
169 178
170 StrictMock<MockCertNetFetcher> mock_fetcher; 179 scoped_refptr<StrictMock<MockCertNetFetcher>> mock_fetcher(
171 CertIssuerSourceAia aia_source(&mock_fetcher); 180 new StrictMock<MockCertNetFetcher>());
181 CertIssuerSourceAia aia_source(mock_fetcher);
172 std::unique_ptr<CertIssuerSource::Request> request; 182 std::unique_ptr<CertIssuerSource::Request> request;
173 aia_source.AsyncGetIssuersOf(cert.get(), &request); 183 aia_source.AsyncGetIssuersOf(cert.get(), &request);
174 EXPECT_EQ(nullptr, request); 184 EXPECT_EQ(nullptr, request);
175 } 185 }
176 186
177 // AuthorityInfoAccess with a single HTTP url pointing to a single DER cert. 187 // AuthorityInfoAccess with a single HTTP url pointing to a single DER cert.
178 TEST(CertIssuerSourceAiaTest, OneAia) { 188 TEST(CertIssuerSourceAiaTest, OneAia) {
179 scoped_refptr<ParsedCertificate> cert; 189 scoped_refptr<ParsedCertificate> cert;
180 ASSERT_TRUE(ReadTestCert("target_one_aia.pem", &cert)); 190 ASSERT_TRUE(ReadTestCert("target_one_aia.pem", &cert));
181 scoped_refptr<ParsedCertificate> intermediate_cert; 191 scoped_refptr<ParsedCertificate> intermediate_cert;
182 ASSERT_TRUE(ReadTestCert("i.pem", &intermediate_cert)); 192 ASSERT_TRUE(ReadTestCert("i.pem", &intermediate_cert));
183 193
184 StrictMock<MockCertNetFetcher> mock_fetcher; 194 scoped_refptr<StrictMock<MockCertNetFetcher>> mock_fetcher(
195 new StrictMock<MockCertNetFetcher>());
185 196
186 EXPECT_CALL(mock_fetcher, 197 EXPECT_CALL(*mock_fetcher.get(),
187 FetchCaIssuers(GURL("http://url-for-aia/I.cer"), _, _)) 198 FetchCaIssuers(GURL("http://url-for-aia/I.cer"), _, _))
188 .WillOnce(Return( 199 .WillOnce(Return(
189 ByMove(CreateMockRequest(CertDataVector(intermediate_cert.get()))))); 200 ByMove(CreateMockRequest(CertDataVector(intermediate_cert.get())))));
190 201
191 CertIssuerSourceAia aia_source(&mock_fetcher); 202 CertIssuerSourceAia aia_source(mock_fetcher);
192 std::unique_ptr<CertIssuerSource::Request> cert_source_request; 203 std::unique_ptr<CertIssuerSource::Request> cert_source_request;
193 aia_source.AsyncGetIssuersOf(cert.get(), &cert_source_request); 204 aia_source.AsyncGetIssuersOf(cert.get(), &cert_source_request);
194 ASSERT_NE(nullptr, cert_source_request); 205 ASSERT_NE(nullptr, cert_source_request);
195 206
196 ParsedCertificateList result_certs; 207 ParsedCertificateList result_certs;
197 cert_source_request->GetNext(&result_certs); 208 cert_source_request->GetNext(&result_certs);
198 ASSERT_EQ(1u, result_certs.size()); 209 ASSERT_EQ(1u, result_certs.size());
199 ASSERT_EQ(result_certs.front()->der_cert(), intermediate_cert->der_cert()); 210 ASSERT_EQ(result_certs.front()->der_cert(), intermediate_cert->der_cert());
200 211
201 result_certs.clear(); 212 result_certs.clear();
202 cert_source_request->GetNext(&result_certs); 213 cert_source_request->GetNext(&result_certs);
203 EXPECT_TRUE(result_certs.empty()); 214 EXPECT_TRUE(result_certs.empty());
204 } 215 }
205 216
206 // AuthorityInfoAccess with two URIs, one a FILE, the other a HTTP. 217 // AuthorityInfoAccess with two URIs, one a FILE, the other a HTTP.
207 // Simulate a ERR_DISALLOWED_URL_SCHEME for the file URL. If FetchCaIssuers is 218 // Simulate a ERR_DISALLOWED_URL_SCHEME for the file URL. If FetchCaIssuers is
208 // modified to synchronously reject disallowed schemes, this test will be more 219 // modified to synchronously reject disallowed schemes, this test will be more
209 // interesting. 220 // interesting.
210 TEST(CertIssuerSourceAiaTest, OneFileOneHttpAia) { 221 TEST(CertIssuerSourceAiaTest, OneFileOneHttpAia) {
211 scoped_refptr<ParsedCertificate> cert; 222 scoped_refptr<ParsedCertificate> cert;
212 ASSERT_TRUE(ReadTestCert("target_file_and_http_aia.pem", &cert)); 223 ASSERT_TRUE(ReadTestCert("target_file_and_http_aia.pem", &cert));
213 scoped_refptr<ParsedCertificate> intermediate_cert; 224 scoped_refptr<ParsedCertificate> intermediate_cert;
214 ASSERT_TRUE(ReadTestCert("i2.pem", &intermediate_cert)); 225 ASSERT_TRUE(ReadTestCert("i2.pem", &intermediate_cert));
215 226
216 StrictMock<MockCertNetFetcher> mock_fetcher; 227 scoped_refptr<StrictMock<MockCertNetFetcher>> mock_fetcher(
228 new StrictMock<MockCertNetFetcher>());
217 229
218 EXPECT_CALL(mock_fetcher, FetchCaIssuers(GURL("file:///dev/null"), _, _)) 230 EXPECT_CALL(*mock_fetcher.get(),
231 FetchCaIssuers(GURL("file:///dev/null"), _, _))
219 .WillOnce(Return(ByMove(CreateMockRequest(ERR_DISALLOWED_URL_SCHEME)))); 232 .WillOnce(Return(ByMove(CreateMockRequest(ERR_DISALLOWED_URL_SCHEME))));
220 233
221 EXPECT_CALL(mock_fetcher, 234 EXPECT_CALL(*mock_fetcher.get(),
222 FetchCaIssuers(GURL("http://url-for-aia2/I2.foo"), _, _)) 235 FetchCaIssuers(GURL("http://url-for-aia2/I2.foo"), _, _))
223 .WillOnce(Return( 236 .WillOnce(Return(
224 ByMove(CreateMockRequest(CertDataVector(intermediate_cert.get()))))); 237 ByMove(CreateMockRequest(CertDataVector(intermediate_cert.get())))));
225 238
226 CertIssuerSourceAia aia_source(&mock_fetcher); 239 CertIssuerSourceAia aia_source(mock_fetcher);
227 std::unique_ptr<CertIssuerSource::Request> cert_source_request; 240 std::unique_ptr<CertIssuerSource::Request> cert_source_request;
228 aia_source.AsyncGetIssuersOf(cert.get(), &cert_source_request); 241 aia_source.AsyncGetIssuersOf(cert.get(), &cert_source_request);
229 ASSERT_NE(nullptr, cert_source_request); 242 ASSERT_NE(nullptr, cert_source_request);
230 243
231 ParsedCertificateList result_certs; 244 ParsedCertificateList result_certs;
232 cert_source_request->GetNext(&result_certs); 245 cert_source_request->GetNext(&result_certs);
233 ASSERT_EQ(1u, result_certs.size()); 246 ASSERT_EQ(1u, result_certs.size());
234 ASSERT_EQ(result_certs.front()->der_cert(), intermediate_cert->der_cert()); 247 ASSERT_EQ(result_certs.front()->der_cert(), intermediate_cert->der_cert());
235 248
236 cert_source_request->GetNext(&result_certs); 249 cert_source_request->GetNext(&result_certs);
237 EXPECT_EQ(1u, result_certs.size()); 250 EXPECT_EQ(1u, result_certs.size());
238 } 251 }
239 252
240 // TODO(eroman): Re-enable these tests! 253 // TODO(eroman): Re-enable these tests!
241 #if 0 254 #if 0
242 // AuthorityInfoAccess with two URIs, one is invalid, the other HTTP. 255 // AuthorityInfoAccess with two URIs, one is invalid, the other HTTP.
243 TEST(CertIssuerSourceAiaTest, OneInvalidOneHttpAia) { 256 TEST(CertIssuerSourceAiaTest, OneInvalidOneHttpAia) {
244 scoped_refptr<ParsedCertificate> cert; 257 scoped_refptr<ParsedCertificate> cert;
245 ASSERT_TRUE(ReadTestCert("target_invalid_and_http_aia.pem", &cert)); 258 ASSERT_TRUE(ReadTestCert("target_invalid_and_http_aia.pem", &cert));
246 scoped_refptr<ParsedCertificate> intermediate_cert; 259 scoped_refptr<ParsedCertificate> intermediate_cert;
247 ASSERT_TRUE(ReadTestCert("i2.pem", &intermediate_cert)); 260 ASSERT_TRUE(ReadTestCert("i2.pem", &intermediate_cert));
248 261
249 StrictMock<MockIssuerCallback> mock_callback; 262 StrictMock<MockIssuerCallback> mock_callback;
250 StrictMock<MockCertNetFetcherImpl> mock_fetcher; 263 scoped_refptr<StrictMock<MockCertNetFetcherImpl>> mock_fetcher(
251 CertIssuerSourceAia aia_source(&mock_fetcher); 264 new StrictMock<MockCertNetFetcherImpl>());
265 CertIssuerSourceAia aia_source(mock_fetcher);
252 std::unique_ptr<CertIssuerSource::Request> cert_source_request; 266 std::unique_ptr<CertIssuerSource::Request> cert_source_request;
253 aia_source.AsyncGetIssuersOf(cert.get(), 267 aia_source.AsyncGetIssuersOf(cert.get(),
254 base::Bind(&MockIssuerCallback::Callback, 268 base::Bind(&MockIssuerCallback::Callback,
255 base::Unretained(&mock_callback)), 269 base::Unretained(&mock_callback)),
256 &cert_source_request); 270 &cert_source_request);
257 ASSERT_NE(nullptr, cert_source_request); 271 ASSERT_NE(nullptr, cert_source_request);
258 272
259 RequestManager* req_manager = 273 RequestManager* req_manager =
260 mock_fetcher.GetRequestManagerForURL(GURL("http://url-for-aia2/I2.foo")); 274 mock_fetcher.GetRequestManagerForURL(GURL("http://url-for-aia2/I2.foo"));
261 ASSERT_TRUE(req_manager); 275 ASSERT_TRUE(req_manager);
(...skipping 23 matching lines...) Expand all
285 // and the results are retrieved. 299 // and the results are retrieved.
286 TEST(CertIssuerSourceAiaTest, TwoAiaCompletedInSeries) { 300 TEST(CertIssuerSourceAiaTest, TwoAiaCompletedInSeries) {
287 scoped_refptr<ParsedCertificate> cert; 301 scoped_refptr<ParsedCertificate> cert;
288 ASSERT_TRUE(ReadTestCert("target_two_aia.pem", &cert)); 302 ASSERT_TRUE(ReadTestCert("target_two_aia.pem", &cert));
289 scoped_refptr<ParsedCertificate> intermediate_cert; 303 scoped_refptr<ParsedCertificate> intermediate_cert;
290 ASSERT_TRUE(ReadTestCert("i.pem", &intermediate_cert)); 304 ASSERT_TRUE(ReadTestCert("i.pem", &intermediate_cert));
291 scoped_refptr<ParsedCertificate> intermediate_cert2; 305 scoped_refptr<ParsedCertificate> intermediate_cert2;
292 ASSERT_TRUE(ReadTestCert("i2.pem", &intermediate_cert2)); 306 ASSERT_TRUE(ReadTestCert("i2.pem", &intermediate_cert2));
293 307
294 StrictMock<MockIssuerCallback> mock_callback; 308 StrictMock<MockIssuerCallback> mock_callback;
295 StrictMock<MockCertNetFetcherImpl> mock_fetcher; 309 scoped_refptr<StrictMock<MockCertNetFetcherImpl>> mock_fetcher(
296 CertIssuerSourceAia aia_source(&mock_fetcher); 310 new StrictMock<MockCertNetFetcherImpl>());
311 CertIssuerSourceAia aia_source(mock_fetcher);
297 std::unique_ptr<CertIssuerSource::Request> cert_source_request; 312 std::unique_ptr<CertIssuerSource::Request> cert_source_request;
298 aia_source.AsyncGetIssuersOf(cert.get(), 313 aia_source.AsyncGetIssuersOf(cert.get(),
299 base::Bind(&MockIssuerCallback::Callback, 314 base::Bind(&MockIssuerCallback::Callback,
300 base::Unretained(&mock_callback)), 315 base::Unretained(&mock_callback)),
301 &cert_source_request); 316 &cert_source_request);
302 ASSERT_NE(nullptr, cert_source_request); 317 ASSERT_NE(nullptr, cert_source_request);
303 318
304 RequestManager* req_manager = 319 RequestManager* req_manager =
305 mock_fetcher.GetRequestManagerForURL(GURL("http://url-for-aia/I.cer")); 320 mock_fetcher.GetRequestManagerForURL(GURL("http://url-for-aia/I.cer"));
306 ASSERT_TRUE(req_manager); 321 ASSERT_TRUE(req_manager);
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
361 // supplied to the caller in the same batch. 376 // supplied to the caller in the same batch.
362 TEST(CertIssuerSourceAiaTest, TwoAiaCompletedBeforeGetNext) { 377 TEST(CertIssuerSourceAiaTest, TwoAiaCompletedBeforeGetNext) {
363 scoped_refptr<ParsedCertificate> cert; 378 scoped_refptr<ParsedCertificate> cert;
364 ASSERT_TRUE(ReadTestCert("target_two_aia.pem", &cert)); 379 ASSERT_TRUE(ReadTestCert("target_two_aia.pem", &cert));
365 scoped_refptr<ParsedCertificate> intermediate_cert; 380 scoped_refptr<ParsedCertificate> intermediate_cert;
366 ASSERT_TRUE(ReadTestCert("i.pem", &intermediate_cert)); 381 ASSERT_TRUE(ReadTestCert("i.pem", &intermediate_cert));
367 scoped_refptr<ParsedCertificate> intermediate_cert2; 382 scoped_refptr<ParsedCertificate> intermediate_cert2;
368 ASSERT_TRUE(ReadTestCert("i2.pem", &intermediate_cert2)); 383 ASSERT_TRUE(ReadTestCert("i2.pem", &intermediate_cert2));
369 384
370 StrictMock<MockIssuerCallback> mock_callback; 385 StrictMock<MockIssuerCallback> mock_callback;
371 StrictMock<MockCertNetFetcherImpl> mock_fetcher; 386 scoped_refptr<StrictMock<MockCertNetFetcherImpl>> mock_fetcher(
372 CertIssuerSourceAia aia_source(&mock_fetcher); 387 new StrictMock<MockCertNetFetcherImpl>());
388 CertIssuerSourceAia aia_source(mock_fetcher);
373 std::unique_ptr<CertIssuerSource::Request> cert_source_request; 389 std::unique_ptr<CertIssuerSource::Request> cert_source_request;
374 aia_source.AsyncGetIssuersOf(cert.get(), 390 aia_source.AsyncGetIssuersOf(cert.get(),
375 base::Bind(&MockIssuerCallback::Callback, 391 base::Bind(&MockIssuerCallback::Callback,
376 base::Unretained(&mock_callback)), 392 base::Unretained(&mock_callback)),
377 &cert_source_request); 393 &cert_source_request);
378 ASSERT_NE(nullptr, cert_source_request); 394 ASSERT_NE(nullptr, cert_source_request);
379 395
380 RequestManager* req_manager = 396 RequestManager* req_manager =
381 mock_fetcher.GetRequestManagerForURL(GURL("http://url-for-aia/I.cer")); 397 mock_fetcher.GetRequestManagerForURL(GURL("http://url-for-aia/I.cer"));
382 ASSERT_TRUE(req_manager); 398 ASSERT_TRUE(req_manager);
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
433 scoped_refptr<ParsedCertificate> cert; 449 scoped_refptr<ParsedCertificate> cert;
434 ASSERT_TRUE(ReadTestCert("target_three_aia.pem", &cert)); 450 ASSERT_TRUE(ReadTestCert("target_three_aia.pem", &cert));
435 scoped_refptr<ParsedCertificate> intermediate_cert; 451 scoped_refptr<ParsedCertificate> intermediate_cert;
436 ASSERT_TRUE(ReadTestCert("i.pem", &intermediate_cert)); 452 ASSERT_TRUE(ReadTestCert("i.pem", &intermediate_cert));
437 scoped_refptr<ParsedCertificate> intermediate_cert2; 453 scoped_refptr<ParsedCertificate> intermediate_cert2;
438 ASSERT_TRUE(ReadTestCert("i2.pem", &intermediate_cert2)); 454 ASSERT_TRUE(ReadTestCert("i2.pem", &intermediate_cert2));
439 scoped_refptr<ParsedCertificate> intermediate_cert3; 455 scoped_refptr<ParsedCertificate> intermediate_cert3;
440 ASSERT_TRUE(ReadTestCert("i3.pem", &intermediate_cert3)); 456 ASSERT_TRUE(ReadTestCert("i3.pem", &intermediate_cert3));
441 457
442 StrictMock<MockIssuerCallback> mock_callback; 458 StrictMock<MockIssuerCallback> mock_callback;
443 StrictMock<MockCertNetFetcherImpl> mock_fetcher; 459 scoped_refptr<StrictMock<MockCertNetFetcherImpl>> mock_fetcher(
444 CertIssuerSourceAia aia_source(&mock_fetcher); 460 new StrictMock<MockCertNetFetcherImpl>());
461 CertIssuerSourceAia aia_source(mock_fetcher);
445 std::unique_ptr<CertIssuerSource::Request> cert_source_request; 462 std::unique_ptr<CertIssuerSource::Request> cert_source_request;
446 aia_source.AsyncGetIssuersOf(cert.get(), 463 aia_source.AsyncGetIssuersOf(cert.get(),
447 base::Bind(&MockIssuerCallback::Callback, 464 base::Bind(&MockIssuerCallback::Callback,
448 base::Unretained(&mock_callback)), 465 base::Unretained(&mock_callback)),
449 &cert_source_request); 466 &cert_source_request);
450 ASSERT_NE(nullptr, cert_source_request); 467 ASSERT_NE(nullptr, cert_source_request);
451 468
452 RequestManager* req_manager = 469 RequestManager* req_manager =
453 mock_fetcher.GetRequestManagerForURL(GURL("http://url-for-aia/I.cer")); 470 mock_fetcher.GetRequestManagerForURL(GURL("http://url-for-aia/I.cer"));
454 ASSERT_TRUE(req_manager); 471 ASSERT_TRUE(req_manager);
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
509 } 526 }
510 527
511 // AuthorityInfoAccess with a single HTTP url pointing to a single DER cert, 528 // AuthorityInfoAccess with a single HTTP url pointing to a single DER cert,
512 // CertNetFetcher request fails. The callback should be called to indicate the 529 // CertNetFetcher request fails. The callback should be called to indicate the
513 // request is complete, but no results should be provided. 530 // request is complete, but no results should be provided.
514 TEST(CertIssuerSourceAiaTest, OneAiaHttpError) { 531 TEST(CertIssuerSourceAiaTest, OneAiaHttpError) {
515 scoped_refptr<ParsedCertificate> cert; 532 scoped_refptr<ParsedCertificate> cert;
516 ASSERT_TRUE(ReadTestCert("target_one_aia.pem", &cert)); 533 ASSERT_TRUE(ReadTestCert("target_one_aia.pem", &cert));
517 534
518 StrictMock<MockIssuerCallback> mock_callback; 535 StrictMock<MockIssuerCallback> mock_callback;
519 StrictMock<MockCertNetFetcherImpl> mock_fetcher; 536 scoped_refptr<StrictMock<MockCertNetFetcherImpl>> mock_fetcher(
520 CertIssuerSourceAia aia_source(&mock_fetcher); 537 new StrictMock<MockCertNetFetcherImpl>());
538 CertIssuerSourceAia aia_source(mock_fetcher);
521 std::unique_ptr<CertIssuerSource::Request> cert_source_request; 539 std::unique_ptr<CertIssuerSource::Request> cert_source_request;
522 aia_source.AsyncGetIssuersOf(cert.get(), 540 aia_source.AsyncGetIssuersOf(cert.get(),
523 base::Bind(&MockIssuerCallback::Callback, 541 base::Bind(&MockIssuerCallback::Callback,
524 base::Unretained(&mock_callback)), 542 base::Unretained(&mock_callback)),
525 &cert_source_request); 543 &cert_source_request);
526 ASSERT_NE(nullptr, cert_source_request); 544 ASSERT_NE(nullptr, cert_source_request);
527 545
528 RequestManager* req_manager = 546 RequestManager* req_manager =
529 mock_fetcher.GetRequestManagerForURL(GURL("http://url-for-aia/I.cer")); 547 mock_fetcher.GetRequestManagerForURL(GURL("http://url-for-aia/I.cer"));
530 ASSERT_TRUE(req_manager); 548 ASSERT_TRUE(req_manager);
(...skipping 12 matching lines...) Expand all
543 561
544 // AuthorityInfoAccess with a single HTTP url pointing to a single DER cert, 562 // AuthorityInfoAccess with a single HTTP url pointing to a single DER cert,
545 // CertNetFetcher request completes, but the DER cert fails to parse. The 563 // CertNetFetcher request completes, but the DER cert fails to parse. The
546 // callback should be called to indicate the request is complete, but no results 564 // callback should be called to indicate the request is complete, but no results
547 // should be provided. 565 // should be provided.
548 TEST(CertIssuerSourceAiaTest, OneAiaParseError) { 566 TEST(CertIssuerSourceAiaTest, OneAiaParseError) {
549 scoped_refptr<ParsedCertificate> cert; 567 scoped_refptr<ParsedCertificate> cert;
550 ASSERT_TRUE(ReadTestCert("target_one_aia.pem", &cert)); 568 ASSERT_TRUE(ReadTestCert("target_one_aia.pem", &cert));
551 569
552 StrictMock<MockIssuerCallback> mock_callback; 570 StrictMock<MockIssuerCallback> mock_callback;
553 StrictMock<MockCertNetFetcherImpl> mock_fetcher; 571 scoped_refptr<StrictMock<MockCertNetFetcherImpl>> mock_fetcher(
554 CertIssuerSourceAia aia_source(&mock_fetcher); 572 new StrictMock<MockCertNetFetcherImpl>());
573 CertIssuerSourceAia aia_source(mock_fetcher);
555 std::unique_ptr<CertIssuerSource::Request> cert_source_request; 574 std::unique_ptr<CertIssuerSource::Request> cert_source_request;
556 aia_source.AsyncGetIssuersOf(cert.get(), 575 aia_source.AsyncGetIssuersOf(cert.get(),
557 base::Bind(&MockIssuerCallback::Callback, 576 base::Bind(&MockIssuerCallback::Callback,
558 base::Unretained(&mock_callback)), 577 base::Unretained(&mock_callback)),
559 &cert_source_request); 578 &cert_source_request);
560 ASSERT_NE(nullptr, cert_source_request); 579 ASSERT_NE(nullptr, cert_source_request);
561 580
562 RequestManager* req_manager = 581 RequestManager* req_manager =
563 mock_fetcher.GetRequestManagerForURL(GURL("http://url-for-aia/I.cer")); 582 mock_fetcher.GetRequestManagerForURL(GURL("http://url-for-aia/I.cer"));
564 ASSERT_TRUE(req_manager); 583 ASSERT_TRUE(req_manager);
(...skipping 13 matching lines...) Expand all
578 // AuthorityInfoAccess with two HTTP urls, each pointing to a single DER cert. 597 // AuthorityInfoAccess with two HTTP urls, each pointing to a single DER cert.
579 // One request fails. No callback should be generated yet. Once the second 598 // One request fails. No callback should be generated yet. Once the second
580 // request completes, the callback should occur. 599 // request completes, the callback should occur.
581 TEST(CertIssuerSourceAiaTest, TwoAiaCompletedInSeriesFirstFails) { 600 TEST(CertIssuerSourceAiaTest, TwoAiaCompletedInSeriesFirstFails) {
582 scoped_refptr<ParsedCertificate> cert; 601 scoped_refptr<ParsedCertificate> cert;
583 ASSERT_TRUE(ReadTestCert("target_two_aia.pem", &cert)); 602 ASSERT_TRUE(ReadTestCert("target_two_aia.pem", &cert));
584 scoped_refptr<ParsedCertificate> intermediate_cert2; 603 scoped_refptr<ParsedCertificate> intermediate_cert2;
585 ASSERT_TRUE(ReadTestCert("i2.pem", &intermediate_cert2)); 604 ASSERT_TRUE(ReadTestCert("i2.pem", &intermediate_cert2));
586 605
587 StrictMock<MockIssuerCallback> mock_callback; 606 StrictMock<MockIssuerCallback> mock_callback;
588 StrictMock<MockCertNetFetcherImpl> mock_fetcher; 607 scoped_refptr<StrictMock<MockCertNetFetcherImpl>> mock_fetcher(
589 CertIssuerSourceAia aia_source(&mock_fetcher); 608 new StrictMock<MockCertNetFetcherImpl>());
609 CertIssuerSourceAia aia_source(mock_fetcher);
590 std::unique_ptr<CertIssuerSource::Request> cert_source_request; 610 std::unique_ptr<CertIssuerSource::Request> cert_source_request;
591 aia_source.AsyncGetIssuersOf(cert.get(), 611 aia_source.AsyncGetIssuersOf(cert.get(),
592 base::Bind(&MockIssuerCallback::Callback, 612 base::Bind(&MockIssuerCallback::Callback,
593 base::Unretained(&mock_callback)), 613 base::Unretained(&mock_callback)),
594 &cert_source_request); 614 &cert_source_request);
595 ASSERT_NE(nullptr, cert_source_request); 615 ASSERT_NE(nullptr, cert_source_request);
596 616
597 RequestManager* req_manager = 617 RequestManager* req_manager =
598 mock_fetcher.GetRequestManagerForURL(GURL("http://url-for-aia/I.cer")); 618 mock_fetcher.GetRequestManagerForURL(GURL("http://url-for-aia/I.cer"));
599 ASSERT_TRUE(req_manager); 619 ASSERT_TRUE(req_manager);
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
632 // First request completes, result is retrieved, then the second request fails. 652 // First request completes, result is retrieved, then the second request fails.
633 // The second callback should occur to indicate that the results are exhausted, 653 // The second callback should occur to indicate that the results are exhausted,
634 // even though no more results are available. 654 // even though no more results are available.
635 TEST(CertIssuerSourceAiaTest, TwoAiaCompletedInSeriesSecondFails) { 655 TEST(CertIssuerSourceAiaTest, TwoAiaCompletedInSeriesSecondFails) {
636 scoped_refptr<ParsedCertificate> cert; 656 scoped_refptr<ParsedCertificate> cert;
637 ASSERT_TRUE(ReadTestCert("target_two_aia.pem", &cert)); 657 ASSERT_TRUE(ReadTestCert("target_two_aia.pem", &cert));
638 scoped_refptr<ParsedCertificate> intermediate_cert; 658 scoped_refptr<ParsedCertificate> intermediate_cert;
639 ASSERT_TRUE(ReadTestCert("i.pem", &intermediate_cert)); 659 ASSERT_TRUE(ReadTestCert("i.pem", &intermediate_cert));
640 660
641 StrictMock<MockIssuerCallback> mock_callback; 661 StrictMock<MockIssuerCallback> mock_callback;
642 StrictMock<MockCertNetFetcherImpl> mock_fetcher; 662 scoped_refptr<StrictMock<MockCertNetFetcherImpl>> mock_fetcher(
643 CertIssuerSourceAia aia_source(&mock_fetcher); 663 new StrictMock<MockCertNetFetcherImpl>());
664 CertIssuerSourceAia aia_source(mock_fetcher);
644 std::unique_ptr<CertIssuerSource::Request> cert_source_request; 665 std::unique_ptr<CertIssuerSource::Request> cert_source_request;
645 aia_source.AsyncGetIssuersOf(cert.get(), 666 aia_source.AsyncGetIssuersOf(cert.get(),
646 base::Bind(&MockIssuerCallback::Callback, 667 base::Bind(&MockIssuerCallback::Callback,
647 base::Unretained(&mock_callback)), 668 base::Unretained(&mock_callback)),
648 &cert_source_request); 669 &cert_source_request);
649 ASSERT_NE(nullptr, cert_source_request); 670 ASSERT_NE(nullptr, cert_source_request);
650 671
651 RequestManager* req_manager = 672 RequestManager* req_manager =
652 mock_fetcher.GetRequestManagerForURL(GURL("http://url-for-aia/I.cer")); 673 mock_fetcher.GetRequestManagerForURL(GURL("http://url-for-aia/I.cer"));
653 ASSERT_TRUE(req_manager); 674 ASSERT_TRUE(req_manager);
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
690 EXPECT_FALSE(result_cert.get()); 711 EXPECT_FALSE(result_cert.get());
691 } 712 }
692 713
693 // AuthorityInfoAccess with two HTTP urls. Request is cancelled before any HTTP 714 // AuthorityInfoAccess with two HTTP urls. Request is cancelled before any HTTP
694 // requests finish. 715 // requests finish.
695 TEST(CertIssuerSourceAiaTest, CertSourceRequestCancelled) { 716 TEST(CertIssuerSourceAiaTest, CertSourceRequestCancelled) {
696 scoped_refptr<ParsedCertificate> cert; 717 scoped_refptr<ParsedCertificate> cert;
697 ASSERT_TRUE(ReadTestCert("target_two_aia.pem", &cert)); 718 ASSERT_TRUE(ReadTestCert("target_two_aia.pem", &cert));
698 719
699 StrictMock<MockIssuerCallback> mock_callback; 720 StrictMock<MockIssuerCallback> mock_callback;
700 StrictMock<MockCertNetFetcherImpl> mock_fetcher; 721 scoped_refptr<StrictMock<MockCertNetFetcherImpl>> mock_fetcher(
701 CertIssuerSourceAia aia_source(&mock_fetcher); 722 new StrictMock<MockCertNetFetcherImpl>());
723 CertIssuerSourceAia aia_source(mock_fetcher);
702 std::unique_ptr<CertIssuerSource::Request> cert_source_request; 724 std::unique_ptr<CertIssuerSource::Request> cert_source_request;
703 aia_source.AsyncGetIssuersOf(cert.get(), 725 aia_source.AsyncGetIssuersOf(cert.get(),
704 base::Bind(&MockIssuerCallback::Callback, 726 base::Bind(&MockIssuerCallback::Callback,
705 base::Unretained(&mock_callback)), 727 base::Unretained(&mock_callback)),
706 &cert_source_request); 728 &cert_source_request);
707 ASSERT_NE(nullptr, cert_source_request); 729 ASSERT_NE(nullptr, cert_source_request);
708 730
709 RequestManager* req_manager = 731 RequestManager* req_manager =
710 mock_fetcher.GetRequestManagerForURL(GURL("http://url-for-aia/I.cer")); 732 mock_fetcher.GetRequestManagerForURL(GURL("http://url-for-aia/I.cer"));
711 ASSERT_TRUE(req_manager); 733 ASSERT_TRUE(req_manager);
(...skipping 14 matching lines...) Expand all
726 // AuthorityInfoAccess with two HTTP urls, each pointing to a single DER cert. 748 // AuthorityInfoAccess with two HTTP urls, each pointing to a single DER cert.
727 // One request completes, results are retrieved, then request is cancelled 749 // One request completes, results are retrieved, then request is cancelled
728 // before the second HTTP request completes. 750 // before the second HTTP request completes.
729 TEST(CertIssuerSourceAiaTest, TwoAiaOneCompletedThenRequestCancelled) { 751 TEST(CertIssuerSourceAiaTest, TwoAiaOneCompletedThenRequestCancelled) {
730 scoped_refptr<ParsedCertificate> cert; 752 scoped_refptr<ParsedCertificate> cert;
731 ASSERT_TRUE(ReadTestCert("target_two_aia.pem", &cert)); 753 ASSERT_TRUE(ReadTestCert("target_two_aia.pem", &cert));
732 scoped_refptr<ParsedCertificate> intermediate_cert; 754 scoped_refptr<ParsedCertificate> intermediate_cert;
733 ASSERT_TRUE(ReadTestCert("i.pem", &intermediate_cert)); 755 ASSERT_TRUE(ReadTestCert("i.pem", &intermediate_cert));
734 756
735 StrictMock<MockIssuerCallback> mock_callback; 757 StrictMock<MockIssuerCallback> mock_callback;
736 StrictMock<MockCertNetFetcherImpl> mock_fetcher; 758 scoped_refptr<StrictMock<MockCertNetFetcherImpl>> mock_fetcher(
737 CertIssuerSourceAia aia_source(&mock_fetcher); 759 new StrictMock<MockCertNetFetcherImpl>());
760 CertIssuerSourceAia aia_source(mock_fetcher);
738 std::unique_ptr<CertIssuerSource::Request> cert_source_request; 761 std::unique_ptr<CertIssuerSource::Request> cert_source_request;
739 aia_source.AsyncGetIssuersOf(cert.get(), 762 aia_source.AsyncGetIssuersOf(cert.get(),
740 base::Bind(&MockIssuerCallback::Callback, 763 base::Bind(&MockIssuerCallback::Callback,
741 base::Unretained(&mock_callback)), 764 base::Unretained(&mock_callback)),
742 &cert_source_request); 765 &cert_source_request);
743 ASSERT_NE(nullptr, cert_source_request); 766 ASSERT_NE(nullptr, cert_source_request);
744 767
745 RequestManager* req_manager = 768 RequestManager* req_manager =
746 mock_fetcher.GetRequestManagerForURL(GURL("http://url-for-aia/I.cer")); 769 mock_fetcher.GetRequestManagerForURL(GURL("http://url-for-aia/I.cer"));
747 ASSERT_TRUE(req_manager); 770 ASSERT_TRUE(req_manager);
(...skipping 29 matching lines...) Expand all
777 EXPECT_FALSE(req_manager2->is_request_alive()); 800 EXPECT_FALSE(req_manager2->is_request_alive());
778 } 801 }
779 802
780 // AuthorityInfoAccess with six HTTP URLs. kMaxFetchesPerCert is 5, so the 803 // AuthorityInfoAccess with six HTTP URLs. kMaxFetchesPerCert is 5, so the
781 // sixth URL should be ignored. 804 // sixth URL should be ignored.
782 TEST(CertIssuerSourceAiaTest, MaxFetchesPerCert) { 805 TEST(CertIssuerSourceAiaTest, MaxFetchesPerCert) {
783 scoped_refptr<ParsedCertificate> cert; 806 scoped_refptr<ParsedCertificate> cert;
784 ASSERT_TRUE(ReadTestCert("target_six_aia.pem", &cert)); 807 ASSERT_TRUE(ReadTestCert("target_six_aia.pem", &cert));
785 808
786 StrictMock<MockIssuerCallback> mock_callback; 809 StrictMock<MockIssuerCallback> mock_callback;
787 StrictMock<MockCertNetFetcherImpl> mock_fetcher; 810 scoped_refptr<StrictMock<MockCertNetFetcherImpl>> mock_fetcher(
788 CertIssuerSourceAia aia_source(&mock_fetcher); 811 new StrictMock<MockCertNetFetcherImpl>());
812 CertIssuerSourceAia aia_source(mock_fetcher);
789 std::unique_ptr<CertIssuerSource::Request> cert_source_request; 813 std::unique_ptr<CertIssuerSource::Request> cert_source_request;
790 aia_source.AsyncGetIssuersOf(cert.get(), 814 aia_source.AsyncGetIssuersOf(cert.get(),
791 base::Bind(&MockIssuerCallback::Callback, 815 base::Bind(&MockIssuerCallback::Callback,
792 base::Unretained(&mock_callback)), 816 base::Unretained(&mock_callback)),
793 &cert_source_request); 817 &cert_source_request);
794 ASSERT_NE(nullptr, cert_source_request); 818 ASSERT_NE(nullptr, cert_source_request);
795 819
796 RequestManager* req_manager = 820 RequestManager* req_manager =
797 mock_fetcher.GetRequestManagerForURL(GURL("http://url-for-aia/I.cer")); 821 mock_fetcher.GetRequestManagerForURL(GURL("http://url-for-aia/I.cer"));
798 ASSERT_TRUE(req_manager); 822 ASSERT_TRUE(req_manager);
(...skipping 22 matching lines...) Expand all
821 // Sixth URL should not have created a request. 845 // Sixth URL should not have created a request.
822 EXPECT_FALSE( 846 EXPECT_FALSE(
823 mock_fetcher.GetRequestManagerForURL(GURL("http://url-for-aia6/I6.foo"))); 847 mock_fetcher.GetRequestManagerForURL(GURL("http://url-for-aia6/I6.foo")));
824 } 848 }
825 849
826 #endif 850 #endif
827 851
828 } // namespace 852 } // namespace
829 853
830 } // namespace net 854 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698