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

Unified Diff: net/http/disk_cache_based_ssl_host_info_unittest.cc

Issue 8670009: SSL Host info: Make sure that we can update certificate chains in (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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « net/http/disk_cache_based_ssl_host_info.cc ('k') | net/http/mock_http_cache.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/http/disk_cache_based_ssl_host_info_unittest.cc
===================================================================
--- net/http/disk_cache_based_ssl_host_info_unittest.cc (revision 111217)
+++ net/http/disk_cache_based_ssl_host_info_unittest.cc (working copy)
@@ -8,6 +8,8 @@
#include "net/http/mock_http_cache.h"
#include "testing/gtest/include/gtest/gtest.h"
+namespace {
+
class DeleteSSLHostInfoOldCompletionCallback : public TestOldCompletionCallback {
public:
explicit DeleteSSLHostInfoOldCompletionCallback(net::SSLHostInfo* ssl_host_info)
@@ -22,6 +24,24 @@
net::SSLHostInfo* ssl_host_info_;
};
+// This is an empty transaction, needed to register the URL and the test mode.
+const MockTransaction kHostInfoTransaction = {
+ "sslhostinfo:https://www.google.com",
+ "",
+ base::Time(),
+ "",
+ net::LOAD_NORMAL,
+ "",
+ "",
+ base::Time(),
+ "",
+ TEST_MODE_NORMAL,
+ NULL,
+ 0
+};
+
+} // namespace
+
// Tests that we can delete a DiskCacheBasedSSLHostInfo object in a
// completion callback for DiskCacheBasedSSLHostInfo::WaitForDataReady.
TEST(DiskCacheBasedSSLHostInfo, DeleteInCallback) {
@@ -42,3 +62,62 @@
factory->FinishCreation();
EXPECT_EQ(net::OK, callback.GetResult(rv));
}
+
+// Tests the basic logic of storing, retrieving and updating data.
+TEST(DiskCacheBasedSSLHostInfo, Update) {
+ MockHttpCache cache;
+ AddMockTransaction(&kHostInfoTransaction);
+ TestOldCompletionCallback callback;
+
+ // Store a certificate chain.
+ net::CertVerifier cert_verifier;
+ net::SSLConfig ssl_config;
+ scoped_ptr<net::SSLHostInfo> ssl_host_info(
+ new net::DiskCacheBasedSSLHostInfo("https://www.google.com", ssl_config,
+ &cert_verifier, cache.http_cache()));
+ ssl_host_info->Start();
+ int rv = ssl_host_info->WaitForDataReady(&callback);
+ EXPECT_EQ(net::OK, callback.GetResult(rv));
+
+ net::SSLHostInfo::State* state = ssl_host_info->mutable_state();
+ EXPECT_TRUE(state->certs.empty());
+ state->certs.push_back(std::string("foo"));
+ ssl_host_info->Persist();
+
+ // Wait until Persist() does the work.
+ MessageLoop::current()->RunAllPending();
+
+ // Open the stored certificate chain.
+ ssl_host_info.reset(
+ new net::DiskCacheBasedSSLHostInfo("https://www.google.com", ssl_config,
+ &cert_verifier, cache.http_cache()));
+ ssl_host_info->Start();
+ rv = ssl_host_info->WaitForDataReady(&callback);
+ EXPECT_EQ(net::OK, callback.GetResult(rv));
+
+ // And now update the data.
+ state = ssl_host_info->mutable_state();
+ EXPECT_EQ(1U, state->certs.size());
+ EXPECT_EQ("foo", state->certs.front());
+ state->certs.push_back(std::string("bar"));
+
+ // Fail instead of DCHECKing double creates.
+ cache.disk_cache()->set_double_create_check(false);
+ ssl_host_info->Persist();
+ MessageLoop::current()->RunAllPending();
+
+ // Verify that the state was updated.
+ ssl_host_info.reset(
+ new net::DiskCacheBasedSSLHostInfo("https://www.google.com", ssl_config,
+ &cert_verifier, cache.http_cache()));
+ ssl_host_info->Start();
+ rv = ssl_host_info->WaitForDataReady(&callback);
+ EXPECT_EQ(net::OK, callback.GetResult(rv));
+
+ state = ssl_host_info->mutable_state();
+ EXPECT_EQ(2U, state->certs.size());
+ EXPECT_EQ("foo", state->certs[0]);
+ EXPECT_EQ("bar", state->certs[1]);
+
+ RemoveMockTransaction(&kHostInfoTransaction);
+}
« no previous file with comments | « net/http/disk_cache_based_ssl_host_info.cc ('k') | net/http/mock_http_cache.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698