Index: content/common/ssl_status_serialization_unittest.cc |
diff --git a/content/common/ssl_status_serialization_unittest.cc b/content/common/ssl_status_serialization_unittest.cc |
index f8b4852f757440f270f3b685a326b679ac5ba7ef..d479518add63ab52a74e694f2eff5b17b7434d8f 100644 |
--- a/content/common/ssl_status_serialization_unittest.cc |
+++ b/content/common/ssl_status_serialization_unittest.cc |
@@ -9,31 +9,49 @@ |
namespace content { |
+namespace { |
+ |
+void SetTestStatus(SSLStatus* status) { |
+ status->security_style = SECURITY_STYLE_AUTHENTICATED; |
+ status->cert_id = 1; |
+ status->cert_status = net::CERT_STATUS_DATE_INVALID; |
+ status->security_bits = 80; |
+ status->key_exchange_info = 23; |
+ status->connection_status = net::SSL_CONNECTION_VERSION_TLS1_2; |
+ status->signed_certificate_timestamp_ids.push_back( |
+ SignedCertificateTimestampIDAndStatus(1, net::ct::SCT_STATUS_OK)); |
+} |
+ |
+bool SSLStatusAreEqual(const SSLStatus& a, const SSLStatus &b) { |
+ return a.Equals(b); |
+} |
+ |
+} // namespace |
+ |
+std::ostream& operator<<(std::ostream& os, const SSLStatus& status) { |
+ return os << "Security Style: " << status.security_style |
+ << "\nCert ID: " << status.cert_id |
+ << "\nCert Status: " << status.cert_status |
+ << "\nSecurity bits: " << status.security_bits |
+ << "\nKey exchange info: " << status.key_exchange_info |
+ << "\nConnection status: " << status.connection_status |
+ << "\nContent Status: " << status.content_status |
+ << "\nNumber of SCTs: " << status.signed_certificate_timestamp_ids.size(); |
+} |
+ |
// Test that a valid serialized SSLStatus returns true on |
// deserialization and deserializes correctly. |
TEST(SSLStatusSerializationTest, DeserializeSerializedStatus) { |
// Serialize dummy data and test that it deserializes properly. |
SSLStatus status; |
- status.security_style = SECURITY_STYLE_AUTHENTICATED; |
- status.cert_id = 1; |
- status.cert_status = net::CERT_STATUS_DATE_INVALID; |
- status.security_bits = 80; |
- status.connection_status = net::SSL_CONNECTION_VERSION_TLS1_2; |
- SignedCertificateTimestampIDAndStatus sct(1, net::ct::SCT_STATUS_OK); |
- status.signed_certificate_timestamp_ids.push_back(sct); |
- |
+ SetTestStatus(&status); |
std::string serialized = SerializeSecurityInfo(status); |
SSLStatus deserialized; |
ASSERT_TRUE(DeserializeSecurityInfo(serialized, &deserialized)); |
- EXPECT_EQ(status.security_style, deserialized.security_style); |
- EXPECT_EQ(status.cert_id, deserialized.cert_id); |
- EXPECT_EQ(status.cert_status, deserialized.cert_status); |
- EXPECT_EQ(status.security_bits, deserialized.security_bits); |
- EXPECT_EQ(status.connection_status, deserialized.connection_status); |
- EXPECT_EQ(status.signed_certificate_timestamp_ids.size(), |
- deserialized.signed_certificate_timestamp_ids.size()); |
- EXPECT_EQ(sct, deserialized.signed_certificate_timestamp_ids[0]); |
+ EXPECT_PRED2(SSLStatusAreEqual, status, deserialized); |
+ EXPECT_EQ(SignedCertificateTimestampIDAndStatus(1, net::ct::SCT_STATUS_OK), |
+ deserialized.signed_certificate_timestamp_ids[0]); |
// Test that |content_status| has the default (initialized) value. |
EXPECT_EQ(SSLStatus::NORMAL_CONTENT, deserialized.content_status); |
} |
@@ -46,66 +64,48 @@ TEST(SSLStatusSerializationTest, DeserializeBogusStatus) { |
SSLStatus invalid_deserialized; |
ASSERT_FALSE( |
DeserializeSecurityInfo("not an SSLStatus", &invalid_deserialized)); |
+ EXPECT_PRED2(SSLStatusAreEqual, SSLStatus(), invalid_deserialized); |
+} |
- SSLStatus default_ssl_status; |
- EXPECT_EQ(default_ssl_status.security_style, |
- invalid_deserialized.security_style); |
- EXPECT_EQ(default_ssl_status.cert_id, invalid_deserialized.cert_id); |
- EXPECT_EQ(default_ssl_status.cert_status, invalid_deserialized.cert_status); |
- EXPECT_EQ(default_ssl_status.security_bits, |
- invalid_deserialized.security_bits); |
- EXPECT_EQ(default_ssl_status.connection_status, |
- invalid_deserialized.connection_status); |
- EXPECT_EQ(default_ssl_status.content_status, |
- invalid_deserialized.content_status); |
- EXPECT_EQ(0u, invalid_deserialized.signed_certificate_timestamp_ids.size()); |
- |
- // Serialize a status with a bad |security_bits| value and test that |
- // deserializing it fails. |
+// Serialize a status with a bad |security_bits| value and test that |
+// deserializing it fails. |
+TEST(SSLStatusSerializationTest, DeserializeBogusSecurityBits) { |
SSLStatus status; |
- status.security_style = SECURITY_STYLE_AUTHENTICATED; |
- status.cert_id = 1; |
- status.cert_status = net::CERT_STATUS_DATE_INVALID; |
+ SetTestStatus(&status); |
// |security_bits| must be <-1. (-1 means the strength is unknown, and |
// |0 means the connection is not encrypted). |
status.security_bits = -5; |
- status.connection_status = net::SSL_CONNECTION_VERSION_TLS1_2; |
- SignedCertificateTimestampIDAndStatus sct(1, net::ct::SCT_STATUS_OK); |
- status.signed_certificate_timestamp_ids.push_back(sct); |
+ std::string serialized = SerializeSecurityInfo(status); |
+ |
+ SSLStatus invalid_deserialized; |
+ ASSERT_FALSE(DeserializeSecurityInfo(serialized, &invalid_deserialized)); |
+ EXPECT_PRED2(SSLStatusAreEqual, SSLStatus(), invalid_deserialized); |
+} |
+// Serialize a status with a bad |key_exchange_info| value and test that |
+// deserializing it fails. |
+TEST(SSLStatusSerializationTest, DeserializeBogusKeyExchangeInfo) { |
+ SSLStatus status; |
+ SetTestStatus(&status); |
+ status.key_exchange_info = -1; |
+ |
+ SSLStatus invalid_deserialized; |
std::string serialized = SerializeSecurityInfo(status); |
ASSERT_FALSE(DeserializeSecurityInfo(serialized, &invalid_deserialized)); |
+ EXPECT_PRED2(SSLStatusAreEqual, SSLStatus(), invalid_deserialized); |
+} |
- EXPECT_EQ(default_ssl_status.security_style, |
- invalid_deserialized.security_style); |
- EXPECT_EQ(default_ssl_status.cert_id, invalid_deserialized.cert_id); |
- EXPECT_EQ(default_ssl_status.cert_status, invalid_deserialized.cert_status); |
- EXPECT_EQ(default_ssl_status.security_bits, |
- invalid_deserialized.security_bits); |
- EXPECT_EQ(default_ssl_status.connection_status, |
- invalid_deserialized.connection_status); |
- EXPECT_EQ(default_ssl_status.content_status, |
- invalid_deserialized.content_status); |
- EXPECT_EQ(0u, invalid_deserialized.signed_certificate_timestamp_ids.size()); |
- |
- // Now serialize a status with a bad |security_style| value and test |
- // that deserializing fails. |
- status.security_bits = 128; |
+// Serialize a status with a bad |security_style| value and test that |
+// deserializing it fails. |
+TEST(SSLStatusSerializationTest, DeserializeBogusSecurityStyle) { |
+ SSLStatus status; |
+ SetTestStatus(&status); |
status.security_style = static_cast<SecurityStyle>(100); |
- serialized = SerializeSecurityInfo(status); |
- ASSERT_FALSE(DeserializeSecurityInfo(serialized, &invalid_deserialized)); |
+ std::string serialized = SerializeSecurityInfo(status); |
- EXPECT_EQ(default_ssl_status.security_style, |
- invalid_deserialized.security_style); |
- EXPECT_EQ(default_ssl_status.cert_id, invalid_deserialized.cert_id); |
- EXPECT_EQ(default_ssl_status.cert_status, invalid_deserialized.cert_status); |
- EXPECT_EQ(default_ssl_status.security_bits, |
- invalid_deserialized.security_bits); |
- EXPECT_EQ(default_ssl_status.connection_status, |
- invalid_deserialized.connection_status); |
- EXPECT_EQ(default_ssl_status.content_status, |
- invalid_deserialized.content_status); |
- EXPECT_EQ(0u, invalid_deserialized.signed_certificate_timestamp_ids.size()); |
+ SSLStatus invalid_deserialized; |
+ ASSERT_FALSE(DeserializeSecurityInfo(serialized, &invalid_deserialized)); |
+ EXPECT_PRED2(SSLStatusAreEqual, SSLStatus(), invalid_deserialized); |
} |
} // namespace |