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 "content/browser/ssl/ssl_host_state.h" | 5 #include "content/browser/ssl/ssl_host_state_impl.h" |
6 #include "testing/gtest/include/gtest/gtest.h" | 6 #include "testing/gtest/include/gtest/gtest.h" |
7 | 7 |
8 namespace { | 8 namespace { |
9 | 9 |
10 // Certificates for test data. They're obtained with: | 10 // Certificates for test data. They're obtained with: |
11 // | 11 // |
12 // $ openssl s_client -connect [host]:443 -showcerts | 12 // $ openssl s_client -connect [host]:443 -showcerts |
13 // $ openssl x509 -inform PEM -outform DER > /tmp/host.der | 13 // $ openssl x509 -inform PEM -outform DER > /tmp/host.der |
14 // $ xxd -i /tmp/host.der | 14 // $ xxd -i /tmp/host.der |
15 | 15 |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
83 0x15, 0x8f, 0x44, 0x52, 0xfa, 0x7c, 0x3c, 0x04, 0xed, 0x7f, 0x37, 0x61, | 83 0x15, 0x8f, 0x44, 0x52, 0xfa, 0x7c, 0x3c, 0x04, 0xed, 0x7f, 0x37, 0x61, |
84 0x04, 0xfe, 0xd5, 0xe9, 0xb9, 0xb0, 0x9e, 0xfe, 0xa5, 0x11, 0x69, 0xc9, | 84 0x04, 0xfe, 0xd5, 0xe9, 0xb9, 0xb0, 0x9e, 0xfe, 0xa5, 0x11, 0x69, 0xc9, |
85 0x63, 0xd6, 0x46, 0x81, 0x6f, 0x00, 0xd8, 0x72, 0x2f, 0x82, 0x37, 0x44, | 85 0x63, 0xd6, 0x46, 0x81, 0x6f, 0x00, 0xd8, 0x72, 0x2f, 0x82, 0x37, 0x44, |
86 0xc1 | 86 0xc1 |
87 }; | 87 }; |
88 | 88 |
89 } // namespace | 89 } // namespace |
90 | 90 |
91 namespace content { | 91 namespace content { |
92 | 92 |
93 class SSLHostStateTest : public testing::Test { | 93 class SSLHostStateImplTest : public testing::Test {}; |
94 }; | |
95 | 94 |
96 TEST_F(SSLHostStateTest, DidHostRunInsecureContent) { | 95 TEST_F(SSLHostStateImplTest, DidHostRunInsecureContent) { |
97 SSLHostState state; | 96 SSLHostStateImpl state; |
98 | 97 |
99 EXPECT_FALSE(state.DidHostRunInsecureContent("www.google.com", 42)); | 98 EXPECT_FALSE(state.DidHostRunInsecureContent("www.google.com", 42)); |
100 EXPECT_FALSE(state.DidHostRunInsecureContent("www.google.com", 191)); | 99 EXPECT_FALSE(state.DidHostRunInsecureContent("www.google.com", 191)); |
101 EXPECT_FALSE(state.DidHostRunInsecureContent("example.com", 42)); | 100 EXPECT_FALSE(state.DidHostRunInsecureContent("example.com", 42)); |
102 | 101 |
103 state.HostRanInsecureContent("www.google.com", 42); | 102 state.HostRanInsecureContent("www.google.com", 42); |
104 | 103 |
105 EXPECT_TRUE(state.DidHostRunInsecureContent("www.google.com", 42)); | 104 EXPECT_TRUE(state.DidHostRunInsecureContent("www.google.com", 42)); |
106 EXPECT_FALSE(state.DidHostRunInsecureContent("www.google.com", 191)); | 105 EXPECT_FALSE(state.DidHostRunInsecureContent("www.google.com", 191)); |
107 EXPECT_FALSE(state.DidHostRunInsecureContent("example.com", 42)); | 106 EXPECT_FALSE(state.DidHostRunInsecureContent("example.com", 42)); |
108 | 107 |
109 state.HostRanInsecureContent("example.com", 42); | 108 state.HostRanInsecureContent("example.com", 42); |
110 | 109 |
111 EXPECT_TRUE(state.DidHostRunInsecureContent("www.google.com", 42)); | 110 EXPECT_TRUE(state.DidHostRunInsecureContent("www.google.com", 42)); |
112 EXPECT_FALSE(state.DidHostRunInsecureContent("www.google.com", 191)); | 111 EXPECT_FALSE(state.DidHostRunInsecureContent("www.google.com", 191)); |
113 EXPECT_TRUE(state.DidHostRunInsecureContent("example.com", 42)); | 112 EXPECT_TRUE(state.DidHostRunInsecureContent("example.com", 42)); |
114 } | 113 } |
115 | 114 |
116 TEST_F(SSLHostStateTest, QueryPolicy) { | 115 TEST_F(SSLHostStateImplTest, QueryPolicy) { |
117 scoped_refptr<net::X509Certificate> google_cert( | 116 scoped_refptr<net::X509Certificate> google_cert( |
118 net::X509Certificate::CreateFromBytes( | 117 net::X509Certificate::CreateFromBytes( |
119 reinterpret_cast<const char*>(google_der), sizeof(google_der))); | 118 reinterpret_cast<const char*>(google_der), sizeof(google_der))); |
120 | 119 |
121 SSLHostState state; | 120 SSLHostStateImpl state; |
122 | 121 |
123 EXPECT_EQ(net::CertPolicy::UNKNOWN, | 122 EXPECT_EQ(net::CertPolicy::UNKNOWN, |
124 state.QueryPolicy(google_cert.get(), | 123 state.QueryPolicy(google_cert.get(), |
125 "www.google.com", | 124 "www.google.com", |
126 net::CERT_STATUS_DATE_INVALID)); | 125 net::CERT_STATUS_DATE_INVALID)); |
127 EXPECT_EQ(net::CertPolicy::UNKNOWN, | 126 EXPECT_EQ(net::CertPolicy::UNKNOWN, |
128 state.QueryPolicy(google_cert.get(), | 127 state.QueryPolicy(google_cert.get(), |
129 "google.com", | 128 "google.com", |
130 net::CERT_STATUS_DATE_INVALID)); | 129 net::CERT_STATUS_DATE_INVALID)); |
131 EXPECT_EQ(net::CertPolicy::UNKNOWN, | 130 EXPECT_EQ(net::CertPolicy::UNKNOWN, |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
194 state.QueryPolicy(google_cert.get(), | 193 state.QueryPolicy(google_cert.get(), |
195 "google.com", | 194 "google.com", |
196 net::CERT_STATUS_DATE_INVALID)); | 195 net::CERT_STATUS_DATE_INVALID)); |
197 EXPECT_EQ(net::CertPolicy::UNKNOWN, | 196 EXPECT_EQ(net::CertPolicy::UNKNOWN, |
198 state.QueryPolicy(google_cert.get(), | 197 state.QueryPolicy(google_cert.get(), |
199 "example.com", | 198 "example.com", |
200 net::CERT_STATUS_DATE_INVALID)); | 199 net::CERT_STATUS_DATE_INVALID)); |
201 } | 200 } |
202 | 201 |
203 } // namespace content | 202 } // namespace content |
OLD | NEW |