| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 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/ssl/client_cert_store_mac.h" | 5 #include "net/ssl/client_cert_store_mac.h" |
| 6 | 6 |
| 7 #include "base/files/file_util.h" |
| 8 #include "base/run_loop.h" |
| 9 #include "net/cert/test_keychain_search_list_mac.h" |
| 7 #include "net/ssl/client_cert_store_unittest-inl.h" | 10 #include "net/ssl/client_cert_store_unittest-inl.h" |
| 8 | 11 |
| 9 namespace net { | 12 namespace net { |
| 10 | 13 |
| 11 class ClientCertStoreMacTestDelegate { | 14 class ClientCertStoreMacTestDelegate { |
| 12 public: | 15 public: |
| 13 bool SelectClientCerts(const CertificateList& input_certs, | 16 bool SelectClientCerts(const CertificateList& input_certs, |
| 14 const SSLCertRequestInfo& cert_request_info, | 17 const SSLCertRequestInfo& cert_request_info, |
| 15 CertificateList* selected_certs) { | 18 CertificateList* selected_certs) { |
| 16 return store_.SelectClientCertsForTesting( | 19 return store_.SelectClientCertsForTesting( |
| 17 input_certs, cert_request_info, selected_certs); | 20 input_certs, cert_request_info, selected_certs); |
| 18 } | 21 } |
| 19 | 22 |
| 20 private: | 23 private: |
| 21 ClientCertStoreMac store_; | 24 ClientCertStoreMac store_; |
| 22 }; | 25 }; |
| 23 | 26 |
| 24 INSTANTIATE_TYPED_TEST_CASE_P(Mac, | 27 INSTANTIATE_TYPED_TEST_CASE_P(Mac, |
| 25 ClientCertStoreTest, | 28 ClientCertStoreTest, |
| 26 ClientCertStoreMacTestDelegate); | 29 ClientCertStoreMacTestDelegate); |
| 27 | 30 |
| 31 class ClientCertStoreChainMacTestDelegate { |
| 32 public: |
| 33 ClientCertStoreChainMacTestDelegate() { |
| 34 test_keychain_search_list_ = TestKeychainSearchList::Create(); |
| 35 CHECK(test_keychain_search_list_); |
| 36 } |
| 37 |
| 38 scoped_refptr<X509Certificate> ImportCertAndKeychain( |
| 39 const std::string& name) { |
| 40 base::FilePath keychain_path( |
| 41 GetTestCertsDirectory().AppendASCII(name + ".keychain")); |
| 42 // SecKeychainOpen does not fail if the file doesn't exist, so assert it |
| 43 // here |
| 44 // for easier debugging. |
| 45 if (!base::PathExists(keychain_path)) { |
| 46 ADD_FAILURE() << "keychain doesn't exist:" |
| 47 << keychain_path.MaybeAsASCII(); |
| 48 return nullptr; |
| 49 } |
| 50 SecKeychainRef keychain; |
| 51 OSStatus status = |
| 52 SecKeychainOpen(keychain_path.MaybeAsASCII().c_str(), &keychain); |
| 53 EXPECT_EQ(errSecSuccess, status); |
| 54 EXPECT_TRUE(keychain); |
| 55 if (status != errSecSuccess || !keychain) |
| 56 return nullptr; |
| 57 base::ScopedCFTypeRef<SecKeychainRef> scoped_keychain(keychain); |
| 58 test_keychain_search_list_->AddKeychain(keychain); |
| 59 |
| 60 return ImportCertFromFile(GetTestCertsDirectory(), name + ".pem"); |
| 61 } |
| 62 |
| 63 scoped_refptr<X509Certificate> ImportClientCert(const std::string& name) { |
| 64 return ImportCertAndKeychain(name); |
| 65 /*return ImportClientCertAndKeyFromFile( |
| 66 GetTestCertsDirectory(), name + ".pem", name + ".pk8", |
| 67 test_db.slot());*/ |
| 68 } |
| 69 |
| 70 scoped_refptr<X509Certificate> ImportClientIntermediate( |
| 71 const std::string& name) { |
| 72 return ImportCertAndKeychain(name); |
| 73 } |
| 74 |
| 75 void GetClientCerts(const SSLCertRequestInfo& cert_request_info, |
| 76 CertificateList* selected_certs) { |
| 77 base::RunLoop loop; |
| 78 store_.GetClientCerts(cert_request_info, selected_certs, |
| 79 loop.QuitClosure()); |
| 80 loop.Run(); |
| 81 } |
| 82 |
| 83 protected: |
| 84 std::unique_ptr<TestKeychainSearchList> test_keychain_search_list_; |
| 85 ClientCertStoreMac store_; |
| 86 }; |
| 87 |
| 88 INSTANTIATE_TYPED_TEST_CASE_P(Mac, |
| 89 ClientCertStoreChainTest, |
| 90 ClientCertStoreChainMacTestDelegate); |
| 91 |
| 28 class ClientCertStoreMacTest : public ::testing::Test { | 92 class ClientCertStoreMacTest : public ::testing::Test { |
| 29 protected: | 93 protected: |
| 30 bool SelectClientCertsGivenPreferred( | 94 bool SelectClientCertsGivenPreferred( |
| 31 const scoped_refptr<X509Certificate>& preferred_cert, | 95 const scoped_refptr<X509Certificate>& preferred_cert, |
| 32 const CertificateList& regular_certs, | 96 const CertificateList& regular_certs, |
| 33 const SSLCertRequestInfo& request, | 97 const SSLCertRequestInfo& request, |
| 34 CertificateList* selected_certs) { | 98 CertificateList* selected_certs) { |
| 35 return store_.SelectClientCertsGivenPreferredForTesting( | 99 return store_.SelectClientCertsGivenPreferredForTesting( |
| 36 preferred_cert, regular_certs, request, selected_certs); | 100 preferred_cert, regular_certs, request, selected_certs); |
| 37 } | 101 } |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 80 std::vector<scoped_refptr<X509Certificate> > selected_certs; | 144 std::vector<scoped_refptr<X509Certificate> > selected_certs; |
| 81 bool rv = SelectClientCertsGivenPreferred( | 145 bool rv = SelectClientCertsGivenPreferred( |
| 82 cert_1, certs, *request.get(), &selected_certs); | 146 cert_1, certs, *request.get(), &selected_certs); |
| 83 EXPECT_TRUE(rv); | 147 EXPECT_TRUE(rv); |
| 84 ASSERT_EQ(2u, selected_certs.size()); | 148 ASSERT_EQ(2u, selected_certs.size()); |
| 85 EXPECT_TRUE(selected_certs[0]->Equals(cert_1.get())); | 149 EXPECT_TRUE(selected_certs[0]->Equals(cert_1.get())); |
| 86 EXPECT_TRUE(selected_certs[1]->Equals(cert_2.get())); | 150 EXPECT_TRUE(selected_certs[1]->Equals(cert_2.get())); |
| 87 } | 151 } |
| 88 | 152 |
| 89 } // namespace net | 153 } // namespace net |
| OLD | NEW |