OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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/ssl/server_bound_cert_service.h" | 5 #include "net/ssl/server_bound_cert_service.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
12 #include "base/message_loop/message_loop.h" | 12 #include "base/message_loop/message_loop.h" |
13 #include "base/message_loop/message_loop_proxy.h" | 13 #include "base/message_loop/message_loop_proxy.h" |
14 #include "base/task_runner.h" | 14 #include "base/task_runner.h" |
15 #include "crypto/ec_private_key.h" | 15 #include "crypto/ec_private_key.h" |
16 #include "net/base/net_errors.h" | 16 #include "net/base/net_errors.h" |
17 #include "net/base/test_completion_callback.h" | 17 #include "net/base/test_completion_callback.h" |
18 #include "net/cert/asn1_util.h" | 18 #include "net/cert/asn1_util.h" |
19 #include "net/cert/x509_certificate.h" | 19 #include "net/cert/x509_certificate.h" |
20 #include "net/ssl/default_server_bound_cert_store.h" | 20 #include "net/ssl/default_server_bound_cert_store.h" |
21 #include "testing/gtest/include/gtest/gtest.h" | 21 #include "testing/gtest/include/gtest/gtest.h" |
22 | 22 |
23 namespace net { | 23 namespace net { |
24 | 24 |
25 namespace { | 25 namespace { |
26 | 26 |
27 #if !defined(USE_OPENSSL) | |
28 void FailTest(int /* result */) { | 27 void FailTest(int /* result */) { |
29 FAIL(); | 28 FAIL(); |
30 } | 29 } |
31 | 30 |
32 // Simple task runner that refuses to actually post any tasks. This simulates | 31 // Simple task runner that refuses to actually post any tasks. This simulates |
33 // a TaskRunner that has been shutdown, by returning false for any attempt to | 32 // a TaskRunner that has been shutdown, by returning false for any attempt to |
34 // add new tasks. | 33 // add new tasks. |
35 class FailingTaskRunner : public base::TaskRunner { | 34 class FailingTaskRunner : public base::TaskRunner { |
36 public: | 35 public: |
37 FailingTaskRunner() {} | 36 FailingTaskRunner() {} |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
110 cert_count_ = 1; | 109 cert_count_ = 1; |
111 base::MessageLoop::current()->PostTask(FROM_HERE, | 110 base::MessageLoop::current()->PostTask(FROM_HERE, |
112 base::Bind(callback_, | 111 base::Bind(callback_, |
113 err, | 112 err, |
114 server_identifier_, | 113 server_identifier_, |
115 expiration_time, | 114 expiration_time, |
116 private_key, | 115 private_key, |
117 cert)); | 116 cert)); |
118 } | 117 } |
119 | 118 |
120 #endif // !defined(USE_OPENSSL) | |
121 | |
122 class ServerBoundCertServiceTest : public testing::Test { | 119 class ServerBoundCertServiceTest : public testing::Test { |
123 public: | 120 public: |
124 ServerBoundCertServiceTest() | 121 ServerBoundCertServiceTest() |
125 : service_(new ServerBoundCertService( | 122 : service_(new ServerBoundCertService( |
126 new DefaultServerBoundCertStore(NULL), | 123 new DefaultServerBoundCertStore(NULL), |
127 base::MessageLoopProxy::current())) { | 124 base::MessageLoopProxy::current())) { |
128 } | 125 } |
129 | 126 |
130 protected: | 127 protected: |
131 scoped_ptr<ServerBoundCertService> service_; | 128 scoped_ptr<ServerBoundCertService> service_; |
(...skipping 11 matching lines...) Expand all Loading... |
143 EXPECT_EQ("appspot.com", | 140 EXPECT_EQ("appspot.com", |
144 ServerBoundCertService::GetDomainForHost("appspot.com")); | 141 ServerBoundCertService::GetDomainForHost("appspot.com")); |
145 EXPECT_EQ("google.com", | 142 EXPECT_EQ("google.com", |
146 ServerBoundCertService::GetDomainForHost("www.mail.google.com")); | 143 ServerBoundCertService::GetDomainForHost("www.mail.google.com")); |
147 EXPECT_EQ("goto", | 144 EXPECT_EQ("goto", |
148 ServerBoundCertService::GetDomainForHost("goto")); | 145 ServerBoundCertService::GetDomainForHost("goto")); |
149 EXPECT_EQ("127.0.0.1", | 146 EXPECT_EQ("127.0.0.1", |
150 ServerBoundCertService::GetDomainForHost("127.0.0.1")); | 147 ServerBoundCertService::GetDomainForHost("127.0.0.1")); |
151 } | 148 } |
152 | 149 |
153 // See http://crbug.com/91512 - implement OpenSSL version of CreateSelfSigned. | |
154 #if !defined(USE_OPENSSL) | |
155 | |
156 TEST_F(ServerBoundCertServiceTest, GetCacheMiss) { | 150 TEST_F(ServerBoundCertServiceTest, GetCacheMiss) { |
157 std::string host("encrypted.google.com"); | 151 std::string host("encrypted.google.com"); |
158 | 152 |
159 int error; | 153 int error; |
160 TestCompletionCallback callback; | 154 TestCompletionCallback callback; |
161 ServerBoundCertService::RequestHandle request_handle; | 155 ServerBoundCertService::RequestHandle request_handle; |
162 | 156 |
163 // Synchronous completion, because the store is initialized. | 157 // Synchronous completion, because the store is initialized. |
164 std::string private_key, der_cert; | 158 std::string private_key, der_cert; |
165 EXPECT_EQ(0, service_->cert_count()); | 159 EXPECT_EQ(0, service_->cert_count()); |
(...skipping 602 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
768 EXPECT_EQ(1u, service_->workers_created()); | 762 EXPECT_EQ(1u, service_->workers_created()); |
769 EXPECT_EQ(1u, service_->inflight_joins()); | 763 EXPECT_EQ(1u, service_->inflight_joins()); |
770 EXPECT_FALSE(der_cert1.empty()); | 764 EXPECT_FALSE(der_cert1.empty()); |
771 EXPECT_EQ(der_cert1, der_cert2); | 765 EXPECT_EQ(der_cert1, der_cert2); |
772 EXPECT_FALSE(private_key1.empty()); | 766 EXPECT_FALSE(private_key1.empty()); |
773 EXPECT_EQ(private_key1, private_key2); | 767 EXPECT_EQ(private_key1, private_key2); |
774 EXPECT_FALSE(request_handle1.is_active()); | 768 EXPECT_FALSE(request_handle1.is_active()); |
775 EXPECT_FALSE(request_handle2.is_active()); | 769 EXPECT_FALSE(request_handle2.is_active()); |
776 } | 770 } |
777 | 771 |
778 #endif // !defined(USE_OPENSSL) | |
779 | |
780 } // namespace | 772 } // namespace |
781 | 773 |
782 } // namespace net | 774 } // namespace net |
OLD | NEW |