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