Chromium Code Reviews| Index: net/cert/internal/trust_store_nss_unittest.cc |
| diff --git a/net/cert/internal/trust_store_nss_unittest.cc b/net/cert/internal/trust_store_nss_unittest.cc |
| index b74c5f971251d528cebc123157a86f68721bdf26..28bc8629c1a0e9b3710c69f07171c98f79ad0bf2 100644 |
| --- a/net/cert/internal/trust_store_nss_unittest.cc |
| +++ b/net/cert/internal/trust_store_nss_unittest.cc |
| @@ -7,14 +7,10 @@ |
| #include <cert.h> |
| #include <certdb.h> |
| -#include "base/bind.h" |
| #include "base/memory/ptr_util.h" |
| -#include "base/run_loop.h" |
| #include "base/strings/string_number_conversions.h" |
| -#include "base/threading/thread_task_runner_handle.h" |
| #include "crypto/scoped_test_nss_db.h" |
| #include "net/cert/internal/test_helpers.h" |
| -#include "net/cert/internal/trust_store_test_helpers.h" |
| #include "net/cert/scoped_nss_types.h" |
| #include "net/cert/x509_certificate.h" |
| #include "testing/gtest/include/gtest/gtest.h" |
| @@ -23,10 +19,6 @@ namespace net { |
| namespace { |
| -void NotCalled(TrustAnchors anchors) { |
| - ADD_FAILURE() << "NotCalled was called"; |
| -} |
| - |
| class TrustStoreNSSTest : public testing::Test { |
| public: |
| void SetUp() override { |
| @@ -61,8 +53,7 @@ class TrustStoreNSSTest : public testing::Test { |
| ASSERT_TRUE(newroot_); |
| ASSERT_TRUE(newrootrollover_); |
| - trust_store_nss_.reset( |
| - new TrustStoreNSS(trustSSL, base::ThreadTaskRunnerHandle::Get())); |
| + trust_store_nss_.reset(new TrustStoreNSS(trustSSL)); |
| } |
| std::string GetUniqueNickname() { |
| @@ -112,27 +103,18 @@ class TrustStoreNSSTest : public testing::Test { |
| } |
| protected: |
| - void ExpectTrustStoreContains(tracked_objects::Location loc, |
| - scoped_refptr<ParsedCertificate> cert, |
| - TrustAnchors expected_async_matches) { |
| - SCOPED_TRACE(loc.ToString()); |
|
mattm
2016/10/28 02:11:55
this was so you could tell which ExpectTrustStoreC
|
| - |
| - TrustAnchors sync_matches; |
| - TrustAnchorResultRecorder anchor_results; |
| - std::unique_ptr<TrustStore::Request> req; |
| - trust_store_nss_->FindTrustAnchorsForCert(cert, anchor_results.Callback(), |
| - &sync_matches, &req); |
| - ASSERT_TRUE(req); |
| - EXPECT_TRUE(sync_matches.empty()); |
| - |
| - anchor_results.Run(); |
| + void ExpectTrustStoreContains(scoped_refptr<ParsedCertificate> cert, |
| + TrustAnchors expected_matches) { |
| + TrustAnchors matches; |
| + trust_store_nss_->FindTrustAnchorsForCert(cert, &matches); |
| + |
| std::vector<der::Input> der_result_matches; |
| - for (const auto& it : anchor_results.matches()) |
| + for (const auto& it : matches) |
| der_result_matches.push_back(it->cert()->der_cert()); |
| std::sort(der_result_matches.begin(), der_result_matches.end()); |
| std::vector<der::Input> der_expected_matches; |
| - for (const auto& it : expected_async_matches) |
| + for (const auto& it : expected_matches) |
| der_expected_matches.push_back(it->cert()->der_cert()); |
| std::sort(der_expected_matches.begin(), der_expected_matches.end()); |
| @@ -154,19 +136,19 @@ class TrustStoreNSSTest : public testing::Test { |
| // Without adding any certs to the NSS DB, should get no anchor results for any |
| // of the test certs. |
| TEST_F(TrustStoreNSSTest, CertsNotPresent) { |
| - ExpectTrustStoreContains(FROM_HERE, target_, TrustAnchors()); |
| - ExpectTrustStoreContains(FROM_HERE, newintermediate_, TrustAnchors()); |
| - ExpectTrustStoreContains(FROM_HERE, newroot_->cert(), TrustAnchors()); |
| + ExpectTrustStoreContains(target_, TrustAnchors()); |
| + ExpectTrustStoreContains(newintermediate_, TrustAnchors()); |
| + ExpectTrustStoreContains(newroot_->cert(), TrustAnchors()); |
| } |
| // If certs are present in NSS DB but aren't marked as trusted, should get no |
| // anchor results for any of the test certs. |
| TEST_F(TrustStoreNSSTest, CertsPresentButNotTrusted) { |
| AddCertsToNSS(); |
| - ExpectTrustStoreContains(FROM_HERE, newintermediate_, TrustAnchors()); |
| - ExpectTrustStoreContains(FROM_HERE, target_, TrustAnchors()); |
| - ExpectTrustStoreContains(FROM_HERE, newintermediate_, TrustAnchors()); |
| - ExpectTrustStoreContains(FROM_HERE, newroot_->cert(), TrustAnchors()); |
| + ExpectTrustStoreContains(newintermediate_, TrustAnchors()); |
| + ExpectTrustStoreContains(target_, TrustAnchors()); |
| + ExpectTrustStoreContains(newintermediate_, TrustAnchors()); |
| + ExpectTrustStoreContains(newroot_->cert(), TrustAnchors()); |
| } |
| // A self-signed CA certificate is trusted. FindTrustAnchorsForCert should |
| @@ -175,12 +157,12 @@ TEST_F(TrustStoreNSSTest, CertsPresentButNotTrusted) { |
| TEST_F(TrustStoreNSSTest, TrustedCA) { |
| AddCertsToNSS(); |
| TrustCert(newroot_.get()); |
| - ExpectTrustStoreContains(FROM_HERE, target_, TrustAnchors()); |
| - ExpectTrustStoreContains(FROM_HERE, newintermediate_, {newroot_}); |
| - ExpectTrustStoreContains(FROM_HERE, oldintermediate_, {newroot_}); |
| - ExpectTrustStoreContains(FROM_HERE, newrootrollover_, {newroot_}); |
| - ExpectTrustStoreContains(FROM_HERE, oldroot_->cert(), {newroot_}); |
| - ExpectTrustStoreContains(FROM_HERE, newroot_->cert(), {newroot_}); |
| + ExpectTrustStoreContains(target_, TrustAnchors()); |
| + ExpectTrustStoreContains(newintermediate_, {newroot_}); |
| + ExpectTrustStoreContains(oldintermediate_, {newroot_}); |
| + ExpectTrustStoreContains(newrootrollover_, {newroot_}); |
| + ExpectTrustStoreContains(oldroot_->cert(), {newroot_}); |
| + ExpectTrustStoreContains(newroot_->cert(), {newroot_}); |
| } |
| // When an intermediate certificate is trusted, FindTrustAnchorsForCert should |
| @@ -190,13 +172,13 @@ TEST_F(TrustStoreNSSTest, TrustedIntermediate) { |
| AddCertsToNSS(); |
| TrustCert(newintermediate_.get()); |
| ExpectTrustStoreContains( |
| - FROM_HERE, target_, |
| + target_, |
| {TrustAnchor::CreateFromCertificateNoConstraints(newintermediate_)}); |
| - ExpectTrustStoreContains(FROM_HERE, newintermediate_, TrustAnchors()); |
| - ExpectTrustStoreContains(FROM_HERE, oldintermediate_, TrustAnchors()); |
| - ExpectTrustStoreContains(FROM_HERE, newrootrollover_, TrustAnchors()); |
| - ExpectTrustStoreContains(FROM_HERE, oldroot_->cert(), TrustAnchors()); |
| - ExpectTrustStoreContains(FROM_HERE, newroot_->cert(), TrustAnchors()); |
| + ExpectTrustStoreContains(newintermediate_, TrustAnchors()); |
| + ExpectTrustStoreContains(oldintermediate_, TrustAnchors()); |
| + ExpectTrustStoreContains(newrootrollover_, TrustAnchors()); |
| + ExpectTrustStoreContains(oldroot_->cert(), TrustAnchors()); |
| + ExpectTrustStoreContains(newroot_->cert(), TrustAnchors()); |
| } |
| // Multiple self-signed CA certificates with the same name are trusted. |
| @@ -206,41 +188,10 @@ TEST_F(TrustStoreNSSTest, MultipleTrustedCAWithSameSubject) { |
| AddCertsToNSS(); |
| TrustCert(oldroot_.get()); |
| TrustCert(newroot_.get()); |
| - ExpectTrustStoreContains(FROM_HERE, target_, TrustAnchors()); |
| - ExpectTrustStoreContains(FROM_HERE, newintermediate_, {newroot_, oldroot_}); |
| - ExpectTrustStoreContains(FROM_HERE, oldintermediate_, {newroot_, oldroot_}); |
| - ExpectTrustStoreContains(FROM_HERE, oldroot_->cert(), {newroot_, oldroot_}); |
| -} |
| - |
| -// Cancel a FindTrustAnchorsForCert request before it has returned any results. |
| -// Callback should not be called. |
| -TEST_F(TrustStoreNSSTest, CancelRequest) { |
| - std::unique_ptr<TrustStore::Request> req; |
| - TrustAnchors sync_matches; |
| - trust_store_nss_->FindTrustAnchorsForCert(target_, base::Bind(&NotCalled), |
| - &sync_matches, &req); |
| - ASSERT_TRUE(req); |
| - req.reset(); |
| - base::RunLoop().RunUntilIdle(); |
| -} |
| - |
| -// Cancel a FindTrustAnchorsForCert request during the callback. Should not |
| -// crash. |
| -TEST_F(TrustStoreNSSTest, CancelRequestDuringCallback) { |
| - AddCertsToNSS(); |
| - TrustCert(newroot_.get()); |
| - |
| - base::RunLoop run_loop; |
| - std::unique_ptr<TrustStore::Request> req; |
| - TrustAnchors sync_matches; |
| - trust_store_nss_->FindTrustAnchorsForCert( |
| - newintermediate_, |
| - base::Bind(&TrustStoreRequestDeleter, &req, run_loop.QuitClosure()), |
| - &sync_matches, &req); |
| - ASSERT_TRUE(req); |
| - run_loop.Run(); |
| - ASSERT_FALSE(req); |
| - base::RunLoop().RunUntilIdle(); |
| + ExpectTrustStoreContains(target_, TrustAnchors()); |
| + ExpectTrustStoreContains(newintermediate_, {newroot_, oldroot_}); |
| + ExpectTrustStoreContains(oldintermediate_, {newroot_, oldroot_}); |
| + ExpectTrustStoreContains(oldroot_->cert(), {newroot_, oldroot_}); |
| } |
| } // namespace |