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 "chromeos/network/onc/onc_utils.h" | 5 #include "chromeos/network/onc/onc_utils.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/values.h" | 9 #include "base/values.h" |
10 #include "chromeos/network/onc/onc_signature.h" | 10 #include "chromeos/network/onc/onc_signature.h" |
11 #include "chromeos/network/onc/onc_test_utils.h" | 11 #include "chromeos/network/onc/onc_test_utils.h" |
| 12 #include "net/cert/x509_certificate.h" |
| 13 #include "net/test/test_certificate_data.h" |
12 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
13 | 15 |
14 namespace chromeos { | 16 namespace chromeos { |
15 namespace onc { | 17 namespace onc { |
16 | 18 |
17 TEST(ONCDecrypterTest, BrokenEncryptionIterations) { | 19 TEST(ONCDecrypterTest, BrokenEncryptionIterations) { |
18 scoped_ptr<base::DictionaryValue> encrypted_onc = | 20 scoped_ptr<base::DictionaryValue> encrypted_onc = |
19 test_utils::ReadTestDictionary("broken-encrypted-iterations.onc"); | 21 test_utils::ReadTestDictionary("broken-encrypted-iterations.onc"); |
20 | 22 |
21 scoped_ptr<base::DictionaryValue> decrypted_onc = | 23 scoped_ptr<base::DictionaryValue> decrypted_onc = |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
82 ExpandStringsInOncObject(kNetworkConfigurationSignature, substitution, | 84 ExpandStringsInOncObject(kNetworkConfigurationSignature, substitution, |
83 vpn_onc.get()); | 85 vpn_onc.get()); |
84 | 86 |
85 std::string actual_expanded; | 87 std::string actual_expanded; |
86 vpn_onc->GetString("VPN.OpenVPN.Username", &actual_expanded); | 88 vpn_onc->GetString("VPN.OpenVPN.Username", &actual_expanded); |
87 EXPECT_EQ(actual_expanded, std::string("abc ") + kLoginEmail + " def"); | 89 EXPECT_EQ(actual_expanded, std::string("abc ") + kLoginEmail + " def"); |
88 } | 90 } |
89 | 91 |
90 TEST(ONCStringExpansion, WiFi_EAP) { | 92 TEST(ONCStringExpansion, WiFi_EAP) { |
91 scoped_ptr<base::DictionaryValue> wifi_onc = | 93 scoped_ptr<base::DictionaryValue> wifi_onc = |
92 test_utils::ReadTestDictionary("valid_wifi_clientcert.onc"); | 94 test_utils::ReadTestDictionary("wifi_clientcert_with_cert_pems.onc"); |
93 | 95 |
94 StringSubstitutionStub substitution; | 96 StringSubstitutionStub substitution; |
95 ExpandStringsInOncObject(kNetworkConfigurationSignature, substitution, | 97 ExpandStringsInOncObject(kNetworkConfigurationSignature, substitution, |
96 wifi_onc.get()); | 98 wifi_onc.get()); |
97 | 99 |
98 std::string actual_expanded; | 100 std::string actual_expanded; |
99 wifi_onc->GetString("WiFi.EAP.Identity", &actual_expanded); | 101 wifi_onc->GetString("WiFi.EAP.Identity", &actual_expanded); |
100 EXPECT_EQ(actual_expanded, std::string("abc ") + kLoginId + "@my.domain.com"); | 102 EXPECT_EQ(actual_expanded, std::string("abc ") + kLoginId + "@my.domain.com"); |
101 } | 103 } |
102 | 104 |
| 105 TEST(ONCResolveServerCertRefs, ResolveServerCertRefs) { |
| 106 scoped_ptr<base::DictionaryValue> test_cases = |
| 107 test_utils::ReadTestDictionary( |
| 108 "network_configs_with_resolved_certs.json"); |
| 109 |
| 110 scoped_refptr<net::X509Certificate> google_cert( |
| 111 net::X509Certificate::CreateFromBytes( |
| 112 reinterpret_cast<const char*>(google_der), sizeof(google_der))); |
| 113 |
| 114 scoped_refptr<net::X509Certificate> webkit_cert( |
| 115 net::X509Certificate::CreateFromBytes( |
| 116 reinterpret_cast<const char*>(webkit_der), sizeof(webkit_der))); |
| 117 |
| 118 CertsByGUIDMap certs; |
| 119 certs["cert_google"] = google_cert; |
| 120 certs["cert_webkit"] = webkit_cert; |
| 121 |
| 122 for (base::DictionaryValue::Iterator it(*test_cases); |
| 123 !it.IsAtEnd(); it.Advance()) { |
| 124 SCOPED_TRACE("Test case: " + it.key()); |
| 125 |
| 126 const base::DictionaryValue* test_case = NULL; |
| 127 it.value().GetAsDictionary(&test_case); |
| 128 |
| 129 const base::ListValue* networks_with_cert_refs = NULL; |
| 130 test_case->GetList("WithCertRefs", &networks_with_cert_refs); |
| 131 |
| 132 const base::ListValue* expected_resolved_onc = NULL; |
| 133 test_case->GetList("WithResolvedRefs", &expected_resolved_onc); |
| 134 |
| 135 bool expected_success = (networks_with_cert_refs->GetSize() == |
| 136 expected_resolved_onc->GetSize()); |
| 137 |
| 138 scoped_ptr<base::ListValue> actual_resolved_onc( |
| 139 networks_with_cert_refs->DeepCopy()); |
| 140 |
| 141 bool success = ResolveServerCertRefsInNetworks(certs, |
| 142 actual_resolved_onc.get()); |
| 143 EXPECT_EQ(expected_success, success); |
| 144 EXPECT_TRUE(test_utils::Equals(expected_resolved_onc, |
| 145 actual_resolved_onc.get())); |
| 146 } |
| 147 } |
| 148 |
103 } // namespace onc | 149 } // namespace onc |
104 } // namespace chromeos | 150 } // namespace chromeos |
OLD | NEW |