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 "chrome/browser/chromeos/cros/onc_network_parser.h" | 5 #include "chrome/browser/chromeos/cros/onc_network_parser.h" |
6 | 6 |
7 #include <cert.h> | 7 #include <cert.h> |
8 #include <keyhi.h> | 8 #include <keyhi.h> |
9 #include <pk11pub.h> | 9 #include <pk11pub.h> |
10 | 10 |
11 #include "base/file_util.h" | 11 #include "base/file_util.h" |
12 #include "base/json/json_string_value_serializer.h" | 12 #include "base/json/json_string_value_serializer.h" |
13 #include "base/lazy_instance.h" | 13 #include "base/lazy_instance.h" |
14 #include "base/message_loop.h" | 14 #include "base/message_loop.h" |
15 #include "base/path_service.h" | 15 #include "base/path_service.h" |
16 #include "base/stringprintf.h" | 16 #include "base/stringprintf.h" |
17 #include "base/threading/thread_restrictions.h" | 17 #include "base/threading/thread_restrictions.h" |
18 #include "base/values.h" | 18 #include "base/values.h" |
19 #include "chrome/browser/chromeos/cros/certificate_pattern.h" | 19 #include "chrome/browser/chromeos/cros/certificate_pattern.h" |
20 #include "chrome/browser/chromeos/cros/cros_library.h" | 20 #include "chrome/browser/chromeos/cros/cros_library.h" |
21 #include "chrome/browser/chromeos/cros/network_library.h" | 21 #include "chrome/browser/chromeos/cros/network_library.h" |
22 #include "chrome/browser/chromeos/dbus/dbus_thread_manager.h" | 22 #include "chrome/browser/chromeos/dbus/dbus_thread_manager.h" |
23 #include "chrome/browser/chromeos/login/mock_user_manager.h" | 23 #include "chrome/browser/chromeos/login/mock_user_manager.h" |
24 #include "chrome/browser/net/pref_proxy_config_tracker_impl.h" | 24 #include "chrome/browser/net/pref_proxy_config_tracker_impl.h" |
25 #include "chrome/common/chrome_paths.h" | 25 #include "chrome/common/chrome_paths.h" |
| 26 #include "chrome/common/net/x509_certificate_model.h" |
26 #include "chrome/test/base/testing_browser_process.h" | 27 #include "chrome/test/base/testing_browser_process.h" |
27 #include "chrome/test/base/testing_pref_service.h" | 28 #include "chrome/test/base/testing_pref_service.h" |
28 #include "content/test/test_browser_thread.h" | 29 #include "content/test/test_browser_thread.h" |
29 #include "crypto/nss_util.h" | 30 #include "crypto/nss_util.h" |
30 #include "net/base/cert_database.h" | 31 #include "net/base/cert_database.h" |
31 #include "net/base/cert_type.h" | 32 #include "net/base/cert_type.h" |
32 #include "net/base/crypto_module.h" | 33 #include "net/base/crypto_module.h" |
33 #include "net/base/x509_certificate.h" | 34 #include "net/base/x509_certificate.h" |
34 #include "net/proxy/proxy_config.h" | 35 #include "net/proxy/proxy_config.h" |
35 #include "net/third_party/mozilla_security_manager/nsNSSCertTrust.h" | 36 #include "net/third_party/mozilla_security_manager/nsNSSCertTrust.h" |
36 #include "testing/gtest/include/gtest/gtest.h" | 37 #include "testing/gtest/include/gtest/gtest.h" |
37 #include "third_party/cros_system_api/dbus/service_constants.h" | 38 #include "third_party/cros_system_api/dbus/service_constants.h" |
38 | 39 |
39 using ::testing::AnyNumber; | 40 using ::testing::AnyNumber; |
40 using ::testing::Return; | 41 using ::testing::Return; |
41 | 42 |
42 namespace msm = mozilla_security_manager; | 43 namespace msm = mozilla_security_manager; |
43 namespace chromeos { | 44 namespace chromeos { |
44 | 45 |
45 namespace { | 46 namespace { |
46 | 47 |
47 const char g_token_name[] = "OncNetworkParserTest token"; | 48 const char g_token_name[] = "OncNetworkParserTest token"; |
48 | 49 |
49 net::CertType GetCertType(const net::X509Certificate* cert) { | 50 net::CertType GetCertType(const net::X509Certificate* cert) { |
50 DCHECK(cert); | 51 DCHECK(cert); |
51 msm::nsNSSCertTrust trust(cert->os_cert_handle()->trust); | 52 return x509_certificate_model::GetType(cert->os_cert_handle()); |
52 if (trust.HasAnyUser()) | |
53 return net::USER_CERT; | |
54 if (trust.HasPeer(PR_TRUE, PR_FALSE, PR_FALSE)) | |
55 return net::SERVER_CERT; | |
56 if (trust.HasAnyCA() || CERT_IsCACert(cert->os_cert_handle(), NULL)) | |
57 return net::CA_CERT; | |
58 return net::UNKNOWN_CERT; | |
59 } | 53 } |
60 | 54 |
61 } // namespace | 55 } // namespace |
62 | 56 |
63 class OncNetworkParserTest : public testing::Test { | 57 class OncNetworkParserTest : public testing::Test { |
64 public: | 58 public: |
65 static void SetUpTestCase() { | 59 static void SetUpTestCase() { |
66 // Ideally, we'd open a test DB for each test case, and close it | 60 // Ideally, we'd open a test DB for each test case, and close it |
67 // again, removing the temp dir, but unfortunately, there's a | 61 // again, removing the temp dir, but unfortunately, there's a |
68 // bug in NSS that prevents this from working, so we just open | 62 // bug in NSS that prevents this from working, so we just open |
(...skipping 850 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
919 | 913 |
920 EXPECT_EQ("a onc b", | 914 EXPECT_EQ("a onc b", |
921 chromeos::OncNetworkParser::GetUserExpandedValue( | 915 chromeos::OncNetworkParser::GetUserExpandedValue( |
922 login_id_pattern, source)); | 916 login_id_pattern, source)); |
923 EXPECT_EQ("a onc@example.com b", | 917 EXPECT_EQ("a onc@example.com b", |
924 chromeos::OncNetworkParser::GetUserExpandedValue( | 918 chromeos::OncNetworkParser::GetUserExpandedValue( |
925 login_email_pattern, source)); | 919 login_email_pattern, source)); |
926 } | 920 } |
927 | 921 |
928 } // namespace chromeos | 922 } // namespace chromeos |
OLD | NEW |