Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 439 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 450 EXPECT_EQ(ERR_IO_PENDING, error); | 450 EXPECT_EQ(ERR_IO_PENDING, error); |
| 451 EXPECT_TRUE(request_handle != NULL); | 451 EXPECT_TRUE(request_handle != NULL); |
| 452 error = callback.WaitForResult(); | 452 error = callback.WaitForResult(); |
| 453 } | 453 } |
| 454 | 454 |
| 455 // Even though the original request was cancelled, the service will still | 455 // Even though the original request was cancelled, the service will still |
| 456 // store the result, it just doesn't call the callback. | 456 // store the result, it just doesn't call the callback. |
| 457 EXPECT_EQ(6, service->cert_count()); | 457 EXPECT_EQ(6, service->cert_count()); |
| 458 } | 458 } |
| 459 | 459 |
| 460 TEST(OriginBoundCertServiceTest, Expiration) { | |
| 461 OriginBoundCertStore* store = new DefaultOriginBoundCertStore(NULL); | |
| 462 store->SetOriginBoundCert("https://good", | |
| 463 CLIENT_CERT_RSA_SIGN, | |
| 464 base::Time::Now() + base::TimeDelta::FromDays(1), | |
| 465 "a", | |
| 466 "b"); | |
| 467 store->SetOriginBoundCert("https://expired", | |
| 468 CLIENT_CERT_RSA_SIGN, | |
| 469 base::Time::Now() - base::TimeDelta::FromDays(1), | |
| 470 "c", | |
| 471 "d"); | |
| 472 scoped_ptr<OriginBoundCertService> service(new OriginBoundCertService(store)); | |
|
wtc
2011/12/15 03:18:51
Nit: 'service' can be allocated on the stack:
Or
mattm
2011/12/20 00:28:38
Done.
| |
| 473 EXPECT_EQ(2, service->cert_count()); | |
| 474 | |
| 475 int error; | |
| 476 std::vector<uint8> types; | |
| 477 types.push_back(CLIENT_CERT_RSA_SIGN); | |
| 478 TestCompletionCallback callback; | |
| 479 OriginBoundCertService::RequestHandle request_handle; | |
| 480 | |
| 481 // Cert still valid - synchronous completion. | |
| 482 SSLClientCertType type1; | |
| 483 std::string private_key_info1, der_cert1; | |
| 484 error = service->GetOriginBoundCert( | |
| 485 "https://good", types, &type1, &private_key_info1, &der_cert1, | |
| 486 callback.callback(), &request_handle); | |
| 487 EXPECT_TRUE(request_handle == NULL); | |
| 488 EXPECT_EQ(OK, error); | |
|
wtc
2011/12/15 03:18:51
Nit: please test 'error' (the return value) before
mattm
2011/12/20 00:28:38
Done.
| |
| 489 EXPECT_EQ(2, service->cert_count()); | |
| 490 EXPECT_EQ(CLIENT_CERT_RSA_SIGN, type1); | |
| 491 EXPECT_STREQ("a", private_key_info1.c_str()); | |
| 492 EXPECT_STREQ("b", der_cert1.c_str()); | |
| 493 | |
| 494 // Cert expired - New cert will be generated, asynchronous completion. | |
| 495 SSLClientCertType type2; | |
| 496 std::string private_key_info2, der_cert2; | |
| 497 error = service->GetOriginBoundCert( | |
| 498 "https://expired", types, &type2, &private_key_info2, &der_cert2, | |
| 499 callback.callback(), &request_handle); | |
| 500 EXPECT_EQ(ERR_IO_PENDING, error); | |
| 501 EXPECT_TRUE(request_handle != NULL); | |
| 502 error = callback.WaitForResult(); | |
| 503 EXPECT_EQ(OK, error); | |
| 504 EXPECT_EQ(2, service->cert_count()); | |
| 505 EXPECT_EQ(CLIENT_CERT_RSA_SIGN, type2); | |
| 506 EXPECT_LT(1U, private_key_info2.size()); | |
| 507 EXPECT_LT(1U, der_cert2.size()); | |
| 508 } | |
| 509 | |
| 460 #endif // !defined(USE_OPENSSL) | 510 #endif // !defined(USE_OPENSSL) |
| 461 | 511 |
| 462 } // namespace | 512 } // namespace |
| 463 | 513 |
| 464 } // namespace net | 514 } // namespace net |
| OLD | NEW |