aw: Move SharedRendererState out of AwContents
[chromium-blink-merge.git] / chromeos / network / onc / onc_utils_unittest.cc
blob90ce28a21cc98d0436756bfcb8ab4b36e4fb8aba
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
3 // found in the LICENSE file.
5 #include "chromeos/network/onc/onc_utils.h"
7 #include <string>
9 #include "base/values.h"
10 #include "chromeos/network/onc/onc_signature.h"
11 #include "chromeos/network/onc/onc_test_utils.h"
12 #include "testing/gtest/include/gtest/gtest.h"
14 namespace chromeos {
15 namespace onc {
17 TEST(ONCDecrypterTest, BrokenEncryptionIterations) {
18 scoped_ptr<base::DictionaryValue> encrypted_onc =
19 test_utils::ReadTestDictionary("broken-encrypted-iterations.onc");
21 scoped_ptr<base::DictionaryValue> decrypted_onc =
22 Decrypt("test0000", *encrypted_onc);
24 EXPECT_EQ(NULL, decrypted_onc.get());
27 TEST(ONCDecrypterTest, BrokenEncryptionZeroIterations) {
28 scoped_ptr<base::DictionaryValue> encrypted_onc =
29 test_utils::ReadTestDictionary("broken-encrypted-zero-iterations.onc");
31 std::string error;
32 scoped_ptr<base::DictionaryValue> decrypted_onc =
33 Decrypt("test0000", *encrypted_onc);
35 EXPECT_EQ(NULL, decrypted_onc.get());
38 TEST(ONCDecrypterTest, LoadEncryptedOnc) {
39 scoped_ptr<base::DictionaryValue> encrypted_onc =
40 test_utils::ReadTestDictionary("encrypted.onc");
41 scoped_ptr<base::DictionaryValue> expected_decrypted_onc =
42 test_utils::ReadTestDictionary("decrypted.onc");
44 std::string error;
45 scoped_ptr<base::DictionaryValue> actual_decrypted_onc =
46 Decrypt("test0000", *encrypted_onc);
48 base::DictionaryValue emptyDict;
49 EXPECT_TRUE(test_utils::Equals(expected_decrypted_onc.get(),
50 actual_decrypted_onc.get()));
53 namespace {
55 const char* kLoginId = "hans";
56 const char* kLoginEmail = "hans@my.domain.com";
58 class StringSubstitutionStub : public StringSubstitution {
59 public:
60 StringSubstitutionStub() {}
61 virtual bool GetSubstitute(const std::string& placeholder,
62 std::string* substitute) const override {
63 if (placeholder == ::onc::substitutes::kLoginIDField)
64 *substitute = kLoginId;
65 else if (placeholder ==::onc::substitutes::kEmailField)
66 *substitute = kLoginEmail;
67 else
68 return false;
69 return true;
71 private:
72 DISALLOW_COPY_AND_ASSIGN(StringSubstitutionStub);
75 } // namespace
77 TEST(ONCStringExpansion, OpenVPN) {
78 scoped_ptr<base::DictionaryValue> vpn_onc =
79 test_utils::ReadTestDictionary("valid_openvpn.onc");
81 StringSubstitutionStub substitution;
82 ExpandStringsInOncObject(kNetworkConfigurationSignature, substitution,
83 vpn_onc.get());
85 std::string actual_expanded;
86 vpn_onc->GetString("VPN.OpenVPN.Username", &actual_expanded);
87 EXPECT_EQ(actual_expanded, std::string("abc ") + kLoginEmail + " def");
90 TEST(ONCStringExpansion, WiFi_EAP) {
91 scoped_ptr<base::DictionaryValue> wifi_onc =
92 test_utils::ReadTestDictionary("wifi_clientcert_with_cert_pems.onc");
94 StringSubstitutionStub substitution;
95 ExpandStringsInOncObject(kNetworkConfigurationSignature, substitution,
96 wifi_onc.get());
98 std::string actual_expanded;
99 wifi_onc->GetString("WiFi.EAP.Identity", &actual_expanded);
100 EXPECT_EQ(actual_expanded, std::string("abc ") + kLoginId + "@my.domain.com");
103 TEST(ONCResolveServerCertRefs, ResolveServerCertRefs) {
104 scoped_ptr<base::DictionaryValue> test_cases =
105 test_utils::ReadTestDictionary(
106 "network_configs_with_resolved_certs.json");
108 CertPEMsByGUIDMap certs;
109 certs["cert_google"] = "pem_google";
110 certs["cert_webkit"] = "pem_webkit";
112 for (base::DictionaryValue::Iterator it(*test_cases);
113 !it.IsAtEnd(); it.Advance()) {
114 SCOPED_TRACE("Test case: " + it.key());
116 const base::DictionaryValue* test_case = NULL;
117 it.value().GetAsDictionary(&test_case);
119 const base::ListValue* networks_with_cert_refs = NULL;
120 test_case->GetList("WithCertRefs", &networks_with_cert_refs);
122 const base::ListValue* expected_resolved_onc = NULL;
123 test_case->GetList("WithResolvedRefs", &expected_resolved_onc);
125 bool expected_success = (networks_with_cert_refs->GetSize() ==
126 expected_resolved_onc->GetSize());
128 scoped_ptr<base::ListValue> actual_resolved_onc(
129 networks_with_cert_refs->DeepCopy());
131 bool success = ResolveServerCertRefsInNetworks(certs,
132 actual_resolved_onc.get());
133 EXPECT_EQ(expected_success, success);
134 EXPECT_TRUE(test_utils::Equals(expected_resolved_onc,
135 actual_resolved_onc.get()));
139 } // namespace onc
140 } // namespace chromeos