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

Side by Side Diff: net/http/disk_cache_based_ssl_host_info_unittest.cc

Issue 135373002: Added SSLHostInfo. Storing of server host info to our standard disk cache. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fixed wtc's comments Created 6 years, 11 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 | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "base/bind.h"
6 #include "base/bind_helpers.h"
7 #include "base/compiler_specific.h"
8 #include "base/message_loop/message_loop.h"
9 #include "net/base/net_errors.h"
10 #include "net/cert/mock_cert_verifier.h"
11 #include "net/http/disk_cache_based_ssl_host_info.h"
12 #include "net/http/mock_http_cache.h"
13 #include "net/socket/ssl_host_info.h"
14 #include "net/ssl/ssl_config_service.h"
15 #include "testing/gtest/include/gtest/gtest.h"
16
17 namespace {
18
19 // This is an empty transaction, needed to register the URL and the test mode.
20 const MockTransaction kHostInfoTransaction = {
21 "sslhostinfo:https://www.google.com",
22 "",
23 base::Time(),
24 "",
25 net::LOAD_NORMAL,
26 "",
27 "",
28 base::Time(),
29 "",
30 TEST_MODE_NORMAL,
31 NULL,
32 0
33 };
34
35 // Tests that we can delete a DiskCacheBasedSSLHostInfo object in a
36 // completion callback for DiskCacheBasedSSLHostInfo::WaitForDataReady.
37 TEST(DiskCacheBasedSSLHostInfo, DeleteInCallback) {
38 scoped_ptr<net::CertVerifier> cert_verifier(new net::MockCertVerifier);
39 // Use the blocking mock backend factory to force asynchronous completion
40 // of ssl_host_info->WaitForDataReady(), so that the callback will run.
41 MockBlockingBackendFactory* factory = new MockBlockingBackendFactory();
42 MockHttpCache cache(factory);
43 net::SSLConfig ssl_config;
44 scoped_ptr<net::SSLHostInfo> ssl_host_info(
45 new net::DiskCacheBasedSSLHostInfo("https://www.verisign.com", ssl_config,
46 cert_verifier.get(),
47 cache.http_cache()));
48 ssl_host_info->Start();
49 net::TestCompletionCallback callback;
50 int rv = ssl_host_info->WaitForDataReady(callback.callback());
51 EXPECT_EQ(net::ERR_IO_PENDING, rv);
52 // Now complete the backend creation and let the callback run.
53 factory->FinishCreation();
54 EXPECT_EQ(net::OK, callback.GetResult(rv));
55 }
56
57 // Tests the basic logic of storing, retrieving and updating data.
58 TEST(DiskCacheBasedSSLHostInfo, Update) {
59 MockHttpCache cache;
60 AddMockTransaction(&kHostInfoTransaction);
61 net::TestCompletionCallback callback;
62
63 // Store a certificate chain.
64 scoped_ptr<net::CertVerifier> cert_verifier(new net::MockCertVerifier);
65 net::SSLConfig ssl_config;
66 scoped_ptr<net::SSLHostInfo> ssl_host_info(
67 new net::DiskCacheBasedSSLHostInfo("https://www.google.com", ssl_config,
68 cert_verifier.get(),
69 cache.http_cache()));
70 ssl_host_info->Start();
71 int rv = ssl_host_info->WaitForDataReady(callback.callback());
72 EXPECT_EQ(net::OK, callback.GetResult(rv));
73
74 net::SSLHostInfo::State* state = ssl_host_info->mutable_state();
75 EXPECT_TRUE(state->certs.empty());
76 state->certs.push_back(std::string("foo"));
77 ssl_host_info->Persist();
78
79 // Wait until Persist() does the work.
80 base::MessageLoop::current()->RunUntilIdle();
81
82 // Open the stored certificate chain.
83 ssl_host_info.reset(
84 new net::DiskCacheBasedSSLHostInfo("https://www.google.com", ssl_config,
85 cert_verifier.get(),
86 cache.http_cache()));
87 ssl_host_info->Start();
88 rv = ssl_host_info->WaitForDataReady(callback.callback());
89 EXPECT_EQ(net::OK, callback.GetResult(rv));
90
91 // And now update the data.
92 state = ssl_host_info->mutable_state();
93 EXPECT_EQ(1U, state->certs.size());
94 EXPECT_EQ("foo", state->certs.front());
95 state->certs.push_back(std::string("bar"));
96
97 // Fail instead of DCHECKing double creates.
98 cache.disk_cache()->set_double_create_check(false);
99 ssl_host_info->Persist();
100 base::MessageLoop::current()->RunUntilIdle();
101
102 // Verify that the state was updated.
103 ssl_host_info.reset(
104 new net::DiskCacheBasedSSLHostInfo("https://www.google.com", ssl_config,
105 cert_verifier.get(),
106 cache.http_cache()));
107 ssl_host_info->Start();
108 rv = ssl_host_info->WaitForDataReady(callback.callback());
109 EXPECT_EQ(net::OK, callback.GetResult(rv));
110
111 state = ssl_host_info->mutable_state();
112 EXPECT_EQ(2U, state->certs.size());
113 EXPECT_EQ("foo", state->certs[0]);
114 EXPECT_EQ("bar", state->certs[1]);
115
116 RemoveMockTransaction(&kHostInfoTransaction);
117 }
118
119 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698