This source file includes following definitions.
- TEST
- TEST
- TEST
- TEST
#include "net/ssl/ssl_client_auth_cache.h"
#include "base/time/time.h"
#include "net/cert/x509_certificate.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace net {
TEST(SSLClientAuthCacheTest, LookupAddRemove) {
SSLClientAuthCache cache;
base::Time start_date = base::Time::Now();
base::Time expiration_date = start_date + base::TimeDelta::FromDays(1);
HostPortPair server1("foo1", 443);
scoped_refptr<X509Certificate> cert1(
new X509Certificate("foo1", "CA", start_date, expiration_date));
HostPortPair server2("foo2", 443);
scoped_refptr<X509Certificate> cert2(
new X509Certificate("foo2", "CA", start_date, expiration_date));
HostPortPair server3("foo3", 443);
scoped_refptr<X509Certificate> cert3(
new X509Certificate("foo3", "CA", start_date, expiration_date));
scoped_refptr<X509Certificate> cached_cert;
cached_cert = NULL;
EXPECT_FALSE(cache.Lookup(server1, &cached_cert));
cache.Add(server1, cert1.get());
cached_cert = NULL;
EXPECT_TRUE(cache.Lookup(server1, &cached_cert));
EXPECT_EQ(cert1, cached_cert);
cache.Add(server2, cert2.get());
cached_cert = NULL;
EXPECT_TRUE(cache.Lookup(server1, &cached_cert));
EXPECT_EQ(cert1, cached_cert.get());
cached_cert = NULL;
EXPECT_TRUE(cache.Lookup(server2, &cached_cert));
EXPECT_EQ(cert2, cached_cert);
cache.Add(server1, cert3.get());
cached_cert = NULL;
EXPECT_TRUE(cache.Lookup(server1, &cached_cert));
EXPECT_EQ(cert3, cached_cert);
cached_cert = NULL;
EXPECT_TRUE(cache.Lookup(server2, &cached_cert));
EXPECT_EQ(cert2, cached_cert);
cache.Remove(server1);
cached_cert = NULL;
EXPECT_FALSE(cache.Lookup(server1, &cached_cert));
cached_cert = NULL;
EXPECT_TRUE(cache.Lookup(server2, &cached_cert));
EXPECT_EQ(cert2, cached_cert);
cache.Remove(server1);
cached_cert = NULL;
EXPECT_FALSE(cache.Lookup(server1, &cached_cert));
cached_cert = NULL;
EXPECT_TRUE(cache.Lookup(server2, &cached_cert));
EXPECT_EQ(cert2, cached_cert);
}
TEST(SSLClientAuthCacheTest, LookupWithPort) {
SSLClientAuthCache cache;
base::Time start_date = base::Time::Now();
base::Time expiration_date = start_date + base::TimeDelta::FromDays(1);
HostPortPair server1("foo", 443);
scoped_refptr<X509Certificate> cert1(
new X509Certificate("foo", "CA", start_date, expiration_date));
HostPortPair server2("foo", 8443);
scoped_refptr<X509Certificate> cert2(
new X509Certificate("foo", "CA", start_date, expiration_date));
cache.Add(server1, cert1.get());
cache.Add(server2, cert2.get());
scoped_refptr<X509Certificate> cached_cert;
EXPECT_TRUE(cache.Lookup(server1, &cached_cert));
EXPECT_EQ(cert1.get(), cached_cert);
EXPECT_TRUE(cache.Lookup(server2, &cached_cert));
EXPECT_EQ(cert2.get(), cached_cert);
}
TEST(SSLClientAuthCacheTest, LookupNullPreference) {
SSLClientAuthCache cache;
base::Time start_date = base::Time::Now();
base::Time expiration_date = start_date + base::TimeDelta::FromDays(1);
HostPortPair server1("foo", 443);
scoped_refptr<X509Certificate> cert1(
new X509Certificate("foo", "CA", start_date, expiration_date));
cache.Add(server1, NULL);
scoped_refptr<X509Certificate> cached_cert(cert1);
EXPECT_TRUE(cache.Lookup(server1, &cached_cert));
EXPECT_EQ(NULL, cached_cert.get());
cache.Remove(server1);
cached_cert = NULL;
EXPECT_FALSE(cache.Lookup(server1, &cached_cert));
cache.Add(server1, cert1.get());
cached_cert = NULL;
EXPECT_TRUE(cache.Lookup(server1, &cached_cert));
EXPECT_EQ(cert1, cached_cert);
cache.Add(server1, NULL);
cached_cert = NULL;
EXPECT_TRUE(cache.Lookup(server1, &cached_cert));
EXPECT_EQ(NULL, cached_cert.get());
}
TEST(SSLClientAuthCacheTest, OnCertAdded) {
SSLClientAuthCache cache;
base::Time start_date = base::Time::Now();
base::Time expiration_date = start_date + base::TimeDelta::FromDays(1);
HostPortPair server1("foo", 443);
scoped_refptr<X509Certificate> cert1(
new X509Certificate("foo", "CA", start_date, expiration_date));
cache.Add(server1, cert1.get());
HostPortPair server2("foo2", 443);
cache.Add(server2, NULL);
scoped_refptr<X509Certificate> cached_cert;
EXPECT_TRUE(cache.Lookup(server1, &cached_cert));
EXPECT_EQ(cert1, cached_cert);
EXPECT_TRUE(cache.Lookup(server2, &cached_cert));
EXPECT_EQ(NULL, cached_cert.get());
cache.OnCertAdded(NULL);
EXPECT_FALSE(cache.Lookup(server1, &cached_cert));
EXPECT_FALSE(cache.Lookup(server2, &cached_cert));
}
}