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" |
| 24 | |
| 25 | using std::string; |
| 26 | using testing::_; |
| 27 | using testing::AnyNumber; |
Darin Petkov | 0e9735d | 2012-04-24 12:33:45 +0200 | [diff] [blame] | 28 | using testing::NiceMock; |
Darin Petkov | b451d6e | 2012-04-23 11:56:41 +0200 | [diff] [blame] | 29 | using testing::Return; |
| 30 | using testing::SetArgumentPointee; |
Darin Petkov | 0e9735d | 2012-04-24 12:33:45 +0200 | [diff] [blame] | 31 | using testing::StrictMock; |
Darin Petkov | b451d6e | 2012-04-23 11:56:41 +0200 | [diff] [blame] | 32 | using testing::Test; |
| 33 | |
| 34 | namespace shill { |
| 35 | |
| 36 | namespace { |
Darin Petkov | 602303f | 2012-06-06 12:15:59 +0200 | [diff] [blame] | 37 | |
Darin Petkov | b451d6e | 2012-04-23 11:56:41 +0200 | [diff] [blame] | 38 | const char kHostProperty[] = "VPN.Host"; |
| 39 | const char kOTPProperty[] = "VPN.OTP"; |
Darin Petkov | cb71529 | 2012-04-25 13:04:37 +0200 | [diff] [blame] | 40 | const char kPINProperty[] = "VPN.PIN"; |
Darin Petkov | 4e9066f | 2012-06-11 13:17:06 +0200 | [diff] [blame] | 41 | const char kPSKProperty[] = "VPN.PSK"; |
Darin Petkov | b451d6e | 2012-04-23 11:56:41 +0200 | [diff] [blame] | 42 | const char kPasswordProperty[] = "VPN.Password"; |
| 43 | const char kPortProperty[] = "VPN.Port"; |
Darin Petkov | cb71529 | 2012-04-25 13:04:37 +0200 | [diff] [blame] | 44 | |
| 45 | const char kPIN[] = "5555"; |
| 46 | const char kPassword[] = "random-password"; |
| 47 | const char kPort[] = "1234"; |
| 48 | const char kStorageID[] = "vpn_service_id"; |
| 49 | |
Darin Petkov | b451d6e | 2012-04-23 11:56:41 +0200 | [diff] [blame] | 50 | } // namespace |
| 51 | |
| 52 | class VPNDriverUnderTest : public VPNDriver { |
| 53 | public: |
Darin Petkov | 602303f | 2012-06-06 12:15:59 +0200 | [diff] [blame] | 54 | VPNDriverUnderTest(EventDispatcher *dispatcher, Manager *manager); |
Darin Petkov | b451d6e | 2012-04-23 11:56:41 +0200 | [diff] [blame] | 55 | virtual ~VPNDriverUnderTest() {} |
| 56 | |
| 57 | // Inherited from VPNDriver. |
| 58 | MOCK_METHOD2(ClaimInterface, bool(const string &link_name, |
| 59 | int interface_index)); |
| 60 | MOCK_METHOD2(Connect, void(const VPNServiceRefPtr &service, Error *error)); |
| 61 | MOCK_METHOD0(Disconnect, void()); |
Darin Petkov | 5eb0542 | 2012-05-11 15:45:25 +0200 | [diff] [blame] | 62 | MOCK_METHOD0(OnConnectionDisconnected, void()); |
Darin Petkov | b451d6e | 2012-04-23 11:56:41 +0200 | [diff] [blame] | 63 | MOCK_CONST_METHOD0(GetProviderType, string()); |
| 64 | |
| 65 | private: |
| 66 | static const Property kProperties[]; |
| 67 | |
| 68 | DISALLOW_COPY_AND_ASSIGN(VPNDriverUnderTest); |
| 69 | }; |
| 70 | |
| 71 | // static |
| 72 | const VPNDriverUnderTest::Property VPNDriverUnderTest::kProperties[] = { |
| 73 | { kHostProperty, 0 }, |
Darin Petkov | cb71529 | 2012-04-25 13:04:37 +0200 | [diff] [blame] | 74 | { kOTPProperty, Property::kEphemeral }, |
| 75 | { kPINProperty, Property::kWriteOnly }, |
Darin Petkov | 4e9066f | 2012-06-11 13:17:06 +0200 | [diff] [blame] | 76 | { kPSKProperty, Property::kCredential }, |
Darin Petkov | cb71529 | 2012-04-25 13:04:37 +0200 | [diff] [blame] | 77 | { kPasswordProperty, Property::kCredential }, |
Darin Petkov | b451d6e | 2012-04-23 11:56:41 +0200 | [diff] [blame] | 78 | { kPortProperty, 0 }, |
Darin Petkov | 4e02ba2 | 2013-04-02 13:44:08 +0200 | [diff] [blame] | 79 | { flimflam::kProviderTypeProperty, 0 }, |
Darin Petkov | b451d6e | 2012-04-23 11:56:41 +0200 | [diff] [blame] | 80 | }; |
| 81 | |
Darin Petkov | 602303f | 2012-06-06 12:15:59 +0200 | [diff] [blame] | 82 | VPNDriverUnderTest::VPNDriverUnderTest( |
| 83 | EventDispatcher *dispatcher, Manager *manager) |
| 84 | : VPNDriver(dispatcher, manager, kProperties, arraysize(kProperties)) {} |
Darin Petkov | b451d6e | 2012-04-23 11:56:41 +0200 | [diff] [blame] | 85 | |
| 86 | class VPNDriverTest : public Test { |
| 87 | public: |
Darin Petkov | 0e9735d | 2012-04-24 12:33:45 +0200 | [diff] [blame] | 88 | VPNDriverTest() |
| 89 | : device_info_(&control_, &dispatcher_, &metrics_, &manager_), |
Thieu Le | 6c1e3bb | 2013-02-06 15:20:35 -0800 | [diff] [blame] | 90 | metrics_(&dispatcher_), |
Darin Petkov | 0e9735d | 2012-04-24 12:33:45 +0200 | [diff] [blame] | 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: |
Darin Petkov | 0cd0d1e | 2013-02-11 12:49:10 +0100 | [diff] [blame] | 97 | EventDispatcher *dispatcher() { return driver_.dispatcher_; } |
| 98 | void set_dispatcher(EventDispatcher *dispatcher) { |
| 99 | driver_.dispatcher_ = dispatcher; |
| 100 | } |
| 101 | |
| 102 | const base::CancelableClosure &connect_timeout_callback() { |
| 103 | return driver_.connect_timeout_callback_; |
| 104 | } |
| 105 | |
| 106 | bool IsConnectTimeoutStarted() { return driver_.IsConnectTimeoutStarted(); } |
| 107 | int connect_timeout_seconds() { return driver_.connect_timeout_seconds(); } |
| 108 | |
| 109 | void StartConnectTimeout(int timeout_seconds) { |
| 110 | driver_.StartConnectTimeout(timeout_seconds); |
| 111 | } |
| 112 | |
| 113 | void StopConnectTimeout() { driver_.StopConnectTimeout(); } |
| 114 | |
Darin Petkov | b451d6e | 2012-04-23 11:56:41 +0200 | [diff] [blame] | 115 | void SetArg(const string &arg, const string &value) { |
| 116 | driver_.args()->SetString(arg, value); |
| 117 | } |
| 118 | |
| 119 | KeyValueStore *GetArgs() { return driver_.args(); } |
| 120 | |
Paul Stewart | 8e7e459 | 2012-04-29 09:47:48 -0700 | [diff] [blame] | 121 | bool GetProviderProperty(const PropertyStore &store, |
| 122 | const string &key, |
| 123 | string *value); |
Darin Petkov | b451d6e | 2012-04-23 11:56:41 +0200 | [diff] [blame] | 124 | |
Darin Petkov | 0e9735d | 2012-04-24 12:33:45 +0200 | [diff] [blame] | 125 | NiceMockControl control_; |
| 126 | NiceMock<MockDeviceInfo> device_info_; |
| 127 | EventDispatcher dispatcher_; |
| 128 | MockMetrics metrics_; |
| 129 | MockGLib glib_; |
| 130 | MockManager manager_; |
Darin Petkov | b451d6e | 2012-04-23 11:56:41 +0200 | [diff] [blame] | 131 | VPNDriverUnderTest driver_; |
| 132 | }; |
| 133 | |
Paul Stewart | 8e7e459 | 2012-04-29 09:47:48 -0700 | [diff] [blame] | 134 | bool VPNDriverTest::GetProviderProperty(const PropertyStore &store, |
| 135 | const string &key, |
| 136 | string *value) { |
Paul Stewart | 8e7e459 | 2012-04-29 09:47:48 -0700 | [diff] [blame] | 137 | KeyValueStore provider_properties; |
Paul Stewart | e6e8e49 | 2013-01-17 11:00:50 -0800 | [diff] [blame] | 138 | Error error; |
| 139 | EXPECT_TRUE(store.GetKeyValueStoreProperty( |
| 140 | flimflam::kProviderProperty, &provider_properties, &error)); |
Paul Stewart | 8e7e459 | 2012-04-29 09:47:48 -0700 | [diff] [blame] | 141 | if (!provider_properties.ContainsString(key)) { |
| 142 | return false; |
Darin Petkov | b451d6e | 2012-04-23 11:56:41 +0200 | [diff] [blame] | 143 | } |
Paul Stewart | 8e7e459 | 2012-04-29 09:47:48 -0700 | [diff] [blame] | 144 | if (value != NULL) { |
| 145 | *value = provider_properties.GetString(key); |
Darin Petkov | b451d6e | 2012-04-23 11:56:41 +0200 | [diff] [blame] | 146 | } |
Paul Stewart | 8e7e459 | 2012-04-29 09:47:48 -0700 | [diff] [blame] | 147 | return true; |
Darin Petkov | b451d6e | 2012-04-23 11:56:41 +0200 | [diff] [blame] | 148 | } |
| 149 | |
| 150 | TEST_F(VPNDriverTest, Load) { |
| 151 | MockStore storage; |
Darin Petkov | 4e9066f | 2012-06-11 13:17:06 +0200 | [diff] [blame] | 152 | GetArgs()->SetString(kHostProperty, "1.2.3.4"); |
| 153 | GetArgs()->SetString(kPSKProperty, "1234"); |
Darin Petkov | b451d6e | 2012-04-23 11:56:41 +0200 | [diff] [blame] | 154 | EXPECT_CALL(storage, GetString(kStorageID, _, _)) |
| 155 | .WillRepeatedly(Return(false)); |
Darin Petkov | cb71529 | 2012-04-25 13:04:37 +0200 | [diff] [blame] | 156 | EXPECT_CALL(storage, GetString(_, kOTPProperty, _)).Times(0); |
| 157 | EXPECT_CALL(storage, GetCryptedString(_, kOTPProperty, _)).Times(0); |
Darin Petkov | b451d6e | 2012-04-23 11:56:41 +0200 | [diff] [blame] | 158 | EXPECT_CALL(storage, GetString(kStorageID, kPortProperty, _)) |
Darin Petkov | cb71529 | 2012-04-25 13:04:37 +0200 | [diff] [blame] | 159 | .WillOnce(DoAll(SetArgumentPointee<2>(string(kPort)), Return(true))); |
| 160 | EXPECT_CALL(storage, GetString(kStorageID, kPINProperty, _)) |
| 161 | .WillOnce(DoAll(SetArgumentPointee<2>(string(kPIN)), Return(true))); |
Darin Petkov | 4e9066f | 2012-06-11 13:17:06 +0200 | [diff] [blame] | 162 | EXPECT_CALL(storage, GetCryptedString(kStorageID, kPSKProperty, _)) |
| 163 | .WillOnce(Return(false)); |
Darin Petkov | b451d6e | 2012-04-23 11:56:41 +0200 | [diff] [blame] | 164 | EXPECT_CALL(storage, GetCryptedString(kStorageID, kPasswordProperty, _)) |
Darin Petkov | cb71529 | 2012-04-25 13:04:37 +0200 | [diff] [blame] | 165 | .WillOnce(DoAll(SetArgumentPointee<2>(string(kPassword)), Return(true))); |
Darin Petkov | b451d6e | 2012-04-23 11:56:41 +0200 | [diff] [blame] | 166 | EXPECT_TRUE(driver_.Load(&storage, kStorageID)); |
| 167 | EXPECT_EQ(kPort, GetArgs()->LookupString(kPortProperty, "")); |
Darin Petkov | cb71529 | 2012-04-25 13:04:37 +0200 | [diff] [blame] | 168 | EXPECT_EQ(kPIN, GetArgs()->LookupString(kPINProperty, "")); |
Darin Petkov | b451d6e | 2012-04-23 11:56:41 +0200 | [diff] [blame] | 169 | EXPECT_EQ(kPassword, GetArgs()->LookupString(kPasswordProperty, "")); |
Darin Petkov | 4e9066f | 2012-06-11 13:17:06 +0200 | [diff] [blame] | 170 | |
| 171 | // Properties missing from the persistent store should be deleted. |
| 172 | EXPECT_FALSE(GetArgs()->ContainsString(kHostProperty)); |
| 173 | EXPECT_FALSE(GetArgs()->ContainsString(kPSKProperty)); |
Darin Petkov | b451d6e | 2012-04-23 11:56:41 +0200 | [diff] [blame] | 174 | } |
| 175 | |
Darin Petkov | 4e9066f | 2012-06-11 13:17:06 +0200 | [diff] [blame] | 176 | TEST_F(VPNDriverTest, Save) { |
Darin Petkov | 4e02ba2 | 2013-04-02 13:44:08 +0200 | [diff] [blame] | 177 | SetArg(flimflam::kProviderTypeProperty, ""); |
Darin Petkov | cb71529 | 2012-04-25 13:04:37 +0200 | [diff] [blame] | 178 | SetArg(kPINProperty, kPIN); |
Darin Petkov | b451d6e | 2012-04-23 11:56:41 +0200 | [diff] [blame] | 179 | SetArg(kPortProperty, kPort); |
| 180 | SetArg(kPasswordProperty, kPassword); |
| 181 | SetArg(kOTPProperty, "987654"); |
| 182 | MockStore storage; |
Darin Petkov | 4e9066f | 2012-06-11 13:17:06 +0200 | [diff] [blame] | 183 | EXPECT_CALL(storage, |
Darin Petkov | 4e02ba2 | 2013-04-02 13:44:08 +0200 | [diff] [blame] | 184 | SetString(kStorageID, flimflam::kProviderTypeProperty, "")) |
Darin Petkov | 4e9066f | 2012-06-11 13:17:06 +0200 | [diff] [blame] | 185 | .WillOnce(Return(true)); |
Darin Petkov | b451d6e | 2012-04-23 11:56:41 +0200 | [diff] [blame] | 186 | EXPECT_CALL(storage, SetString(kStorageID, kPortProperty, kPort)) |
| 187 | .WillOnce(Return(true)); |
Darin Petkov | cb71529 | 2012-04-25 13:04:37 +0200 | [diff] [blame] | 188 | EXPECT_CALL(storage, SetString(kStorageID, kPINProperty, kPIN)) |
| 189 | .WillOnce(Return(true)); |
Darin Petkov | b451d6e | 2012-04-23 11:56:41 +0200 | [diff] [blame] | 190 | EXPECT_CALL(storage, |
| 191 | SetCryptedString(kStorageID, kPasswordProperty, kPassword)) |
| 192 | .WillOnce(Return(true)); |
Darin Petkov | cb71529 | 2012-04-25 13:04:37 +0200 | [diff] [blame] | 193 | EXPECT_CALL(storage, SetCryptedString(_, kOTPProperty, _)).Times(0); |
| 194 | EXPECT_CALL(storage, SetString(_, kOTPProperty, _)).Times(0); |
Darin Petkov | 4e02ba2 | 2013-04-02 13:44:08 +0200 | [diff] [blame] | 195 | EXPECT_CALL(storage, DeleteKey(kStorageID, flimflam::kProviderTypeProperty)) |
Darin Petkov | 4e9066f | 2012-06-11 13:17:06 +0200 | [diff] [blame] | 196 | .Times(0); |
| 197 | EXPECT_CALL(storage, DeleteKey(kStorageID, kPSKProperty)).Times(1); |
Darin Petkov | b451d6e | 2012-04-23 11:56:41 +0200 | [diff] [blame] | 198 | EXPECT_CALL(storage, DeleteKey(kStorageID, kHostProperty)).Times(1); |
Darin Petkov | cb71529 | 2012-04-25 13:04:37 +0200 | [diff] [blame] | 199 | EXPECT_TRUE(driver_.Save(&storage, kStorageID, true)); |
| 200 | } |
| 201 | |
Darin Petkov | 4e9066f | 2012-06-11 13:17:06 +0200 | [diff] [blame] | 202 | TEST_F(VPNDriverTest, SaveNoCredentials) { |
Darin Petkov | cb71529 | 2012-04-25 13:04:37 +0200 | [diff] [blame] | 203 | SetArg(kPasswordProperty, kPassword); |
Darin Petkov | 4e9066f | 2012-06-11 13:17:06 +0200 | [diff] [blame] | 204 | SetArg(kPSKProperty, ""); |
Darin Petkov | cb71529 | 2012-04-25 13:04:37 +0200 | [diff] [blame] | 205 | MockStore storage; |
| 206 | EXPECT_CALL(storage, SetString(_, kPasswordProperty, _)).Times(0); |
| 207 | EXPECT_CALL(storage, SetCryptedString(_, kPasswordProperty, _)).Times(0); |
| 208 | EXPECT_CALL(storage, DeleteKey(kStorageID, _)).Times(AnyNumber()); |
| 209 | EXPECT_CALL(storage, DeleteKey(kStorageID, kPasswordProperty)).Times(1); |
Darin Petkov | 4e9066f | 2012-06-11 13:17:06 +0200 | [diff] [blame] | 210 | EXPECT_CALL(storage, DeleteKey(kStorageID, kPSKProperty)).Times(1); |
Darin Petkov | cb71529 | 2012-04-25 13:04:37 +0200 | [diff] [blame] | 211 | EXPECT_TRUE(driver_.Save(&storage, kStorageID, false)); |
| 212 | } |
| 213 | |
| 214 | TEST_F(VPNDriverTest, UnloadCredentials) { |
| 215 | SetArg(kOTPProperty, "654321"); |
| 216 | SetArg(kPasswordProperty, kPassword); |
| 217 | SetArg(kPortProperty, kPort); |
| 218 | driver_.UnloadCredentials(); |
| 219 | EXPECT_FALSE(GetArgs()->ContainsString(kOTPProperty)); |
| 220 | EXPECT_FALSE(GetArgs()->ContainsString(kPasswordProperty)); |
| 221 | EXPECT_EQ(kPort, GetArgs()->LookupString(kPortProperty, "")); |
Darin Petkov | b451d6e | 2012-04-23 11:56:41 +0200 | [diff] [blame] | 222 | } |
| 223 | |
| 224 | TEST_F(VPNDriverTest, InitPropertyStore) { |
| 225 | // Figure out if the store is actually hooked up to the driver argument |
| 226 | // KeyValueStore. |
| 227 | PropertyStore store; |
| 228 | driver_.InitPropertyStore(&store); |
| 229 | |
| 230 | // An un-set property should not be readable. |
Paul Stewart | e6e8e49 | 2013-01-17 11:00:50 -0800 | [diff] [blame] | 231 | { |
| 232 | Error error; |
| 233 | EXPECT_FALSE(store.GetStringProperty(kPortProperty, NULL, &error)); |
| 234 | EXPECT_EQ(Error::kInvalidArguments, error.type()); |
| 235 | } |
Paul Stewart | 8e7e459 | 2012-04-29 09:47:48 -0700 | [diff] [blame] | 236 | EXPECT_FALSE(GetProviderProperty(store, kPortProperty, NULL)); |
Darin Petkov | b451d6e | 2012-04-23 11:56:41 +0200 | [diff] [blame] | 237 | |
Darin Petkov | 4e02ba2 | 2013-04-02 13:44:08 +0200 | [diff] [blame] | 238 | const string kProviderType = "boo"; |
Darin Petkov | b451d6e | 2012-04-23 11:56:41 +0200 | [diff] [blame] | 239 | SetArg(kPortProperty, kPort); |
| 240 | SetArg(kPasswordProperty, kPassword); |
Darin Petkov | 4e02ba2 | 2013-04-02 13:44:08 +0200 | [diff] [blame] | 241 | SetArg(flimflam::kProviderTypeProperty, kProviderType); |
Darin Petkov | 4e9066f | 2012-06-11 13:17:06 +0200 | [diff] [blame] | 242 | SetArg(kHostProperty, ""); |
Darin Petkov | b451d6e | 2012-04-23 11:56:41 +0200 | [diff] [blame] | 243 | |
| 244 | // We should not be able to read a property out of the driver args using the |
| 245 | // key to the args directly. |
Paul Stewart | e6e8e49 | 2013-01-17 11:00:50 -0800 | [diff] [blame] | 246 | { |
| 247 | Error error; |
| 248 | EXPECT_FALSE(store.GetStringProperty(kPortProperty, NULL, &error)); |
| 249 | EXPECT_EQ(Error::kInvalidArguments, error.type()); |
| 250 | } |
Darin Petkov | b451d6e | 2012-04-23 11:56:41 +0200 | [diff] [blame] | 251 | |
| 252 | // We should instead be able to find it within the "Provider" stringmap. |
Paul Stewart | e6e8e49 | 2013-01-17 11:00:50 -0800 | [diff] [blame] | 253 | { |
| 254 | string value; |
| 255 | EXPECT_TRUE(GetProviderProperty(store, kPortProperty, &value)); |
| 256 | EXPECT_EQ(kPort, value); |
| 257 | } |
Darin Petkov | b451d6e | 2012-04-23 11:56:41 +0200 | [diff] [blame] | 258 | |
Darin Petkov | 4e9066f | 2012-06-11 13:17:06 +0200 | [diff] [blame] | 259 | // We should be able to read empty properties from the "Provider" stringmap. |
| 260 | { |
| 261 | string value; |
| 262 | EXPECT_TRUE(GetProviderProperty(store, kHostProperty, &value)); |
| 263 | EXPECT_TRUE(value.empty()); |
| 264 | } |
| 265 | |
Darin Petkov | b451d6e | 2012-04-23 11:56:41 +0200 | [diff] [blame] | 266 | // Properties that start with the prefix "Provider." should be mapped to the |
| 267 | // name in the Properties dict with the prefix removed. |
Paul Stewart | e6e8e49 | 2013-01-17 11:00:50 -0800 | [diff] [blame] | 268 | { |
| 269 | string value; |
Darin Petkov | 4e02ba2 | 2013-04-02 13:44:08 +0200 | [diff] [blame] | 270 | EXPECT_TRUE(GetProviderProperty(store, flimflam::kTypeProperty, &value)); |
| 271 | EXPECT_EQ(kProviderType, value); |
Paul Stewart | e6e8e49 | 2013-01-17 11:00:50 -0800 | [diff] [blame] | 272 | } |
Darin Petkov | b451d6e | 2012-04-23 11:56:41 +0200 | [diff] [blame] | 273 | |
Paul Stewart | 8e7e459 | 2012-04-29 09:47:48 -0700 | [diff] [blame] | 274 | // 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] | 275 | { |
| 276 | Error error; |
| 277 | EXPECT_TRUE(store.ClearProperty(kPortProperty, &error)); |
| 278 | EXPECT_TRUE(error.IsSuccess()); |
Paul Stewart | 8e7e459 | 2012-04-29 09:47:48 -0700 | [diff] [blame] | 279 | EXPECT_FALSE(GetProviderProperty(store, kPortProperty, NULL)); |
Darin Petkov | b451d6e | 2012-04-23 11:56:41 +0200 | [diff] [blame] | 280 | } |
| 281 | |
| 282 | // A second attempt to clear this property should return an error. |
| 283 | { |
| 284 | Error error; |
| 285 | EXPECT_FALSE(store.ClearProperty(kPortProperty, &error)); |
| 286 | EXPECT_EQ(Error::kNotFound, error.type()); |
| 287 | } |
| 288 | |
Darin Petkov | cb71529 | 2012-04-25 13:04:37 +0200 | [diff] [blame] | 289 | // Test write only properties. |
Paul Stewart | 8e7e459 | 2012-04-29 09:47:48 -0700 | [diff] [blame] | 290 | EXPECT_FALSE(GetProviderProperty(store, kPINProperty, NULL)); |
Darin Petkov | b451d6e | 2012-04-23 11:56:41 +0200 | [diff] [blame] | 291 | |
| 292 | // Write properties to the driver args using the PropertyStore interface. |
Darin Petkov | cb71529 | 2012-04-25 13:04:37 +0200 | [diff] [blame] | 293 | { |
| 294 | const string kValue = "some-value"; |
Darin Petkov | b451d6e | 2012-04-23 11:56:41 +0200 | [diff] [blame] | 295 | Error error; |
Darin Petkov | cb71529 | 2012-04-25 13:04:37 +0200 | [diff] [blame] | 296 | EXPECT_TRUE(store.SetStringProperty(kPINProperty, kValue, &error)); |
| 297 | EXPECT_EQ(kValue, GetArgs()->GetString(kPINProperty)); |
Darin Petkov | b451d6e | 2012-04-23 11:56:41 +0200 | [diff] [blame] | 298 | } |
| 299 | } |
| 300 | |
Darin Petkov | 602303f | 2012-06-06 12:15:59 +0200 | [diff] [blame] | 301 | TEST_F(VPNDriverTest, ConnectTimeout) { |
Darin Petkov | 0cd0d1e | 2013-02-11 12:49:10 +0100 | [diff] [blame] | 302 | EXPECT_EQ(&dispatcher_, dispatcher()); |
| 303 | EXPECT_TRUE(connect_timeout_callback().IsCancelled()); |
| 304 | EXPECT_FALSE(IsConnectTimeoutStarted()); |
| 305 | StartConnectTimeout(0); |
| 306 | EXPECT_FALSE(connect_timeout_callback().IsCancelled()); |
| 307 | EXPECT_TRUE(IsConnectTimeoutStarted()); |
| 308 | set_dispatcher(NULL); |
| 309 | StartConnectTimeout(0); // Expect no crash. |
Darin Petkov | 602303f | 2012-06-06 12:15:59 +0200 | [diff] [blame] | 310 | dispatcher_.DispatchPendingEvents(); |
Darin Petkov | 0cd0d1e | 2013-02-11 12:49:10 +0100 | [diff] [blame] | 311 | EXPECT_TRUE(connect_timeout_callback().IsCancelled()); |
| 312 | EXPECT_FALSE(IsConnectTimeoutStarted()); |
| 313 | } |
| 314 | |
| 315 | TEST_F(VPNDriverTest, StartStopConnectTimeout) { |
| 316 | EXPECT_FALSE(IsConnectTimeoutStarted()); |
| 317 | EXPECT_EQ(0, connect_timeout_seconds()); |
| 318 | const int kTimeout = 123; |
| 319 | StartConnectTimeout(kTimeout); |
| 320 | EXPECT_TRUE(IsConnectTimeoutStarted()); |
| 321 | EXPECT_EQ(kTimeout, connect_timeout_seconds()); |
| 322 | StartConnectTimeout(kTimeout - 20); |
| 323 | EXPECT_EQ(kTimeout, connect_timeout_seconds()); |
| 324 | StopConnectTimeout(); |
| 325 | EXPECT_FALSE(IsConnectTimeoutStarted()); |
| 326 | EXPECT_EQ(0, connect_timeout_seconds()); |
Darin Petkov | 602303f | 2012-06-06 12:15:59 +0200 | [diff] [blame] | 327 | } |
| 328 | |
Darin Petkov | b451d6e | 2012-04-23 11:56:41 +0200 | [diff] [blame] | 329 | } // namespace shill |