Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1134)

Side by Side Diff: net/ssl/ssl_client_auth_cache_unittest.cc

Issue 2363653002: Cleanup unreachable cert adding code (Closed)
Patch Set: Rebased Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « net/ssl/ssl_client_auth_cache.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
OLDNEW
« no previous file with comments | « net/ssl/ssl_client_auth_cache.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698