OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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/ssl_client_auth_cache.h" | 5 #include "net/ssl/ssl_client_auth_cache.h" |
6 | 6 |
7 #include "base/macros.h" | 7 #include "base/macros.h" |
8 #include "base/time/time.h" | 8 #include "base/time/time.h" |
9 #include "net/cert/x509_certificate.h" | 9 #include "net/cert/x509_certificate.h" |
10 #include "net/ssl/ssl_private_key.h" | 10 #include "net/ssl/ssl_private_key.h" |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
163 EXPECT_TRUE(cache.Lookup(server1, &cached_cert, &cached_pkey)); | 163 EXPECT_TRUE(cache.Lookup(server1, &cached_cert, &cached_pkey)); |
164 EXPECT_EQ(cert1, cached_cert); | 164 EXPECT_EQ(cert1, cached_cert); |
165 | 165 |
166 // Replace the specific preference with a nullptr certificate. | 166 // Replace the specific preference with a nullptr certificate. |
167 cache.Add(server1, nullptr, new MockSSLPrivateKey); | 167 cache.Add(server1, nullptr, new MockSSLPrivateKey); |
168 cached_cert = nullptr; | 168 cached_cert = nullptr; |
169 EXPECT_TRUE(cache.Lookup(server1, &cached_cert, &cached_pkey)); | 169 EXPECT_TRUE(cache.Lookup(server1, &cached_cert, &cached_pkey)); |
170 EXPECT_EQ(nullptr, cached_cert.get()); | 170 EXPECT_EQ(nullptr, cached_cert.get()); |
171 } | 171 } |
172 | 172 |
173 // Check that the OnCertAdded() method removes all cache entries. | 173 // Check that the OnCertDBChanged() method removes all cache entries. |
174 TEST(SSLClientAuthCacheTest, OnCertAdded) { | 174 TEST(SSLClientAuthCacheTest, OnCertDBChanged) { |
175 SSLClientAuthCache cache; | 175 SSLClientAuthCache cache; |
176 | 176 |
177 HostPortPair server1("foo", 443); | 177 HostPortPair server1("foo", 443); |
178 scoped_refptr<X509Certificate> cert1( | 178 scoped_refptr<X509Certificate> cert1( |
179 ImportCertFromFile(GetTestCertsDirectory(), "ok_cert.pem")); | 179 ImportCertFromFile(GetTestCertsDirectory(), "ok_cert.pem")); |
180 ASSERT_TRUE(cert1); | 180 ASSERT_TRUE(cert1); |
181 | 181 |
182 cache.Add(server1, cert1.get(), new MockSSLPrivateKey); | 182 cache.Add(server1, cert1.get(), new MockSSLPrivateKey); |
183 | 183 |
184 HostPortPair server2("foo2", 443); | 184 HostPortPair server2("foo2", 443); |
185 cache.Add(server2, nullptr, new MockSSLPrivateKey); | 185 cache.Add(server2, nullptr, new MockSSLPrivateKey); |
186 | 186 |
187 scoped_refptr<X509Certificate> cached_cert; | 187 scoped_refptr<X509Certificate> cached_cert; |
188 scoped_refptr<SSLPrivateKey> cached_pkey; | 188 scoped_refptr<SSLPrivateKey> cached_pkey; |
189 | 189 |
190 // Demonstrate the set up is correct. | 190 // Demonstrate the set up is correct. |
191 EXPECT_TRUE(cache.Lookup(server1, &cached_cert, &cached_pkey)); | 191 EXPECT_TRUE(cache.Lookup(server1, &cached_cert, &cached_pkey)); |
192 EXPECT_EQ(cert1, cached_cert); | 192 EXPECT_EQ(cert1, cached_cert); |
193 | 193 |
194 EXPECT_TRUE(cache.Lookup(server2, &cached_cert, &cached_pkey)); | 194 EXPECT_TRUE(cache.Lookup(server2, &cached_cert, &cached_pkey)); |
195 EXPECT_EQ(nullptr, cached_cert.get()); | 195 EXPECT_EQ(nullptr, cached_cert.get()); |
196 | 196 |
197 cache.OnCertAdded(nullptr); | 197 cache.OnCertDBChanged(nullptr); |
198 | 198 |
199 // Check that we no longer have entries for either server. | 199 // Check that we no longer have entries for either server. |
200 EXPECT_FALSE(cache.Lookup(server1, &cached_cert, &cached_pkey)); | 200 EXPECT_FALSE(cache.Lookup(server1, &cached_cert, &cached_pkey)); |
201 EXPECT_FALSE(cache.Lookup(server2, &cached_cert, &cached_pkey)); | 201 EXPECT_FALSE(cache.Lookup(server2, &cached_cert, &cached_pkey)); |
202 } | 202 } |
203 | 203 |
204 } // namespace net | 204 } // namespace net |
OLD | NEW |