mukesh agrawal | 8a3188d | 2011-12-01 20:56:44 +0000 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium OS Authors. All rights reserved. |
Chris Masone | 34af218 | 2011-08-22 11:59:36 -0700 | [diff] [blame] | 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 "shill/wifi_service.h" |
| 6 | |
mukesh agrawal | d835b20 | 2011-10-07 15:26:47 -0700 | [diff] [blame] | 7 | #include <map> |
Paul Stewart | 85aea15 | 2013-01-22 09:31:56 -0800 | [diff] [blame] | 8 | #include <set> |
Chris Masone | 34af218 | 2011-08-22 11:59:36 -0700 | [diff] [blame] | 9 | #include <string> |
| 10 | #include <vector> |
| 11 | |
Paul Stewart | 85aea15 | 2013-01-22 09:31:56 -0800 | [diff] [blame] | 12 | #include <base/stringprintf.h> |
Paul Stewart | 71a4d3b | 2013-01-18 18:12:56 -0800 | [diff] [blame] | 13 | #include <base/string_number_conversions.h> |
Chris Masone | 34af218 | 2011-08-22 11:59:36 -0700 | [diff] [blame] | 14 | #include <base/string_util.h> |
| 15 | #include <chromeos/dbus/service_constants.h> |
| 16 | #include <gmock/gmock.h> |
| 17 | #include <gtest/gtest.h> |
| 18 | |
Paul Stewart | 26b327e | 2011-10-19 11:38:09 -0700 | [diff] [blame] | 19 | #include "shill/event_dispatcher.h" |
Chris Masone | 34af218 | 2011-08-22 11:59:36 -0700 | [diff] [blame] | 20 | #include "shill/manager.h" |
mukesh agrawal | f6b3209 | 2013-04-10 15:49:55 -0700 | [diff] [blame] | 21 | #include "shill/metrics.h" |
Chris Masone | 34af218 | 2011-08-22 11:59:36 -0700 | [diff] [blame] | 22 | #include "shill/mock_adaptors.h" |
Paul Stewart | 5baebb7 | 2013-03-14 11:43:29 -0700 | [diff] [blame] | 23 | #include "shill/mock_certificate_file.h" |
Chris Masone | 34af218 | 2011-08-22 11:59:36 -0700 | [diff] [blame] | 24 | #include "shill/mock_control.h" |
Paul Stewart | 71a4d3b | 2013-01-18 18:12:56 -0800 | [diff] [blame] | 25 | #include "shill/mock_log.h" |
Paul Stewart | ecf4cd1 | 2012-04-17 11:08:39 -0700 | [diff] [blame] | 26 | #include "shill/mock_nss.h" |
Christopher Wiley | 1ce658d | 2012-10-10 10:02:03 -0700 | [diff] [blame] | 27 | #include "shill/mock_profile.h" |
Chris Masone | 34af218 | 2011-08-22 11:59:36 -0700 | [diff] [blame] | 28 | #include "shill/mock_service.h" |
| 29 | #include "shill/mock_store.h" |
mukesh agrawal | 6e27777 | 2011-09-29 15:04:23 -0700 | [diff] [blame] | 30 | #include "shill/mock_wifi.h" |
Paul Stewart | 3c50401 | 2013-01-17 17:49:58 -0800 | [diff] [blame] | 31 | #include "shill/mock_wifi_provider.h" |
Chris Masone | 34af218 | 2011-08-22 11:59:36 -0700 | [diff] [blame] | 32 | #include "shill/property_store_unittest.h" |
mukesh agrawal | 8a3188d | 2011-12-01 20:56:44 +0000 | [diff] [blame] | 33 | #include "shill/refptr_types.h" |
| 34 | #include "shill/wifi_endpoint.h" |
mukesh agrawal | 6e27777 | 2011-09-29 15:04:23 -0700 | [diff] [blame] | 35 | #include "shill/wpa_supplicant.h" |
Chris Masone | 34af218 | 2011-08-22 11:59:36 -0700 | [diff] [blame] | 36 | |
Albert Chaulk | 0e1cdea | 2013-02-27 15:32:55 -0800 | [diff] [blame] | 37 | using base::FilePath; |
mukesh agrawal | d835b20 | 2011-10-07 15:26:47 -0700 | [diff] [blame] | 38 | using std::map; |
Paul Stewart | 85aea15 | 2013-01-22 09:31:56 -0800 | [diff] [blame] | 39 | using std::set; |
Chris Masone | 34af218 | 2011-08-22 11:59:36 -0700 | [diff] [blame] | 40 | using std::string; |
| 41 | using std::vector; |
Paul Stewart | d08f443 | 2011-11-04 07:48:20 -0700 | [diff] [blame] | 42 | using ::testing::_; |
mukesh agrawal | e1d90e9 | 2012-02-15 17:36:08 -0800 | [diff] [blame] | 43 | using ::testing::AnyNumber; |
Paul Stewart | d08f443 | 2011-11-04 07:48:20 -0700 | [diff] [blame] | 44 | using ::testing::DoAll; |
Paul Stewart | 71a4d3b | 2013-01-18 18:12:56 -0800 | [diff] [blame] | 45 | using ::testing::EndsWith; |
Paul Stewart | 3c50401 | 2013-01-17 17:49:58 -0800 | [diff] [blame] | 46 | using ::testing::HasSubstr; |
mukesh agrawal | e1d90e9 | 2012-02-15 17:36:08 -0800 | [diff] [blame] | 47 | using ::testing::Mock; |
mukesh agrawal | 6e27777 | 2011-09-29 15:04:23 -0700 | [diff] [blame] | 48 | using ::testing::NiceMock; |
Paul Stewart | d08f443 | 2011-11-04 07:48:20 -0700 | [diff] [blame] | 49 | using ::testing::Return; |
| 50 | using ::testing::SetArgumentPointee; |
| 51 | using ::testing::StrEq; |
Paul Stewart | d8ad3c4 | 2012-01-09 12:39:38 -0800 | [diff] [blame] | 52 | using ::testing::StrNe; |
Paul Stewart | 85aea15 | 2013-01-22 09:31:56 -0800 | [diff] [blame] | 53 | using ::testing::StrictMock; |
Chris Masone | 34af218 | 2011-08-22 11:59:36 -0700 | [diff] [blame] | 54 | |
mukesh agrawal | b20776f | 2012-02-10 16:00:36 -0800 | [diff] [blame] | 55 | namespace shill { |
| 56 | |
Chris Masone | 34af218 | 2011-08-22 11:59:36 -0700 | [diff] [blame] | 57 | class WiFiServiceTest : public PropertyStoreTest { |
| 58 | public: |
Paul Stewart | 3c50401 | 2013-01-17 17:49:58 -0800 | [diff] [blame] | 59 | WiFiServiceTest() |
| 60 | : wifi_(new NiceMock<MockWiFi>( |
| 61 | control_interface(), |
| 62 | dispatcher(), |
| 63 | metrics(), |
| 64 | manager(), |
| 65 | "wifi", |
| 66 | fake_mac, |
| 67 | 0)), |
| 68 | simple_ssid_(1, 'a'), |
| 69 | simple_ssid_string_("a") {} |
Chris Masone | 34af218 | 2011-08-22 11:59:36 -0700 | [diff] [blame] | 70 | virtual ~WiFiServiceTest() {} |
mukesh agrawal | 6e27777 | 2011-09-29 15:04:23 -0700 | [diff] [blame] | 71 | |
| 72 | protected: |
| 73 | static const char fake_mac[]; |
mukesh agrawal | e1d90e9 | 2012-02-15 17:36:08 -0800 | [diff] [blame] | 74 | |
Gaurav Shah | 10109f2 | 2011-11-11 20:16:22 -0800 | [diff] [blame] | 75 | bool CheckConnectable(const std::string &security, const char *passphrase, |
Paul Stewart | 0654ece | 2013-03-26 15:21:26 -0700 | [diff] [blame] | 76 | EapCredentials *eap) { |
mukesh agrawal | 29c13a1 | 2011-11-24 00:09:19 +0000 | [diff] [blame] | 77 | Error error; |
Paul Stewart | 3c50401 | 2013-01-17 17:49:58 -0800 | [diff] [blame] | 78 | WiFiServiceRefPtr service = MakeSimpleService(security); |
mukesh agrawal | 29c13a1 | 2011-11-24 00:09:19 +0000 | [diff] [blame] | 79 | if (passphrase) |
| 80 | service->SetPassphrase(passphrase, &error); |
Gaurav Shah | 10109f2 | 2011-11-11 20:16:22 -0800 | [diff] [blame] | 81 | if (eap) { |
| 82 | service->set_eap(*eap); |
| 83 | } |
mukesh agrawal | 29c13a1 | 2011-11-24 00:09:19 +0000 | [diff] [blame] | 84 | return service->connectable(); |
| 85 | } |
mukesh agrawal | e1d90e9 | 2012-02-15 17:36:08 -0800 | [diff] [blame] | 86 | WiFiEndpoint *MakeEndpoint(const string &ssid, const string &bssid, |
mukesh agrawal | 43970a2 | 2013-02-15 16:00:07 -0800 | [diff] [blame] | 87 | uint16 frequency, int16 signal_dbm, |
| 88 | bool has_wpa_property, bool has_rsn_property) { |
| 89 | return WiFiEndpoint::MakeEndpoint( |
Paul Stewart | 0654ece | 2013-03-26 15:21:26 -0700 | [diff] [blame] | 90 | NULL, wifi(), ssid, bssid, WPASupplicant::kNetworkModeInfrastructure, |
mukesh agrawal | 43970a2 | 2013-02-15 16:00:07 -0800 | [diff] [blame] | 91 | frequency, signal_dbm, has_wpa_property, has_rsn_property); |
| 92 | } |
| 93 | WiFiEndpoint *MakeOpenEndpoint(const string &ssid, const string &bssid, |
| 94 | uint16 frequency, int16 signal_dbm) { |
mukesh agrawal | e1d90e9 | 2012-02-15 17:36:08 -0800 | [diff] [blame] | 95 | return WiFiEndpoint::MakeOpenEndpoint( |
Paul Stewart | 0654ece | 2013-03-26 15:21:26 -0700 | [diff] [blame] | 96 | NULL, wifi(), ssid, bssid, WPASupplicant::kNetworkModeInfrastructure, |
Paul Stewart | 3c50401 | 2013-01-17 17:49:58 -0800 | [diff] [blame] | 97 | frequency, signal_dbm); |
mukesh agrawal | e1d90e9 | 2012-02-15 17:36:08 -0800 | [diff] [blame] | 98 | } |
Paul Stewart | 3c50401 | 2013-01-17 17:49:58 -0800 | [diff] [blame] | 99 | WiFiServiceRefPtr MakeSimpleService(const string &security) { |
mukesh agrawal | e1d90e9 | 2012-02-15 17:36:08 -0800 | [diff] [blame] | 100 | return new WiFiService(control_interface(), |
| 101 | dispatcher(), |
| 102 | metrics(), |
| 103 | manager(), |
Paul Stewart | 3c50401 | 2013-01-17 17:49:58 -0800 | [diff] [blame] | 104 | &provider_, |
| 105 | simple_ssid_, |
mukesh agrawal | e1d90e9 | 2012-02-15 17:36:08 -0800 | [diff] [blame] | 106 | flimflam::kModeManaged, |
Paul Stewart | 3c50401 | 2013-01-17 17:49:58 -0800 | [diff] [blame] | 107 | security, |
mukesh agrawal | e1d90e9 | 2012-02-15 17:36:08 -0800 | [diff] [blame] | 108 | false); |
| 109 | } |
Paul Stewart | 3c50401 | 2013-01-17 17:49:58 -0800 | [diff] [blame] | 110 | WiFiServiceRefPtr MakeGenericService() { |
| 111 | return MakeSimpleService(flimflam::kSecurityWep); |
| 112 | } |
| 113 | void SetWiFiForService(WiFiServiceRefPtr service, WiFiRefPtr wifi) { |
| 114 | service->wifi_ = wifi; |
| 115 | } |
| 116 | WiFiServiceRefPtr MakeServiceWithWiFi(const string &security) { |
| 117 | WiFiServiceRefPtr service = MakeSimpleService(security); |
| 118 | SetWiFiForService(service, wifi_); |
| 119 | return service; |
| 120 | } |
mukesh agrawal | e1d90e9 | 2012-02-15 17:36:08 -0800 | [diff] [blame] | 121 | ServiceMockAdaptor *GetAdaptor(WiFiService *service) { |
| 122 | return dynamic_cast<ServiceMockAdaptor *>(service->adaptor()); |
mukesh agrawal | 8a3188d | 2011-12-01 20:56:44 +0000 | [diff] [blame] | 123 | } |
Paul Stewart | 3c50401 | 2013-01-17 17:49:58 -0800 | [diff] [blame] | 124 | Error::Type TestConfigurePassphrase(const string &security, |
| 125 | const char *passphrase) { |
| 126 | WiFiServiceRefPtr service = MakeSimpleService(security); |
| 127 | KeyValueStore args; |
| 128 | if (passphrase) { |
| 129 | args.SetString(flimflam::kPassphraseProperty, passphrase); |
| 130 | } |
| 131 | Error error; |
| 132 | service->Configure(args, &error); |
| 133 | return error.type(); |
| 134 | } |
mukesh agrawal | 6e27777 | 2011-09-29 15:04:23 -0700 | [diff] [blame] | 135 | scoped_refptr<MockWiFi> wifi() { return wifi_; } |
Paul Stewart | 3c50401 | 2013-01-17 17:49:58 -0800 | [diff] [blame] | 136 | MockWiFiProvider *provider() { return &provider_; } |
| 137 | string GetAnyDeviceAddress() { return WiFiService::kAnyDeviceAddress; } |
| 138 | const vector<uint8_t> &simple_ssid() { return simple_ssid_; } |
| 139 | const string &simple_ssid_string() { return simple_ssid_string_; } |
mukesh agrawal | 6e27777 | 2011-09-29 15:04:23 -0700 | [diff] [blame] | 140 | |
| 141 | private: |
| 142 | scoped_refptr<MockWiFi> wifi_; |
Paul Stewart | 3c50401 | 2013-01-17 17:49:58 -0800 | [diff] [blame] | 143 | MockWiFiProvider provider_; |
| 144 | const vector<uint8_t> simple_ssid_; |
| 145 | const string simple_ssid_string_; |
Chris Masone | 34af218 | 2011-08-22 11:59:36 -0700 | [diff] [blame] | 146 | }; |
| 147 | |
mukesh agrawal | 6e27777 | 2011-09-29 15:04:23 -0700 | [diff] [blame] | 148 | // static |
| 149 | const char WiFiServiceTest::fake_mac[] = "AaBBcCDDeeFF"; |
| 150 | |
Paul Stewart | 71a4d3b | 2013-01-18 18:12:56 -0800 | [diff] [blame] | 151 | MATCHER_P3(ContainsWiFiProperties, ssid, mode, security, "") { |
| 152 | string hex_ssid = base::HexEncode(ssid.data(), ssid.size()); |
| 153 | return |
| 154 | arg.ContainsString(WiFiService::kStorageType) && |
| 155 | arg.GetString(WiFiService::kStorageType) == flimflam::kTypeWifi && |
| 156 | arg.ContainsString(WiFiService::kStorageSSID) && |
| 157 | arg.GetString(WiFiService::kStorageSSID) == hex_ssid && |
| 158 | arg.ContainsString(WiFiService::kStorageMode) && |
| 159 | arg.GetString(WiFiService::kStorageMode) == mode && |
| 160 | arg.ContainsString(WiFiService::kStorageSecurityClass) && |
| 161 | arg.GetString(WiFiService::kStorageSecurityClass) == security; |
| 162 | } |
| 163 | |
Paul Stewart | d08f443 | 2011-11-04 07:48:20 -0700 | [diff] [blame] | 164 | class WiFiServiceSecurityTest : public WiFiServiceTest { |
| 165 | public: |
Paul Stewart | d08f443 | 2011-11-04 07:48:20 -0700 | [diff] [blame] | 166 | bool TestStorageSecurityIs(WiFiServiceRefPtr wifi_service, |
| 167 | const string &security) { |
| 168 | string id = wifi_service->GetStorageIdentifier(); |
Paul Stewart | 3c50401 | 2013-01-17 17:49:58 -0800 | [diff] [blame] | 169 | size_t mac_pos = id.find(StringToLowerASCII(GetAnyDeviceAddress())); |
Paul Stewart | d08f443 | 2011-11-04 07:48:20 -0700 | [diff] [blame] | 170 | EXPECT_NE(mac_pos, string::npos); |
| 171 | size_t mode_pos = id.find(string(flimflam::kModeManaged), mac_pos); |
| 172 | EXPECT_NE(mode_pos, string::npos); |
| 173 | return id.find(string(security), mode_pos) != string::npos; |
| 174 | } |
| 175 | |
| 176 | // Test that a service that is created with security |from_security| |
| 177 | // gets by default a storage identifier with |to_security| as its |
Paul Stewart | 71a4d3b | 2013-01-18 18:12:56 -0800 | [diff] [blame] | 178 | // security component, and that when saved, it sets the Security |
| 179 | // property in to |to_security| as well. |
Paul Stewart | d08f443 | 2011-11-04 07:48:20 -0700 | [diff] [blame] | 180 | bool TestStorageMapping(const string &from_security, |
| 181 | const string &to_security) { |
Paul Stewart | 3c50401 | 2013-01-17 17:49:58 -0800 | [diff] [blame] | 182 | WiFiServiceRefPtr wifi_service = MakeSimpleService(from_security); |
Paul Stewart | 71a4d3b | 2013-01-18 18:12:56 -0800 | [diff] [blame] | 183 | NiceMock<MockStore> mock_store; |
| 184 | EXPECT_CALL(mock_store, SetString(_, _, _)).WillRepeatedly(Return(true)); |
| 185 | EXPECT_CALL(mock_store, |
| 186 | SetString(_, WiFiService::kStorageSecurity, from_security)) |
| 187 | .Times(1); |
| 188 | EXPECT_CALL(mock_store, |
| 189 | SetString(_, WiFiService::kStorageSecurityClass, to_security)) |
| 190 | .Times(1); |
| 191 | wifi_service->Save(&mock_store); |
Paul Stewart | d08f443 | 2011-11-04 07:48:20 -0700 | [diff] [blame] | 192 | return TestStorageSecurityIs(wifi_service, to_security); |
| 193 | } |
| 194 | |
| 195 | // Test whether a service of type |service_security| can load from a |
| 196 | // storage interface containing an entry for |storage_security|. |
| 197 | // Make sure the result meets |expectation|. If |expectation| is |
| 198 | // true, also make sure the service storage identifier changes to |
| 199 | // match |storage_security|. |
| 200 | bool TestLoadMapping(const string &service_security, |
| 201 | const string &storage_security, |
| 202 | bool expectation) { |
Paul Stewart | 3c50401 | 2013-01-17 17:49:58 -0800 | [diff] [blame] | 203 | WiFiServiceRefPtr wifi_service = MakeSimpleService(service_security); |
Paul Stewart | d08f443 | 2011-11-04 07:48:20 -0700 | [diff] [blame] | 204 | NiceMock<MockStore> mock_store; |
Paul Stewart | 71a4d3b | 2013-01-18 18:12:56 -0800 | [diff] [blame] | 205 | EXPECT_CALL(mock_store, GetGroupsWithProperties(_)) |
| 206 | .WillRepeatedly(Return(set<string>())); |
| 207 | const string kStorageId = "storage_id"; |
| 208 | EXPECT_CALL(mock_store, ContainsGroup(kStorageId)) |
Paul Stewart | d08f443 | 2011-11-04 07:48:20 -0700 | [diff] [blame] | 209 | .WillRepeatedly(Return(true)); |
Paul Stewart | 71a4d3b | 2013-01-18 18:12:56 -0800 | [diff] [blame] | 210 | set<string> groups; |
| 211 | groups.insert(kStorageId); |
| 212 | EXPECT_CALL(mock_store, GetGroupsWithProperties( |
| 213 | ContainsWiFiProperties(wifi_service->ssid(), |
| 214 | flimflam::kModeManaged, |
| 215 | storage_security))) |
| 216 | .WillRepeatedly(Return(groups)); |
Paul Stewart | d08f443 | 2011-11-04 07:48:20 -0700 | [diff] [blame] | 217 | bool is_loadable = wifi_service->IsLoadableFrom(&mock_store); |
| 218 | EXPECT_EQ(expectation, is_loadable); |
| 219 | bool is_loaded = wifi_service->Load(&mock_store); |
| 220 | EXPECT_EQ(expectation, is_loaded); |
| 221 | |
| 222 | if (expectation != is_loadable || expectation != is_loaded) { |
| 223 | return false; |
| 224 | } else if (!expectation) { |
| 225 | return true; |
| 226 | } else { |
Paul Stewart | 71a4d3b | 2013-01-18 18:12:56 -0800 | [diff] [blame] | 227 | return wifi_service->GetStorageIdentifier() == kStorageId; |
Paul Stewart | d08f443 | 2011-11-04 07:48:20 -0700 | [diff] [blame] | 228 | } |
| 229 | } |
| 230 | }; |
| 231 | |
mukesh agrawal | e1d90e9 | 2012-02-15 17:36:08 -0800 | [diff] [blame] | 232 | class WiFiServiceUpdateFromEndpointsTest : public WiFiServiceTest { |
| 233 | public: |
| 234 | WiFiServiceUpdateFromEndpointsTest() |
| 235 | : kOkEndpointStrength(WiFiService::SignalToStrength(kOkEndpointSignal)), |
| 236 | kBadEndpointStrength(WiFiService::SignalToStrength(kBadEndpointSignal)), |
| 237 | kGoodEndpointStrength( |
| 238 | WiFiService::SignalToStrength(kGoodEndpointSignal)), |
| 239 | service(MakeGenericService()), |
| 240 | adaptor(*GetAdaptor(service)) { |
mukesh agrawal | 43970a2 | 2013-02-15 16:00:07 -0800 | [diff] [blame] | 241 | ok_endpoint = MakeOpenEndpoint( |
Paul Stewart | 3c50401 | 2013-01-17 17:49:58 -0800 | [diff] [blame] | 242 | simple_ssid_string(), kOkEndpointBssId, kOkEndpointFrequency, |
| 243 | kOkEndpointSignal); |
mukesh agrawal | 43970a2 | 2013-02-15 16:00:07 -0800 | [diff] [blame] | 244 | good_endpoint = MakeOpenEndpoint( |
Paul Stewart | 3c50401 | 2013-01-17 17:49:58 -0800 | [diff] [blame] | 245 | simple_ssid_string(), kGoodEndpointBssId, kGoodEndpointFrequency, |
| 246 | kGoodEndpointSignal); |
mukesh agrawal | 43970a2 | 2013-02-15 16:00:07 -0800 | [diff] [blame] | 247 | bad_endpoint = MakeOpenEndpoint( |
Paul Stewart | 3c50401 | 2013-01-17 17:49:58 -0800 | [diff] [blame] | 248 | simple_ssid_string(), kBadEndpointBssId, kBadEndpointFrequency, |
| 249 | kBadEndpointSignal); |
mukesh agrawal | e1d90e9 | 2012-02-15 17:36:08 -0800 | [diff] [blame] | 250 | } |
| 251 | |
| 252 | protected: |
| 253 | static const uint16 kOkEndpointFrequency = 2422; |
| 254 | static const uint16 kBadEndpointFrequency = 2417; |
| 255 | static const uint16 kGoodEndpointFrequency = 2412; |
| 256 | static const int16 kOkEndpointSignal = -50; |
| 257 | static const int16 kBadEndpointSignal = -75; |
| 258 | static const int16 kGoodEndpointSignal = -25; |
mukesh agrawal | 923f14f | 2012-06-04 16:46:08 -0700 | [diff] [blame] | 259 | static const char *kOkEndpointBssId; |
| 260 | static const char *kGoodEndpointBssId; |
| 261 | static const char *kBadEndpointBssId; |
mukesh agrawal | e1d90e9 | 2012-02-15 17:36:08 -0800 | [diff] [blame] | 262 | // Can't be both static and const (because initialization requires a |
| 263 | // function call). So choose to be just const. |
| 264 | const uint8 kOkEndpointStrength; |
| 265 | const uint8 kBadEndpointStrength; |
| 266 | const uint8 kGoodEndpointStrength; |
| 267 | WiFiEndpointRefPtr ok_endpoint; |
| 268 | WiFiEndpointRefPtr bad_endpoint; |
| 269 | WiFiEndpointRefPtr good_endpoint; |
| 270 | WiFiServiceRefPtr service; |
| 271 | ServiceMockAdaptor &adaptor; |
| 272 | }; |
| 273 | |
mukesh agrawal | 923f14f | 2012-06-04 16:46:08 -0700 | [diff] [blame] | 274 | const char *WiFiServiceUpdateFromEndpointsTest::kOkEndpointBssId = |
| 275 | "00:00:00:00:00:01"; |
| 276 | const char *WiFiServiceUpdateFromEndpointsTest::kGoodEndpointBssId = |
| 277 | "00:00:00:00:00:02"; |
| 278 | const char *WiFiServiceUpdateFromEndpointsTest::kBadEndpointBssId = |
| 279 | "00:00:00:00:00:03"; |
mukesh agrawal | e1d90e9 | 2012-02-15 17:36:08 -0800 | [diff] [blame] | 280 | |
Paul Stewart | 85aea15 | 2013-01-22 09:31:56 -0800 | [diff] [blame] | 281 | class WiFiServiceFixupStorageTest : public WiFiServiceTest { |
| 282 | protected: |
| 283 | void AddGroup(string group_name) { |
| 284 | groups_.insert(group_name); |
| 285 | } |
| 286 | |
Paul Stewart | 71a4d3b | 2013-01-18 18:12:56 -0800 | [diff] [blame] | 287 | void AddServiceEntry(bool has_type, bool has_mode, bool has_security, |
| 288 | bool has_security_class) { |
Paul Stewart | 85aea15 | 2013-01-22 09:31:56 -0800 | [diff] [blame] | 289 | int index = groups_.size(); |
| 290 | string id = base::StringPrintf("%s_%d_%d_%s_%s", flimflam::kTypeWifi, |
| 291 | index, index, flimflam::kModeManaged, |
Paul Stewart | 71a4d3b | 2013-01-18 18:12:56 -0800 | [diff] [blame] | 292 | flimflam::kSecurityWpa); |
Paul Stewart | 85aea15 | 2013-01-22 09:31:56 -0800 | [diff] [blame] | 293 | AddGroup(id); |
| 294 | EXPECT_CALL(store_, GetString(id, WiFiService::kStorageType, _)) |
| 295 | .WillOnce(Return(has_type)); |
| 296 | if (!has_type) { |
| 297 | EXPECT_CALL(store_, SetString(id, WiFiService::kStorageType, |
| 298 | flimflam::kTypeWifi)); |
| 299 | } |
| 300 | EXPECT_CALL(store_, GetString(id, WiFiService::kStorageMode, _)) |
| 301 | .WillOnce(Return(has_mode)); |
| 302 | if (!has_mode) { |
| 303 | EXPECT_CALL(store_, SetString(id, WiFiService::kStorageMode, |
| 304 | flimflam::kModeManaged)); |
| 305 | } |
| 306 | EXPECT_CALL(store_, GetString(id, WiFiService::kStorageSecurity, _)) |
| 307 | .WillOnce(Return(has_security)); |
| 308 | if (!has_security) { |
| 309 | EXPECT_CALL(store_, SetString(id, WiFiService::kStorageSecurity, |
Paul Stewart | 71a4d3b | 2013-01-18 18:12:56 -0800 | [diff] [blame] | 310 | flimflam::kSecurityWpa)); |
| 311 | } |
| 312 | EXPECT_CALL(store_, GetString(id, WiFiService::kStorageSecurityClass, _)) |
| 313 | .WillOnce(Return(has_security_class)); |
| 314 | if (!has_security_class) { |
| 315 | EXPECT_CALL(store_, SetString(id, WiFiService::kStorageSecurityClass, |
| 316 | flimflam::kSecurityPsk)); |
Paul Stewart | 85aea15 | 2013-01-22 09:31:56 -0800 | [diff] [blame] | 317 | } |
| 318 | } |
| 319 | |
| 320 | bool FixupServiceEntries() { |
| 321 | EXPECT_CALL(store_, GetGroups()).WillOnce(Return(groups_)); |
| 322 | return WiFiService::FixupServiceEntries(&store_); |
| 323 | } |
| 324 | |
| 325 | private: |
| 326 | StrictMock<MockStore> store_; |
| 327 | set<string> groups_; |
| 328 | }; |
| 329 | |
Chris Masone | 34af218 | 2011-08-22 11:59:36 -0700 | [diff] [blame] | 330 | TEST_F(WiFiServiceTest, StorageId) { |
Paul Stewart | 3c50401 | 2013-01-17 17:49:58 -0800 | [diff] [blame] | 331 | WiFiServiceRefPtr wifi_service = MakeSimpleService(flimflam::kSecurityNone); |
Chris Masone | 9d77993 | 2011-08-25 16:33:41 -0700 | [diff] [blame] | 332 | string id = wifi_service->GetStorageIdentifier(); |
Chris Masone | 34af218 | 2011-08-22 11:59:36 -0700 | [diff] [blame] | 333 | for (uint i = 0; i < id.length(); ++i) { |
| 334 | EXPECT_TRUE(id[i] == '_' || |
| 335 | isxdigit(id[i]) || |
| 336 | (isalpha(id[i]) && islower(id[i]))); |
| 337 | } |
Paul Stewart | 3c50401 | 2013-01-17 17:49:58 -0800 | [diff] [blame] | 338 | size_t mac_pos = id.find(StringToLowerASCII(GetAnyDeviceAddress())); |
Chris Masone | 34af218 | 2011-08-22 11:59:36 -0700 | [diff] [blame] | 339 | EXPECT_NE(mac_pos, string::npos); |
| 340 | EXPECT_NE(id.find(string(flimflam::kModeManaged), mac_pos), string::npos); |
| 341 | } |
| 342 | |
Gaurav Shah | da6218a | 2011-11-11 12:09:33 -0800 | [diff] [blame] | 343 | // Make sure the passphrase is registered as a write only property |
| 344 | // by reading and comparing all string properties returned on the store. |
| 345 | TEST_F(WiFiServiceTest, PassphraseWriteOnly) { |
Paul Stewart | 3c50401 | 2013-01-17 17:49:58 -0800 | [diff] [blame] | 346 | WiFiServiceRefPtr wifi_service = MakeSimpleService(flimflam::kSecurityWpa); |
Gaurav Shah | da6218a | 2011-11-11 12:09:33 -0800 | [diff] [blame] | 347 | ReadablePropertyConstIterator<string> it = |
| 348 | (wifi_service->store()).GetStringPropertiesIter(); |
| 349 | for( ; !it.AtEnd(); it.Advance()) |
| 350 | EXPECT_NE(it.Key(), flimflam::kPassphraseProperty); |
| 351 | } |
| 352 | |
Thieu Le | f770945 | 2011-11-15 01:13:19 +0000 | [diff] [blame] | 353 | // Make sure setting the passphrase via D-Bus Service.SetProperty validates |
| 354 | // the passphrase. |
| 355 | TEST_F(WiFiServiceTest, PassphraseSetPropertyValidation) { |
| 356 | // We only spot check two password cases here to make sure the |
| 357 | // SetProperty code path does validation. We're not going to exhaustively |
| 358 | // test for all types of passwords. |
Paul Stewart | 3c50401 | 2013-01-17 17:49:58 -0800 | [diff] [blame] | 359 | WiFiServiceRefPtr wifi_service = MakeSimpleService(flimflam::kSecurityWep); |
Thieu Le | f770945 | 2011-11-15 01:13:19 +0000 | [diff] [blame] | 360 | Error error; |
| 361 | EXPECT_TRUE(wifi_service->mutable_store()->SetStringProperty( |
| 362 | flimflam::kPassphraseProperty, "0:abcde", &error)); |
| 363 | EXPECT_FALSE(wifi_service->mutable_store()->SetStringProperty( |
| 364 | flimflam::kPassphraseProperty, "invalid", &error)); |
| 365 | EXPECT_EQ(Error::kInvalidPassphrase, error.type()); |
| 366 | } |
| 367 | |
| 368 | TEST_F(WiFiServiceTest, PassphraseSetPropertyOpenNetwork) { |
Paul Stewart | 3c50401 | 2013-01-17 17:49:58 -0800 | [diff] [blame] | 369 | WiFiServiceRefPtr wifi_service = MakeSimpleService(flimflam::kSecurityNone); |
Thieu Le | f770945 | 2011-11-15 01:13:19 +0000 | [diff] [blame] | 370 | Error error; |
| 371 | EXPECT_FALSE(wifi_service->mutable_store()->SetStringProperty( |
| 372 | flimflam::kPassphraseProperty, "invalid", &error)); |
| 373 | EXPECT_EQ(Error::kNotSupported, error.type()); |
| 374 | } |
| 375 | |
mukesh agrawal | d835b20 | 2011-10-07 15:26:47 -0700 | [diff] [blame] | 376 | TEST_F(WiFiServiceTest, NonUTF8SSID) { |
| 377 | vector<uint8_t> ssid; |
| 378 | |
| 379 | ssid.push_back(0xff); // not a valid UTF-8 byte-sequence |
| 380 | WiFiServiceRefPtr wifi_service = new WiFiService(control_interface(), |
| 381 | dispatcher(), |
Thieu Le | 3426c8f | 2012-01-11 17:35:11 -0800 | [diff] [blame] | 382 | metrics(), |
mukesh agrawal | d835b20 | 2011-10-07 15:26:47 -0700 | [diff] [blame] | 383 | manager(), |
Paul Stewart | 3c50401 | 2013-01-17 17:49:58 -0800 | [diff] [blame] | 384 | provider(), |
mukesh agrawal | d835b20 | 2011-10-07 15:26:47 -0700 | [diff] [blame] | 385 | ssid, |
| 386 | flimflam::kModeManaged, |
Paul Stewart | ced6a0b | 2011-11-08 15:32:04 -0800 | [diff] [blame] | 387 | flimflam::kSecurityNone, |
| 388 | false); |
mukesh agrawal | d835b20 | 2011-10-07 15:26:47 -0700 | [diff] [blame] | 389 | map<string, ::DBus::Variant> properties; |
| 390 | // if service doesn't propertly sanitize SSID, this will generate SIGABRT. |
| 391 | DBusAdaptor::GetProperties(wifi_service->store(), &properties, NULL); |
| 392 | } |
| 393 | |
Paul Stewart | 4108db9 | 2013-03-11 12:13:24 -0700 | [diff] [blame] | 394 | MATCHER(PSKSecurityArgs, "") { |
Paul Stewart | 0654ece | 2013-03-26 15:21:26 -0700 | [diff] [blame] | 395 | return ContainsKey(arg, WPASupplicant::kPropertySecurityProtocol) && |
| 396 | arg.find(WPASupplicant::kPropertySecurityProtocol)->second. |
Paul Stewart | 4108db9 | 2013-03-11 12:13:24 -0700 | [diff] [blame] | 397 | reader().get_string() == string("WPA RSN") && |
Paul Stewart | 0654ece | 2013-03-26 15:21:26 -0700 | [diff] [blame] | 398 | ContainsKey(arg, WPASupplicant::kPropertyPreSharedKey); |
Gaurav Shah | da6218a | 2011-11-11 12:09:33 -0800 | [diff] [blame] | 399 | } |
| 400 | |
Paul Stewart | a5e7d5f | 2013-01-09 18:06:15 -0800 | [diff] [blame] | 401 | MATCHER(WPA80211wSecurityArgs, "") { |
Paul Stewart | 0654ece | 2013-03-26 15:21:26 -0700 | [diff] [blame] | 402 | return ContainsKey(arg, WPASupplicant::kPropertySecurityProtocol) && |
| 403 | ContainsKey(arg, WPASupplicant::kPropertyPreSharedKey) && |
| 404 | ContainsKey(arg, WPASupplicant::kNetworkPropertyIeee80211w); |
Paul Stewart | a5e7d5f | 2013-01-09 18:06:15 -0800 | [diff] [blame] | 405 | } |
| 406 | |
Gaurav Shah | 10109f2 | 2011-11-11 20:16:22 -0800 | [diff] [blame] | 407 | MATCHER(EAPSecurityArgs, "") { |
Paul Stewart | 0654ece | 2013-03-26 15:21:26 -0700 | [diff] [blame] | 408 | return ContainsKey(arg, WPASupplicant::kNetworkPropertyEapIdentity) && |
| 409 | ContainsKey(arg, WPASupplicant::kNetworkPropertyCaPath); |
Gaurav Shah | 10109f2 | 2011-11-11 20:16:22 -0800 | [diff] [blame] | 410 | } |
| 411 | |
Paul Stewart | e2d7c50 | 2012-07-16 16:35:10 -0700 | [diff] [blame] | 412 | MATCHER_P(FrequencyArg, has_arg, "") { |
| 413 | return has_arg == |
Paul Stewart | 0654ece | 2013-03-26 15:21:26 -0700 | [diff] [blame] | 414 | ContainsKey(arg, WPASupplicant::kNetworkPropertyFrequency); |
Paul Stewart | e2d7c50 | 2012-07-16 16:35:10 -0700 | [diff] [blame] | 415 | } |
| 416 | |
mukesh agrawal | f2fd745 | 2011-10-03 16:38:47 -0700 | [diff] [blame] | 417 | TEST_F(WiFiServiceTest, ConnectTaskWPA) { |
Paul Stewart | 3c50401 | 2013-01-17 17:49:58 -0800 | [diff] [blame] | 418 | WiFiServiceRefPtr wifi_service = MakeServiceWithWiFi(flimflam::kSecurityWpa); |
Paul Stewart | 4108db9 | 2013-03-11 12:13:24 -0700 | [diff] [blame] | 419 | EXPECT_CALL(*wifi(), ConnectTo(wifi_service.get(), PSKSecurityArgs())); |
Wade Guthrie | 005bd34 | 2012-05-02 09:37:07 -0700 | [diff] [blame] | 420 | Error error; |
| 421 | wifi_service->SetPassphrase("0:mumblemumblem", &error); |
mukesh agrawal | dc7b844 | 2012-09-27 13:48:14 -0700 | [diff] [blame] | 422 | wifi_service->Connect(NULL, "in test"); |
mukesh agrawal | 6e27777 | 2011-09-29 15:04:23 -0700 | [diff] [blame] | 423 | } |
| 424 | |
mukesh agrawal | f2fd745 | 2011-10-03 16:38:47 -0700 | [diff] [blame] | 425 | TEST_F(WiFiServiceTest, ConnectTaskRSN) { |
Paul Stewart | 3c50401 | 2013-01-17 17:49:58 -0800 | [diff] [blame] | 426 | WiFiServiceRefPtr wifi_service = MakeServiceWithWiFi(flimflam::kSecurityRsn); |
Paul Stewart | 4108db9 | 2013-03-11 12:13:24 -0700 | [diff] [blame] | 427 | EXPECT_CALL(*wifi(), ConnectTo(wifi_service.get(), PSKSecurityArgs())); |
Wade Guthrie | 005bd34 | 2012-05-02 09:37:07 -0700 | [diff] [blame] | 428 | Error error; |
| 429 | wifi_service->SetPassphrase("0:mumblemumblem", &error); |
mukesh agrawal | dc7b844 | 2012-09-27 13:48:14 -0700 | [diff] [blame] | 430 | wifi_service->Connect(NULL, "in test"); |
mukesh agrawal | f2fd745 | 2011-10-03 16:38:47 -0700 | [diff] [blame] | 431 | } |
| 432 | |
Christopher Wiley | 1ce658d | 2012-10-10 10:02:03 -0700 | [diff] [blame] | 433 | TEST_F(WiFiServiceTest, ConnectConditions) { |
| 434 | Error error; |
Paul Stewart | 3c50401 | 2013-01-17 17:49:58 -0800 | [diff] [blame] | 435 | WiFiServiceRefPtr wifi_service = MakeServiceWithWiFi(flimflam::kSecurityNone); |
Christopher Wiley | 1ce658d | 2012-10-10 10:02:03 -0700 | [diff] [blame] | 436 | scoped_refptr<MockProfile> mock_profile( |
Thieu Le | 5133b71 | 2013-02-19 14:47:21 -0800 | [diff] [blame] | 437 | new NiceMock<MockProfile>(control_interface(), metrics(), manager())); |
Christopher Wiley | 1ce658d | 2012-10-10 10:02:03 -0700 | [diff] [blame] | 438 | wifi_service->set_profile(mock_profile); |
| 439 | // With nothing else going on, the service should attempt to connect. |
| 440 | EXPECT_CALL(*wifi(), ConnectTo(wifi_service.get(), _)); |
mukesh agrawal | dc7b844 | 2012-09-27 13:48:14 -0700 | [diff] [blame] | 441 | wifi_service->Connect(&error, "in test"); |
Christopher Wiley | 1ce658d | 2012-10-10 10:02:03 -0700 | [diff] [blame] | 442 | Mock::VerifyAndClearExpectations(wifi()); |
| 443 | |
| 444 | // But if we're already "connecting" or "connected" then we shouldn't attempt |
| 445 | // again. |
| 446 | EXPECT_CALL(*wifi(), |
| 447 | ConnectTo(wifi_service.get(), _)).Times(0); |
| 448 | wifi_service->SetState(Service::kStateAssociating); |
mukesh agrawal | dc7b844 | 2012-09-27 13:48:14 -0700 | [diff] [blame] | 449 | wifi_service->Connect(&error, "in test"); |
Christopher Wiley | 1ce658d | 2012-10-10 10:02:03 -0700 | [diff] [blame] | 450 | wifi_service->SetState(Service::kStateConfiguring); |
mukesh agrawal | dc7b844 | 2012-09-27 13:48:14 -0700 | [diff] [blame] | 451 | wifi_service->Connect(&error, "in test"); |
Christopher Wiley | 1ce658d | 2012-10-10 10:02:03 -0700 | [diff] [blame] | 452 | wifi_service->SetState(Service::kStateConnected); |
mukesh agrawal | dc7b844 | 2012-09-27 13:48:14 -0700 | [diff] [blame] | 453 | wifi_service->Connect(&error, "in test"); |
Christopher Wiley | 1ce658d | 2012-10-10 10:02:03 -0700 | [diff] [blame] | 454 | wifi_service->SetState(Service::kStatePortal); |
mukesh agrawal | dc7b844 | 2012-09-27 13:48:14 -0700 | [diff] [blame] | 455 | wifi_service->Connect(&error, "in test"); |
Christopher Wiley | 1ce658d | 2012-10-10 10:02:03 -0700 | [diff] [blame] | 456 | wifi_service->SetState(Service::kStateOnline); |
mukesh agrawal | dc7b844 | 2012-09-27 13:48:14 -0700 | [diff] [blame] | 457 | wifi_service->Connect(&error, "in test"); |
Christopher Wiley | 1ce658d | 2012-10-10 10:02:03 -0700 | [diff] [blame] | 458 | Mock::VerifyAndClearExpectations(wifi()); |
| 459 | } |
| 460 | |
Gaurav Shah | f8721ee | 2011-11-07 09:12:46 -0800 | [diff] [blame] | 461 | TEST_F(WiFiServiceTest, ConnectTaskPSK) { |
Paul Stewart | 3c50401 | 2013-01-17 17:49:58 -0800 | [diff] [blame] | 462 | WiFiServiceRefPtr wifi_service = MakeServiceWithWiFi(flimflam::kSecurityPsk); |
Paul Stewart | 4108db9 | 2013-03-11 12:13:24 -0700 | [diff] [blame] | 463 | EXPECT_CALL(*wifi(), ConnectTo(wifi_service.get(), PSKSecurityArgs())); |
Wade Guthrie | 005bd34 | 2012-05-02 09:37:07 -0700 | [diff] [blame] | 464 | Error error; |
| 465 | wifi_service->SetPassphrase("0:mumblemumblem", &error); |
mukesh agrawal | dc7b844 | 2012-09-27 13:48:14 -0700 | [diff] [blame] | 466 | wifi_service->Connect(NULL, "in test"); |
Gaurav Shah | f8721ee | 2011-11-07 09:12:46 -0800 | [diff] [blame] | 467 | } |
| 468 | |
Gaurav Shah | 10109f2 | 2011-11-11 20:16:22 -0800 | [diff] [blame] | 469 | TEST_F(WiFiServiceTest, ConnectTask8021x) { |
Paul Stewart | 3c50401 | 2013-01-17 17:49:58 -0800 | [diff] [blame] | 470 | WiFiServiceRefPtr service = MakeServiceWithWiFi(flimflam::kSecurity8021x); |
Paul Stewart | 0654ece | 2013-03-26 15:21:26 -0700 | [diff] [blame] | 471 | EapCredentials eap; |
Gaurav Shah | 10109f2 | 2011-11-11 20:16:22 -0800 | [diff] [blame] | 472 | eap.identity = "identity"; |
Wade Guthrie | 005bd34 | 2012-05-02 09:37:07 -0700 | [diff] [blame] | 473 | eap.password = "mumble"; |
Paul Stewart | 3c50401 | 2013-01-17 17:49:58 -0800 | [diff] [blame] | 474 | service->set_eap(eap); |
| 475 | EXPECT_CALL(*wifi(), ConnectTo(service.get(), EAPSecurityArgs())); |
mukesh agrawal | dc7b844 | 2012-09-27 13:48:14 -0700 | [diff] [blame] | 476 | service->Connect(NULL, "in test"); |
Gaurav Shah | 10109f2 | 2011-11-11 20:16:22 -0800 | [diff] [blame] | 477 | } |
| 478 | |
Paul Stewart | e2d7c50 | 2012-07-16 16:35:10 -0700 | [diff] [blame] | 479 | TEST_F(WiFiServiceTest, ConnectTaskAdHocFrequency) { |
| 480 | vector<uint8_t> ssid(1, 'a'); |
| 481 | WiFiEndpointRefPtr endpoint_nofreq = |
mukesh agrawal | 43970a2 | 2013-02-15 16:00:07 -0800 | [diff] [blame] | 482 | MakeOpenEndpoint("a", "00:00:00:00:00:01", 0, 0); |
Paul Stewart | e2d7c50 | 2012-07-16 16:35:10 -0700 | [diff] [blame] | 483 | WiFiEndpointRefPtr endpoint_freq = |
mukesh agrawal | 43970a2 | 2013-02-15 16:00:07 -0800 | [diff] [blame] | 484 | MakeOpenEndpoint("a", "00:00:00:00:00:02", 2412, 0); |
Paul Stewart | e2d7c50 | 2012-07-16 16:35:10 -0700 | [diff] [blame] | 485 | |
Paul Stewart | 3c50401 | 2013-01-17 17:49:58 -0800 | [diff] [blame] | 486 | WiFiServiceRefPtr wifi_service = MakeServiceWithWiFi(flimflam::kSecurityNone); |
Paul Stewart | e2d7c50 | 2012-07-16 16:35:10 -0700 | [diff] [blame] | 487 | wifi_service->AddEndpoint(endpoint_freq); |
| 488 | EXPECT_CALL(*wifi(), |
| 489 | ConnectTo(wifi_service.get(), FrequencyArg(false))); |
mukesh agrawal | dc7b844 | 2012-09-27 13:48:14 -0700 | [diff] [blame] | 490 | wifi_service->Connect(NULL, "in test"); |
Paul Stewart | e2d7c50 | 2012-07-16 16:35:10 -0700 | [diff] [blame] | 491 | |
| 492 | wifi_service = new WiFiService(control_interface(), |
| 493 | dispatcher(), |
| 494 | metrics(), |
| 495 | manager(), |
Paul Stewart | 3c50401 | 2013-01-17 17:49:58 -0800 | [diff] [blame] | 496 | provider(), |
Paul Stewart | e2d7c50 | 2012-07-16 16:35:10 -0700 | [diff] [blame] | 497 | ssid, |
| 498 | flimflam::kModeAdhoc, |
| 499 | flimflam::kSecurityNone, |
| 500 | false); |
| 501 | EXPECT_CALL(*wifi(), |
| 502 | ConnectTo(wifi_service.get(), FrequencyArg(false))); |
Paul Stewart | 3c50401 | 2013-01-17 17:49:58 -0800 | [diff] [blame] | 503 | SetWiFiForService(wifi_service, wifi()); |
mukesh agrawal | dc7b844 | 2012-09-27 13:48:14 -0700 | [diff] [blame] | 504 | wifi_service->Connect(NULL, "in test"); |
Paul Stewart | e2d7c50 | 2012-07-16 16:35:10 -0700 | [diff] [blame] | 505 | |
| 506 | wifi_service = new WiFiService(control_interface(), |
| 507 | dispatcher(), |
| 508 | metrics(), |
| 509 | manager(), |
Paul Stewart | 3c50401 | 2013-01-17 17:49:58 -0800 | [diff] [blame] | 510 | provider(), |
Paul Stewart | e2d7c50 | 2012-07-16 16:35:10 -0700 | [diff] [blame] | 511 | ssid, |
| 512 | flimflam::kModeAdhoc, |
| 513 | flimflam::kSecurityNone, |
| 514 | false); |
| 515 | wifi_service->AddEndpoint(endpoint_nofreq); |
Paul Stewart | 3c50401 | 2013-01-17 17:49:58 -0800 | [diff] [blame] | 516 | SetWiFiForService(wifi_service, wifi()); |
Paul Stewart | e2d7c50 | 2012-07-16 16:35:10 -0700 | [diff] [blame] | 517 | EXPECT_CALL(*wifi(), |
| 518 | ConnectTo(wifi_service.get(), FrequencyArg(false))); |
mukesh agrawal | dc7b844 | 2012-09-27 13:48:14 -0700 | [diff] [blame] | 519 | wifi_service->Connect(NULL, "in test"); |
Paul Stewart | e2d7c50 | 2012-07-16 16:35:10 -0700 | [diff] [blame] | 520 | |
| 521 | wifi_service = new WiFiService(control_interface(), |
| 522 | dispatcher(), |
| 523 | metrics(), |
| 524 | manager(), |
Paul Stewart | 3c50401 | 2013-01-17 17:49:58 -0800 | [diff] [blame] | 525 | provider(), |
Paul Stewart | e2d7c50 | 2012-07-16 16:35:10 -0700 | [diff] [blame] | 526 | ssid, |
| 527 | flimflam::kModeAdhoc, |
| 528 | flimflam::kSecurityNone, |
| 529 | false); |
| 530 | wifi_service->AddEndpoint(endpoint_freq); |
Paul Stewart | 3c50401 | 2013-01-17 17:49:58 -0800 | [diff] [blame] | 531 | SetWiFiForService(wifi_service, wifi()); |
Paul Stewart | e2d7c50 | 2012-07-16 16:35:10 -0700 | [diff] [blame] | 532 | EXPECT_CALL(*wifi(), |
| 533 | ConnectTo(wifi_service.get(), FrequencyArg(true))); |
mukesh agrawal | dc7b844 | 2012-09-27 13:48:14 -0700 | [diff] [blame] | 534 | wifi_service->Connect(NULL, "in test"); |
Paul Stewart | e2d7c50 | 2012-07-16 16:35:10 -0700 | [diff] [blame] | 535 | } |
| 536 | |
Paul Stewart | a5e7d5f | 2013-01-09 18:06:15 -0800 | [diff] [blame] | 537 | TEST_F(WiFiServiceTest, ConnectTaskWPA80211w) { |
Paul Stewart | 3c50401 | 2013-01-17 17:49:58 -0800 | [diff] [blame] | 538 | WiFiServiceRefPtr wifi_service = MakeServiceWithWiFi(flimflam::kSecurityPsk); |
mukesh agrawal | 43970a2 | 2013-02-15 16:00:07 -0800 | [diff] [blame] | 539 | WiFiEndpointRefPtr endpoint = |
| 540 | MakeOpenEndpoint("a", "00:00:00:00:00:01", 0, 0); |
Paul Stewart | a5e7d5f | 2013-01-09 18:06:15 -0800 | [diff] [blame] | 541 | endpoint->ieee80211w_required_ = true; |
| 542 | wifi_service->AddEndpoint(endpoint); |
| 543 | Error error; |
| 544 | wifi_service->SetPassphrase("0:mumblemumblem", &error); |
| 545 | EXPECT_CALL(*wifi(), |
| 546 | ConnectTo(wifi_service.get(), WPA80211wSecurityArgs())); |
mukesh agrawal | dc7b844 | 2012-09-27 13:48:14 -0700 | [diff] [blame] | 547 | wifi_service->Connect(NULL, "in test"); |
Paul Stewart | a5e7d5f | 2013-01-09 18:06:15 -0800 | [diff] [blame] | 548 | } |
| 549 | |
Thieu Le | f4cbda9 | 2011-11-10 23:41:24 +0000 | [diff] [blame] | 550 | MATCHER(WEPSecurityArgsKeyIndex0, "") { |
Paul Stewart | 0654ece | 2013-03-26 15:21:26 -0700 | [diff] [blame] | 551 | return ContainsKey(arg, WPASupplicant::kPropertyAuthAlg) && |
| 552 | ContainsKey(arg, WPASupplicant::kPropertyWEPKey + std::string("0")) && |
| 553 | ContainsKey(arg, WPASupplicant::kPropertyWEPTxKeyIndex) && |
| 554 | (arg.find(WPASupplicant::kPropertyWEPTxKeyIndex)->second. |
Thieu Le | f4cbda9 | 2011-11-10 23:41:24 +0000 | [diff] [blame] | 555 | reader().get_uint32() == 0); |
| 556 | } |
| 557 | |
| 558 | MATCHER(WEPSecurityArgsKeyIndex1, "") { |
Paul Stewart | 0654ece | 2013-03-26 15:21:26 -0700 | [diff] [blame] | 559 | return ContainsKey(arg, WPASupplicant::kPropertyAuthAlg) && |
| 560 | ContainsKey(arg, WPASupplicant::kPropertyWEPKey + std::string("1")) && |
| 561 | ContainsKey(arg, WPASupplicant::kPropertyWEPTxKeyIndex) && |
| 562 | (arg.find(WPASupplicant::kPropertyWEPTxKeyIndex)->second. |
Thieu Le | f4cbda9 | 2011-11-10 23:41:24 +0000 | [diff] [blame] | 563 | reader().get_uint32() == 1); |
| 564 | } |
| 565 | |
| 566 | MATCHER(WEPSecurityArgsKeyIndex2, "") { |
Paul Stewart | 0654ece | 2013-03-26 15:21:26 -0700 | [diff] [blame] | 567 | return ContainsKey(arg, WPASupplicant::kPropertyAuthAlg) && |
| 568 | ContainsKey(arg, WPASupplicant::kPropertyWEPKey + std::string("2")) && |
| 569 | ContainsKey(arg, WPASupplicant::kPropertyWEPTxKeyIndex) && |
| 570 | (arg.find(WPASupplicant::kPropertyWEPTxKeyIndex)->second. |
Thieu Le | f4cbda9 | 2011-11-10 23:41:24 +0000 | [diff] [blame] | 571 | reader().get_uint32() == 2); |
| 572 | } |
| 573 | |
| 574 | MATCHER(WEPSecurityArgsKeyIndex3, "") { |
Paul Stewart | 0654ece | 2013-03-26 15:21:26 -0700 | [diff] [blame] | 575 | return ContainsKey(arg, WPASupplicant::kPropertyAuthAlg) && |
| 576 | ContainsKey(arg, WPASupplicant::kPropertyWEPKey + std::string("3")) && |
| 577 | ContainsKey(arg, WPASupplicant::kPropertyWEPTxKeyIndex) && |
| 578 | (arg.find(WPASupplicant::kPropertyWEPTxKeyIndex)->second. |
Thieu Le | f4cbda9 | 2011-11-10 23:41:24 +0000 | [diff] [blame] | 579 | reader().get_uint32() == 3); |
| 580 | } |
| 581 | |
| 582 | TEST_F(WiFiServiceTest, ConnectTaskWEP) { |
Paul Stewart | 3c50401 | 2013-01-17 17:49:58 -0800 | [diff] [blame] | 583 | WiFiServiceRefPtr wifi_service = MakeServiceWithWiFi(flimflam::kSecurityWep); |
Thieu Le | f4cbda9 | 2011-11-10 23:41:24 +0000 | [diff] [blame] | 584 | Error error; |
| 585 | wifi_service->SetPassphrase("0:abcdefghijklm", &error); |
| 586 | EXPECT_CALL(*wifi(), |
| 587 | ConnectTo(wifi_service.get(), WEPSecurityArgsKeyIndex0())); |
mukesh agrawal | dc7b844 | 2012-09-27 13:48:14 -0700 | [diff] [blame] | 588 | wifi_service->Connect(NULL, "in test"); |
Thieu Le | f4cbda9 | 2011-11-10 23:41:24 +0000 | [diff] [blame] | 589 | |
| 590 | wifi_service->SetPassphrase("abcdefghijklm", &error); |
| 591 | EXPECT_CALL(*wifi(), |
| 592 | ConnectTo(wifi_service.get(), WEPSecurityArgsKeyIndex0())); |
mukesh agrawal | dc7b844 | 2012-09-27 13:48:14 -0700 | [diff] [blame] | 593 | wifi_service->Connect(NULL, "in test"); |
Thieu Le | f4cbda9 | 2011-11-10 23:41:24 +0000 | [diff] [blame] | 594 | |
| 595 | wifi_service->SetPassphrase("1:abcdefghijklm", &error); |
| 596 | EXPECT_CALL(*wifi(), |
| 597 | ConnectTo(wifi_service.get(), WEPSecurityArgsKeyIndex1())); |
mukesh agrawal | dc7b844 | 2012-09-27 13:48:14 -0700 | [diff] [blame] | 598 | wifi_service->Connect(NULL, "in test"); |
Thieu Le | f4cbda9 | 2011-11-10 23:41:24 +0000 | [diff] [blame] | 599 | |
| 600 | wifi_service->SetPassphrase("2:abcdefghijklm", &error); |
| 601 | EXPECT_CALL(*wifi(), |
| 602 | ConnectTo(wifi_service.get(), WEPSecurityArgsKeyIndex2())); |
mukesh agrawal | dc7b844 | 2012-09-27 13:48:14 -0700 | [diff] [blame] | 603 | wifi_service->Connect(NULL, "in test"); |
Thieu Le | f4cbda9 | 2011-11-10 23:41:24 +0000 | [diff] [blame] | 604 | |
| 605 | wifi_service->SetPassphrase("3:abcdefghijklm", &error); |
| 606 | EXPECT_CALL(*wifi(), |
| 607 | ConnectTo(wifi_service.get(), WEPSecurityArgsKeyIndex3())); |
mukesh agrawal | dc7b844 | 2012-09-27 13:48:14 -0700 | [diff] [blame] | 608 | wifi_service->Connect(NULL, "in test"); |
Thieu Le | f4cbda9 | 2011-11-10 23:41:24 +0000 | [diff] [blame] | 609 | } |
| 610 | |
Gaurav Shah | 29d6888 | 2012-01-30 19:06:42 -0800 | [diff] [blame] | 611 | |
| 612 | MATCHER(DynamicWEPArgs, "") { |
Paul Stewart | 0654ece | 2013-03-26 15:21:26 -0700 | [diff] [blame] | 613 | return ContainsKey(arg, WPASupplicant::kNetworkPropertyEapIdentity) && |
| 614 | ContainsKey(arg, WPASupplicant::kNetworkPropertyCaPath) && |
| 615 | !ContainsKey(arg, WPASupplicant::kPropertySecurityProtocol); |
Gaurav Shah | 29d6888 | 2012-01-30 19:06:42 -0800 | [diff] [blame] | 616 | } |
| 617 | |
| 618 | // Dynamic WEP + 802.1x. |
| 619 | TEST_F(WiFiServiceTest, ConnectTaskDynamicWEP) { |
Paul Stewart | 3c50401 | 2013-01-17 17:49:58 -0800 | [diff] [blame] | 620 | WiFiServiceRefPtr wifi_service = MakeServiceWithWiFi(flimflam::kSecurityWep); |
Gaurav Shah | 29d6888 | 2012-01-30 19:06:42 -0800 | [diff] [blame] | 621 | |
Paul Stewart | 0654ece | 2013-03-26 15:21:26 -0700 | [diff] [blame] | 622 | EapCredentials eap; |
Gaurav Shah | 29d6888 | 2012-01-30 19:06:42 -0800 | [diff] [blame] | 623 | eap.key_management = "IEEE8021X"; |
| 624 | eap.identity = "something"; |
Wade Guthrie | 005bd34 | 2012-05-02 09:37:07 -0700 | [diff] [blame] | 625 | eap.password = "mumble"; |
Gaurav Shah | 29d6888 | 2012-01-30 19:06:42 -0800 | [diff] [blame] | 626 | wifi_service->set_eap(eap); |
| 627 | EXPECT_CALL(*wifi(), |
| 628 | ConnectTo(wifi_service.get(), DynamicWEPArgs())); |
mukesh agrawal | dc7b844 | 2012-09-27 13:48:14 -0700 | [diff] [blame] | 629 | wifi_service->Connect(NULL, "in test"); |
Gaurav Shah | 29d6888 | 2012-01-30 19:06:42 -0800 | [diff] [blame] | 630 | } |
| 631 | |
Paul Stewart | 835934a | 2012-12-06 19:27:09 -0800 | [diff] [blame] | 632 | TEST_F(WiFiServiceTest, SetPassphraseRemovesCachedCredentials) { |
| 633 | vector<uint8_t> ssid(5); |
Paul Stewart | 3c50401 | 2013-01-17 17:49:58 -0800 | [diff] [blame] | 634 | WiFiServiceRefPtr wifi_service = MakeServiceWithWiFi(flimflam::kSecurityRsn); |
Paul Stewart | 835934a | 2012-12-06 19:27:09 -0800 | [diff] [blame] | 635 | |
| 636 | const string kPassphrase = "abcdefgh"; |
| 637 | |
| 638 | { |
| 639 | Error error; |
| 640 | // A changed passphrase should trigger cache removal. |
| 641 | EXPECT_CALL(*wifi(), ClearCachedCredentials(wifi_service.get())); |
| 642 | wifi_service->SetPassphrase(kPassphrase, &error); |
| 643 | Mock::VerifyAndClearExpectations(wifi()); |
| 644 | EXPECT_TRUE(error.IsSuccess()); |
| 645 | } |
| 646 | |
| 647 | { |
| 648 | Error error; |
| 649 | // An unchanged passphrase should not trigger cache removal. |
| 650 | EXPECT_CALL(*wifi(), ClearCachedCredentials(_)).Times(0); |
| 651 | wifi_service->SetPassphrase(kPassphrase, &error); |
| 652 | Mock::VerifyAndClearExpectations(wifi()); |
| 653 | EXPECT_TRUE(error.IsSuccess()); |
| 654 | } |
| 655 | |
| 656 | { |
| 657 | Error error; |
| 658 | // A modified passphrase should trigger cache removal. |
| 659 | EXPECT_CALL(*wifi(), ClearCachedCredentials(wifi_service.get())); |
| 660 | wifi_service->SetPassphrase(kPassphrase + "X", &error); |
| 661 | Mock::VerifyAndClearExpectations(wifi()); |
| 662 | EXPECT_TRUE(error.IsSuccess()); |
| 663 | } |
| 664 | |
| 665 | { |
| 666 | Error error; |
| 667 | // A cleared passphrase should also trigger cache removal. |
| 668 | EXPECT_CALL(*wifi(), ClearCachedCredentials(wifi_service.get())); |
| 669 | wifi_service->ClearPassphrase(&error); |
| 670 | Mock::VerifyAndClearExpectations(wifi()); |
| 671 | EXPECT_TRUE(error.IsSuccess()); |
| 672 | } |
| 673 | |
| 674 | { |
| 675 | Error error; |
| 676 | // An invalid passphrase should not trigger cache removal. |
| 677 | EXPECT_CALL(*wifi(), ClearCachedCredentials(_)).Times(0); |
| 678 | wifi_service->SetPassphrase("", &error); |
| 679 | Mock::VerifyAndClearExpectations(wifi()); |
| 680 | EXPECT_FALSE(error.IsSuccess()); |
| 681 | } |
| 682 | |
| 683 | { |
| 684 | // Any change to EAP parameters (including a null one) will trigger cache |
| 685 | // removal. This is a lot less granular than the passphrase checks above. |
| 686 | EXPECT_CALL(*wifi(), ClearCachedCredentials(wifi_service.get())); |
Paul Stewart | 0654ece | 2013-03-26 15:21:26 -0700 | [diff] [blame] | 687 | wifi_service->set_eap(EapCredentials()); |
Paul Stewart | 835934a | 2012-12-06 19:27:09 -0800 | [diff] [blame] | 688 | Mock::VerifyAndClearExpectations(wifi()); |
| 689 | } |
| 690 | } |
| 691 | |
Paul Stewart | d08f443 | 2011-11-04 07:48:20 -0700 | [diff] [blame] | 692 | TEST_F(WiFiServiceTest, LoadHidden) { |
Paul Stewart | 3c50401 | 2013-01-17 17:49:58 -0800 | [diff] [blame] | 693 | WiFiServiceRefPtr service = MakeSimpleService(flimflam::kSecurityNone); |
Paul Stewart | d08f443 | 2011-11-04 07:48:20 -0700 | [diff] [blame] | 694 | ASSERT_FALSE(service->hidden_ssid_); |
| 695 | NiceMock<MockStore> mock_store; |
| 696 | const string storage_id = service->GetStorageIdentifier(); |
Paul Stewart | 71a4d3b | 2013-01-18 18:12:56 -0800 | [diff] [blame] | 697 | set<string> groups; |
| 698 | groups.insert(storage_id); |
Paul Stewart | d08f443 | 2011-11-04 07:48:20 -0700 | [diff] [blame] | 699 | EXPECT_CALL(mock_store, ContainsGroup(StrEq(storage_id))) |
| 700 | .WillRepeatedly(Return(true)); |
Paul Stewart | 71a4d3b | 2013-01-18 18:12:56 -0800 | [diff] [blame] | 701 | EXPECT_CALL(mock_store, GetGroupsWithProperties( |
| 702 | ContainsWiFiProperties( |
Paul Stewart | 3c50401 | 2013-01-17 17:49:58 -0800 | [diff] [blame] | 703 | simple_ssid(), flimflam::kModeManaged, flimflam::kSecurityNone))) |
Paul Stewart | 71a4d3b | 2013-01-18 18:12:56 -0800 | [diff] [blame] | 704 | .WillRepeatedly(Return(groups)); |
Paul Stewart | d08f443 | 2011-11-04 07:48:20 -0700 | [diff] [blame] | 705 | EXPECT_CALL(mock_store, GetBool(_, _, _)) |
| 706 | .WillRepeatedly(Return(false)); |
| 707 | EXPECT_CALL(mock_store, |
| 708 | GetBool(StrEq(storage_id), WiFiService::kStorageHiddenSSID, _)) |
| 709 | .WillRepeatedly(DoAll(SetArgumentPointee<2>(true), Return(true))); |
| 710 | EXPECT_TRUE(service->Load(&mock_store)); |
| 711 | EXPECT_TRUE(service->hidden_ssid_); |
| 712 | } |
| 713 | |
Paul Stewart | fa013ab | 2013-04-11 07:12:03 -0700 | [diff] [blame^] | 714 | TEST_F(WiFiServiceTest, LoadPassphraseForNonPassphraseService) { |
| 715 | WiFiServiceRefPtr service = MakeSimpleService(flimflam::kSecurityNone); |
| 716 | NiceMock<MockStore> mock_store; |
| 717 | const string storage_id = service->GetStorageIdentifier(); |
| 718 | set<string> groups; |
| 719 | groups.insert(storage_id); |
| 720 | EXPECT_CALL(mock_store, ContainsGroup(StrEq(storage_id))) |
| 721 | .WillRepeatedly(Return(true)); |
| 722 | EXPECT_CALL(mock_store, GetGroupsWithProperties( |
| 723 | ContainsWiFiProperties( |
| 724 | simple_ssid(), flimflam::kModeManaged, flimflam::kSecurityNone))) |
| 725 | .WillRepeatedly(Return(groups)); |
| 726 | EXPECT_CALL(mock_store, |
| 727 | GetCryptedString(StrEq(storage_id), |
| 728 | StrNe(WiFiService::kStoragePassphrase), _)) |
| 729 | .WillRepeatedly(Return(false)); |
| 730 | EXPECT_CALL(mock_store, |
| 731 | GetCryptedString(StrEq(storage_id), |
| 732 | WiFiService::kStoragePassphrase, _)) |
| 733 | .WillOnce(DoAll(SetArgumentPointee<2>(string("password")), Return(true))) |
| 734 | .WillOnce(DoAll(SetArgumentPointee<2>(string()), Return(true))); |
| 735 | ScopedMockLog log; |
| 736 | EXPECT_CALL(log, Log(logging::LOG_ERROR, _, |
| 737 | EndsWith("Passphrase could not be set: " |
| 738 | "org.chromium.flimflam.Error.NotSupported"))) |
| 739 | .Times(1); |
| 740 | EXPECT_TRUE(service->Load(&mock_store)); |
| 741 | Mock::VerifyAndClearExpectations(&log); |
| 742 | EXPECT_CALL(log, Log(logging::LOG_ERROR, _, _)).Times(0); |
| 743 | EXPECT_TRUE(service->Load(&mock_store)); |
| 744 | } |
| 745 | |
Paul Stewart | 71a4d3b | 2013-01-18 18:12:56 -0800 | [diff] [blame] | 746 | TEST_F(WiFiServiceTest, LoadMultipleMatchingGroups) { |
Paul Stewart | 3c50401 | 2013-01-17 17:49:58 -0800 | [diff] [blame] | 747 | WiFiServiceRefPtr service = MakeServiceWithWiFi(flimflam::kSecurityNone); |
Paul Stewart | 71a4d3b | 2013-01-18 18:12:56 -0800 | [diff] [blame] | 748 | set<string> groups; |
| 749 | groups.insert("id0"); |
| 750 | groups.insert("id1"); |
| 751 | // Make sure we retain the first matched group in the same way that |
| 752 | // WiFiService::Load() will. |
| 753 | string first_group = *groups.begin(); |
| 754 | |
| 755 | NiceMock<MockStore> mock_store; |
| 756 | EXPECT_CALL(mock_store, GetGroupsWithProperties( |
| 757 | ContainsWiFiProperties( |
Paul Stewart | 3c50401 | 2013-01-17 17:49:58 -0800 | [diff] [blame] | 758 | simple_ssid(), flimflam::kModeManaged, flimflam::kSecurityNone))) |
Paul Stewart | 71a4d3b | 2013-01-18 18:12:56 -0800 | [diff] [blame] | 759 | .WillRepeatedly(Return(groups)); |
| 760 | EXPECT_CALL(mock_store, ContainsGroup(first_group)) |
| 761 | .WillRepeatedly(Return(true)); |
| 762 | EXPECT_CALL(mock_store, ContainsGroup(StrNe(first_group))).Times(0); |
| 763 | EXPECT_CALL(mock_store, GetBool(first_group, _, _)) |
| 764 | .WillRepeatedly(Return(false)); |
| 765 | EXPECT_CALL(mock_store, GetBool(StrNe(first_group), _, _)).Times(0); |
| 766 | ScopedMockLog log; |
| 767 | EXPECT_CALL(log, Log(_, _, _)).Times(AnyNumber()); |
| 768 | EXPECT_CALL(log, Log(logging::LOG_WARNING, _, |
| 769 | EndsWith("choosing the first."))); |
| 770 | EXPECT_TRUE(service->Load(&mock_store)); |
| 771 | } |
| 772 | |
Paul Stewart | d08f443 | 2011-11-04 07:48:20 -0700 | [diff] [blame] | 773 | TEST_F(WiFiServiceSecurityTest, WPAMapping) { |
| 774 | EXPECT_TRUE(TestStorageMapping(flimflam::kSecurityRsn, |
| 775 | flimflam::kSecurityPsk)); |
| 776 | EXPECT_TRUE(TestStorageMapping(flimflam::kSecurityWpa, |
| 777 | flimflam::kSecurityPsk)); |
| 778 | EXPECT_TRUE(TestStorageMapping(flimflam::kSecurityPsk, |
| 779 | flimflam::kSecurityPsk)); |
| 780 | EXPECT_TRUE(TestStorageMapping(flimflam::kSecurityWep, |
| 781 | flimflam::kSecurityWep)); |
| 782 | EXPECT_TRUE(TestStorageMapping(flimflam::kSecurityNone, |
| 783 | flimflam::kSecurityNone)); |
Gaurav Shah | 10109f2 | 2011-11-11 20:16:22 -0800 | [diff] [blame] | 784 | EXPECT_TRUE(TestStorageMapping(flimflam::kSecurity8021x, |
| 785 | flimflam::kSecurity8021x)); |
Paul Stewart | d08f443 | 2011-11-04 07:48:20 -0700 | [diff] [blame] | 786 | } |
| 787 | |
| 788 | TEST_F(WiFiServiceSecurityTest, LoadMapping) { |
| 789 | EXPECT_TRUE(TestLoadMapping(flimflam::kSecurityRsn, |
| 790 | flimflam::kSecurityPsk, |
| 791 | true)); |
| 792 | EXPECT_TRUE(TestLoadMapping(flimflam::kSecurityRsn, |
| 793 | flimflam::kSecurityRsn, |
Paul Stewart | 71a4d3b | 2013-01-18 18:12:56 -0800 | [diff] [blame] | 794 | false)); |
Paul Stewart | d08f443 | 2011-11-04 07:48:20 -0700 | [diff] [blame] | 795 | EXPECT_TRUE(TestLoadMapping(flimflam::kSecurityRsn, |
| 796 | flimflam::kSecurityWpa, |
| 797 | false)); |
| 798 | EXPECT_TRUE(TestLoadMapping(flimflam::kSecurityWpa, |
| 799 | flimflam::kSecurityPsk, |
| 800 | true)); |
| 801 | EXPECT_TRUE(TestLoadMapping(flimflam::kSecurityWpa, |
| 802 | flimflam::kSecurityWpa, |
Paul Stewart | 71a4d3b | 2013-01-18 18:12:56 -0800 | [diff] [blame] | 803 | false)); |
Paul Stewart | d08f443 | 2011-11-04 07:48:20 -0700 | [diff] [blame] | 804 | EXPECT_TRUE(TestLoadMapping(flimflam::kSecurityWpa, |
| 805 | flimflam::kSecurityRsn, |
| 806 | false)); |
| 807 | EXPECT_TRUE(TestLoadMapping(flimflam::kSecurityWep, |
| 808 | flimflam::kSecurityWep, |
| 809 | true)); |
| 810 | EXPECT_TRUE(TestLoadMapping(flimflam::kSecurityWep, |
| 811 | flimflam::kSecurityPsk, |
| 812 | false)); |
| 813 | } |
| 814 | |
Paul Stewart | d8ad3c4 | 2012-01-09 12:39:38 -0800 | [diff] [blame] | 815 | TEST_F(WiFiServiceTest, LoadAndUnloadPassphrase) { |
Paul Stewart | 3c50401 | 2013-01-17 17:49:58 -0800 | [diff] [blame] | 816 | WiFiServiceRefPtr service = MakeSimpleService(flimflam::kSecurityPsk); |
Paul Stewart | d8ad3c4 | 2012-01-09 12:39:38 -0800 | [diff] [blame] | 817 | NiceMock<MockStore> mock_store; |
| 818 | const string storage_id = service->GetStorageIdentifier(); |
| 819 | EXPECT_CALL(mock_store, ContainsGroup(StrEq(storage_id))) |
| 820 | .WillRepeatedly(Return(true)); |
Paul Stewart | 71a4d3b | 2013-01-18 18:12:56 -0800 | [diff] [blame] | 821 | set<string> groups; |
| 822 | groups.insert(storage_id); |
| 823 | EXPECT_CALL(mock_store, GetGroupsWithProperties( |
| 824 | ContainsWiFiProperties( |
Paul Stewart | 3c50401 | 2013-01-17 17:49:58 -0800 | [diff] [blame] | 825 | simple_ssid(), flimflam::kModeManaged, flimflam::kSecurityPsk))) |
Paul Stewart | 71a4d3b | 2013-01-18 18:12:56 -0800 | [diff] [blame] | 826 | .WillRepeatedly(Return(groups)); |
Paul Stewart | d8ad3c4 | 2012-01-09 12:39:38 -0800 | [diff] [blame] | 827 | EXPECT_CALL(mock_store, GetBool(_, _, _)) |
| 828 | .WillRepeatedly(Return(false)); |
| 829 | const string passphrase = "passphrase"; |
| 830 | EXPECT_CALL(mock_store, |
| 831 | GetCryptedString(StrEq(storage_id), |
| 832 | WiFiService::kStoragePassphrase, _)) |
| 833 | .WillRepeatedly(DoAll(SetArgumentPointee<2>(passphrase), Return(true))); |
| 834 | EXPECT_CALL(mock_store, |
| 835 | GetCryptedString(StrEq(storage_id), |
| 836 | StrNe(WiFiService::kStoragePassphrase), _)) |
| 837 | .WillRepeatedly(Return(false)); |
| 838 | EXPECT_TRUE(service->need_passphrase_); |
| 839 | EXPECT_TRUE(service->Load(&mock_store)); |
| 840 | EXPECT_EQ(passphrase, service->passphrase_); |
| 841 | EXPECT_TRUE(service->connectable()); |
| 842 | EXPECT_FALSE(service->need_passphrase_); |
| 843 | service->Unload(); |
| 844 | EXPECT_EQ(string(""), service->passphrase_); |
| 845 | EXPECT_FALSE(service->connectable()); |
| 846 | EXPECT_TRUE(service->need_passphrase_); |
| 847 | } |
| 848 | |
Christopher Wiley | 27b4723 | 2012-11-02 13:13:00 -0700 | [diff] [blame] | 849 | TEST_F(WiFiServiceTest, ConfigureMakesConnectable) { |
| 850 | string guid("legit_guid"); |
| 851 | KeyValueStore args; |
| 852 | args.SetString(flimflam::kEapIdentityProperty, "legit_identity"); |
| 853 | args.SetString(flimflam::kEapPasswordProperty, "legit_password"); |
| 854 | args.SetString(flimflam::kEAPEAPProperty, "PEAP"); |
| 855 | args.SetString(flimflam::kGuidProperty, guid); |
| 856 | Error error; |
Christopher Wiley | 27b4723 | 2012-11-02 13:13:00 -0700 | [diff] [blame] | 857 | |
Paul Stewart | 3c50401 | 2013-01-17 17:49:58 -0800 | [diff] [blame] | 858 | WiFiServiceRefPtr service = MakeSimpleService(flimflam::kSecurity8021x); |
Christopher Wiley | 27b4723 | 2012-11-02 13:13:00 -0700 | [diff] [blame] | 859 | // Hack the GUID in so that we don't have to mess about with WiFi to regsiter |
| 860 | // our service. This way, Manager will handle the lookup itself. |
| 861 | service->set_guid(guid); |
| 862 | manager()->RegisterService(service); |
| 863 | EXPECT_FALSE(service->connectable()); |
| 864 | EXPECT_EQ(service.get(), manager()->GetService(args, &error).get()); |
| 865 | EXPECT_TRUE(error.IsSuccess()); |
| 866 | EXPECT_TRUE(service->connectable()); |
| 867 | } |
| 868 | |
Paul Stewart | 3c50401 | 2013-01-17 17:49:58 -0800 | [diff] [blame] | 869 | TEST_F(WiFiServiceTest, ConfigurePassphrase) { |
| 870 | EXPECT_EQ(Error::kNotSupported, |
| 871 | TestConfigurePassphrase(flimflam::kSecurityNone, "")); |
| 872 | EXPECT_EQ(Error::kNotSupported, |
| 873 | TestConfigurePassphrase(flimflam::kSecurityNone, "foo")); |
| 874 | EXPECT_EQ(Error::kSuccess, |
| 875 | TestConfigurePassphrase(flimflam::kSecurityWep, NULL)); |
| 876 | EXPECT_EQ(Error::kInvalidPassphrase, |
| 877 | TestConfigurePassphrase(flimflam::kSecurityWep, "")); |
| 878 | EXPECT_EQ(Error::kInvalidPassphrase, |
| 879 | TestConfigurePassphrase(flimflam::kSecurityWep, "abcd")); |
| 880 | EXPECT_EQ(Error::kSuccess, |
| 881 | TestConfigurePassphrase(flimflam::kSecurityWep, "abcde")); |
| 882 | EXPECT_EQ(Error::kSuccess, |
| 883 | TestConfigurePassphrase(flimflam::kSecurityWep, "abcdefghijklm")); |
| 884 | EXPECT_EQ(Error::kSuccess, |
| 885 | TestConfigurePassphrase(flimflam::kSecurityWep, "0:abcdefghijklm")); |
| 886 | EXPECT_EQ(Error::kSuccess, |
| 887 | TestConfigurePassphrase(flimflam::kSecurityWep, "0102030405")); |
| 888 | EXPECT_EQ(Error::kInvalidPassphrase, |
| 889 | TestConfigurePassphrase(flimflam::kSecurityWep, "0x0102030405")); |
| 890 | EXPECT_EQ(Error::kInvalidPassphrase, |
| 891 | TestConfigurePassphrase(flimflam::kSecurityWep, "O102030405")); |
| 892 | EXPECT_EQ(Error::kInvalidPassphrase, |
| 893 | TestConfigurePassphrase(flimflam::kSecurityWep, "1:O102030405")); |
| 894 | EXPECT_EQ(Error::kInvalidPassphrase, |
| 895 | TestConfigurePassphrase(flimflam::kSecurityWep, "1:0xO102030405")); |
| 896 | EXPECT_EQ(Error::kInvalidPassphrase, |
| 897 | TestConfigurePassphrase(flimflam::kSecurityWep, "0xO102030405")); |
| 898 | EXPECT_EQ(Error::kSuccess, |
| 899 | TestConfigurePassphrase(flimflam::kSecurityWep, |
| 900 | "0102030405060708090a0b0c0d")); |
| 901 | EXPECT_EQ(Error::kSuccess, |
| 902 | TestConfigurePassphrase(flimflam::kSecurityWep, |
| 903 | "0102030405060708090A0B0C0D")); |
| 904 | EXPECT_EQ(Error::kSuccess, |
| 905 | TestConfigurePassphrase(flimflam::kSecurityWep, |
| 906 | "0:0102030405060708090a0b0c0d")); |
| 907 | EXPECT_EQ(Error::kSuccess, |
| 908 | TestConfigurePassphrase(flimflam::kSecurityWep, |
| 909 | "0:0x0102030405060708090a0b0c0d")); |
| 910 | EXPECT_EQ(Error::kSuccess, |
| 911 | TestConfigurePassphrase(flimflam::kSecurityWpa, NULL)); |
| 912 | EXPECT_EQ(Error::kSuccess, |
| 913 | TestConfigurePassphrase(flimflam::kSecurityWpa, "secure password")); |
| 914 | EXPECT_EQ(Error::kInvalidPassphrase, |
| 915 | TestConfigurePassphrase(flimflam::kSecurityWpa, "")); |
| 916 | EXPECT_EQ(Error::kSuccess, TestConfigurePassphrase( |
| 917 | flimflam::kSecurityWpa, |
| 918 | string(IEEE_80211::kWPAAsciiMinLen, 'Z').c_str())); |
| 919 | EXPECT_EQ(Error::kSuccess, TestConfigurePassphrase( |
| 920 | flimflam::kSecurityWpa, |
| 921 | string(IEEE_80211::kWPAAsciiMaxLen, 'Z').c_str())); |
| 922 | // subtle: invalid length for hex key, but valid as ascii passphrase |
| 923 | EXPECT_EQ(Error::kSuccess, TestConfigurePassphrase( |
| 924 | flimflam::kSecurityWpa, |
| 925 | string(IEEE_80211::kWPAHexLen-1, '1').c_str())); |
| 926 | EXPECT_EQ(Error::kSuccess, TestConfigurePassphrase( |
| 927 | flimflam::kSecurityWpa, |
| 928 | string(IEEE_80211::kWPAHexLen, '1').c_str())); |
| 929 | EXPECT_EQ(Error::kInvalidPassphrase, TestConfigurePassphrase( |
| 930 | flimflam::kSecurityWpa, |
| 931 | string(IEEE_80211::kWPAAsciiMinLen-1, 'Z').c_str())); |
| 932 | EXPECT_EQ(Error::kInvalidPassphrase, TestConfigurePassphrase( |
| 933 | flimflam::kSecurityWpa, |
| 934 | string(IEEE_80211::kWPAAsciiMaxLen+1, 'Z').c_str())); |
| 935 | EXPECT_EQ(Error::kInvalidPassphrase, TestConfigurePassphrase( |
| 936 | flimflam::kSecurityWpa, |
| 937 | string(IEEE_80211::kWPAHexLen+1, '1').c_str())); |
| 938 | } |
| 939 | |
| 940 | TEST_F(WiFiServiceTest, ConfigureRedundantProperties) { |
| 941 | WiFiServiceRefPtr service = MakeSimpleService(flimflam::kSecurityNone); |
| 942 | KeyValueStore args; |
| 943 | args.SetString(flimflam::kTypeProperty, flimflam::kTypeWifi); |
| 944 | args.SetString(flimflam::kSSIDProperty, simple_ssid_string()); |
| 945 | args.SetString(flimflam::kSecurityProperty, flimflam::kSecurityNone); |
| 946 | const string kGUID = "aguid"; |
| 947 | args.SetString(flimflam::kGuidProperty, kGUID); |
| 948 | |
| 949 | EXPECT_EQ("", service->guid()); |
| 950 | Error error; |
| 951 | service->Configure(args, &error); |
| 952 | EXPECT_TRUE(error.IsSuccess()); |
| 953 | EXPECT_EQ(kGUID, service->guid()); |
| 954 | } |
| 955 | |
| 956 | TEST_F(WiFiServiceTest, DisconnectWithWiFi) { |
| 957 | WiFiServiceRefPtr service = MakeServiceWithWiFi(flimflam::kSecurityWep); |
| 958 | EXPECT_CALL(*wifi(), DisconnectFrom(service.get())).Times(1); |
| 959 | Error error; |
| 960 | service->Disconnect(&error); |
| 961 | } |
| 962 | |
| 963 | TEST_F(WiFiServiceTest, DisconnectWithoutWiFi) { |
| 964 | WiFiServiceRefPtr service = MakeSimpleService(flimflam::kSecurityWep); |
| 965 | EXPECT_CALL(*wifi(), DisconnectFrom(_)).Times(0); |
| 966 | Error error; |
| 967 | service->Disconnect(&error); |
| 968 | EXPECT_EQ(Error::kOperationFailed, error.type()); |
| 969 | } |
| 970 | |
| 971 | TEST_F(WiFiServiceTest, DisconnectWithoutWiFiWhileAssociating) { |
| 972 | WiFiServiceRefPtr service = MakeSimpleService(flimflam::kSecurityWep); |
| 973 | EXPECT_CALL(*wifi(), DisconnectFrom(_)).Times(0); |
| 974 | service->SetState(Service::kStateAssociating); |
| 975 | ScopedMockLog log; |
| 976 | EXPECT_CALL(log, Log(_, _, _)).Times(AnyNumber()); |
| 977 | EXPECT_CALL(log, Log(logging::LOG_ERROR, _, |
| 978 | HasSubstr("WiFi endpoints do not (yet) exist."))); |
| 979 | Error error; |
| 980 | service->Disconnect(&error); |
| 981 | EXPECT_EQ(Error::kOperationFailed, error.type()); |
| 982 | } |
| 983 | |
Paul Stewart | 835934a | 2012-12-06 19:27:09 -0800 | [diff] [blame] | 984 | TEST_F(WiFiServiceTest, UnloadAndClearCacheWEP) { |
Paul Stewart | 3c50401 | 2013-01-17 17:49:58 -0800 | [diff] [blame] | 985 | WiFiServiceRefPtr service = MakeServiceWithWiFi(flimflam::kSecurityWep); |
Paul Stewart | 835934a | 2012-12-06 19:27:09 -0800 | [diff] [blame] | 986 | EXPECT_CALL(*wifi(), ClearCachedCredentials(service.get())).Times(1); |
| 987 | EXPECT_CALL(*wifi(), DisconnectFrom(service.get())).Times(1); |
Paul Stewart | 66c8600 | 2012-01-30 18:00:52 -0800 | [diff] [blame] | 988 | service->Unload(); |
| 989 | } |
| 990 | |
| 991 | TEST_F(WiFiServiceTest, UnloadAndClearCache8021x) { |
Paul Stewart | 3c50401 | 2013-01-17 17:49:58 -0800 | [diff] [blame] | 992 | WiFiServiceRefPtr service = MakeServiceWithWiFi(flimflam::kSecurity8021x); |
Paul Stewart | 835934a | 2012-12-06 19:27:09 -0800 | [diff] [blame] | 993 | EXPECT_CALL(*wifi(), ClearCachedCredentials(service.get())).Times(1); |
| 994 | EXPECT_CALL(*wifi(), DisconnectFrom(service.get())).Times(1); |
Paul Stewart | 66c8600 | 2012-01-30 18:00:52 -0800 | [diff] [blame] | 995 | service->Unload(); |
| 996 | } |
| 997 | |
Paul Stewart | 0756db9 | 2012-01-27 08:34:47 -0800 | [diff] [blame] | 998 | TEST_F(WiFiServiceTest, ParseStorageIdentifierNone) { |
Paul Stewart | 3c50401 | 2013-01-17 17:49:58 -0800 | [diff] [blame] | 999 | WiFiServiceRefPtr service = MakeSimpleService(flimflam::kSecurityNone); |
Paul Stewart | a41e38d | 2011-11-11 07:47:29 -0800 | [diff] [blame] | 1000 | const string storage_id = service->GetStorageIdentifier(); |
| 1001 | string address; |
| 1002 | string mode; |
| 1003 | string security; |
| 1004 | EXPECT_TRUE(service->ParseStorageIdentifier(storage_id, &address, &mode, |
| 1005 | &security)); |
Paul Stewart | 3c50401 | 2013-01-17 17:49:58 -0800 | [diff] [blame] | 1006 | EXPECT_EQ(StringToLowerASCII(GetAnyDeviceAddress()), address); |
Paul Stewart | a41e38d | 2011-11-11 07:47:29 -0800 | [diff] [blame] | 1007 | EXPECT_EQ(flimflam::kModeManaged, mode); |
| 1008 | EXPECT_EQ(flimflam::kSecurityNone, security); |
| 1009 | } |
| 1010 | |
Paul Stewart | 0756db9 | 2012-01-27 08:34:47 -0800 | [diff] [blame] | 1011 | TEST_F(WiFiServiceTest, ParseStorageIdentifier8021x) { |
| 1012 | // Do a separate test for 802.1x, since kSecurity8021x contains a "_", |
| 1013 | // which needs to be dealt with specially in the parser. |
Paul Stewart | 3c50401 | 2013-01-17 17:49:58 -0800 | [diff] [blame] | 1014 | WiFiServiceRefPtr service = MakeSimpleService(flimflam::kSecurity8021x); |
Paul Stewart | 0756db9 | 2012-01-27 08:34:47 -0800 | [diff] [blame] | 1015 | const string storage_id = service->GetStorageIdentifier(); |
| 1016 | string address; |
| 1017 | string mode; |
| 1018 | string security; |
| 1019 | EXPECT_TRUE(service->ParseStorageIdentifier(storage_id, &address, &mode, |
| 1020 | &security)); |
Paul Stewart | 3c50401 | 2013-01-17 17:49:58 -0800 | [diff] [blame] | 1021 | EXPECT_EQ(StringToLowerASCII(GetAnyDeviceAddress()), address); |
Paul Stewart | 0756db9 | 2012-01-27 08:34:47 -0800 | [diff] [blame] | 1022 | EXPECT_EQ(flimflam::kModeManaged, mode); |
| 1023 | EXPECT_EQ(flimflam::kSecurity8021x, security); |
| 1024 | } |
| 1025 | |
Paul Stewart | 85aea15 | 2013-01-22 09:31:56 -0800 | [diff] [blame] | 1026 | TEST_F(WiFiServiceFixupStorageTest, FixedEntries) { |
| 1027 | const string kNonWiFiId = "vpn_foo"; |
| 1028 | const string kUnparsableWiFiId = "wifi_foo"; |
| 1029 | |
| 1030 | AddGroup(kNonWiFiId); |
| 1031 | AddGroup(kUnparsableWiFiId); |
Paul Stewart | 71a4d3b | 2013-01-18 18:12:56 -0800 | [diff] [blame] | 1032 | AddServiceEntry(true, true, true, true); |
| 1033 | AddServiceEntry(false, false, false, false); |
| 1034 | AddServiceEntry(true, true, true, true); |
| 1035 | AddServiceEntry(false, false, false, false); |
Paul Stewart | 85aea15 | 2013-01-22 09:31:56 -0800 | [diff] [blame] | 1036 | EXPECT_TRUE(FixupServiceEntries()); |
| 1037 | } |
| 1038 | |
| 1039 | TEST_F(WiFiServiceFixupStorageTest, NoFixedEntries) { |
| 1040 | const string kNonWiFiId = "vpn_foo"; |
| 1041 | const string kUnparsableWiFiId = "wifi_foo"; |
| 1042 | |
| 1043 | AddGroup(kNonWiFiId); |
| 1044 | AddGroup(kUnparsableWiFiId); |
Paul Stewart | 71a4d3b | 2013-01-18 18:12:56 -0800 | [diff] [blame] | 1045 | AddServiceEntry(true, true, true, true); |
Paul Stewart | 85aea15 | 2013-01-22 09:31:56 -0800 | [diff] [blame] | 1046 | EXPECT_FALSE(FixupServiceEntries()); |
| 1047 | } |
| 1048 | |
| 1049 | TEST_F(WiFiServiceFixupStorageTest, MissingTypeProperty) { |
Paul Stewart | 71a4d3b | 2013-01-18 18:12:56 -0800 | [diff] [blame] | 1050 | AddServiceEntry(false, true, true, true); |
Paul Stewart | 85aea15 | 2013-01-22 09:31:56 -0800 | [diff] [blame] | 1051 | EXPECT_TRUE(FixupServiceEntries()); |
| 1052 | } |
| 1053 | |
| 1054 | TEST_F(WiFiServiceFixupStorageTest, MissingModeProperty) { |
Paul Stewart | 71a4d3b | 2013-01-18 18:12:56 -0800 | [diff] [blame] | 1055 | AddServiceEntry(true, false, true, true); |
Paul Stewart | 85aea15 | 2013-01-22 09:31:56 -0800 | [diff] [blame] | 1056 | EXPECT_TRUE(FixupServiceEntries()); |
| 1057 | } |
| 1058 | |
| 1059 | TEST_F(WiFiServiceFixupStorageTest, MissingSecurityProperty) { |
Paul Stewart | 71a4d3b | 2013-01-18 18:12:56 -0800 | [diff] [blame] | 1060 | AddServiceEntry(true, true, false, true); |
Paul Stewart | 85aea15 | 2013-01-22 09:31:56 -0800 | [diff] [blame] | 1061 | EXPECT_TRUE(FixupServiceEntries()); |
| 1062 | } |
| 1063 | |
Paul Stewart | 71a4d3b | 2013-01-18 18:12:56 -0800 | [diff] [blame] | 1064 | TEST_F(WiFiServiceFixupStorageTest, MissingSecurityClassProperty) { |
| 1065 | AddServiceEntry(true, true, true, false); |
| 1066 | EXPECT_TRUE(FixupServiceEntries()); |
| 1067 | } |
Paul Stewart | 85aea15 | 2013-01-22 09:31:56 -0800 | [diff] [blame] | 1068 | |
mukesh agrawal | 29c13a1 | 2011-11-24 00:09:19 +0000 | [diff] [blame] | 1069 | TEST_F(WiFiServiceTest, Connectable) { |
| 1070 | // Open network should be connectable. |
Gaurav Shah | 10109f2 | 2011-11-11 20:16:22 -0800 | [diff] [blame] | 1071 | EXPECT_TRUE(CheckConnectable(flimflam::kSecurityNone, NULL, NULL)); |
mukesh agrawal | 29c13a1 | 2011-11-24 00:09:19 +0000 | [diff] [blame] | 1072 | |
| 1073 | // Open network should remain connectable if we try to set a password on it. |
Gaurav Shah | 10109f2 | 2011-11-11 20:16:22 -0800 | [diff] [blame] | 1074 | EXPECT_TRUE(CheckConnectable(flimflam::kSecurityNone, "abcde", NULL)); |
mukesh agrawal | 29c13a1 | 2011-11-24 00:09:19 +0000 | [diff] [blame] | 1075 | |
| 1076 | // WEP network with passphrase set should be connectable. |
Gaurav Shah | 10109f2 | 2011-11-11 20:16:22 -0800 | [diff] [blame] | 1077 | EXPECT_TRUE(CheckConnectable(flimflam::kSecurityWep, "abcde", NULL)); |
mukesh agrawal | 29c13a1 | 2011-11-24 00:09:19 +0000 | [diff] [blame] | 1078 | |
| 1079 | // WEP network without passphrase set should NOT be connectable. |
Gaurav Shah | 10109f2 | 2011-11-11 20:16:22 -0800 | [diff] [blame] | 1080 | EXPECT_FALSE(CheckConnectable(flimflam::kSecurityWep, NULL, NULL)); |
mukesh agrawal | 29c13a1 | 2011-11-24 00:09:19 +0000 | [diff] [blame] | 1081 | |
| 1082 | // A bad passphrase should not make a WEP network connectable. |
Gaurav Shah | 10109f2 | 2011-11-11 20:16:22 -0800 | [diff] [blame] | 1083 | EXPECT_FALSE(CheckConnectable(flimflam::kSecurityWep, "a", NULL)); |
mukesh agrawal | 29c13a1 | 2011-11-24 00:09:19 +0000 | [diff] [blame] | 1084 | |
| 1085 | // Similar to WEP, for WPA. |
Gaurav Shah | 10109f2 | 2011-11-11 20:16:22 -0800 | [diff] [blame] | 1086 | EXPECT_TRUE(CheckConnectable(flimflam::kSecurityWpa, "abcdefgh", NULL)); |
| 1087 | EXPECT_FALSE(CheckConnectable(flimflam::kSecurityWpa, NULL, NULL)); |
| 1088 | EXPECT_FALSE(CheckConnectable(flimflam::kSecurityWpa, "a", NULL)); |
mukesh agrawal | 29c13a1 | 2011-11-24 00:09:19 +0000 | [diff] [blame] | 1089 | |
| 1090 | // Unconfigured 802.1x should NOT be connectable. |
Gaurav Shah | 10109f2 | 2011-11-11 20:16:22 -0800 | [diff] [blame] | 1091 | EXPECT_FALSE(CheckConnectable(flimflam::kSecurity8021x, NULL, NULL)); |
| 1092 | |
Paul Stewart | 0654ece | 2013-03-26 15:21:26 -0700 | [diff] [blame] | 1093 | EapCredentials eap; |
Gaurav Shah | 10109f2 | 2011-11-11 20:16:22 -0800 | [diff] [blame] | 1094 | // Empty EAP credentials should not make a 802.1x network connectable. |
| 1095 | EXPECT_FALSE(CheckConnectable(flimflam::kSecurity8021x, NULL, &eap)); |
| 1096 | |
| 1097 | eap.identity = "something"; |
| 1098 | // If client certificate is being used, a private key must exist. |
| 1099 | eap.client_cert = "some client cert"; |
| 1100 | EXPECT_FALSE(CheckConnectable(flimflam::kSecurity8021x, NULL, &eap)); |
| 1101 | eap.private_key = "some private key"; |
| 1102 | EXPECT_TRUE(CheckConnectable(flimflam::kSecurity8021x, NULL, &eap)); |
| 1103 | |
| 1104 | // Identity is always required. |
| 1105 | eap.identity.clear(); |
| 1106 | EXPECT_FALSE(CheckConnectable(flimflam::kSecurity8021x, NULL, &eap)); |
| 1107 | |
| 1108 | eap.identity = "something"; |
| 1109 | // For non EAP-TLS types, a password is required. |
| 1110 | eap.eap = "Non-TLS"; |
| 1111 | EXPECT_FALSE(CheckConnectable(flimflam::kSecurity8021x, NULL, &eap)); |
| 1112 | eap.password = "some password"; |
| 1113 | EXPECT_TRUE(CheckConnectable(flimflam::kSecurity8021x, NULL, &eap)); |
Gaurav Shah | 29d6888 | 2012-01-30 19:06:42 -0800 | [diff] [blame] | 1114 | // Dynamic WEP + 802.1X should be connectable under the same conditions. |
| 1115 | eap.key_management = "IEEE8021X"; |
| 1116 | EXPECT_TRUE(CheckConnectable(flimflam::kSecurityWep, NULL, &eap)); |
mukesh agrawal | 29c13a1 | 2011-11-24 00:09:19 +0000 | [diff] [blame] | 1117 | } |
| 1118 | |
mukesh agrawal | 8a3188d | 2011-12-01 20:56:44 +0000 | [diff] [blame] | 1119 | TEST_F(WiFiServiceTest, IsAutoConnectable) { |
mukesh agrawal | bf14e94 | 2012-03-02 14:36:34 -0800 | [diff] [blame] | 1120 | const char *reason; |
Paul Stewart | 3c50401 | 2013-01-17 17:49:58 -0800 | [diff] [blame] | 1121 | WiFiServiceRefPtr service = MakeSimpleService(flimflam::kSecurityNone); |
mukesh agrawal | 8a3188d | 2011-12-01 20:56:44 +0000 | [diff] [blame] | 1122 | EXPECT_CALL(*wifi(), IsIdle()) |
| 1123 | .WillRepeatedly(Return(true)); |
| 1124 | EXPECT_FALSE(service->HasEndpoints()); |
mukesh agrawal | bf14e94 | 2012-03-02 14:36:34 -0800 | [diff] [blame] | 1125 | EXPECT_FALSE(service->IsAutoConnectable(&reason)); |
| 1126 | EXPECT_STREQ(WiFiService::kAutoConnNoEndpoint, reason); |
mukesh agrawal | 8a3188d | 2011-12-01 20:56:44 +0000 | [diff] [blame] | 1127 | |
mukesh agrawal | bf14e94 | 2012-03-02 14:36:34 -0800 | [diff] [blame] | 1128 | reason = ""; |
mukesh agrawal | 43970a2 | 2013-02-15 16:00:07 -0800 | [diff] [blame] | 1129 | WiFiEndpointRefPtr endpoint = |
| 1130 | MakeOpenEndpoint("a", "00:00:00:00:00:01", 0, 0); |
mukesh agrawal | 8a3188d | 2011-12-01 20:56:44 +0000 | [diff] [blame] | 1131 | service->AddEndpoint(endpoint); |
| 1132 | EXPECT_CALL(*wifi(), IsIdle()) |
| 1133 | .WillRepeatedly(Return(true)); |
| 1134 | EXPECT_TRUE(service->HasEndpoints()); |
mukesh agrawal | bf14e94 | 2012-03-02 14:36:34 -0800 | [diff] [blame] | 1135 | EXPECT_TRUE(service->IsAutoConnectable(&reason)); |
| 1136 | EXPECT_STREQ("", reason); |
mukesh agrawal | 8a3188d | 2011-12-01 20:56:44 +0000 | [diff] [blame] | 1137 | |
| 1138 | // WiFi only supports connecting to one Service at a time. So, to |
| 1139 | // avoid disrupting connectivity, we only allow auto-connection to |
| 1140 | // a WiFiService when the corresponding WiFi is idle. |
| 1141 | EXPECT_CALL(*wifi(), IsIdle()) |
| 1142 | .WillRepeatedly(Return(false)); |
| 1143 | EXPECT_TRUE(service->HasEndpoints()); |
mukesh agrawal | bf14e94 | 2012-03-02 14:36:34 -0800 | [diff] [blame] | 1144 | EXPECT_FALSE(service->IsAutoConnectable(&reason)); |
| 1145 | EXPECT_STREQ(WiFiService::kAutoConnBusy, reason); |
mukesh agrawal | 8a3188d | 2011-12-01 20:56:44 +0000 | [diff] [blame] | 1146 | } |
| 1147 | |
| 1148 | TEST_F(WiFiServiceTest, AutoConnect) { |
mukesh agrawal | bf14e94 | 2012-03-02 14:36:34 -0800 | [diff] [blame] | 1149 | const char *reason; |
Paul Stewart | 3c50401 | 2013-01-17 17:49:58 -0800 | [diff] [blame] | 1150 | WiFiServiceRefPtr service = MakeSimpleService(flimflam::kSecurityNone); |
mukesh agrawal | bf14e94 | 2012-03-02 14:36:34 -0800 | [diff] [blame] | 1151 | EXPECT_FALSE(service->IsAutoConnectable(&reason)); |
mukesh agrawal | 8a3188d | 2011-12-01 20:56:44 +0000 | [diff] [blame] | 1152 | EXPECT_CALL(*wifi(), ConnectTo(_, _)) |
| 1153 | .Times(0); |
| 1154 | service->AutoConnect(); |
Eric Shienbrood | 3e20a23 | 2012-02-16 11:35:56 -0500 | [diff] [blame] | 1155 | dispatcher()->DispatchPendingEvents(); |
mukesh agrawal | 8a3188d | 2011-12-01 20:56:44 +0000 | [diff] [blame] | 1156 | |
mukesh agrawal | 43970a2 | 2013-02-15 16:00:07 -0800 | [diff] [blame] | 1157 | WiFiEndpointRefPtr endpoint = |
| 1158 | MakeOpenEndpoint("a", "00:00:00:00:00:01", 0, 0); |
mukesh agrawal | 8a3188d | 2011-12-01 20:56:44 +0000 | [diff] [blame] | 1159 | service->AddEndpoint(endpoint); |
| 1160 | EXPECT_CALL(*wifi(), IsIdle()) |
| 1161 | .WillRepeatedly(Return(true)); |
mukesh agrawal | bf14e94 | 2012-03-02 14:36:34 -0800 | [diff] [blame] | 1162 | EXPECT_TRUE(service->IsAutoConnectable(&reason)); |
mukesh agrawal | 8a3188d | 2011-12-01 20:56:44 +0000 | [diff] [blame] | 1163 | EXPECT_CALL(*wifi(), ConnectTo(_, _)); |
| 1164 | service->AutoConnect(); |
Eric Shienbrood | 3e20a23 | 2012-02-16 11:35:56 -0500 | [diff] [blame] | 1165 | dispatcher()->DispatchPendingEvents(); |
mukesh agrawal | adb6848 | 2012-01-17 16:31:51 -0800 | [diff] [blame] | 1166 | |
| 1167 | Error error; |
Christopher Wiley | abd3b50 | 2012-09-26 13:08:52 -0700 | [diff] [blame] | 1168 | service->UserInitiatedDisconnect(&error); |
Eric Shienbrood | 3e20a23 | 2012-02-16 11:35:56 -0500 | [diff] [blame] | 1169 | dispatcher()->DispatchPendingEvents(); |
mukesh agrawal | bf14e94 | 2012-03-02 14:36:34 -0800 | [diff] [blame] | 1170 | EXPECT_FALSE(service->IsAutoConnectable(&reason)); |
mukesh agrawal | 8a3188d | 2011-12-01 20:56:44 +0000 | [diff] [blame] | 1171 | } |
| 1172 | |
mukesh agrawal | 8abd2f6 | 2012-01-30 14:56:14 -0800 | [diff] [blame] | 1173 | TEST_F(WiFiServiceTest, ClearWriteOnlyDerivedProperty) { |
Paul Stewart | 3c50401 | 2013-01-17 17:49:58 -0800 | [diff] [blame] | 1174 | WiFiServiceRefPtr wifi_service = MakeSimpleService(flimflam::kSecurityWep); |
mukesh agrawal | 8abd2f6 | 2012-01-30 14:56:14 -0800 | [diff] [blame] | 1175 | |
| 1176 | EXPECT_EQ("", wifi_service->passphrase_); |
| 1177 | |
| 1178 | ::DBus::Error error; |
mukesh agrawal | 6bb9e7c | 2012-01-30 14:57:54 -0800 | [diff] [blame] | 1179 | EXPECT_TRUE(DBusAdaptor::SetProperty( |
mukesh agrawal | 8abd2f6 | 2012-01-30 14:56:14 -0800 | [diff] [blame] | 1180 | wifi_service->mutable_store(), |
| 1181 | flimflam::kPassphraseProperty, |
| 1182 | DBusAdaptor::StringToVariant("0:abcde"), |
| 1183 | &error)); |
| 1184 | EXPECT_EQ("0:abcde", wifi_service->passphrase_); |
| 1185 | |
| 1186 | EXPECT_TRUE(DBusAdaptor::ClearProperty(wifi_service->mutable_store(), |
| 1187 | flimflam::kPassphraseProperty, |
| 1188 | &error)); |
| 1189 | EXPECT_EQ("", wifi_service->passphrase_); |
| 1190 | } |
| 1191 | |
mukesh agrawal | e1d90e9 | 2012-02-15 17:36:08 -0800 | [diff] [blame] | 1192 | TEST_F(WiFiServiceTest, SignalToStrength) { |
| 1193 | // Verify that our mapping is sane, in the sense that it preserves ordering. |
| 1194 | // We break the test into two domains, because we assume that positive |
| 1195 | // values aren't actually in dBm. |
| 1196 | for (int16 i = std::numeric_limits<int16>::min(); i < 0; ++i) { |
| 1197 | int16 current_mapped = WiFiService::SignalToStrength(i); |
| 1198 | int16 next_mapped = WiFiService::SignalToStrength(i+1); |
| 1199 | EXPECT_LE(current_mapped, next_mapped) |
| 1200 | << "(original values " << i << " " << i+1 << ")"; |
mukesh agrawal | 8f3f775 | 2012-02-17 19:42:09 -0800 | [diff] [blame] | 1201 | EXPECT_GE(current_mapped, Service::kStrengthMin); |
| 1202 | EXPECT_LE(current_mapped, Service::kStrengthMax); |
mukesh agrawal | e1d90e9 | 2012-02-15 17:36:08 -0800 | [diff] [blame] | 1203 | } |
| 1204 | for (int16 i = 1; i < std::numeric_limits<int16>::max(); ++i) { |
| 1205 | int16 current_mapped = WiFiService::SignalToStrength(i); |
| 1206 | int16 next_mapped = WiFiService::SignalToStrength(i+1); |
| 1207 | EXPECT_LE(current_mapped, next_mapped) |
| 1208 | << "(original values " << i << " " << i+1 << ")"; |
mukesh agrawal | 8f3f775 | 2012-02-17 19:42:09 -0800 | [diff] [blame] | 1209 | EXPECT_GE(current_mapped, Service::kStrengthMin); |
| 1210 | EXPECT_LE(current_mapped, Service::kStrengthMax); |
mukesh agrawal | e1d90e9 | 2012-02-15 17:36:08 -0800 | [diff] [blame] | 1211 | } |
| 1212 | } |
| 1213 | |
| 1214 | TEST_F(WiFiServiceUpdateFromEndpointsTest, Strengths) { |
| 1215 | // If the chosen signal values don't map to distinct strength |
| 1216 | // values, then we can't expect our other tests to pass. So verify |
| 1217 | // their distinctness. |
| 1218 | EXPECT_TRUE(kOkEndpointStrength != kBadEndpointStrength); |
| 1219 | EXPECT_TRUE(kOkEndpointStrength != kGoodEndpointStrength); |
| 1220 | EXPECT_TRUE(kGoodEndpointStrength != kBadEndpointStrength); |
| 1221 | } |
| 1222 | |
| 1223 | TEST_F(WiFiServiceUpdateFromEndpointsTest, Floating) { |
| 1224 | // Initial endpoint updates values. |
| 1225 | EXPECT_CALL(adaptor, EmitUint16Changed( |
| 1226 | flimflam::kWifiFrequency, kOkEndpointFrequency)); |
mukesh agrawal | 923f14f | 2012-06-04 16:46:08 -0700 | [diff] [blame] | 1227 | EXPECT_CALL(adaptor, EmitStringChanged( |
| 1228 | flimflam::kWifiBSsid, kOkEndpointBssId)); |
| 1229 | EXPECT_CALL(adaptor, EmitUint8Changed( |
mukesh agrawal | e1d90e9 | 2012-02-15 17:36:08 -0800 | [diff] [blame] | 1230 | flimflam::kSignalStrengthProperty, kOkEndpointStrength)); |
mukesh agrawal | f6b3209 | 2013-04-10 15:49:55 -0700 | [diff] [blame] | 1231 | EXPECT_CALL(adaptor, EmitUint16Changed( |
| 1232 | flimflam::kWifiPhyMode, Metrics::kWiFiNetworkPhyMode11b)); |
mukesh agrawal | e1d90e9 | 2012-02-15 17:36:08 -0800 | [diff] [blame] | 1233 | service->AddEndpoint(ok_endpoint); |
Darin Petkov | 4a66cc5 | 2012-06-15 10:08:29 +0200 | [diff] [blame] | 1234 | EXPECT_EQ(1, service->GetEndpointCount()); |
mukesh agrawal | e1d90e9 | 2012-02-15 17:36:08 -0800 | [diff] [blame] | 1235 | Mock::VerifyAndClearExpectations(&adaptor); |
| 1236 | |
| 1237 | // Endpoint with stronger signal updates values. |
| 1238 | EXPECT_CALL(adaptor, EmitUint16Changed( |
| 1239 | flimflam::kWifiFrequency, kGoodEndpointFrequency)); |
mukesh agrawal | 923f14f | 2012-06-04 16:46:08 -0700 | [diff] [blame] | 1240 | EXPECT_CALL(adaptor, EmitStringChanged( |
| 1241 | flimflam::kWifiBSsid, kGoodEndpointBssId)); |
mukesh agrawal | e1d90e9 | 2012-02-15 17:36:08 -0800 | [diff] [blame] | 1242 | EXPECT_CALL(adaptor, EmitUint8Changed( |
| 1243 | flimflam::kSignalStrengthProperty, kGoodEndpointStrength)); |
mukesh agrawal | f6b3209 | 2013-04-10 15:49:55 -0700 | [diff] [blame] | 1244 | // However, both endpoints are 11b. |
| 1245 | EXPECT_CALL(adaptor, EmitUint16Changed(flimflam::kWifiPhyMode, _)).Times(0); |
mukesh agrawal | e1d90e9 | 2012-02-15 17:36:08 -0800 | [diff] [blame] | 1246 | service->AddEndpoint(good_endpoint); |
Darin Petkov | 4a66cc5 | 2012-06-15 10:08:29 +0200 | [diff] [blame] | 1247 | EXPECT_EQ(2, service->GetEndpointCount()); |
mukesh agrawal | e1d90e9 | 2012-02-15 17:36:08 -0800 | [diff] [blame] | 1248 | Mock::VerifyAndClearExpectations(&adaptor); |
| 1249 | |
| 1250 | // Endpoint with lower signal does not change values. |
| 1251 | EXPECT_CALL(adaptor, EmitUint16Changed(flimflam::kWifiFrequency, _)).Times(0); |
mukesh agrawal | 923f14f | 2012-06-04 16:46:08 -0700 | [diff] [blame] | 1252 | EXPECT_CALL(adaptor, EmitStringChanged(flimflam::kWifiBSsid, _)).Times(0); |
mukesh agrawal | e1d90e9 | 2012-02-15 17:36:08 -0800 | [diff] [blame] | 1253 | EXPECT_CALL(adaptor, |
| 1254 | EmitUint8Changed(flimflam::kSignalStrengthProperty, _)).Times(0); |
mukesh agrawal | f6b3209 | 2013-04-10 15:49:55 -0700 | [diff] [blame] | 1255 | EXPECT_CALL(adaptor, EmitUint16Changed(flimflam::kWifiPhyMode, _)).Times(0); |
mukesh agrawal | e1d90e9 | 2012-02-15 17:36:08 -0800 | [diff] [blame] | 1256 | service->AddEndpoint(bad_endpoint); |
Darin Petkov | 4a66cc5 | 2012-06-15 10:08:29 +0200 | [diff] [blame] | 1257 | EXPECT_EQ(3, service->GetEndpointCount()); |
mukesh agrawal | e1d90e9 | 2012-02-15 17:36:08 -0800 | [diff] [blame] | 1258 | Mock::VerifyAndClearExpectations(&adaptor); |
| 1259 | |
| 1260 | // Removing non-optimal endpoint does not change values. |
| 1261 | EXPECT_CALL(adaptor, EmitUint16Changed(flimflam::kWifiFrequency, _)).Times(0); |
mukesh agrawal | 923f14f | 2012-06-04 16:46:08 -0700 | [diff] [blame] | 1262 | EXPECT_CALL(adaptor, EmitStringChanged(flimflam::kWifiBSsid, _)).Times(0); |
mukesh agrawal | e1d90e9 | 2012-02-15 17:36:08 -0800 | [diff] [blame] | 1263 | EXPECT_CALL(adaptor, |
| 1264 | EmitUint8Changed(flimflam::kSignalStrengthProperty, _)).Times(0); |
mukesh agrawal | f6b3209 | 2013-04-10 15:49:55 -0700 | [diff] [blame] | 1265 | EXPECT_CALL(adaptor, EmitUint16Changed(flimflam::kWifiPhyMode, _)).Times(0); |
mukesh agrawal | e1d90e9 | 2012-02-15 17:36:08 -0800 | [diff] [blame] | 1266 | service->RemoveEndpoint(bad_endpoint); |
Darin Petkov | 4a66cc5 | 2012-06-15 10:08:29 +0200 | [diff] [blame] | 1267 | EXPECT_EQ(2, service->GetEndpointCount()); |
mukesh agrawal | e1d90e9 | 2012-02-15 17:36:08 -0800 | [diff] [blame] | 1268 | Mock::VerifyAndClearExpectations(&adaptor); |
| 1269 | |
| 1270 | // Removing optimal endpoint updates values. |
| 1271 | EXPECT_CALL(adaptor, EmitUint16Changed( |
| 1272 | flimflam::kWifiFrequency, kOkEndpointFrequency)); |
mukesh agrawal | 923f14f | 2012-06-04 16:46:08 -0700 | [diff] [blame] | 1273 | EXPECT_CALL(adaptor, EmitStringChanged( |
| 1274 | flimflam::kWifiBSsid, kOkEndpointBssId)); |
mukesh agrawal | e1d90e9 | 2012-02-15 17:36:08 -0800 | [diff] [blame] | 1275 | EXPECT_CALL(adaptor, EmitUint8Changed( |
| 1276 | flimflam::kSignalStrengthProperty, kOkEndpointStrength)); |
mukesh agrawal | f6b3209 | 2013-04-10 15:49:55 -0700 | [diff] [blame] | 1277 | // However, both endpoints are 11b. |
| 1278 | EXPECT_CALL(adaptor, EmitUint16Changed(flimflam::kWifiPhyMode, _)).Times(0); |
mukesh agrawal | e1d90e9 | 2012-02-15 17:36:08 -0800 | [diff] [blame] | 1279 | service->RemoveEndpoint(good_endpoint); |
Darin Petkov | 4a66cc5 | 2012-06-15 10:08:29 +0200 | [diff] [blame] | 1280 | EXPECT_EQ(1, service->GetEndpointCount()); |
mukesh agrawal | e1d90e9 | 2012-02-15 17:36:08 -0800 | [diff] [blame] | 1281 | Mock::VerifyAndClearExpectations(&adaptor); |
| 1282 | |
| 1283 | // Removing last endpoint updates values (and doesn't crash). |
| 1284 | EXPECT_CALL(adaptor, EmitUint16Changed(flimflam::kWifiFrequency, _)); |
mukesh agrawal | 923f14f | 2012-06-04 16:46:08 -0700 | [diff] [blame] | 1285 | EXPECT_CALL(adaptor, EmitStringChanged(flimflam::kWifiBSsid, _)); |
mukesh agrawal | e1d90e9 | 2012-02-15 17:36:08 -0800 | [diff] [blame] | 1286 | EXPECT_CALL(adaptor, EmitUint8Changed(flimflam::kSignalStrengthProperty, _)); |
mukesh agrawal | f6b3209 | 2013-04-10 15:49:55 -0700 | [diff] [blame] | 1287 | EXPECT_CALL(adaptor, EmitUint16Changed( |
| 1288 | flimflam::kWifiPhyMode, Metrics::kWiFiNetworkPhyModeUndef)); |
mukesh agrawal | e1d90e9 | 2012-02-15 17:36:08 -0800 | [diff] [blame] | 1289 | service->RemoveEndpoint(ok_endpoint); |
Darin Petkov | 4a66cc5 | 2012-06-15 10:08:29 +0200 | [diff] [blame] | 1290 | EXPECT_EQ(0, service->GetEndpointCount()); |
mukesh agrawal | e1d90e9 | 2012-02-15 17:36:08 -0800 | [diff] [blame] | 1291 | Mock::VerifyAndClearExpectations(&adaptor); |
| 1292 | } |
| 1293 | |
| 1294 | TEST_F(WiFiServiceUpdateFromEndpointsTest, Connected) { |
| 1295 | EXPECT_CALL(adaptor, EmitUint16Changed(_, _)).Times(AnyNumber()); |
mukesh agrawal | 923f14f | 2012-06-04 16:46:08 -0700 | [diff] [blame] | 1296 | EXPECT_CALL(adaptor, EmitStringChanged(_, _)).Times(AnyNumber()); |
mukesh agrawal | e1d90e9 | 2012-02-15 17:36:08 -0800 | [diff] [blame] | 1297 | EXPECT_CALL(adaptor, EmitUint8Changed(_, _)).Times(AnyNumber()); |
| 1298 | EXPECT_CALL(adaptor, EmitBoolChanged(_, _)).Times(AnyNumber()); |
| 1299 | service->AddEndpoint(bad_endpoint); |
| 1300 | service->AddEndpoint(ok_endpoint); |
Darin Petkov | 4a66cc5 | 2012-06-15 10:08:29 +0200 | [diff] [blame] | 1301 | EXPECT_EQ(2, service->GetEndpointCount()); |
mukesh agrawal | e1d90e9 | 2012-02-15 17:36:08 -0800 | [diff] [blame] | 1302 | Mock::VerifyAndClearExpectations(&adaptor); |
| 1303 | |
| 1304 | // Setting current endpoint forces adoption of its values, even if it |
| 1305 | // doesn't have the highest signal. |
| 1306 | EXPECT_CALL(adaptor, EmitUint16Changed( |
| 1307 | flimflam::kWifiFrequency, kBadEndpointFrequency)); |
mukesh agrawal | 923f14f | 2012-06-04 16:46:08 -0700 | [diff] [blame] | 1308 | EXPECT_CALL(adaptor, EmitStringChanged( |
| 1309 | flimflam::kWifiBSsid, kBadEndpointBssId)); |
mukesh agrawal | e1d90e9 | 2012-02-15 17:36:08 -0800 | [diff] [blame] | 1310 | EXPECT_CALL(adaptor, EmitUint8Changed( |
| 1311 | flimflam::kSignalStrengthProperty, kBadEndpointStrength)); |
| 1312 | service->NotifyCurrentEndpoint(bad_endpoint); |
| 1313 | Mock::VerifyAndClearExpectations(&adaptor); |
| 1314 | |
| 1315 | // Adding a better endpoint doesn't matter, when current endpoint is set. |
| 1316 | EXPECT_CALL(adaptor, EmitUint16Changed(flimflam::kWifiFrequency, _)).Times(0); |
mukesh agrawal | 923f14f | 2012-06-04 16:46:08 -0700 | [diff] [blame] | 1317 | EXPECT_CALL(adaptor, EmitStringChanged(flimflam::kWifiBSsid, _)).Times(0); |
mukesh agrawal | e1d90e9 | 2012-02-15 17:36:08 -0800 | [diff] [blame] | 1318 | EXPECT_CALL(adaptor, |
| 1319 | EmitUint8Changed(flimflam::kSignalStrengthProperty, _)).Times(0); |
| 1320 | service->AddEndpoint(good_endpoint); |
Darin Petkov | 4a66cc5 | 2012-06-15 10:08:29 +0200 | [diff] [blame] | 1321 | EXPECT_EQ(3, service->GetEndpointCount()); |
mukesh agrawal | e1d90e9 | 2012-02-15 17:36:08 -0800 | [diff] [blame] | 1322 | Mock::VerifyAndClearExpectations(&adaptor); |
| 1323 | |
| 1324 | // Removing a better endpoint doesn't matter, when current endpoint is set. |
| 1325 | EXPECT_CALL(adaptor, EmitUint16Changed(flimflam::kWifiFrequency, _)).Times(0); |
mukesh agrawal | 923f14f | 2012-06-04 16:46:08 -0700 | [diff] [blame] | 1326 | EXPECT_CALL(adaptor, EmitStringChanged(flimflam::kWifiBSsid, _)).Times(0); |
mukesh agrawal | e1d90e9 | 2012-02-15 17:36:08 -0800 | [diff] [blame] | 1327 | EXPECT_CALL(adaptor, |
| 1328 | EmitUint8Changed(flimflam::kSignalStrengthProperty, _)).Times(0); |
| 1329 | service->RemoveEndpoint(good_endpoint); |
| 1330 | Mock::VerifyAndClearExpectations(&adaptor); |
| 1331 | |
| 1332 | // Removing the current endpoint is safe and sane. |
| 1333 | EXPECT_CALL(adaptor, EmitUint16Changed( |
| 1334 | flimflam::kWifiFrequency, kOkEndpointFrequency)); |
mukesh agrawal | 923f14f | 2012-06-04 16:46:08 -0700 | [diff] [blame] | 1335 | EXPECT_CALL(adaptor, EmitStringChanged( |
| 1336 | flimflam::kWifiBSsid, kOkEndpointBssId)); |
mukesh agrawal | e1d90e9 | 2012-02-15 17:36:08 -0800 | [diff] [blame] | 1337 | EXPECT_CALL(adaptor, EmitUint8Changed( |
| 1338 | flimflam::kSignalStrengthProperty, kOkEndpointStrength)); |
| 1339 | service->RemoveEndpoint(bad_endpoint); |
| 1340 | Mock::VerifyAndClearExpectations(&adaptor); |
| 1341 | |
| 1342 | // Clearing the current endpoint (without removing it) is also safe and sane. |
| 1343 | service->NotifyCurrentEndpoint(ok_endpoint); |
| 1344 | EXPECT_CALL(adaptor, EmitUint16Changed(flimflam::kWifiFrequency, _)).Times(0); |
mukesh agrawal | 923f14f | 2012-06-04 16:46:08 -0700 | [diff] [blame] | 1345 | EXPECT_CALL(adaptor, EmitStringChanged(flimflam::kWifiBSsid, _)).Times(0); |
mukesh agrawal | e1d90e9 | 2012-02-15 17:36:08 -0800 | [diff] [blame] | 1346 | EXPECT_CALL(adaptor, |
| 1347 | EmitUint8Changed(flimflam::kSignalStrengthProperty, _)).Times(0); |
| 1348 | service->NotifyCurrentEndpoint(NULL); |
| 1349 | Mock::VerifyAndClearExpectations(&adaptor); |
| 1350 | } |
| 1351 | |
| 1352 | TEST_F(WiFiServiceUpdateFromEndpointsTest, EndpointModified) { |
| 1353 | EXPECT_CALL(adaptor, EmitUint16Changed(_, _)).Times(AnyNumber()); |
mukesh agrawal | 923f14f | 2012-06-04 16:46:08 -0700 | [diff] [blame] | 1354 | EXPECT_CALL(adaptor, EmitStringChanged(_, _)).Times(AnyNumber()); |
mukesh agrawal | e1d90e9 | 2012-02-15 17:36:08 -0800 | [diff] [blame] | 1355 | EXPECT_CALL(adaptor, EmitUint8Changed(_, _)).Times(AnyNumber()); |
| 1356 | EXPECT_CALL(adaptor, EmitBoolChanged(_, _)).Times(AnyNumber()); |
| 1357 | service->AddEndpoint(ok_endpoint); |
| 1358 | service->AddEndpoint(good_endpoint); |
Darin Petkov | 4a66cc5 | 2012-06-15 10:08:29 +0200 | [diff] [blame] | 1359 | EXPECT_EQ(2, service->GetEndpointCount()); |
mukesh agrawal | e1d90e9 | 2012-02-15 17:36:08 -0800 | [diff] [blame] | 1360 | Mock::VerifyAndClearExpectations(&adaptor); |
| 1361 | |
| 1362 | // Updating sub-optimal Endpoint doesn't update Service. |
| 1363 | EXPECT_CALL(adaptor, EmitUint16Changed(flimflam::kWifiFrequency, _)).Times(0); |
mukesh agrawal | 923f14f | 2012-06-04 16:46:08 -0700 | [diff] [blame] | 1364 | EXPECT_CALL(adaptor, EmitStringChanged(flimflam::kWifiBSsid, _)).Times(0); |
mukesh agrawal | e1d90e9 | 2012-02-15 17:36:08 -0800 | [diff] [blame] | 1365 | EXPECT_CALL(adaptor, |
| 1366 | EmitUint8Changed(flimflam::kSignalStrengthProperty, _)).Times(0); |
| 1367 | ok_endpoint->signal_strength_ = (kOkEndpointSignal + kGoodEndpointSignal) / 2; |
Paul Stewart | 3c50401 | 2013-01-17 17:49:58 -0800 | [diff] [blame] | 1368 | service->NotifyEndpointUpdated(ok_endpoint); |
mukesh agrawal | e1d90e9 | 2012-02-15 17:36:08 -0800 | [diff] [blame] | 1369 | Mock::VerifyAndClearExpectations(&adaptor); |
| 1370 | |
| 1371 | // Updating optimal Endpoint updates appropriate Service property. |
| 1372 | EXPECT_CALL(adaptor, EmitUint16Changed(flimflam::kWifiFrequency, _)).Times(0); |
mukesh agrawal | 923f14f | 2012-06-04 16:46:08 -0700 | [diff] [blame] | 1373 | EXPECT_CALL(adaptor, EmitStringChanged(flimflam::kWifiBSsid, _)).Times(0); |
mukesh agrawal | e1d90e9 | 2012-02-15 17:36:08 -0800 | [diff] [blame] | 1374 | EXPECT_CALL(adaptor, EmitUint8Changed(flimflam::kSignalStrengthProperty, _)); |
| 1375 | good_endpoint->signal_strength_ = kGoodEndpointSignal + 1; |
Paul Stewart | 3c50401 | 2013-01-17 17:49:58 -0800 | [diff] [blame] | 1376 | service->NotifyEndpointUpdated(good_endpoint); |
mukesh agrawal | e1d90e9 | 2012-02-15 17:36:08 -0800 | [diff] [blame] | 1377 | Mock::VerifyAndClearExpectations(&adaptor); |
| 1378 | |
| 1379 | // Change in optimal Endpoint updates Service properties. |
| 1380 | EXPECT_CALL(adaptor, EmitUint16Changed( |
| 1381 | flimflam::kWifiFrequency, kOkEndpointFrequency)); |
mukesh agrawal | 923f14f | 2012-06-04 16:46:08 -0700 | [diff] [blame] | 1382 | EXPECT_CALL(adaptor, EmitStringChanged( |
| 1383 | flimflam::kWifiBSsid, kOkEndpointBssId)); |
mukesh agrawal | e1d90e9 | 2012-02-15 17:36:08 -0800 | [diff] [blame] | 1384 | EXPECT_CALL(adaptor, EmitUint8Changed(flimflam::kSignalStrengthProperty, _)); |
| 1385 | ok_endpoint->signal_strength_ = kGoodEndpointSignal + 2; |
Paul Stewart | 3c50401 | 2013-01-17 17:49:58 -0800 | [diff] [blame] | 1386 | service->NotifyEndpointUpdated(ok_endpoint); |
mukesh agrawal | e1d90e9 | 2012-02-15 17:36:08 -0800 | [diff] [blame] | 1387 | Mock::VerifyAndClearExpectations(&adaptor); |
| 1388 | } |
| 1389 | |
Paul Stewart | a5e7d5f | 2013-01-09 18:06:15 -0800 | [diff] [blame] | 1390 | TEST_F(WiFiServiceUpdateFromEndpointsTest, Ieee80211w) { |
| 1391 | EXPECT_CALL(adaptor, EmitUint16Changed(_, _)).Times(AnyNumber()); |
| 1392 | EXPECT_CALL(adaptor, EmitStringChanged(_, _)).Times(AnyNumber()); |
| 1393 | EXPECT_CALL(adaptor, EmitUint8Changed(_, _)).Times(AnyNumber()); |
| 1394 | EXPECT_CALL(adaptor, EmitBoolChanged(_, _)).Times(AnyNumber()); |
| 1395 | service->AddEndpoint(ok_endpoint); |
| 1396 | EXPECT_FALSE(service->ieee80211w_required()); |
| 1397 | good_endpoint->ieee80211w_required_ = true; |
| 1398 | service->AddEndpoint(good_endpoint); |
| 1399 | EXPECT_TRUE(service->ieee80211w_required()); |
| 1400 | service->RemoveEndpoint(good_endpoint); |
| 1401 | EXPECT_TRUE(service->ieee80211w_required()); |
| 1402 | } |
| 1403 | |
mukesh agrawal | f6b3209 | 2013-04-10 15:49:55 -0700 | [diff] [blame] | 1404 | TEST_F(WiFiServiceUpdateFromEndpointsTest, PhysicalMode) { |
| 1405 | EXPECT_CALL(adaptor, EmitUint16Changed(_, _)).Times(AnyNumber()); |
| 1406 | EXPECT_CALL(adaptor, EmitStringChanged(_, _)).Times(AnyNumber()); |
| 1407 | EXPECT_CALL(adaptor, EmitUint8Changed(_, _)).Times(AnyNumber()); |
| 1408 | EXPECT_CALL(adaptor, EmitBoolChanged(_, _)).Times(AnyNumber()); |
| 1409 | |
| 1410 | // No endpoints -> undef. |
| 1411 | EXPECT_EQ(Metrics::kWiFiNetworkPhyModeUndef, service->physical_mode()); |
| 1412 | |
| 1413 | // Endpoint has unknown physical mode -> undef. |
| 1414 | ok_endpoint->physical_mode_ = Metrics::kWiFiNetworkPhyModeUndef; |
| 1415 | service->AddEndpoint(ok_endpoint); |
| 1416 | EXPECT_EQ(Metrics::kWiFiNetworkPhyModeUndef, service->physical_mode()); |
| 1417 | |
| 1418 | // New endpoint with 802.11a -> 802.11a. |
| 1419 | good_endpoint->physical_mode_ = Metrics::kWiFiNetworkPhyMode11a; |
| 1420 | service->AddEndpoint(good_endpoint); |
| 1421 | EXPECT_EQ(Metrics::kWiFiNetworkPhyMode11a, service->physical_mode()); |
| 1422 | |
| 1423 | // Remove 802.11a endpoint -> undef. |
| 1424 | service->RemoveEndpoint(good_endpoint); |
| 1425 | EXPECT_EQ(Metrics::kWiFiNetworkPhyModeUndef, service->physical_mode()); |
| 1426 | |
| 1427 | // Change endpoint -> take endpoint's new value. |
| 1428 | ok_endpoint->physical_mode_ = Metrics::kWiFiNetworkPhyMode11n; |
| 1429 | service->NotifyEndpointUpdated(ok_endpoint); |
| 1430 | EXPECT_EQ(Metrics::kWiFiNetworkPhyMode11n, service->physical_mode()); |
| 1431 | |
| 1432 | // No endpoints -> undef. |
| 1433 | service->RemoveEndpoint(ok_endpoint); |
| 1434 | EXPECT_EQ(Metrics::kWiFiNetworkPhyModeUndef, service->physical_mode()); |
| 1435 | } |
| 1436 | |
Paul Stewart | 8653f46 | 2013-02-06 12:21:05 -0800 | [diff] [blame] | 1437 | TEST_F(WiFiServiceUpdateFromEndpointsTest, WarningOnDisconnect) { |
| 1438 | service->AddEndpoint(ok_endpoint); |
| 1439 | service->SetState(Service::kStateAssociating); |
| 1440 | ScopedMockLog log; |
| 1441 | EXPECT_CALL(log, Log(_, _, _)).Times(AnyNumber()); |
| 1442 | EXPECT_CALL(log, Log(logging::LOG_WARNING, _, |
| 1443 | EndsWith("disconnect due to no remaining endpoints."))); |
| 1444 | service->RemoveEndpoint(ok_endpoint); |
| 1445 | } |
| 1446 | |
Paul Stewart | 6df20bd | 2013-03-13 19:31:25 -0700 | [diff] [blame] | 1447 | TEST_F(WiFiServiceTest, SecurityFromCurrentEndpoint) { |
| 1448 | WiFiServiceRefPtr service(MakeSimpleService(flimflam::kSecurityPsk)); |
| 1449 | EXPECT_EQ(flimflam::kSecurityPsk, service->GetSecurity(NULL)); |
| 1450 | WiFiEndpoint *endpoint = MakeOpenEndpoint( |
| 1451 | simple_ssid_string(), "00:00:00:00:00:00", 0, 0); |
| 1452 | service->AddEndpoint(endpoint); |
| 1453 | EXPECT_EQ(flimflam::kSecurityPsk, service->GetSecurity(NULL)); |
| 1454 | service->NotifyCurrentEndpoint(endpoint); |
| 1455 | EXPECT_EQ(flimflam::kSecurityNone, service->GetSecurity(NULL)); |
| 1456 | service->NotifyCurrentEndpoint(NULL); |
| 1457 | EXPECT_EQ(flimflam::kSecurityPsk, service->GetSecurity(NULL)); |
| 1458 | } |
| 1459 | |
mukesh agrawal | 43970a2 | 2013-02-15 16:00:07 -0800 | [diff] [blame] | 1460 | TEST_F(WiFiServiceTest, UpdateSecurity) { |
| 1461 | // Cleartext and pre-shared-key crypto. |
| 1462 | { |
| 1463 | WiFiServiceRefPtr service = MakeSimpleService(flimflam::kSecurityNone); |
| 1464 | EXPECT_EQ(Service::kCryptoNone, service->crypto_algorithm()); |
| 1465 | EXPECT_FALSE(service->key_rotation()); |
| 1466 | EXPECT_FALSE(service->endpoint_auth()); |
| 1467 | } |
| 1468 | { |
| 1469 | WiFiServiceRefPtr service = MakeSimpleService(flimflam::kSecurityWep); |
| 1470 | EXPECT_EQ(Service::kCryptoRc4, service->crypto_algorithm()); |
| 1471 | EXPECT_FALSE(service->key_rotation()); |
| 1472 | EXPECT_FALSE(service->endpoint_auth()); |
| 1473 | } |
| 1474 | { |
| 1475 | WiFiServiceRefPtr service = MakeSimpleService(flimflam::kSecurityPsk); |
| 1476 | EXPECT_EQ(Service::kCryptoRc4, service->crypto_algorithm()); |
| 1477 | EXPECT_TRUE(service->key_rotation()); |
| 1478 | EXPECT_FALSE(service->endpoint_auth()); |
| 1479 | } |
| 1480 | { |
| 1481 | WiFiServiceRefPtr service = MakeSimpleService(flimflam::kSecurityWpa); |
| 1482 | EXPECT_EQ(Service::kCryptoRc4, service->crypto_algorithm()); |
| 1483 | EXPECT_TRUE(service->key_rotation()); |
| 1484 | EXPECT_FALSE(service->endpoint_auth()); |
| 1485 | } |
| 1486 | { |
| 1487 | WiFiServiceRefPtr service = MakeSimpleService(flimflam::kSecurityRsn); |
| 1488 | EXPECT_EQ(Service::kCryptoAes, service->crypto_algorithm()); |
| 1489 | EXPECT_TRUE(service->key_rotation()); |
| 1490 | EXPECT_FALSE(service->endpoint_auth()); |
| 1491 | } |
| 1492 | |
| 1493 | // Crypto with 802.1X key management. |
| 1494 | { |
| 1495 | // WEP |
| 1496 | WiFiServiceRefPtr service = MakeSimpleService(flimflam::kSecurityWep); |
| 1497 | service->SetEAPKeyManagement("IEEE8021X"); |
| 1498 | EXPECT_EQ(Service::kCryptoRc4, service->crypto_algorithm()); |
| 1499 | EXPECT_TRUE(service->key_rotation()); |
| 1500 | EXPECT_TRUE(service->endpoint_auth()); |
| 1501 | } |
| 1502 | { |
| 1503 | // WPA |
| 1504 | WiFiServiceRefPtr service = MakeSimpleService(flimflam::kSecurity8021x); |
| 1505 | WiFiEndpointRefPtr endpoint = |
| 1506 | MakeEndpoint("a", "00:00:00:00:00:01", 0, 0, true, false); |
| 1507 | service->AddEndpoint(endpoint); |
| 1508 | EXPECT_EQ(Service::kCryptoRc4, service->crypto_algorithm()); |
| 1509 | EXPECT_TRUE(service->key_rotation()); |
| 1510 | EXPECT_TRUE(service->endpoint_auth()); |
| 1511 | } |
| 1512 | { |
| 1513 | // RSN |
| 1514 | WiFiServiceRefPtr service = MakeSimpleService(flimflam::kSecurity8021x); |
| 1515 | WiFiEndpointRefPtr endpoint = |
| 1516 | MakeEndpoint("a", "00:00:00:00:00:01", 0, 0, false, true); |
| 1517 | service->AddEndpoint(endpoint); |
| 1518 | EXPECT_EQ(Service::kCryptoAes, service->crypto_algorithm()); |
| 1519 | EXPECT_TRUE(service->key_rotation()); |
| 1520 | EXPECT_TRUE(service->endpoint_auth()); |
| 1521 | } |
| 1522 | { |
| 1523 | // AP supports both WPA and RSN. |
| 1524 | WiFiServiceRefPtr service = MakeSimpleService(flimflam::kSecurity8021x); |
| 1525 | WiFiEndpointRefPtr endpoint = |
| 1526 | MakeEndpoint("a", "00:00:00:00:00:01", 0, 0, true, true); |
| 1527 | service->AddEndpoint(endpoint); |
| 1528 | EXPECT_EQ(Service::kCryptoAes, service->crypto_algorithm()); |
| 1529 | EXPECT_TRUE(service->key_rotation()); |
| 1530 | EXPECT_TRUE(service->endpoint_auth()); |
| 1531 | } |
| 1532 | } |
| 1533 | |
| 1534 | TEST_F(WiFiServiceTest, ComputeCipher8021x) { |
| 1535 | // No endpoints. |
| 1536 | { |
| 1537 | const set<WiFiEndpointConstRefPtr> endpoints; |
| 1538 | EXPECT_EQ(Service::kCryptoNone, |
| 1539 | WiFiService::ComputeCipher8021x(endpoints)); |
| 1540 | } |
| 1541 | |
| 1542 | // Single endpoint, various configs. |
| 1543 | { |
| 1544 | set<WiFiEndpointConstRefPtr> endpoints; |
| 1545 | endpoints.insert( |
| 1546 | MakeEndpoint("a", "00:00:00:00:00:01", 0, 0, false, false)); |
| 1547 | EXPECT_EQ(Service::kCryptoNone, |
| 1548 | WiFiService::ComputeCipher8021x(endpoints)); |
| 1549 | } |
| 1550 | { |
| 1551 | set<WiFiEndpointConstRefPtr> endpoints; |
| 1552 | endpoints.insert( |
| 1553 | MakeEndpoint("a", "00:00:00:00:00:01", 0, 0, true, false)); |
| 1554 | EXPECT_EQ(Service::kCryptoRc4, |
| 1555 | WiFiService::ComputeCipher8021x(endpoints)); |
| 1556 | } |
| 1557 | { |
| 1558 | set<WiFiEndpointConstRefPtr> endpoints; |
| 1559 | endpoints.insert( |
| 1560 | MakeEndpoint("a", "00:00:00:00:00:01", 0, 0, false, true)); |
| 1561 | EXPECT_EQ(Service::kCryptoAes, |
| 1562 | WiFiService::ComputeCipher8021x(endpoints)); |
| 1563 | } |
| 1564 | { |
| 1565 | set<WiFiEndpointConstRefPtr> endpoints; |
| 1566 | endpoints.insert( |
| 1567 | MakeEndpoint("a", "00:00:00:00:00:01", 0, 0, true, true)); |
| 1568 | EXPECT_EQ(Service::kCryptoAes, |
| 1569 | WiFiService::ComputeCipher8021x(endpoints)); |
| 1570 | } |
| 1571 | |
| 1572 | // Multiple endpoints. |
| 1573 | { |
| 1574 | set<WiFiEndpointConstRefPtr> endpoints; |
| 1575 | endpoints.insert( |
| 1576 | MakeEndpoint("a", "00:00:00:00:00:01", 0, 0, false, false)); |
| 1577 | endpoints.insert( |
| 1578 | MakeEndpoint("a", "00:00:00:00:00:02", 0, 0, false, false)); |
| 1579 | EXPECT_EQ(Service::kCryptoNone, |
| 1580 | WiFiService::ComputeCipher8021x(endpoints)); |
| 1581 | } |
| 1582 | { |
| 1583 | set<WiFiEndpointConstRefPtr> endpoints; |
| 1584 | endpoints.insert( |
| 1585 | MakeEndpoint("a", "00:00:00:00:00:01", 0, 0, false, false)); |
| 1586 | endpoints.insert( |
| 1587 | MakeEndpoint("a", "00:00:00:00:00:02", 0, 0, true, false)); |
| 1588 | EXPECT_EQ(Service::kCryptoNone, |
| 1589 | WiFiService::ComputeCipher8021x(endpoints)); |
| 1590 | } |
| 1591 | { |
| 1592 | set<WiFiEndpointConstRefPtr> endpoints; |
| 1593 | endpoints.insert( |
| 1594 | MakeEndpoint("a", "00:00:00:00:00:01", 0, 0, true, false)); |
| 1595 | endpoints.insert( |
| 1596 | MakeEndpoint("a", "00:00:00:00:00:02", 0, 0, true, false)); |
| 1597 | EXPECT_EQ(Service::kCryptoRc4, |
| 1598 | WiFiService::ComputeCipher8021x(endpoints)); |
| 1599 | } |
| 1600 | { |
| 1601 | set<WiFiEndpointConstRefPtr> endpoints; |
| 1602 | endpoints.insert( |
| 1603 | MakeEndpoint("a", "00:00:00:00:00:01", 0, 0, true, false)); |
| 1604 | endpoints.insert( |
| 1605 | MakeEndpoint("a", "00:00:00:00:00:02", 0, 0, false, true)); |
| 1606 | EXPECT_EQ(Service::kCryptoRc4, |
| 1607 | WiFiService::ComputeCipher8021x(endpoints)); |
| 1608 | } |
| 1609 | { |
| 1610 | set<WiFiEndpointConstRefPtr> endpoints; |
| 1611 | endpoints.insert( |
| 1612 | MakeEndpoint("a", "00:00:00:00:00:01", 0, 0, false, true)); |
| 1613 | endpoints.insert( |
| 1614 | MakeEndpoint("a", "00:00:00:00:00:02", 0, 0, false, true)); |
| 1615 | EXPECT_EQ(Service::kCryptoAes, |
| 1616 | WiFiService::ComputeCipher8021x(endpoints)); |
| 1617 | } |
| 1618 | { |
| 1619 | set<WiFiEndpointConstRefPtr> endpoints; |
| 1620 | endpoints.insert( |
| 1621 | MakeEndpoint("a", "00:00:00:00:00:01", 0, 0, true, true)); |
| 1622 | endpoints.insert( |
| 1623 | MakeEndpoint("a", "00:00:00:00:00:02", 0, 0, true, true)); |
| 1624 | EXPECT_EQ(Service::kCryptoAes, |
| 1625 | WiFiService::ComputeCipher8021x(endpoints)); |
| 1626 | } |
| 1627 | } |
| 1628 | |
Albert Chaulk | 0e1cdea | 2013-02-27 15:32:55 -0800 | [diff] [blame] | 1629 | TEST_F(WiFiServiceTest, Unload) { |
| 1630 | WiFiServiceRefPtr service = MakeServiceWithWiFi(flimflam::kSecurityNone); |
| 1631 | EXPECT_CALL(*wifi(), DestroyIPConfigLease(service->GetStorageIdentifier())). |
| 1632 | Times(1); |
| 1633 | service->Unload(); |
| 1634 | } |
| 1635 | |
| 1636 | |
Chris Masone | 34af218 | 2011-08-22 11:59:36 -0700 | [diff] [blame] | 1637 | } // namespace shill |