Darin Petkov | b451d6e | 2012-04-23 11:56:41 +0200 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium OS Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "shill/vpn_driver.h" |
| 6 | |
| 7 | #include <base/stl_util.h> |
| 8 | #include <base/string_number_conversions.h> |
| 9 | #include <chromeos/dbus/service_constants.h> |
| 10 | #include <gmock/gmock.h> |
| 11 | #include <gtest/gtest.h> |
| 12 | |
Darin Petkov | 0e9735d | 2012-04-24 12:33:45 +0200 | [diff] [blame] | 13 | #include "shill/event_dispatcher.h" |
| 14 | #include "shill/glib.h" |
| 15 | #include "shill/mock_connection.h" |
| 16 | #include "shill/mock_device_info.h" |
| 17 | #include "shill/mock_glib.h" |
| 18 | #include "shill/mock_manager.h" |
| 19 | #include "shill/mock_metrics.h" |
| 20 | #include "shill/mock_service.h" |
Darin Petkov | b451d6e | 2012-04-23 11:56:41 +0200 | [diff] [blame] | 21 | #include "shill/mock_store.h" |
Darin Petkov | 0e9735d | 2012-04-24 12:33:45 +0200 | [diff] [blame] | 22 | #include "shill/nice_mock_control.h" |
Darin Petkov | b451d6e | 2012-04-23 11:56:41 +0200 | [diff] [blame] | 23 | #include "shill/property_store.h" |
Paul Stewart | 8e7e459 | 2012-04-29 09:47:48 -0700 | [diff] [blame] | 24 | #include "shill/property_store_inspector.h" |
Darin Petkov | b451d6e | 2012-04-23 11:56:41 +0200 | [diff] [blame] | 25 | |
| 26 | using std::string; |
| 27 | using testing::_; |
| 28 | using testing::AnyNumber; |
Darin Petkov | 0e9735d | 2012-04-24 12:33:45 +0200 | [diff] [blame] | 29 | using testing::NiceMock; |
Darin Petkov | b451d6e | 2012-04-23 11:56:41 +0200 | [diff] [blame] | 30 | using testing::Return; |
| 31 | using testing::SetArgumentPointee; |
Darin Petkov | 0e9735d | 2012-04-24 12:33:45 +0200 | [diff] [blame] | 32 | using testing::StrictMock; |
Darin Petkov | b451d6e | 2012-04-23 11:56:41 +0200 | [diff] [blame] | 33 | using testing::Test; |
| 34 | |
| 35 | namespace shill { |
| 36 | |
| 37 | namespace { |
Darin Petkov | 602303f | 2012-06-06 12:15:59 +0200 | [diff] [blame] | 38 | |
Darin Petkov | b451d6e | 2012-04-23 11:56:41 +0200 | [diff] [blame] | 39 | const char kHostProperty[] = "VPN.Host"; |
| 40 | const char kOTPProperty[] = "VPN.OTP"; |
Darin Petkov | cb71529 | 2012-04-25 13:04:37 +0200 | [diff] [blame] | 41 | const char kPINProperty[] = "VPN.PIN"; |
Darin Petkov | 4e9066f | 2012-06-11 13:17:06 +0200 | [diff] [blame] | 42 | const char kPSKProperty[] = "VPN.PSK"; |
Darin Petkov | b451d6e | 2012-04-23 11:56:41 +0200 | [diff] [blame] | 43 | const char kPasswordProperty[] = "VPN.Password"; |
| 44 | const char kPortProperty[] = "VPN.Port"; |
Darin Petkov | cb71529 | 2012-04-25 13:04:37 +0200 | [diff] [blame] | 45 | |
| 46 | const char kPIN[] = "5555"; |
| 47 | const char kPassword[] = "random-password"; |
| 48 | const char kPort[] = "1234"; |
| 49 | const char kStorageID[] = "vpn_service_id"; |
| 50 | |
Darin Petkov | b451d6e | 2012-04-23 11:56:41 +0200 | [diff] [blame] | 51 | } // namespace |
| 52 | |
| 53 | class VPNDriverUnderTest : public VPNDriver { |
| 54 | public: |
Darin Petkov | 602303f | 2012-06-06 12:15:59 +0200 | [diff] [blame] | 55 | VPNDriverUnderTest(EventDispatcher *dispatcher, Manager *manager); |
Darin Petkov | b451d6e | 2012-04-23 11:56:41 +0200 | [diff] [blame] | 56 | virtual ~VPNDriverUnderTest() {} |
| 57 | |
| 58 | // Inherited from VPNDriver. |
| 59 | MOCK_METHOD2(ClaimInterface, bool(const string &link_name, |
| 60 | int interface_index)); |
| 61 | MOCK_METHOD2(Connect, void(const VPNServiceRefPtr &service, Error *error)); |
| 62 | MOCK_METHOD0(Disconnect, void()); |
Darin Petkov | 5eb0542 | 2012-05-11 15:45:25 +0200 | [diff] [blame] | 63 | MOCK_METHOD0(OnConnectionDisconnected, void()); |
Darin Petkov | b451d6e | 2012-04-23 11:56:41 +0200 | [diff] [blame] | 64 | MOCK_CONST_METHOD0(GetProviderType, string()); |
| 65 | |
| 66 | private: |
| 67 | static const Property kProperties[]; |
| 68 | |
| 69 | DISALLOW_COPY_AND_ASSIGN(VPNDriverUnderTest); |
| 70 | }; |
| 71 | |
| 72 | // static |
| 73 | const VPNDriverUnderTest::Property VPNDriverUnderTest::kProperties[] = { |
| 74 | { kHostProperty, 0 }, |
Darin Petkov | cb71529 | 2012-04-25 13:04:37 +0200 | [diff] [blame] | 75 | { kOTPProperty, Property::kEphemeral }, |
| 76 | { kPINProperty, Property::kWriteOnly }, |
Darin Petkov | 4e9066f | 2012-06-11 13:17:06 +0200 | [diff] [blame] | 77 | { kPSKProperty, Property::kCredential }, |
Darin Petkov | cb71529 | 2012-04-25 13:04:37 +0200 | [diff] [blame] | 78 | { kPasswordProperty, Property::kCredential }, |
Darin Petkov | b451d6e | 2012-04-23 11:56:41 +0200 | [diff] [blame] | 79 | { kPortProperty, 0 }, |
| 80 | { flimflam::kProviderNameProperty, 0 }, |
| 81 | }; |
| 82 | |
Darin Petkov | 602303f | 2012-06-06 12:15:59 +0200 | [diff] [blame] | 83 | VPNDriverUnderTest::VPNDriverUnderTest( |
| 84 | EventDispatcher *dispatcher, Manager *manager) |
| 85 | : VPNDriver(dispatcher, manager, kProperties, arraysize(kProperties)) {} |
Darin Petkov | b451d6e | 2012-04-23 11:56:41 +0200 | [diff] [blame] | 86 | |
| 87 | class VPNDriverTest : public Test { |
| 88 | public: |
Darin Petkov | 0e9735d | 2012-04-24 12:33:45 +0200 | [diff] [blame] | 89 | VPNDriverTest() |
| 90 | : device_info_(&control_, &dispatcher_, &metrics_, &manager_), |
| 91 | manager_(&control_, &dispatcher_, &metrics_, &glib_), |
Darin Petkov | 602303f | 2012-06-06 12:15:59 +0200 | [diff] [blame] | 92 | driver_(&dispatcher_, &manager_) {} |
Darin Petkov | b451d6e | 2012-04-23 11:56:41 +0200 | [diff] [blame] | 93 | |
| 94 | virtual ~VPNDriverTest() {} |
| 95 | |
| 96 | protected: |
| 97 | void SetArg(const string &arg, const string &value) { |
| 98 | driver_.args()->SetString(arg, value); |
| 99 | } |
| 100 | |
| 101 | KeyValueStore *GetArgs() { return driver_.args(); } |
| 102 | |
Paul Stewart | 8e7e459 | 2012-04-29 09:47:48 -0700 | [diff] [blame] | 103 | bool GetProviderProperty(const PropertyStore &store, |
| 104 | const string &key, |
| 105 | string *value); |
Darin Petkov | b451d6e | 2012-04-23 11:56:41 +0200 | [diff] [blame] | 106 | |
Darin Petkov | 0e9735d | 2012-04-24 12:33:45 +0200 | [diff] [blame] | 107 | NiceMockControl control_; |
| 108 | NiceMock<MockDeviceInfo> device_info_; |
| 109 | EventDispatcher dispatcher_; |
| 110 | MockMetrics metrics_; |
| 111 | MockGLib glib_; |
| 112 | MockManager manager_; |
Darin Petkov | b451d6e | 2012-04-23 11:56:41 +0200 | [diff] [blame] | 113 | VPNDriverUnderTest driver_; |
| 114 | }; |
| 115 | |
Paul Stewart | 8e7e459 | 2012-04-29 09:47:48 -0700 | [diff] [blame] | 116 | bool VPNDriverTest::GetProviderProperty(const PropertyStore &store, |
| 117 | const string &key, |
| 118 | string *value) { |
Paul Stewart | 8e7e459 | 2012-04-29 09:47:48 -0700 | [diff] [blame] | 119 | PropertyStoreInspector inspector(&store); |
| 120 | KeyValueStore provider_properties; |
| 121 | EXPECT_TRUE(inspector.GetKeyValueStoreProperty( |
Darin Petkov | 4682aa8 | 2012-05-31 16:24:11 +0200 | [diff] [blame] | 122 | flimflam::kProviderProperty, &provider_properties)); |
Paul Stewart | 8e7e459 | 2012-04-29 09:47:48 -0700 | [diff] [blame] | 123 | if (!provider_properties.ContainsString(key)) { |
| 124 | return false; |
Darin Petkov | b451d6e | 2012-04-23 11:56:41 +0200 | [diff] [blame] | 125 | } |
Paul Stewart | 8e7e459 | 2012-04-29 09:47:48 -0700 | [diff] [blame] | 126 | if (value != NULL) { |
| 127 | *value = provider_properties.GetString(key); |
Darin Petkov | b451d6e | 2012-04-23 11:56:41 +0200 | [diff] [blame] | 128 | } |
Paul Stewart | 8e7e459 | 2012-04-29 09:47:48 -0700 | [diff] [blame] | 129 | return true; |
Darin Petkov | b451d6e | 2012-04-23 11:56:41 +0200 | [diff] [blame] | 130 | } |
| 131 | |
| 132 | TEST_F(VPNDriverTest, Load) { |
| 133 | MockStore storage; |
Darin Petkov | 4e9066f | 2012-06-11 13:17:06 +0200 | [diff] [blame] | 134 | GetArgs()->SetString(kHostProperty, "1.2.3.4"); |
| 135 | GetArgs()->SetString(kPSKProperty, "1234"); |
Darin Petkov | b451d6e | 2012-04-23 11:56:41 +0200 | [diff] [blame] | 136 | EXPECT_CALL(storage, GetString(kStorageID, _, _)) |
| 137 | .WillRepeatedly(Return(false)); |
Darin Petkov | cb71529 | 2012-04-25 13:04:37 +0200 | [diff] [blame] | 138 | EXPECT_CALL(storage, GetString(_, kOTPProperty, _)).Times(0); |
| 139 | EXPECT_CALL(storage, GetCryptedString(_, kOTPProperty, _)).Times(0); |
Darin Petkov | b451d6e | 2012-04-23 11:56:41 +0200 | [diff] [blame] | 140 | EXPECT_CALL(storage, GetString(kStorageID, kPortProperty, _)) |
Darin Petkov | cb71529 | 2012-04-25 13:04:37 +0200 | [diff] [blame] | 141 | .WillOnce(DoAll(SetArgumentPointee<2>(string(kPort)), Return(true))); |
| 142 | EXPECT_CALL(storage, GetString(kStorageID, kPINProperty, _)) |
| 143 | .WillOnce(DoAll(SetArgumentPointee<2>(string(kPIN)), Return(true))); |
Darin Petkov | 4e9066f | 2012-06-11 13:17:06 +0200 | [diff] [blame] | 144 | EXPECT_CALL(storage, GetCryptedString(kStorageID, kPSKProperty, _)) |
| 145 | .WillOnce(Return(false)); |
Darin Petkov | b451d6e | 2012-04-23 11:56:41 +0200 | [diff] [blame] | 146 | EXPECT_CALL(storage, GetCryptedString(kStorageID, kPasswordProperty, _)) |
Darin Petkov | cb71529 | 2012-04-25 13:04:37 +0200 | [diff] [blame] | 147 | .WillOnce(DoAll(SetArgumentPointee<2>(string(kPassword)), Return(true))); |
Darin Petkov | b451d6e | 2012-04-23 11:56:41 +0200 | [diff] [blame] | 148 | EXPECT_TRUE(driver_.Load(&storage, kStorageID)); |
| 149 | EXPECT_EQ(kPort, GetArgs()->LookupString(kPortProperty, "")); |
Darin Petkov | cb71529 | 2012-04-25 13:04:37 +0200 | [diff] [blame] | 150 | EXPECT_EQ(kPIN, GetArgs()->LookupString(kPINProperty, "")); |
Darin Petkov | b451d6e | 2012-04-23 11:56:41 +0200 | [diff] [blame] | 151 | EXPECT_EQ(kPassword, GetArgs()->LookupString(kPasswordProperty, "")); |
Darin Petkov | 4e9066f | 2012-06-11 13:17:06 +0200 | [diff] [blame] | 152 | |
| 153 | // Properties missing from the persistent store should be deleted. |
| 154 | EXPECT_FALSE(GetArgs()->ContainsString(kHostProperty)); |
| 155 | EXPECT_FALSE(GetArgs()->ContainsString(kPSKProperty)); |
Darin Petkov | b451d6e | 2012-04-23 11:56:41 +0200 | [diff] [blame] | 156 | } |
| 157 | |
Darin Petkov | 4e9066f | 2012-06-11 13:17:06 +0200 | [diff] [blame] | 158 | TEST_F(VPNDriverTest, Save) { |
| 159 | SetArg(flimflam::kProviderNameProperty, ""); |
Darin Petkov | cb71529 | 2012-04-25 13:04:37 +0200 | [diff] [blame] | 160 | SetArg(kPINProperty, kPIN); |
Darin Petkov | b451d6e | 2012-04-23 11:56:41 +0200 | [diff] [blame] | 161 | SetArg(kPortProperty, kPort); |
| 162 | SetArg(kPasswordProperty, kPassword); |
| 163 | SetArg(kOTPProperty, "987654"); |
| 164 | MockStore storage; |
Darin Petkov | 4e9066f | 2012-06-11 13:17:06 +0200 | [diff] [blame] | 165 | EXPECT_CALL(storage, |
| 166 | SetString(kStorageID, flimflam::kProviderNameProperty, "")) |
| 167 | .WillOnce(Return(true)); |
Darin Petkov | b451d6e | 2012-04-23 11:56:41 +0200 | [diff] [blame] | 168 | EXPECT_CALL(storage, SetString(kStorageID, kPortProperty, kPort)) |
| 169 | .WillOnce(Return(true)); |
Darin Petkov | cb71529 | 2012-04-25 13:04:37 +0200 | [diff] [blame] | 170 | EXPECT_CALL(storage, SetString(kStorageID, kPINProperty, kPIN)) |
| 171 | .WillOnce(Return(true)); |
Darin Petkov | b451d6e | 2012-04-23 11:56:41 +0200 | [diff] [blame] | 172 | EXPECT_CALL(storage, |
| 173 | SetCryptedString(kStorageID, kPasswordProperty, kPassword)) |
| 174 | .WillOnce(Return(true)); |
Darin Petkov | cb71529 | 2012-04-25 13:04:37 +0200 | [diff] [blame] | 175 | EXPECT_CALL(storage, SetCryptedString(_, kOTPProperty, _)).Times(0); |
| 176 | EXPECT_CALL(storage, SetString(_, kOTPProperty, _)).Times(0); |
Darin Petkov | 4e9066f | 2012-06-11 13:17:06 +0200 | [diff] [blame] | 177 | EXPECT_CALL(storage, DeleteKey(kStorageID, flimflam::kProviderNameProperty)) |
| 178 | .Times(0); |
| 179 | EXPECT_CALL(storage, DeleteKey(kStorageID, kPSKProperty)).Times(1); |
Darin Petkov | b451d6e | 2012-04-23 11:56:41 +0200 | [diff] [blame] | 180 | EXPECT_CALL(storage, DeleteKey(kStorageID, kHostProperty)).Times(1); |
Darin Petkov | cb71529 | 2012-04-25 13:04:37 +0200 | [diff] [blame] | 181 | EXPECT_TRUE(driver_.Save(&storage, kStorageID, true)); |
| 182 | } |
| 183 | |
Darin Petkov | 4e9066f | 2012-06-11 13:17:06 +0200 | [diff] [blame] | 184 | TEST_F(VPNDriverTest, SaveNoCredentials) { |
Darin Petkov | cb71529 | 2012-04-25 13:04:37 +0200 | [diff] [blame] | 185 | SetArg(kPasswordProperty, kPassword); |
Darin Petkov | 4e9066f | 2012-06-11 13:17:06 +0200 | [diff] [blame] | 186 | SetArg(kPSKProperty, ""); |
Darin Petkov | cb71529 | 2012-04-25 13:04:37 +0200 | [diff] [blame] | 187 | MockStore storage; |
| 188 | EXPECT_CALL(storage, SetString(_, kPasswordProperty, _)).Times(0); |
| 189 | EXPECT_CALL(storage, SetCryptedString(_, kPasswordProperty, _)).Times(0); |
| 190 | EXPECT_CALL(storage, DeleteKey(kStorageID, _)).Times(AnyNumber()); |
| 191 | EXPECT_CALL(storage, DeleteKey(kStorageID, kPasswordProperty)).Times(1); |
Darin Petkov | 4e9066f | 2012-06-11 13:17:06 +0200 | [diff] [blame] | 192 | EXPECT_CALL(storage, DeleteKey(kStorageID, kPSKProperty)).Times(1); |
Darin Petkov | cb71529 | 2012-04-25 13:04:37 +0200 | [diff] [blame] | 193 | EXPECT_TRUE(driver_.Save(&storage, kStorageID, false)); |
| 194 | } |
| 195 | |
| 196 | TEST_F(VPNDriverTest, UnloadCredentials) { |
| 197 | SetArg(kOTPProperty, "654321"); |
| 198 | SetArg(kPasswordProperty, kPassword); |
| 199 | SetArg(kPortProperty, kPort); |
| 200 | driver_.UnloadCredentials(); |
| 201 | EXPECT_FALSE(GetArgs()->ContainsString(kOTPProperty)); |
| 202 | EXPECT_FALSE(GetArgs()->ContainsString(kPasswordProperty)); |
| 203 | EXPECT_EQ(kPort, GetArgs()->LookupString(kPortProperty, "")); |
Darin Petkov | b451d6e | 2012-04-23 11:56:41 +0200 | [diff] [blame] | 204 | } |
| 205 | |
| 206 | TEST_F(VPNDriverTest, InitPropertyStore) { |
| 207 | // Figure out if the store is actually hooked up to the driver argument |
| 208 | // KeyValueStore. |
| 209 | PropertyStore store; |
| 210 | driver_.InitPropertyStore(&store); |
Paul Stewart | 8e7e459 | 2012-04-29 09:47:48 -0700 | [diff] [blame] | 211 | PropertyStoreInspector inspector(&store); |
Darin Petkov | b451d6e | 2012-04-23 11:56:41 +0200 | [diff] [blame] | 212 | |
| 213 | // An un-set property should not be readable. |
Darin Petkov | 4682aa8 | 2012-05-31 16:24:11 +0200 | [diff] [blame] | 214 | EXPECT_FALSE(inspector.GetStringProperty(kPortProperty, NULL)); |
Paul Stewart | 8e7e459 | 2012-04-29 09:47:48 -0700 | [diff] [blame] | 215 | EXPECT_FALSE(GetProviderProperty(store, kPortProperty, NULL)); |
Darin Petkov | b451d6e | 2012-04-23 11:56:41 +0200 | [diff] [blame] | 216 | |
Darin Petkov | b451d6e | 2012-04-23 11:56:41 +0200 | [diff] [blame] | 217 | const string kProviderName = "boo"; |
| 218 | SetArg(kPortProperty, kPort); |
| 219 | SetArg(kPasswordProperty, kPassword); |
| 220 | SetArg(flimflam::kProviderNameProperty, kProviderName); |
Darin Petkov | 4e9066f | 2012-06-11 13:17:06 +0200 | [diff] [blame] | 221 | SetArg(kHostProperty, ""); |
Darin Petkov | b451d6e | 2012-04-23 11:56:41 +0200 | [diff] [blame] | 222 | |
| 223 | // We should not be able to read a property out of the driver args using the |
| 224 | // key to the args directly. |
Darin Petkov | 4682aa8 | 2012-05-31 16:24:11 +0200 | [diff] [blame] | 225 | EXPECT_FALSE(inspector.GetStringProperty(kPortProperty, NULL)); |
Darin Petkov | b451d6e | 2012-04-23 11:56:41 +0200 | [diff] [blame] | 226 | |
| 227 | // We should instead be able to find it within the "Provider" stringmap. |
Paul Stewart | 8e7e459 | 2012-04-29 09:47:48 -0700 | [diff] [blame] | 228 | string value; |
| 229 | EXPECT_TRUE(GetProviderProperty(store, kPortProperty, &value)); |
| 230 | EXPECT_EQ(kPort, value); |
Darin Petkov | b451d6e | 2012-04-23 11:56:41 +0200 | [diff] [blame] | 231 | |
Darin Petkov | 4e9066f | 2012-06-11 13:17:06 +0200 | [diff] [blame] | 232 | // We should be able to read empty properties from the "Provider" stringmap. |
| 233 | { |
| 234 | string value; |
| 235 | EXPECT_TRUE(GetProviderProperty(store, kHostProperty, &value)); |
| 236 | EXPECT_TRUE(value.empty()); |
| 237 | } |
| 238 | |
Darin Petkov | b451d6e | 2012-04-23 11:56:41 +0200 | [diff] [blame] | 239 | // Properties that start with the prefix "Provider." should be mapped to the |
| 240 | // name in the Properties dict with the prefix removed. |
Paul Stewart | 8e7e459 | 2012-04-29 09:47:48 -0700 | [diff] [blame] | 241 | EXPECT_TRUE(GetProviderProperty(store, flimflam::kNameProperty, &value)); |
| 242 | EXPECT_EQ(kProviderName, value); |
Darin Petkov | b451d6e | 2012-04-23 11:56:41 +0200 | [diff] [blame] | 243 | |
Paul Stewart | 8e7e459 | 2012-04-29 09:47:48 -0700 | [diff] [blame] | 244 | // If we clear a property, we should no longer be able to find it. |
Darin Petkov | b451d6e | 2012-04-23 11:56:41 +0200 | [diff] [blame] | 245 | { |
| 246 | Error error; |
| 247 | EXPECT_TRUE(store.ClearProperty(kPortProperty, &error)); |
| 248 | EXPECT_TRUE(error.IsSuccess()); |
Paul Stewart | 8e7e459 | 2012-04-29 09:47:48 -0700 | [diff] [blame] | 249 | EXPECT_FALSE(GetProviderProperty(store, kPortProperty, NULL)); |
Darin Petkov | b451d6e | 2012-04-23 11:56:41 +0200 | [diff] [blame] | 250 | } |
| 251 | |
| 252 | // A second attempt to clear this property should return an error. |
| 253 | { |
| 254 | Error error; |
| 255 | EXPECT_FALSE(store.ClearProperty(kPortProperty, &error)); |
| 256 | EXPECT_EQ(Error::kNotFound, error.type()); |
| 257 | } |
| 258 | |
Darin Petkov | cb71529 | 2012-04-25 13:04:37 +0200 | [diff] [blame] | 259 | // Test write only properties. |
Paul Stewart | 8e7e459 | 2012-04-29 09:47:48 -0700 | [diff] [blame] | 260 | EXPECT_FALSE(GetProviderProperty(store, kPINProperty, NULL)); |
Darin Petkov | b451d6e | 2012-04-23 11:56:41 +0200 | [diff] [blame] | 261 | |
| 262 | // Write properties to the driver args using the PropertyStore interface. |
Darin Petkov | cb71529 | 2012-04-25 13:04:37 +0200 | [diff] [blame] | 263 | { |
| 264 | const string kValue = "some-value"; |
Darin Petkov | b451d6e | 2012-04-23 11:56:41 +0200 | [diff] [blame] | 265 | Error error; |
Darin Petkov | cb71529 | 2012-04-25 13:04:37 +0200 | [diff] [blame] | 266 | EXPECT_TRUE(store.SetStringProperty(kPINProperty, kValue, &error)); |
| 267 | EXPECT_EQ(kValue, GetArgs()->GetString(kPINProperty)); |
Darin Petkov | b451d6e | 2012-04-23 11:56:41 +0200 | [diff] [blame] | 268 | } |
| 269 | } |
| 270 | |
Darin Petkov | 602303f | 2012-06-06 12:15:59 +0200 | [diff] [blame] | 271 | TEST_F(VPNDriverTest, ConnectTimeout) { |
| 272 | EXPECT_EQ(&dispatcher_, driver_.dispatcher_); |
| 273 | EXPECT_TRUE(driver_.connect_timeout_callback_.IsCancelled()); |
| 274 | EXPECT_FALSE(driver_.IsConnectTimeoutStarted()); |
| 275 | EXPECT_EQ(VPNDriver::kDefaultConnectTimeoutSeconds, |
| 276 | driver_.connect_timeout_seconds_); |
| 277 | driver_.connect_timeout_seconds_ = 0; |
| 278 | driver_.StartConnectTimeout(); |
| 279 | EXPECT_FALSE(driver_.connect_timeout_callback_.IsCancelled()); |
| 280 | EXPECT_TRUE(driver_.IsConnectTimeoutStarted()); |
| 281 | driver_.dispatcher_ = NULL; |
| 282 | driver_.StartConnectTimeout(); // Expect no crash. |
| 283 | EXPECT_CALL(driver_, OnConnectionDisconnected()); |
| 284 | dispatcher_.DispatchPendingEvents(); |
| 285 | EXPECT_TRUE(driver_.connect_timeout_callback_.IsCancelled()); |
| 286 | EXPECT_FALSE(driver_.IsConnectTimeoutStarted()); |
| 287 | } |
| 288 | |
Darin Petkov | b451d6e | 2012-04-23 11:56:41 +0200 | [diff] [blame] | 289 | } // namespace shill |