summaryrefslogtreecommitdiffstats
path: root/net
diff options
context:
space:
mode:
authorbulach@chromium.org <bulach@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-03-08 15:34:46 +0000
committerbulach@chromium.org <bulach@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-03-08 15:34:46 +0000
commitfaedb7f408ec4a58baf55c7054efc6c04bf4c299 (patch)
tree5269792b23fdc72e643df18ca73fac1cbe89f29e /net
parent62aa55da5c41fa891038053e541a2f33c0dcc8a9 (diff)
downloadchromium_src-faedb7f408ec4a58baf55c7054efc6c04bf4c299.zip
chromium_src-faedb7f408ec4a58baf55c7054efc6c04bf4c299.tar.gz
chromium_src-faedb7f408ec4a58baf55c7054efc6c04bf4c299.tar.bz2
Moves X509CertificateNameVerifyTest and removes x509_openssl_util_unittest.cc
BUG=none TEST=X509CertificateNameVerifyTest.VerifyHostname, and also compiles with use_openssl=1 flag. Review URL: http://codereview.chromium.org/6627051 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@77285 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net')
-rw-r--r--net/base/x509_certificate.h1
-rw-r--r--net/base/x509_certificate_unittest.cc84
-rw-r--r--net/base/x509_openssl_util_unittest.cc103
-rw-r--r--net/net.gyp1
4 files changed, 85 insertions, 104 deletions
diff --git a/net/base/x509_certificate.h b/net/base/x509_certificate.h
index 5c8a285..b1a15aa 100644
--- a/net/base/x509_certificate.h
+++ b/net/base/x509_certificate.h
@@ -328,6 +328,7 @@ class X509Certificate : public base::RefCountedThreadSafe<X509Certificate> {
friend class TestRootCerts; // For unit tests
FRIEND_TEST_ALL_PREFIXES(X509CertificateTest, Cache);
FRIEND_TEST_ALL_PREFIXES(X509CertificateTest, IntermediateCertificates);
+ FRIEND_TEST_ALL_PREFIXES(X509CertificateNameVerifyTest, VerifyHostname);
// Construct an X509Certificate from a handle to the certificate object
// in the underlying crypto library.
diff --git a/net/base/x509_certificate_unittest.cc b/net/base/x509_certificate_unittest.cc
index c5f27ae..8871c34 100644
--- a/net/base/x509_certificate_unittest.cc
+++ b/net/base/x509_certificate_unittest.cc
@@ -7,6 +7,7 @@
#include "base/file_util.h"
#include "base/path_service.h"
#include "base/pickle.h"
+#include "base/string_split.h"
#include "net/base/cert_status_flags.h"
#include "net/base/cert_test_util.h"
#include "net/base/cert_verify_result.h"
@@ -837,4 +838,87 @@ TEST_P(X509CertificateParseTest, CanParseFormat) {
INSTANTIATE_TEST_CASE_P(, X509CertificateParseTest,
testing::ValuesIn(FormatTestData));
+struct CertificateNameVerifyTestData {
+ // true iff we expect hostname to match an entry in cert_names.
+ bool expected;
+ // The hostname to match.
+ const char* hostname;
+ // '/' separated list of certificate names to match against. Any occurrence
+ // of '#' will be replaced with a null character before processing.
+ const char* cert_names;
+};
+
+const CertificateNameVerifyTestData kNameVerifyTestData[] = {
+ { true, "foo.com", "foo.com" },
+ { true, "foo.com", "foo.com." },
+ { true, "f", "f" },
+ { true, "f", "f." },
+ { true, "bar.foo.com", "*.foo.com" },
+ { true, "www-3.bar.foo.com", "*.bar.foo.com." },
+ { true, "www.test.fr", "*.test.com/*.test.co.uk/*.test.de/*.test.fr" },
+ { true, "wwW.tESt.fr", "//*.*/*.test.de/*.test.FR/www" },
+ { false, "foo.com", "*.com" },
+ { false, "f.uk", ".uk" },
+ { true, "h.co.uk", "*.co.uk" },
+ { false, "192.168.1.11", "*.168.1.11" },
+ { false, "foo.us", "*.us" },
+ { false, "www.bar.foo.com",
+ "*.foo.com/*.*.foo.com/*.*.bar.foo.com/*w*.bar.foo.com/*..bar.foo.com" },
+ { false, "w.bar.foo.com", "?.bar.foo.com" },
+ { false, "www.foo.com", "(www|ftp).foo.com" },
+ { false, "www.foo.com", "www.foo.com#*.foo.com/#" }, // # = null char.
+ { false, "foo", "*" },
+ { false, "foo.", "*." },
+ { false, "test.org", "www.test.org/*.test.org/*.org" },
+ { false, "1.2.3.4.5.6", "*.2.3.4.5.6" },
+ // IDN tests
+ { true, "xn--poema-9qae5a.com.br", "xn--poema-9qae5a.com.br" },
+ { true, "www.xn--poema-9qae5a.com.br", "*.xn--poema-9qae5a.com.br" },
+ { false, "xn--poema-9qae5a.com.br", "*.xn--poema-9qae5a.com.br" },
+ // The following are adapted from the examples in
+ // http://tools.ietf.org/html/draft-saintandre-tls-server-id-check-09#section-4.4.3
+ { true, "foo.example.com", "*.example.com" },
+ { false, "bar.foo.example.com", "*.example.com" },
+ { false, "example.com", "*.example.com" },
+ { false, "baz1.example.net", "baz*.example.net" },
+ { false, "baz2.example.net", "baz*.example.net" },
+ { false, "bar.*.example.net", "bar.*.example.net" },
+ { false, "bar.f*o.example.net", "bar.f*o.example.net" },
+ // IP addresses currently not supported, except for the localhost.
+ { true, "127.0.0.1", "127.0.0.1" },
+ { false, "192.168.1.1", "192.168.1.1" },
+ { false, "FEDC:BA98:7654:3210:FEDC:BA98:7654:3210",
+ "FEDC:BA98:7654:3210:FEDC:BA98:7654:3210" },
+ { false, "FEDC:BA98:7654:3210:FEDC:BA98:7654:3210", "*.]" },
+ { false, "::192.9.5.5", "::192.9.5.5" },
+ { false, "::192.9.5.5", "*.9.5.5" },
+ { false, "2010:836B:4179::836B:4179", "*:836B:4179::836B:4179" },
+ // Invalid host names.
+ { false, "www%26.foo.com", "www%26.foo.com" },
+ { false, "www.*.com", "www.*.com" },
+ { false, "w$w.f.com", "w$w.f.com" },
+ { false, "www-1.[::FFFF:129.144.52.38]", "*.[::FFFF:129.144.52.38]" },
+};
+
+class X509CertificateNameVerifyTest
+ : public testing::TestWithParam<CertificateNameVerifyTestData> {
+};
+
+TEST_P(X509CertificateNameVerifyTest, VerifyHostname) {
+ CertificateNameVerifyTestData test_data = GetParam();
+
+ std::string cert_name_line(test_data.cert_names);
+ std::replace(cert_name_line.begin(), cert_name_line.end(), '#', '\0');
+ std::vector<std::string> cert_names;
+ base::SplitString(cert_name_line, '/', &cert_names);
+
+ EXPECT_EQ(test_data.expected,
+ X509Certificate::VerifyHostname(test_data.hostname, cert_names))
+ << "Host [" << test_data.hostname
+ << "], cert name [" << test_data.cert_names << "]";
+}
+
+INSTANTIATE_TEST_CASE_P(, X509CertificateNameVerifyTest,
+ testing::ValuesIn(kNameVerifyTestData));
+
} // namespace net
diff --git a/net/base/x509_openssl_util_unittest.cc b/net/base/x509_openssl_util_unittest.cc
deleted file mode 100644
index 4727d4c..0000000
--- a/net/base/x509_openssl_util_unittest.cc
+++ /dev/null
@@ -1,103 +0,0 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "net/base/x509_openssl_util.h"
-
-#include <algorithm>
-
-#include "base/string_split.h"
-#include "testing/gtest/include/gtest/gtest.h"
-
-namespace net {
-
-namespace x509_openssl_util {
-
-namespace {
-
-struct CertificateNameVerifyTestData {
- // true iff we expect hostname to match an entry in cert_names.
- const bool expected;
- // The hostname to match.
- const char* const hostname;
- // '/' separated list of certificate names to match against. Any occurrence
- // of '#' will be replaced with a null character before processing.
- const char* const cert_names;
-};
-
-CertificateNameVerifyTestData kNameVerifyTestData[] = {
- { true, "foo.com", "foo.com" },
- { true, "foo.com", "foo.com." },
- { true, "f", "f" },
- { true, "f", "f." },
- { true, "bar.foo.com", "*.foo.com" },
- { true, "www-3.bar.foo.com", "*.bar.foo.com." },
- { true, "www.test.fr", "*.test.com/*.test.co.uk/*.test.de/*.test.fr" },
- { true, "wwW.tESt.fr", "//*.*/*.test.de/*.test.FR/www" },
- { false, "foo.com", "*.com" },
- { false, "f.uk", ".uk" },
- { true, "h.co.uk", "*.co.uk" },
- { false, "192.168.1.11", "*.168.1.11" },
- { false, "foo.us", "*.us" },
- { false, "www.bar.foo.com",
- "*.foo.com/*.*.foo.com/*.*.bar.foo.com/*w*.bar.foo.com/*..bar.foo.com" },
- { false, "w.bar.foo.com", "?.bar.foo.com" },
- { false, "www.foo.com", "(www|ftp).foo.com" },
- { false, "www.foo.com", "www.foo.com#*.foo.com/#" }, // # = null char.
- { false, "foo", "*" },
- { false, "foo.", "*." },
- { false, "test.org", "www.test.org/*.test.org/*.org" },
- { false, "1.2.3.4.5.6", "*.2.3.4.5.6" },
- // IDN tests
- { true, "xn--poema-9qae5a.com.br", "xn--poema-9qae5a.com.br" },
- { true, "www.xn--poema-9qae5a.com.br", "*.xn--poema-9qae5a.com.br" },
- { false, "xn--poema-9qae5a.com.br", "*.xn--poema-9qae5a.com.br" },
- // The following are adapted from the examples in http://tools.ietf.org/html/draft-saintandre-tls-server-id-check-09#section-4.4.3
- { true, "foo.example.com", "*.example.com" },
- { false, "bar.foo.example.com", "*.example.com" },
- { false, "example.com", "*.example.com" },
- { false, "baz1.example.net", "baz*.example.net" },
- { false, "baz2.example.net", "baz*.example.net" },
- { false, "bar.*.example.net", "bar.*.example.net" },
- { false, "bar.f*o.example.net", "bar.f*o.example.net" },
- // IP addresses currently not supported, except for the localhost.
- { true, "127.0.0.1", "127.0.0.1" },
- { false, "192.168.1.1", "192.168.1.1" },
- { false, "FEDC:BA98:7654:3210:FEDC:BA98:7654:3210",
- "FEDC:BA98:7654:3210:FEDC:BA98:7654:3210" },
- { false, "FEDC:BA98:7654:3210:FEDC:BA98:7654:3210", "*.]" },
- { false, "::192.9.5.5", "::192.9.5.5" },
- { false, "::192.9.5.5", "*.9.5.5" },
- { false, "2010:836B:4179::836B:4179", "*:836B:4179::836B:4179" },
- // Invalid host names.
- { false, "www%26.foo.com", "www%26.foo.com" },
- { false, "www.*.com", "www.*.com" },
- { false, "w$w.f.com", "w$w.f.com" },
- { false, "www-1.[::FFFF:129.144.52.38]", "*.[::FFFF:129.144.52.38]" },
-};
-
-class X509CertificateNameVerifyTest
- : public testing::TestWithParam<CertificateNameVerifyTestData> {
-};
-
-TEST_P(X509CertificateNameVerifyTest, VerifyHostname) {
- CertificateNameVerifyTestData test_data(GetParam());
-
- std::string cert_name_line(test_data.cert_names);
- std::replace(cert_name_line.begin(), cert_name_line.end(), '#', '\0');
- std::vector<std::string> cert_names;
- base::SplitString(cert_name_line, '/', &cert_names);
-
- EXPECT_EQ(test_data.expected, VerifyHostname(test_data.hostname, cert_names))
- << "Host [" << test_data.hostname
- << "], cert name [" << test_data.cert_names << "]";
-}
-
-INSTANTIATE_TEST_CASE_P(, X509CertificateNameVerifyTest,
- testing::ValuesIn(kNameVerifyTestData));
-
-} // namespace
-
-} // namespace x509_openssl_util
-
-} // namespace net
diff --git a/net/net.gyp b/net/net.gyp
index 1aff097..3c3e44e 100644
--- a/net/net.gyp
+++ b/net/net.gyp
@@ -896,7 +896,6 @@
'base/upload_data_stream_unittest.cc',
'base/x509_certificate_unittest.cc',
'base/x509_cert_types_mac_unittest.cc',
- 'base/x509_openssl_util_unittest.cc',
'disk_cache/addr_unittest.cc',
'disk_cache/backend_unittest.cc',
'disk_cache/bitmap_unittest.cc',