OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/common/ssl_status_serialization.h" | 5 #include "content/common/ssl_status_serialization.h" |
6 | 6 |
7 #include "net/ssl/ssl_connection_status_flags.h" | 7 #include "net/ssl/ssl_connection_status_flags.h" |
8 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
9 | 9 |
10 namespace content { | 10 namespace content { |
11 | 11 |
12 namespace { | 12 namespace { |
13 | 13 |
14 void SetTestStatus(SSLStatus* status) { | 14 void SetTestStatus(SSLStatus* status) { |
15 status->security_style = SECURITY_STYLE_AUTHENTICATED; | 15 status->security_style = SECURITY_STYLE_AUTHENTICATED; |
16 status->cert_id = 1; | 16 status->cert_id = 1; |
17 status->cert_status = net::CERT_STATUS_DATE_INVALID; | 17 status->cert_status = net::CERT_STATUS_DATE_INVALID; |
18 status->security_bits = 80; | 18 status->security_bits = 80; |
19 status->key_exchange_info = 23; | 19 status->key_exchange_info = 23; |
20 status->connection_status = net::SSL_CONNECTION_VERSION_TLS1_2; | 20 status->connection_status = net::SSL_CONNECTION_VERSION_TLS1_2; |
21 status->signed_certificate_timestamp_ids.push_back( | 21 status->num_unknown_scts = 0; |
22 SignedCertificateTimestampIDAndStatus(1, net::ct::SCT_STATUS_OK)); | 22 status->num_invalid_scts = 0; |
| 23 status->num_valid_scts = 3; |
23 } | 24 } |
24 | 25 |
25 bool SSLStatusAreEqual(const SSLStatus& a, const SSLStatus &b) { | 26 bool SSLStatusAreEqual(const SSLStatus& a, const SSLStatus &b) { |
26 return a.Equals(b); | 27 return a.Equals(b); |
27 } | 28 } |
28 | 29 |
29 } // namespace | 30 } // namespace |
30 | 31 |
31 std::ostream& operator<<(std::ostream& os, const SSLStatus& status) { | 32 std::ostream& operator<<(std::ostream& os, const SSLStatus& status) { |
32 return os << "Security Style: " << status.security_style | 33 return os << "Security Style: " << status.security_style |
33 << "\nCert ID: " << status.cert_id | 34 << "\nCert ID: " << status.cert_id |
34 << "\nCert Status: " << status.cert_status | 35 << "\nCert Status: " << status.cert_status |
35 << "\nSecurity bits: " << status.security_bits | 36 << "\nSecurity bits: " << status.security_bits |
36 << "\nKey exchange info: " << status.key_exchange_info | 37 << "\nKey exchange info: " << status.key_exchange_info |
37 << "\nConnection status: " << status.connection_status | 38 << "\nConnection status: " << status.connection_status |
38 << "\nContent Status: " << status.content_status | 39 << "\nContent Status: " << status.content_status |
39 << "\nNumber of SCTs: " << status.signed_certificate_timestamp_ids.size(); | 40 << "\nNumber of unknown SCTs: " << status.num_unknown_scts |
| 41 << "\nNumber of invalid SCTs: " << status.num_invalid_scts |
| 42 << "\nNumber of valid SCTs: " << status.num_valid_scts; |
40 } | 43 } |
41 | 44 |
42 // Test that a valid serialized SSLStatus returns true on | 45 // Test that a valid serialized SSLStatus returns true on |
43 // deserialization and deserializes correctly. | 46 // deserialization and deserializes correctly. |
44 TEST(SSLStatusSerializationTest, DeserializeSerializedStatus) { | 47 TEST(SSLStatusSerializationTest, DeserializeSerializedStatus) { |
45 // Serialize dummy data and test that it deserializes properly. | 48 // Serialize dummy data and test that it deserializes properly. |
46 SSLStatus status; | 49 SSLStatus status; |
47 SetTestStatus(&status); | 50 SetTestStatus(&status); |
48 std::string serialized = SerializeSecurityInfo(status); | 51 std::string serialized = SerializeSecurityInfo(status); |
49 | 52 |
50 SSLStatus deserialized; | 53 SSLStatus deserialized; |
51 ASSERT_TRUE(DeserializeSecurityInfo(serialized, &deserialized)); | 54 ASSERT_TRUE(DeserializeSecurityInfo(serialized, &deserialized)); |
52 EXPECT_PRED2(SSLStatusAreEqual, status, deserialized); | 55 EXPECT_PRED2(SSLStatusAreEqual, status, deserialized); |
53 EXPECT_EQ(SignedCertificateTimestampIDAndStatus(1, net::ct::SCT_STATUS_OK), | |
54 deserialized.signed_certificate_timestamp_ids[0]); | |
55 // Test that |content_status| has the default (initialized) value. | 56 // Test that |content_status| has the default (initialized) value. |
56 EXPECT_EQ(SSLStatus::NORMAL_CONTENT, deserialized.content_status); | 57 EXPECT_EQ(SSLStatus::NORMAL_CONTENT, deserialized.content_status); |
57 } | 58 } |
58 | 59 |
59 // Test that an invalid serialized SSLStatus returns false on | 60 // Test that an invalid serialized SSLStatus returns false on |
60 // deserialization. | 61 // deserialization. |
61 TEST(SSLStatusSerializationTest, DeserializeBogusStatus) { | 62 TEST(SSLStatusSerializationTest, DeserializeBogusStatus) { |
62 // Test that a failure to deserialize returns false and returns | 63 // Test that a failure to deserialize returns false and returns |
63 // initialized, default data. | 64 // initialized, default data. |
64 SSLStatus invalid_deserialized; | 65 SSLStatus invalid_deserialized; |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
102 SetTestStatus(&status); | 103 SetTestStatus(&status); |
103 status.security_style = static_cast<SecurityStyle>(100); | 104 status.security_style = static_cast<SecurityStyle>(100); |
104 std::string serialized = SerializeSecurityInfo(status); | 105 std::string serialized = SerializeSecurityInfo(status); |
105 | 106 |
106 SSLStatus invalid_deserialized; | 107 SSLStatus invalid_deserialized; |
107 ASSERT_FALSE(DeserializeSecurityInfo(serialized, &invalid_deserialized)); | 108 ASSERT_FALSE(DeserializeSecurityInfo(serialized, &invalid_deserialized)); |
108 EXPECT_PRED2(SSLStatusAreEqual, SSLStatus(), invalid_deserialized); | 109 EXPECT_PRED2(SSLStatusAreEqual, SSLStatus(), invalid_deserialized); |
109 } | 110 } |
110 | 111 |
111 } // namespace | 112 } // namespace |
OLD | NEW |