OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/base/default_origin_bound_cert_store.h" | 5 #include "net/base/default_origin_bound_cert_store.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
70 | 70 |
71 void MockPersistentStore::Flush(const base::Closure& completion_task) { | 71 void MockPersistentStore::Flush(const base::Closure& completion_task) { |
72 NOTREACHED(); | 72 NOTREACHED(); |
73 } | 73 } |
74 | 74 |
75 TEST(DefaultOriginBoundCertStoreTest, TestLoading) { | 75 TEST(DefaultOriginBoundCertStoreTest, TestLoading) { |
76 scoped_refptr<MockPersistentStore> persistent_store(new MockPersistentStore); | 76 scoped_refptr<MockPersistentStore> persistent_store(new MockPersistentStore); |
77 | 77 |
78 persistent_store->AddOriginBoundCert( | 78 persistent_store->AddOriginBoundCert( |
79 DefaultOriginBoundCertStore::OriginBoundCert( | 79 DefaultOriginBoundCertStore::OriginBoundCert( |
80 "https://encrypted.google.com/", "a", "b")); | 80 "https://encrypted.google.com/", CLIENT_CERT_RSA_SIGN, "a", "b")); |
81 persistent_store->AddOriginBoundCert( | 81 persistent_store->AddOriginBoundCert( |
82 DefaultOriginBoundCertStore::OriginBoundCert( | 82 DefaultOriginBoundCertStore::OriginBoundCert( |
83 "https://www.verisign.com/", "c", "d")); | 83 "https://www.verisign.com/", CLIENT_CERT_ECDSA_SIGN, "c", "d")); |
84 | 84 |
85 // Make sure certs load properly. | 85 // Make sure certs load properly. |
86 DefaultOriginBoundCertStore store(persistent_store.get()); | 86 DefaultOriginBoundCertStore store(persistent_store.get()); |
87 EXPECT_EQ(2, store.GetCertCount()); | 87 EXPECT_EQ(2, store.GetCertCount()); |
88 store.SetOriginBoundCert("https://www.verisign.com/", "e", "f"); | 88 store.SetOriginBoundCert( |
| 89 "https://www.verisign.com/", CLIENT_CERT_RSA_SIGN, "e", "f"); |
89 EXPECT_EQ(2, store.GetCertCount()); | 90 EXPECT_EQ(2, store.GetCertCount()); |
90 store.SetOriginBoundCert("https://www.twitter.com/", "g", "h"); | 91 store.SetOriginBoundCert( |
| 92 "https://www.twitter.com/", CLIENT_CERT_RSA_SIGN, "g", "h"); |
91 EXPECT_EQ(3, store.GetCertCount()); | 93 EXPECT_EQ(3, store.GetCertCount()); |
92 } | 94 } |
93 | 95 |
94 TEST(DefaultOriginBoundCertStoreTest, TestSettingAndGetting) { | 96 TEST(DefaultOriginBoundCertStoreTest, TestSettingAndGetting) { |
95 DefaultOriginBoundCertStore store(NULL); | 97 DefaultOriginBoundCertStore store(NULL); |
| 98 SSLClientCertType type; |
96 std::string private_key, cert; | 99 std::string private_key, cert; |
97 EXPECT_EQ(0, store.GetCertCount()); | 100 EXPECT_EQ(0, store.GetCertCount()); |
98 EXPECT_FALSE(store.GetOriginBoundCert("https://www.verisign.com/", | 101 EXPECT_FALSE(store.GetOriginBoundCert("https://www.verisign.com/", |
99 &private_key, | 102 &type, |
100 &cert)); | 103 &private_key, |
| 104 &cert)); |
101 EXPECT_TRUE(private_key.empty()); | 105 EXPECT_TRUE(private_key.empty()); |
102 EXPECT_TRUE(cert.empty()); | 106 EXPECT_TRUE(cert.empty()); |
103 store.SetOriginBoundCert("https://www.verisign.com/", "i", "j"); | 107 store.SetOriginBoundCert( |
| 108 "https://www.verisign.com/", CLIENT_CERT_RSA_SIGN, "i", "j"); |
104 EXPECT_TRUE(store.GetOriginBoundCert("https://www.verisign.com/", | 109 EXPECT_TRUE(store.GetOriginBoundCert("https://www.verisign.com/", |
105 &private_key, | 110 &type, |
106 &cert)); | 111 &private_key, |
| 112 &cert)); |
| 113 EXPECT_EQ(CLIENT_CERT_RSA_SIGN, type); |
107 EXPECT_EQ("i", private_key); | 114 EXPECT_EQ("i", private_key); |
108 EXPECT_EQ("j", cert); | 115 EXPECT_EQ("j", cert); |
109 } | 116 } |
110 | 117 |
111 TEST(DefaultOriginBoundCertStoreTest, TestDuplicateCerts) { | 118 TEST(DefaultOriginBoundCertStoreTest, TestDuplicateCerts) { |
112 scoped_refptr<MockPersistentStore> persistent_store(new MockPersistentStore); | 119 scoped_refptr<MockPersistentStore> persistent_store(new MockPersistentStore); |
113 DefaultOriginBoundCertStore store(persistent_store.get()); | 120 DefaultOriginBoundCertStore store(persistent_store.get()); |
114 | 121 |
| 122 SSLClientCertType type; |
115 std::string private_key, cert; | 123 std::string private_key, cert; |
116 EXPECT_EQ(0, store.GetCertCount()); | 124 EXPECT_EQ(0, store.GetCertCount()); |
117 store.SetOriginBoundCert("https://www.verisign.com/", "a", "b"); | 125 store.SetOriginBoundCert( |
118 store.SetOriginBoundCert("https://www.verisign.com/", "c", "d"); | 126 "https://www.verisign.com/", CLIENT_CERT_RSA_SIGN, "a", "b"); |
| 127 store.SetOriginBoundCert( |
| 128 "https://www.verisign.com/", CLIENT_CERT_ECDSA_SIGN, "c", "d"); |
119 | 129 |
120 EXPECT_EQ(1, store.GetCertCount()); | 130 EXPECT_EQ(1, store.GetCertCount()); |
121 EXPECT_TRUE(store.GetOriginBoundCert("https://www.verisign.com/", | 131 EXPECT_TRUE(store.GetOriginBoundCert("https://www.verisign.com/", |
122 &private_key, | 132 &type, |
123 &cert)); | 133 &private_key, |
| 134 &cert)); |
| 135 EXPECT_EQ(CLIENT_CERT_ECDSA_SIGN, type); |
124 EXPECT_EQ("c", private_key); | 136 EXPECT_EQ("c", private_key); |
125 EXPECT_EQ("d", cert); | 137 EXPECT_EQ("d", cert); |
126 } | 138 } |
127 | 139 |
128 TEST(DefaultOriginBoundCertStoreTest, TestDeleteAll) { | 140 TEST(DefaultOriginBoundCertStoreTest, TestDeleteAll) { |
129 scoped_refptr<MockPersistentStore> persistent_store(new MockPersistentStore); | 141 scoped_refptr<MockPersistentStore> persistent_store(new MockPersistentStore); |
130 DefaultOriginBoundCertStore store(persistent_store.get()); | 142 DefaultOriginBoundCertStore store(persistent_store.get()); |
131 | 143 |
132 EXPECT_EQ(0, store.GetCertCount()); | 144 EXPECT_EQ(0, store.GetCertCount()); |
133 store.SetOriginBoundCert("https://www.verisign.com/", "a", "b"); | 145 store.SetOriginBoundCert( |
134 store.SetOriginBoundCert("https://www.google.com/", "c", "d"); | 146 "https://www.verisign.com/", CLIENT_CERT_RSA_SIGN, "a", "b"); |
135 store.SetOriginBoundCert("https://www.harvard.com/", "e", "f"); | 147 store.SetOriginBoundCert( |
| 148 "https://www.google.com/", CLIENT_CERT_RSA_SIGN, "c", "d"); |
| 149 store.SetOriginBoundCert( |
| 150 "https://www.harvard.com/", CLIENT_CERT_RSA_SIGN, "e", "f"); |
136 | 151 |
137 EXPECT_EQ(3, store.GetCertCount()); | 152 EXPECT_EQ(3, store.GetCertCount()); |
138 store.DeleteAll(); | 153 store.DeleteAll(); |
139 EXPECT_EQ(0, store.GetCertCount()); | 154 EXPECT_EQ(0, store.GetCertCount()); |
140 } | 155 } |
141 | 156 |
142 TEST(DefaultOriginBoundCertStoreTest, TestDelete) { | 157 TEST(DefaultOriginBoundCertStoreTest, TestDelete) { |
143 scoped_refptr<MockPersistentStore> persistent_store(new MockPersistentStore); | 158 scoped_refptr<MockPersistentStore> persistent_store(new MockPersistentStore); |
144 DefaultOriginBoundCertStore store(persistent_store.get()); | 159 DefaultOriginBoundCertStore store(persistent_store.get()); |
145 | 160 |
| 161 SSLClientCertType type; |
146 std::string private_key, cert; | 162 std::string private_key, cert; |
147 EXPECT_EQ(0, store.GetCertCount()); | 163 EXPECT_EQ(0, store.GetCertCount()); |
148 store.SetOriginBoundCert("https://www.verisign.com/", "a", "b"); | 164 store.SetOriginBoundCert( |
149 store.SetOriginBoundCert("https://www.google.com/", "c", "d"); | 165 "https://www.verisign.com/", CLIENT_CERT_RSA_SIGN, "a", "b"); |
| 166 store.SetOriginBoundCert( |
| 167 "https://www.google.com/", CLIENT_CERT_ECDSA_SIGN, "c", "d"); |
150 | 168 |
151 EXPECT_EQ(2, store.GetCertCount()); | 169 EXPECT_EQ(2, store.GetCertCount()); |
152 store.DeleteOriginBoundCert("https://www.verisign.com/"); | 170 store.DeleteOriginBoundCert("https://www.verisign.com/"); |
153 EXPECT_EQ(1, store.GetCertCount()); | 171 EXPECT_EQ(1, store.GetCertCount()); |
154 EXPECT_FALSE(store.GetOriginBoundCert("https://www.verisign.com/", | 172 EXPECT_FALSE(store.GetOriginBoundCert("https://www.verisign.com/", |
155 &private_key, | 173 &type, |
156 &cert)); | |
157 EXPECT_TRUE(store.GetOriginBoundCert("https://www.google.com/", | |
158 &private_key, | 174 &private_key, |
159 &cert)); | 175 &cert)); |
| 176 EXPECT_TRUE(store.GetOriginBoundCert("https://www.google.com/", |
| 177 &type, |
| 178 &private_key, |
| 179 &cert)); |
160 store.DeleteOriginBoundCert("https://www.google.com/"); | 180 store.DeleteOriginBoundCert("https://www.google.com/"); |
161 EXPECT_EQ(0, store.GetCertCount()); | 181 EXPECT_EQ(0, store.GetCertCount()); |
162 EXPECT_FALSE(store.GetOriginBoundCert("https://www.google.com/", | 182 EXPECT_FALSE(store.GetOriginBoundCert("https://www.google.com/", |
163 &private_key, | 183 &type, |
164 &cert)); | 184 &private_key, |
| 185 &cert)); |
165 } | 186 } |
166 | 187 |
167 TEST(DefaultOriginBoundCertStoreTest, TestGetAll) { | 188 TEST(DefaultOriginBoundCertStoreTest, TestGetAll) { |
168 scoped_refptr<MockPersistentStore> persistent_store(new MockPersistentStore); | 189 scoped_refptr<MockPersistentStore> persistent_store(new MockPersistentStore); |
169 DefaultOriginBoundCertStore store(persistent_store.get()); | 190 DefaultOriginBoundCertStore store(persistent_store.get()); |
170 | 191 |
171 EXPECT_EQ(0, store.GetCertCount()); | 192 EXPECT_EQ(0, store.GetCertCount()); |
172 store.SetOriginBoundCert("https://www.verisign.com/", "a", "b"); | 193 store.SetOriginBoundCert( |
173 store.SetOriginBoundCert("https://www.google.com/", "c", "d"); | 194 "https://www.verisign.com/", CLIENT_CERT_RSA_SIGN, "a", "b"); |
174 store.SetOriginBoundCert("https://www.harvard.com/", "e", "f"); | 195 store.SetOriginBoundCert( |
175 store.SetOriginBoundCert("https://www.mit.com/", "g", "h"); | 196 "https://www.google.com/", CLIENT_CERT_ECDSA_SIGN, "c", "d"); |
| 197 store.SetOriginBoundCert( |
| 198 "https://www.harvard.com/", CLIENT_CERT_RSA_SIGN, "e", "f"); |
| 199 store.SetOriginBoundCert( |
| 200 "https://www.mit.com/", CLIENT_CERT_RSA_SIGN, "g", "h"); |
176 | 201 |
177 EXPECT_EQ(4, store.GetCertCount()); | 202 EXPECT_EQ(4, store.GetCertCount()); |
178 std::vector<OriginBoundCertStore::OriginBoundCertInfo> certs; | 203 std::vector<OriginBoundCertStore::OriginBoundCert> certs; |
179 store.GetAllOriginBoundCerts(&certs); | 204 store.GetAllOriginBoundCerts(&certs); |
180 EXPECT_EQ(4u, certs.size()); | 205 EXPECT_EQ(4u, certs.size()); |
181 } | 206 } |
182 | 207 |
183 } // namespace net | 208 } // namespace net |
OLD | NEW |