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

Side by Side Diff: net/base/default_origin_bound_cert_store_unittest.cc

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

Powered by Google App Engine
This is Rietveld 408576698