Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2015 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. | |
| 4 | |
| 5 #include "components/wifi_sync/wifi_credential.h" | |
| 6 | |
| 7 #include "base/values.h" | |
| 8 #include "components/onc/onc_constants.h" | |
| 9 #include "testing/gtest/include/gtest/gtest.h" | |
| 10 | |
| 11 namespace wifi_sync { | |
| 12 | |
| 13 WifiCredential MakeCredential(const std::string& ssid, | |
| 14 WifiSecurityClass security_class, | |
| 15 const std::string& passphrase) { | |
| 16 return WifiCredential( | |
| 17 WifiCredential::MakeSsidBytes(ssid), security_class, passphrase); | |
| 18 } | |
|
stevenjb
2015/01/08 17:27:51
nit: helper functions should be in a local namespa
erikwright (departed)
2015/01/08 19:27:08
by which he means anonymous.
mukesh agrawal
2015/01/09 02:00:18
Done.
mukesh agrawal
2015/01/09 02:00:18
Done.
| |
| 19 | |
| 20 bool TypeIsWifi(const base::DictionaryValue& onc_properties) { | |
| 21 std::string network_type; | |
| 22 EXPECT_TRUE(onc_properties.GetString( | |
| 23 onc::toplevel_config::kType, &network_type)); | |
| 24 return network_type == onc::network_type::kWiFi; | |
| 25 } | |
| 26 | |
| 27 std::string GetSsid(const base::DictionaryValue& onc_properties) { | |
| 28 std::string ssid; | |
| 29 EXPECT_TRUE(onc_properties.GetString( | |
| 30 onc::network_config::WifiProperty(onc::wifi::kSSID), &ssid)); | |
| 31 return ssid; | |
| 32 } | |
| 33 | |
| 34 std::string GetOncSecurity(const base::DictionaryValue& onc_properties) { | |
| 35 std::string onc_security; | |
| 36 EXPECT_TRUE(onc_properties.GetString( | |
| 37 onc::network_config::WifiProperty(onc::wifi::kSecurity), &onc_security)); | |
| 38 return onc_security; | |
| 39 } | |
| 40 | |
| 41 std::string GetPassphrase(const base::DictionaryValue& onc_properties) { | |
| 42 std::string passphrase; | |
| 43 EXPECT_TRUE(onc_properties.GetString( | |
| 44 onc::network_config::WifiProperty(onc::wifi::kPassphrase), &passphrase)); | |
| 45 return passphrase; | |
| 46 } | |
| 47 | |
| 48 TEST(WifiCredentialTest, ToOncPropertiesSecurityNone) { | |
| 49 const auto kCredential(MakeCredential("fake-ssid", SECURITY_CLASS_NONE, "")); | |
|
stevenjb
2015/01/08 17:27:51
nit: use a const string for repeated strings here
erikwright (departed)
2015/01/08 19:27:08
not a valid use of auto.
"Use auto to avoid type
mukesh agrawal
2015/01/09 02:00:18
Done.
mukesh agrawal
2015/01/09 02:00:18
Done.
| |
| 50 base::DictionaryValue onc_properties; | |
| 51 EXPECT_TRUE(kCredential.ToOncProperties(&onc_properties)); | |
| 52 EXPECT_TRUE(TypeIsWifi(onc_properties)); | |
| 53 EXPECT_EQ("fake-ssid", GetSsid(onc_properties)); | |
| 54 EXPECT_EQ(onc::wifi::kSecurityNone, GetOncSecurity(onc_properties)); | |
| 55 } | |
| 56 | |
| 57 TEST(WifiCredntialTest, ToOncPropertiesSecurityWep) { | |
| 58 const auto kCredential( | |
| 59 MakeCredential("fake-ssid", SECURITY_CLASS_WEP, "abcde")); | |
| 60 base::DictionaryValue onc_properties; | |
| 61 EXPECT_TRUE(kCredential.ToOncProperties(&onc_properties)); | |
| 62 EXPECT_TRUE(TypeIsWifi(onc_properties)); | |
| 63 EXPECT_EQ("fake-ssid", GetSsid(onc_properties)); | |
| 64 EXPECT_EQ(onc::wifi::kWEP_PSK, GetOncSecurity(onc_properties)); | |
| 65 EXPECT_EQ("abcde", GetPassphrase(onc_properties)); | |
| 66 } | |
| 67 | |
| 68 TEST(WifiCredentialTest, ToOncPropertiesSecurityPsk) { | |
| 69 const auto kCredential( | |
| 70 MakeCredential("fake-ssid", SECURITY_CLASS_PSK, "fake-passphrase")); | |
| 71 base::DictionaryValue onc_properties; | |
| 72 EXPECT_TRUE(kCredential.ToOncProperties(&onc_properties)); | |
| 73 EXPECT_TRUE(TypeIsWifi(onc_properties)); | |
| 74 EXPECT_EQ("fake-ssid", GetSsid(onc_properties)); | |
| 75 EXPECT_EQ(onc::wifi::kWPA_PSK, GetOncSecurity(onc_properties)); | |
| 76 EXPECT_EQ("fake-passphrase", GetPassphrase(onc_properties)); | |
| 77 } | |
| 78 | |
| 79 TEST(WifiCredentialTest, ToOncPropertiesSecurity8021X) { | |
| 80 const auto kCredential( | |
| 81 MakeCredential("fake-ssid", SECURITY_CLASS_802_1X, "fake-passphrase")); | |
| 82 base::DictionaryValue onc_properties; | |
| 83 EXPECT_TRUE(kCredential.ToOncProperties(&onc_properties)); | |
| 84 EXPECT_TRUE(TypeIsWifi(onc_properties)); | |
| 85 EXPECT_EQ("fake-ssid", GetSsid(onc_properties)); | |
| 86 EXPECT_EQ(onc::wifi::kWPA_EAP, GetOncSecurity(onc_properties)); | |
| 87 EXPECT_EQ("fake-passphrase", GetPassphrase(onc_properties)); | |
| 88 } | |
| 89 | |
| 90 TEST(WifiCredentialTest, ToOncPropertiesSecurityInvalid) { | |
| 91 const auto kCredential( | |
| 92 MakeCredential("fake-ssid", SECURITY_CLASS_INVALID, "fake-passphrase")); | |
| 93 base::DictionaryValue onc_properties; | |
| 94 EXPECT_FALSE(kCredential.ToOncProperties(&onc_properties)); | |
| 95 EXPECT_TRUE(onc_properties.empty()); | |
| 96 } | |
| 97 | |
| 98 TEST(WifiCredentialTest, ToOncPropertiesSsidNonUtf8) { | |
| 99 const auto kCredential(MakeCredential("\xc0", SECURITY_CLASS_NONE, "")); | |
| 100 base::DictionaryValue onc_properties; | |
| 101 EXPECT_FALSE(kCredential.ToOncProperties(&onc_properties)); | |
| 102 EXPECT_TRUE(onc_properties.empty()); | |
| 103 } | |
| 104 | |
| 105 } // namespace wifi_sync | |
| OLD | NEW |