OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/base/origin_bound_cert_service.h" | 5 #include "net/base/origin_bound_cert_service.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
334 EXPECT_EQ(ERR_IO_PENDING, error); | 334 EXPECT_EQ(ERR_IO_PENDING, error); |
335 EXPECT_TRUE(request_handle != NULL); | 335 EXPECT_TRUE(request_handle != NULL); |
336 service->CancelRequest(request_handle); | 336 service->CancelRequest(request_handle); |
337 | 337 |
338 // Issue a few more requests to the worker pool and wait for their | 338 // Issue a few more requests to the worker pool and wait for their |
339 // completion, so that the task of the canceled request (which runs on a | 339 // completion, so that the task of the canceled request (which runs on a |
340 // worker thread) is likely to complete by the end of this test. | 340 // worker thread) is likely to complete by the end of this test. |
341 TestCompletionCallback callback; | 341 TestCompletionCallback callback; |
342 for (int i = 0; i < 5; ++i) { | 342 for (int i = 0; i < 5; ++i) { |
343 error = service->GetOriginBoundCert( | 343 error = service->GetOriginBoundCert( |
344 "https://encrypted.google.com:" + std::string(1, (char) ('1' + i)), | 344 "https://foo" + std::string(1, (char) ('1' + i)), |
345 types, | 345 types, |
346 &type, | 346 &type, |
347 &private_key_info, | 347 &private_key_info, |
348 &der_cert, | 348 &der_cert, |
349 callback.callback(), | 349 callback.callback(), |
350 &request_handle); | 350 &request_handle); |
351 EXPECT_EQ(ERR_IO_PENDING, error); | 351 EXPECT_EQ(ERR_IO_PENDING, error); |
352 EXPECT_TRUE(request_handle != NULL); | 352 EXPECT_TRUE(request_handle != NULL); |
353 error = callback.WaitForResult(); | 353 error = callback.WaitForResult(); |
354 } | 354 } |
355 | 355 |
356 // Even though the original request was cancelled, the service will still | 356 // Even though the original request was cancelled, the service will still |
357 // store the result, it just doesn't call the callback. | 357 // store the result, it just doesn't call the callback. |
358 EXPECT_EQ(6, service->cert_count()); | 358 EXPECT_EQ(6, service->cert_count()); |
359 } | 359 } |
360 | 360 |
361 TEST(OriginBoundCertServiceTest, Expiration) { | 361 TEST(OriginBoundCertServiceTest, Expiration) { |
362 OriginBoundCertStore* store = new DefaultOriginBoundCertStore(NULL); | 362 OriginBoundCertStore* store = new DefaultOriginBoundCertStore(NULL); |
363 base::Time now = base::Time::Now(); | 363 base::Time now = base::Time::Now(); |
364 store->SetOriginBoundCert("https://good", | 364 store->SetOriginBoundCert("good", |
365 CLIENT_CERT_ECDSA_SIGN, | 365 CLIENT_CERT_ECDSA_SIGN, |
366 now, | 366 now, |
367 now + base::TimeDelta::FromDays(1), | 367 now + base::TimeDelta::FromDays(1), |
368 "a", | 368 "a", |
369 "b"); | 369 "b"); |
370 store->SetOriginBoundCert("https://expired", | 370 store->SetOriginBoundCert("expired", |
371 CLIENT_CERT_ECDSA_SIGN, | 371 CLIENT_CERT_ECDSA_SIGN, |
372 now - base::TimeDelta::FromDays(2), | 372 now - base::TimeDelta::FromDays(2), |
373 now - base::TimeDelta::FromDays(1), | 373 now - base::TimeDelta::FromDays(1), |
374 "c", | 374 "c", |
375 "d"); | 375 "d"); |
376 OriginBoundCertService service(store); | 376 OriginBoundCertService service(store); |
377 EXPECT_EQ(2, service.cert_count()); | 377 EXPECT_EQ(2, service.cert_count()); |
378 | 378 |
379 int error; | 379 int error; |
380 std::vector<uint8> types; | 380 std::vector<uint8> types; |
(...skipping 28 matching lines...) Expand all Loading... |
409 EXPECT_EQ(CLIENT_CERT_ECDSA_SIGN, type2); | 409 EXPECT_EQ(CLIENT_CERT_ECDSA_SIGN, type2); |
410 EXPECT_LT(1U, private_key_info2.size()); | 410 EXPECT_LT(1U, private_key_info2.size()); |
411 EXPECT_LT(1U, der_cert2.size()); | 411 EXPECT_LT(1U, der_cert2.size()); |
412 } | 412 } |
413 | 413 |
414 #endif // !defined(USE_OPENSSL) | 414 #endif // !defined(USE_OPENSSL) |
415 | 415 |
416 } // namespace | 416 } // namespace |
417 | 417 |
418 } // namespace net | 418 } // namespace net |
OLD | NEW |