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_test_utils.h" | 10 #include "chromeos/network/onc/onc_test_utils.h" |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
42 | 42 |
43 std::string error; | 43 std::string error; |
44 scoped_ptr<base::DictionaryValue> actual_decrypted_onc = | 44 scoped_ptr<base::DictionaryValue> actual_decrypted_onc = |
45 Decrypt("test0000", *encrypted_onc); | 45 Decrypt("test0000", *encrypted_onc); |
46 | 46 |
47 base::DictionaryValue emptyDict; | 47 base::DictionaryValue emptyDict; |
48 EXPECT_TRUE(test_utils::Equals(expected_decrypted_onc.get(), | 48 EXPECT_TRUE(test_utils::Equals(expected_decrypted_onc.get(), |
49 actual_decrypted_onc.get())); | 49 actual_decrypted_onc.get())); |
50 } | 50 } |
51 | 51 |
| 52 namespace { |
| 53 |
| 54 const char* kLoginId = "hans"; |
| 55 const char* kLoginEmail = "hans@my.domain.com"; |
| 56 |
| 57 class StringSubstitutionStub : public StringSubstitution { |
| 58 public: |
| 59 StringSubstitutionStub() {} |
| 60 virtual bool GetSubstitute(std::string placeholder, |
| 61 std::string* substitute) const { |
| 62 if (placeholder == substitutes::kLoginIDField) |
| 63 *substitute = kLoginId; |
| 64 else if (placeholder == substitutes::kEmailField) |
| 65 *substitute = kLoginEmail; |
| 66 else |
| 67 return false; |
| 68 return true; |
| 69 } |
| 70 private: |
| 71 DISALLOW_COPY_AND_ASSIGN(StringSubstitutionStub); |
| 72 }; |
| 73 |
| 74 } // namespace |
| 75 |
| 76 TEST(ONCStringExpansion, OpenVPN) { |
| 77 scoped_ptr<base::DictionaryValue> vpn_onc = |
| 78 test_utils::ReadTestDictionary("valid_openvpn.onc"); |
| 79 |
| 80 StringSubstitutionStub substitution; |
| 81 ExpandStringsInOncObject(kNetworkConfigurationSignature, substitution, |
| 82 vpn_onc.get()); |
| 83 |
| 84 std::string actual_expanded; |
| 85 vpn_onc->GetString("VPN.OpenVPN.Username", &actual_expanded); |
| 86 EXPECT_EQ(actual_expanded, std::string("abc ") + kLoginEmail + " def"); |
| 87 } |
| 88 |
| 89 TEST(ONCStringExpansion, WiFi_EAP) { |
| 90 scoped_ptr<base::DictionaryValue> wifi_onc = |
| 91 test_utils::ReadTestDictionary("valid_wifi_clientcert.onc"); |
| 92 |
| 93 StringSubstitutionStub substitution; |
| 94 ExpandStringsInOncObject(kNetworkConfigurationSignature, substitution, |
| 95 wifi_onc.get()); |
| 96 |
| 97 std::string actual_expanded; |
| 98 wifi_onc->GetString("WiFi.EAP.Identity", &actual_expanded); |
| 99 EXPECT_EQ(actual_expanded, std::string("abc ") + kLoginId + "@my.domain.com"); |
| 100 } |
| 101 |
52 } // namespace onc | 102 } // namespace onc |
53 } // namespace chromeos | 103 } // namespace chromeos |
OLD | NEW |