Chromium Code Reviews| Index: net/base/x509_certificate_unittest.cc |
| diff --git a/net/base/x509_certificate_unittest.cc b/net/base/x509_certificate_unittest.cc |
| index 4855d89bf41060f3f676838ff5d2b9e8b1cdd2dd..d33b1d895c5b06ccf6b8829177ed1f8b926f5844 100644 |
| --- a/net/base/x509_certificate_unittest.cc |
| +++ b/net/base/x509_certificate_unittest.cc |
| @@ -438,6 +438,44 @@ TEST(X509CertificateTest, CAFingerprints) { |
| cert_chain3_ca_fingerprint, 20) == 0); |
| } |
| +TEST(X509CertificateTest, ParseSubjectAltNames) { |
| + FilePath certs_dir = GetTestCertsDirectory(); |
| + |
| + scoped_refptr<X509Certificate> san_cert = |
| + ImportCertFromFile(certs_dir, "subjectAltName_sanity_check.pem"); |
| + ASSERT_NE(static_cast<X509Certificate*>(NULL), san_cert); |
| + |
| + std::vector<std::string> dns_names; |
| + std::vector<std::string> ip_addresses; |
| + san_cert->GetSubjectAltName(&dns_names, &ip_addresses); |
| + |
| + // Ensure that DNS names are correctly parsed. |
| + ASSERT_EQ(1U, dns_names.size()); |
| + EXPECT_EQ("test.example", dns_names[0]); |
| + |
| + // Ensure that both IPv4 and IPv6 addresses are correctly parsed. |
| + ASSERT_EQ(2U, ip_addresses.size()); |
| + |
| + static const unsigned char kIPv4Address[] = { |
|
agl
2012/04/03 10:41:22
s/unsigned char/uint8 ?
Ryan Sleevi
2012/04/03 17:17:18
Done. Since this file was a mixed of unsigned char
|
| + 0x7F, 0x00, 0x00, 0x02 |
| + }; |
| + ASSERT_EQ(arraysize(kIPv4Address), ip_addresses[0].size()); |
| + EXPECT_EQ(0, memcmp(ip_addresses[0].data(), kIPv4Address, |
| + arraysize(kIPv4Address))); |
| + |
| + static const unsigned char kIPv6Address[] = { |
|
agl
2012/04/03 10:41:22
ditto
|
| + 0xFE, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 |
| + }; |
| + ASSERT_EQ(arraysize(kIPv6Address), ip_addresses[1].size()); |
| + EXPECT_EQ(0, memcmp(ip_addresses[1].data(), kIPv6Address, |
| + arraysize(kIPv6Address))); |
| + |
| + // Ensure the subjectAltName dirName has not influenced the handling of |
| + // the subject commonName. |
| + EXPECT_EQ("127.0.0.1", san_cert->subject().common_name); |
| +} |
| + |
| TEST(X509CertificateTest, ExtractSPKIFromDERCert) { |
| FilePath certs_dir = GetTestCertsDirectory(); |
| scoped_refptr<X509Certificate> cert = |