mukesh agrawal | 6bb9e7c | 2012-01-30 14:57:54 -0800 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium OS Authors. All rights reserved. |
Darin Petkov | e7cb7f8 | 2011-06-03 13:21:51 -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 | |
Chris Masone | 8a7b8be | 2011-07-22 12:43:37 -0700 | [diff] [blame] | 5 | #include "shill/dhcp_config.h" |
| 6 | |
Alex Vakulenko | 8a53229 | 2014-06-16 17:18:44 -0700 | [diff] [blame^] | 7 | #include <string> |
| 8 | #include <vector> |
| 9 | |
Eric Shienbrood | 3e20a23 | 2012-02-16 11:35:56 -0500 | [diff] [blame] | 10 | #include <base/bind.h> |
Darin Petkov | 92c4390 | 2011-06-09 20:46:06 -0700 | [diff] [blame] | 11 | #include <base/file_util.h> |
Paul Stewart | 5ad1606 | 2013-02-21 18:10:48 -0800 | [diff] [blame] | 12 | #include <base/files/scoped_temp_dir.h> |
Ben Chan | a0ddf46 | 2014-02-06 11:32:42 -0800 | [diff] [blame] | 13 | #include <base/strings/stringprintf.h> |
Chris Masone | 43b48a1 | 2011-07-01 13:37:07 -0700 | [diff] [blame] | 14 | #include <chromeos/dbus/service_constants.h> |
Darin Petkov | 92c4390 | 2011-06-09 20:46:06 -0700 | [diff] [blame] | 15 | |
Chris Masone | 43b48a1 | 2011-07-01 13:37:07 -0700 | [diff] [blame] | 16 | #include "shill/dbus_adaptor.h" |
Darin Petkov | f7897bc | 2011-06-08 17:13:36 -0700 | [diff] [blame] | 17 | #include "shill/dhcp_provider.h" |
Paul Stewart | 26b327e | 2011-10-19 11:38:09 -0700 | [diff] [blame] | 18 | #include "shill/event_dispatcher.h" |
Chris Masone | 19e3040 | 2011-07-19 15:48:47 -0700 | [diff] [blame] | 19 | #include "shill/mock_control.h" |
Darin Petkov | 98dd6a0 | 2011-06-10 15:12:57 -0700 | [diff] [blame] | 20 | #include "shill/mock_dhcp_proxy.h" |
Darin Petkov | f7897bc | 2011-06-08 17:13:36 -0700 | [diff] [blame] | 21 | #include "shill/mock_glib.h" |
mukesh agrawal | 6c6655d | 2012-12-06 14:49:50 -0800 | [diff] [blame] | 22 | #include "shill/mock_log.h" |
Jorge Lucangeli Obes | ad43cc6 | 2012-04-11 16:25:43 -0700 | [diff] [blame] | 23 | #include "shill/mock_minijail.h" |
Ben Chan | a55469d | 2014-01-27 16:35:29 -0800 | [diff] [blame] | 24 | #include "shill/mock_proxy_factory.h" |
Chris Masone | 43b48a1 | 2011-07-01 13:37:07 -0700 | [diff] [blame] | 25 | #include "shill/property_store_unittest.h" |
Ben Chan | a55469d | 2014-01-27 16:35:29 -0800 | [diff] [blame] | 26 | #include "shill/testing.h" |
Darin Petkov | e7cb7f8 | 2011-06-03 13:21:51 -0700 | [diff] [blame] | 27 | |
Eric Shienbrood | 3e20a23 | 2012-02-16 11:35:56 -0500 | [diff] [blame] | 28 | using base::Bind; |
Albert Chaulk | 0e1cdea | 2013-02-27 15:32:55 -0800 | [diff] [blame] | 29 | using base::FilePath; |
Paul Stewart | 5ad1606 | 2013-02-21 18:10:48 -0800 | [diff] [blame] | 30 | using base::ScopedTempDir; |
Eric Shienbrood | 3e20a23 | 2012-02-16 11:35:56 -0500 | [diff] [blame] | 31 | using base::Unretained; |
Darin Petkov | e7cb7f8 | 2011-06-03 13:21:51 -0700 | [diff] [blame] | 32 | using std::string; |
| 33 | using std::vector; |
Darin Petkov | f7897bc | 2011-06-08 17:13:36 -0700 | [diff] [blame] | 34 | using testing::_; |
mukesh agrawal | 1835e77 | 2013-01-15 18:35:03 -0800 | [diff] [blame] | 35 | using testing::AnyNumber; |
| 36 | using testing::ContainsRegex; |
Paul Stewart | 475c072 | 2014-04-18 08:52:00 -0700 | [diff] [blame] | 37 | using testing::InvokeWithoutArgs; |
Paul Stewart | 21f7b34 | 2013-11-19 10:15:58 -0800 | [diff] [blame] | 38 | using testing::Mock; |
Darin Petkov | f7897bc | 2011-06-08 17:13:36 -0700 | [diff] [blame] | 39 | using testing::Return; |
| 40 | using testing::SetArgumentPointee; |
Darin Petkov | e7cb7f8 | 2011-06-03 13:21:51 -0700 | [diff] [blame] | 41 | using testing::Test; |
| 42 | |
| 43 | namespace shill { |
| 44 | |
Darin Petkov | 92c4390 | 2011-06-09 20:46:06 -0700 | [diff] [blame] | 45 | namespace { |
Darin Petkov | a7b8949 | 2011-07-27 12:48:17 -0700 | [diff] [blame] | 46 | const char kDeviceName[] = "eth0"; |
Paul Stewart | d32f484 | 2012-01-11 16:08:13 -0800 | [diff] [blame] | 47 | const char kHostName[] = "hostname"; |
Paul Stewart | d408fdf | 2012-05-07 17:15:57 -0700 | [diff] [blame] | 48 | const char kLeaseFileSuffix[] = "leasefilesuffix"; |
| 49 | const bool kArpGateway = true; |
Paul Stewart | 75a68b9 | 2013-10-24 10:50:27 -0700 | [diff] [blame] | 50 | const bool kHasHostname = true; |
| 51 | const bool kHasLeaseSuffix = true; |
| 52 | const bool kMinimalConfig = true; |
Alex Vakulenko | 8a53229 | 2014-06-16 17:18:44 -0700 | [diff] [blame^] | 53 | } // namespace |
Darin Petkov | 92c4390 | 2011-06-09 20:46:06 -0700 | [diff] [blame] | 54 | |
Chris Masone | 43b48a1 | 2011-07-01 13:37:07 -0700 | [diff] [blame] | 55 | class DHCPConfigTest : public PropertyStoreTest { |
Darin Petkov | e7cb7f8 | 2011-06-03 13:21:51 -0700 | [diff] [blame] | 56 | public: |
Darin Petkov | f7897bc | 2011-06-08 17:13:36 -0700 | [diff] [blame] | 57 | DHCPConfigTest() |
Darin Petkov | f65e928 | 2011-06-21 14:29:56 -0700 | [diff] [blame] | 58 | : proxy_(new MockDHCPProxy()), |
Jorge Lucangeli Obes | ad43cc6 | 2012-04-11 16:25:43 -0700 | [diff] [blame] | 59 | minijail_(new MockMinijail()), |
Chris Masone | 19e3040 | 2011-07-19 15:48:47 -0700 | [diff] [blame] | 60 | config_(new DHCPConfig(&control_, |
Chris Masone | 2176a88 | 2011-09-14 22:29:15 -0700 | [diff] [blame] | 61 | dispatcher(), |
Chris Masone | 19e3040 | 2011-07-19 15:48:47 -0700 | [diff] [blame] | 62 | DHCPProvider::GetInstance(), |
Darin Petkov | 92c4390 | 2011-06-09 20:46:06 -0700 | [diff] [blame] | 63 | kDeviceName, |
Paul Stewart | d32f484 | 2012-01-11 16:08:13 -0800 | [diff] [blame] | 64 | kHostName, |
Paul Stewart | d408fdf | 2012-05-07 17:15:57 -0700 | [diff] [blame] | 65 | kLeaseFileSuffix, |
| 66 | kArpGateway, |
Paul Stewart | 75a68b9 | 2013-10-24 10:50:27 -0700 | [diff] [blame] | 67 | !kMinimalConfig, |
Chris Masone | 2176a88 | 2011-09-14 22:29:15 -0700 | [diff] [blame] | 68 | glib())) {} |
Darin Petkov | a7b8949 | 2011-07-27 12:48:17 -0700 | [diff] [blame] | 69 | |
| 70 | virtual void SetUp() { |
Darin Petkov | ab565bb | 2011-10-06 02:55:51 -0700 | [diff] [blame] | 71 | config_->proxy_factory_ = &proxy_factory_; |
Jorge Lucangeli Obes | ad43cc6 | 2012-04-11 16:25:43 -0700 | [diff] [blame] | 72 | config_->minijail_ = minijail_.get(); |
Darin Petkov | a7b8949 | 2011-07-27 12:48:17 -0700 | [diff] [blame] | 73 | } |
| 74 | |
| 75 | virtual void TearDown() { |
Darin Petkov | ab565bb | 2011-10-06 02:55:51 -0700 | [diff] [blame] | 76 | config_->proxy_factory_ = NULL; |
Jorge Lucangeli Obes | ad43cc6 | 2012-04-11 16:25:43 -0700 | [diff] [blame] | 77 | config_->minijail_ = NULL; |
Darin Petkov | 98dd6a0 | 2011-06-10 15:12:57 -0700 | [diff] [blame] | 78 | } |
Darin Petkov | e7cb7f8 | 2011-06-03 13:21:51 -0700 | [diff] [blame] | 79 | |
Paul Stewart | 475c072 | 2014-04-18 08:52:00 -0700 | [diff] [blame] | 80 | void StopInstance() { |
| 81 | config_->Stop("In test"); |
| 82 | } |
| 83 | |
Jorge Lucangeli Obes | ad43cc6 | 2012-04-11 16:25:43 -0700 | [diff] [blame] | 84 | DHCPConfigRefPtr CreateMockMinijailConfig(const string &hostname, |
Paul Stewart | 75a68b9 | 2013-10-24 10:50:27 -0700 | [diff] [blame] | 85 | const string &lease_suffix, |
| 86 | bool arp_gateway, |
| 87 | bool minimal_config); |
Paul Stewart | d408fdf | 2012-05-07 17:15:57 -0700 | [diff] [blame] | 88 | DHCPConfigRefPtr CreateRunningConfig(const string &hostname, |
| 89 | const string &lease_suffix, |
Paul Stewart | 75a68b9 | 2013-10-24 10:50:27 -0700 | [diff] [blame] | 90 | bool arp_gateway, |
| 91 | bool minimal_config); |
Paul Stewart | d408fdf | 2012-05-07 17:15:57 -0700 | [diff] [blame] | 92 | void StopRunningConfigAndExpect(DHCPConfigRefPtr config, |
| 93 | bool lease_file_exists); |
| 94 | |
Darin Petkov | e7cb7f8 | 2011-06-03 13:21:51 -0700 | [diff] [blame] | 95 | protected: |
Paul Stewart | d408fdf | 2012-05-07 17:15:57 -0700 | [diff] [blame] | 96 | static const int kPID; |
| 97 | static const unsigned int kTag; |
| 98 | |
| 99 | FilePath lease_file_; |
| 100 | FilePath pid_file_; |
| 101 | ScopedTempDir temp_dir_; |
Darin Petkov | a7b8949 | 2011-07-27 12:48:17 -0700 | [diff] [blame] | 102 | scoped_ptr<MockDHCPProxy> proxy_; |
Ben Chan | a55469d | 2014-01-27 16:35:29 -0800 | [diff] [blame] | 103 | MockProxyFactory proxy_factory_; |
Chris Masone | 19e3040 | 2011-07-19 15:48:47 -0700 | [diff] [blame] | 104 | MockControl control_; |
Jorge Lucangeli Obes | ad43cc6 | 2012-04-11 16:25:43 -0700 | [diff] [blame] | 105 | scoped_ptr<MockMinijail> minijail_; |
Darin Petkov | f7897bc | 2011-06-08 17:13:36 -0700 | [diff] [blame] | 106 | DHCPConfigRefPtr config_; |
Darin Petkov | e7cb7f8 | 2011-06-03 13:21:51 -0700 | [diff] [blame] | 107 | }; |
| 108 | |
Paul Stewart | d408fdf | 2012-05-07 17:15:57 -0700 | [diff] [blame] | 109 | const int DHCPConfigTest::kPID = 123456; |
| 110 | const unsigned int DHCPConfigTest::kTag = 77; |
| 111 | |
Jorge Lucangeli Obes | ad43cc6 | 2012-04-11 16:25:43 -0700 | [diff] [blame] | 112 | DHCPConfigRefPtr DHCPConfigTest::CreateMockMinijailConfig( |
Paul Stewart | 75a68b9 | 2013-10-24 10:50:27 -0700 | [diff] [blame] | 113 | const string &hostname, |
| 114 | const string &lease_suffix, |
| 115 | bool arp_gateway, |
| 116 | bool minimal_config) { |
Jorge Lucangeli Obes | ad43cc6 | 2012-04-11 16:25:43 -0700 | [diff] [blame] | 117 | DHCPConfigRefPtr config(new DHCPConfig(&control_, |
| 118 | dispatcher(), |
| 119 | DHCPProvider::GetInstance(), |
| 120 | kDeviceName, |
| 121 | hostname, |
| 122 | lease_suffix, |
| 123 | arp_gateway, |
Paul Stewart | 75a68b9 | 2013-10-24 10:50:27 -0700 | [diff] [blame] | 124 | minimal_config, |
Jorge Lucangeli Obes | ad43cc6 | 2012-04-11 16:25:43 -0700 | [diff] [blame] | 125 | glib())); |
| 126 | config->minijail_ = minijail_.get(); |
Jorge Lucangeli Obes | ad43cc6 | 2012-04-11 16:25:43 -0700 | [diff] [blame] | 127 | |
| 128 | return config; |
| 129 | } |
| 130 | |
Paul Stewart | 75a68b9 | 2013-10-24 10:50:27 -0700 | [diff] [blame] | 131 | DHCPConfigRefPtr DHCPConfigTest::CreateRunningConfig( |
| 132 | const string &hostname, |
| 133 | const string &lease_suffix, |
| 134 | bool arp_gateway, |
| 135 | bool minimal_config) { |
Paul Stewart | d408fdf | 2012-05-07 17:15:57 -0700 | [diff] [blame] | 136 | DHCPConfigRefPtr config(new DHCPConfig(&control_, |
| 137 | dispatcher(), |
| 138 | DHCPProvider::GetInstance(), |
| 139 | kDeviceName, |
| 140 | hostname, |
| 141 | lease_suffix, |
| 142 | arp_gateway, |
Paul Stewart | 75a68b9 | 2013-10-24 10:50:27 -0700 | [diff] [blame] | 143 | minimal_config, |
Paul Stewart | d408fdf | 2012-05-07 17:15:57 -0700 | [diff] [blame] | 144 | glib())); |
Jorge Lucangeli Obes | ad43cc6 | 2012-04-11 16:25:43 -0700 | [diff] [blame] | 145 | config->minijail_ = minijail_.get(); |
| 146 | EXPECT_CALL(*minijail_, RunAndDestroy(_, _, _)) |
| 147 | .WillOnce(DoAll(SetArgumentPointee<2>(kPID), Return(true))); |
Paul Stewart | d408fdf | 2012-05-07 17:15:57 -0700 | [diff] [blame] | 148 | EXPECT_CALL(*glib(), ChildWatchAdd(kPID, _, _)).WillOnce(Return(kTag)); |
| 149 | EXPECT_TRUE(config->Start()); |
| 150 | EXPECT_EQ(kPID, config->pid_); |
| 151 | EXPECT_EQ(config.get(), DHCPProvider::GetInstance()->GetConfig(kPID).get()); |
| 152 | EXPECT_EQ(kTag, config->child_watch_tag_); |
| 153 | |
| 154 | EXPECT_TRUE(temp_dir_.CreateUniqueTempDir()); |
| 155 | config->root_ = temp_dir_.path(); |
Jorge Lucangeli Obes | 2f3169d | 2012-04-25 11:38:25 -0700 | [diff] [blame] | 156 | FilePath varrun = temp_dir_.path().Append("var/run/dhcpcd"); |
Ben Chan | a0ddf46 | 2014-02-06 11:32:42 -0800 | [diff] [blame] | 157 | EXPECT_TRUE(base::CreateDirectory(varrun)); |
Paul Stewart | d408fdf | 2012-05-07 17:15:57 -0700 | [diff] [blame] | 158 | pid_file_ = varrun.Append(base::StringPrintf("dhcpcd-%s.pid", kDeviceName)); |
| 159 | FilePath varlib = temp_dir_.path().Append("var/lib/dhcpcd"); |
Ben Chan | a0ddf46 | 2014-02-06 11:32:42 -0800 | [diff] [blame] | 160 | EXPECT_TRUE(base::CreateDirectory(varlib)); |
Paul Stewart | d408fdf | 2012-05-07 17:15:57 -0700 | [diff] [blame] | 161 | lease_file_ = |
| 162 | varlib.Append(base::StringPrintf("dhcpcd-%s.lease", kDeviceName)); |
Ben Chan | 6fbf64f | 2014-05-21 18:07:01 -0700 | [diff] [blame] | 163 | EXPECT_EQ(0, base::WriteFile(pid_file_, "", 0)); |
| 164 | EXPECT_EQ(0, base::WriteFile(lease_file_, "", 0)); |
Ben Chan | a0ddf46 | 2014-02-06 11:32:42 -0800 | [diff] [blame] | 165 | EXPECT_TRUE(base::PathExists(pid_file_)); |
| 166 | EXPECT_TRUE(base::PathExists(lease_file_)); |
Paul Stewart | d408fdf | 2012-05-07 17:15:57 -0700 | [diff] [blame] | 167 | |
| 168 | return config; |
| 169 | } |
| 170 | |
| 171 | void DHCPConfigTest::StopRunningConfigAndExpect(DHCPConfigRefPtr config, |
| 172 | bool lease_file_exists) { |
mukesh agrawal | 6c6655d | 2012-12-06 14:49:50 -0800 | [diff] [blame] | 173 | ScopedMockLog log; |
| 174 | // We use a non-zero exit status so that we get the log message. |
| 175 | EXPECT_CALL(log, Log(_, _, ::testing::EndsWith("status 10"))); |
| 176 | DHCPConfig::ChildWatchCallback(kPID, 10, config.get()); |
Paul Stewart | d408fdf | 2012-05-07 17:15:57 -0700 | [diff] [blame] | 177 | EXPECT_EQ(NULL, DHCPProvider::GetInstance()->GetConfig(kPID).get()); |
| 178 | |
Ben Chan | a0ddf46 | 2014-02-06 11:32:42 -0800 | [diff] [blame] | 179 | EXPECT_FALSE(base::PathExists(pid_file_)); |
| 180 | EXPECT_EQ(lease_file_exists, base::PathExists(lease_file_)); |
Paul Stewart | d408fdf | 2012-05-07 17:15:57 -0700 | [diff] [blame] | 181 | } |
| 182 | |
Darin Petkov | e7cb7f8 | 2011-06-03 13:21:51 -0700 | [diff] [blame] | 183 | TEST_F(DHCPConfigTest, GetIPv4AddressString) { |
Darin Petkov | f7897bc | 2011-06-08 17:13:36 -0700 | [diff] [blame] | 184 | EXPECT_EQ("255.255.255.255", config_->GetIPv4AddressString(0xffffffff)); |
| 185 | EXPECT_EQ("0.0.0.0", config_->GetIPv4AddressString(0)); |
| 186 | EXPECT_EQ("1.2.3.4", config_->GetIPv4AddressString(0x04030201)); |
Darin Petkov | e7cb7f8 | 2011-06-03 13:21:51 -0700 | [diff] [blame] | 187 | } |
| 188 | |
Darin Petkov | a7b8949 | 2011-07-27 12:48:17 -0700 | [diff] [blame] | 189 | TEST_F(DHCPConfigTest, InitProxy) { |
| 190 | static const char kService[] = ":1.200"; |
Darin Petkov | a7b8949 | 2011-07-27 12:48:17 -0700 | [diff] [blame] | 191 | EXPECT_TRUE(proxy_.get()); |
| 192 | EXPECT_FALSE(config_->proxy_.get()); |
Ben Chan | a55469d | 2014-01-27 16:35:29 -0800 | [diff] [blame] | 193 | EXPECT_CALL(proxy_factory_, CreateDHCPProxy(kService)) |
| 194 | .WillOnce(ReturnAndReleasePointee(&proxy_)); |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 195 | config_->InitProxy(kService); |
Darin Petkov | a7b8949 | 2011-07-27 12:48:17 -0700 | [diff] [blame] | 196 | EXPECT_FALSE(proxy_.get()); |
| 197 | EXPECT_TRUE(config_->proxy_.get()); |
| 198 | |
| 199 | config_->InitProxy(kService); |
Darin Petkov | a7b8949 | 2011-07-27 12:48:17 -0700 | [diff] [blame] | 200 | } |
| 201 | |
Paul Stewart | 65bcd08 | 2012-11-16 09:37:14 -0800 | [diff] [blame] | 202 | TEST_F(DHCPConfigTest, ParseClasslessStaticRoutes) { |
| 203 | const string kDefaultAddress = "0.0.0.0"; |
| 204 | const string kDefaultDestination = kDefaultAddress + "/0"; |
| 205 | const string kRouter0 = "10.0.0.254"; |
| 206 | const string kAddress1 = "192.168.1.0"; |
| 207 | const string kDestination1 = kAddress1 + "/24"; |
| 208 | // Last gateway missing, leaving an odd number of parameters. |
| 209 | const string kBrokenClasslessRoutes0 = kDefaultDestination + " " + kRouter0 + |
| 210 | " " + kDestination1; |
| 211 | IPConfig::Properties properties; |
| 212 | EXPECT_FALSE(DHCPConfig::ParseClasslessStaticRoutes(kBrokenClasslessRoutes0, |
| 213 | &properties)); |
| 214 | EXPECT_TRUE(properties.routes.empty()); |
| 215 | EXPECT_TRUE(properties.gateway.empty()); |
| 216 | |
| 217 | // Gateway argument for the second route is malformed, but we were able |
| 218 | // to salvage a default gateway. |
| 219 | const string kBrokenRouter1 = "10.0.0"; |
| 220 | const string kBrokenClasslessRoutes1 = kBrokenClasslessRoutes0 + " " + |
| 221 | kBrokenRouter1; |
| 222 | EXPECT_FALSE(DHCPConfig::ParseClasslessStaticRoutes(kBrokenClasslessRoutes1, |
| 223 | &properties)); |
| 224 | EXPECT_TRUE(properties.routes.empty()); |
| 225 | EXPECT_EQ(kRouter0, properties.gateway); |
| 226 | |
| 227 | const string kRouter1 = "10.0.0.253"; |
| 228 | const string kRouter2 = "10.0.0.252"; |
| 229 | const string kClasslessRoutes0 = kDefaultDestination + " " + kRouter2 + " " + |
| 230 | kDestination1 + " " + kRouter1; |
| 231 | EXPECT_TRUE(DHCPConfig::ParseClasslessStaticRoutes(kClasslessRoutes0, |
| 232 | &properties)); |
| 233 | // The old default route is preserved. |
| 234 | EXPECT_EQ(kRouter0, properties.gateway); |
| 235 | |
| 236 | // The two routes (including the one which would have otherwise been |
| 237 | // classified as a default route) are added to the routing table. |
| 238 | EXPECT_EQ(2, properties.routes.size()); |
| 239 | const IPConfig::Route &route0 = properties.routes[0]; |
| 240 | EXPECT_EQ(kDefaultAddress, route0.host); |
| 241 | EXPECT_EQ("0.0.0.0", route0.netmask); |
| 242 | EXPECT_EQ(kRouter2, route0.gateway); |
| 243 | |
| 244 | const IPConfig::Route &route1 = properties.routes[1]; |
| 245 | EXPECT_EQ(kAddress1, route1.host); |
| 246 | EXPECT_EQ("255.255.255.0", route1.netmask); |
| 247 | EXPECT_EQ(kRouter1, route1.gateway); |
| 248 | |
| 249 | // A malformed routing table should not affect the current table. |
| 250 | EXPECT_FALSE(DHCPConfig::ParseClasslessStaticRoutes(kBrokenClasslessRoutes1, |
| 251 | &properties)); |
| 252 | EXPECT_EQ(2, properties.routes.size()); |
| 253 | EXPECT_EQ(kRouter0, properties.gateway); |
| 254 | } |
| 255 | |
Darin Petkov | e7cb7f8 | 2011-06-03 13:21:51 -0700 | [diff] [blame] | 256 | TEST_F(DHCPConfigTest, ParseConfiguration) { |
| 257 | DHCPConfig::Configuration conf; |
| 258 | conf[DHCPConfig::kConfigurationKeyIPAddress].writer().append_uint32( |
| 259 | 0x01020304); |
| 260 | conf[DHCPConfig::kConfigurationKeySubnetCIDR].writer().append_byte( |
| 261 | 16); |
| 262 | conf[DHCPConfig::kConfigurationKeyBroadcastAddress].writer().append_uint32( |
| 263 | 0x10203040); |
| 264 | { |
Darin Petkov | e7cb7f8 | 2011-06-03 13:21:51 -0700 | [diff] [blame] | 265 | vector<unsigned int> routers; |
| 266 | routers.push_back(0x02040608); |
| 267 | routers.push_back(0x03050709); |
Darin Petkov | f7897bc | 2011-06-08 17:13:36 -0700 | [diff] [blame] | 268 | DBus::MessageIter writer = |
| 269 | conf[DHCPConfig::kConfigurationKeyRouters].writer(); |
Darin Petkov | e7cb7f8 | 2011-06-03 13:21:51 -0700 | [diff] [blame] | 270 | writer << routers; |
Darin Petkov | e7cb7f8 | 2011-06-03 13:21:51 -0700 | [diff] [blame] | 271 | } |
| 272 | { |
Darin Petkov | e7cb7f8 | 2011-06-03 13:21:51 -0700 | [diff] [blame] | 273 | vector<unsigned int> dns; |
| 274 | dns.push_back(0x09070503); |
| 275 | dns.push_back(0x08060402); |
Darin Petkov | f7897bc | 2011-06-08 17:13:36 -0700 | [diff] [blame] | 276 | DBus::MessageIter writer = conf[DHCPConfig::kConfigurationKeyDNS].writer(); |
Darin Petkov | e7cb7f8 | 2011-06-03 13:21:51 -0700 | [diff] [blame] | 277 | writer << dns; |
Darin Petkov | e7cb7f8 | 2011-06-03 13:21:51 -0700 | [diff] [blame] | 278 | } |
| 279 | conf[DHCPConfig::kConfigurationKeyDomainName].writer().append_string( |
| 280 | "domain-name"); |
| 281 | { |
Darin Petkov | e7cb7f8 | 2011-06-03 13:21:51 -0700 | [diff] [blame] | 282 | vector<string> search; |
| 283 | search.push_back("foo.com"); |
| 284 | search.push_back("bar.com"); |
Darin Petkov | f7897bc | 2011-06-08 17:13:36 -0700 | [diff] [blame] | 285 | DBus::MessageIter writer = |
| 286 | conf[DHCPConfig::kConfigurationKeyDomainSearch].writer(); |
Darin Petkov | e7cb7f8 | 2011-06-03 13:21:51 -0700 | [diff] [blame] | 287 | writer << search; |
Darin Petkov | e7cb7f8 | 2011-06-03 13:21:51 -0700 | [diff] [blame] | 288 | } |
| 289 | conf[DHCPConfig::kConfigurationKeyMTU].writer().append_uint16(600); |
| 290 | conf["UnknownKey"] = DBus::Variant(); |
| 291 | |
Darin Petkov | e7cb7f8 | 2011-06-03 13:21:51 -0700 | [diff] [blame] | 292 | IPConfig::Properties properties; |
Darin Petkov | f7897bc | 2011-06-08 17:13:36 -0700 | [diff] [blame] | 293 | ASSERT_TRUE(config_->ParseConfiguration(conf, &properties)); |
Darin Petkov | e7cb7f8 | 2011-06-03 13:21:51 -0700 | [diff] [blame] | 294 | EXPECT_EQ("4.3.2.1", properties.address); |
Paul Stewart | 48100b0 | 2012-03-19 07:53:52 -0700 | [diff] [blame] | 295 | EXPECT_EQ(16, properties.subnet_prefix); |
Darin Petkov | e7cb7f8 | 2011-06-03 13:21:51 -0700 | [diff] [blame] | 296 | EXPECT_EQ("64.48.32.16", properties.broadcast_address); |
| 297 | EXPECT_EQ("8.6.4.2", properties.gateway); |
| 298 | ASSERT_EQ(2, properties.dns_servers.size()); |
| 299 | EXPECT_EQ("3.5.7.9", properties.dns_servers[0]); |
| 300 | EXPECT_EQ("2.4.6.8", properties.dns_servers[1]); |
| 301 | EXPECT_EQ("domain-name", properties.domain_name); |
| 302 | ASSERT_EQ(2, properties.domain_search.size()); |
| 303 | EXPECT_EQ("foo.com", properties.domain_search[0]); |
| 304 | EXPECT_EQ("bar.com", properties.domain_search[1]); |
| 305 | EXPECT_EQ(600, properties.mtu); |
| 306 | } |
| 307 | |
Darin Petkov | 92c4390 | 2011-06-09 20:46:06 -0700 | [diff] [blame] | 308 | TEST_F(DHCPConfigTest, StartFail) { |
Jorge Lucangeli Obes | ad43cc6 | 2012-04-11 16:25:43 -0700 | [diff] [blame] | 309 | EXPECT_CALL(*minijail_, RunAndDestroy(_, _, _)).WillOnce(Return(false)); |
Chris Masone | 2176a88 | 2011-09-14 22:29:15 -0700 | [diff] [blame] | 310 | EXPECT_CALL(*glib(), ChildWatchAdd(_, _, _)).Times(0); |
Darin Petkov | f7897bc | 2011-06-08 17:13:36 -0700 | [diff] [blame] | 311 | EXPECT_FALSE(config_->Start()); |
| 312 | EXPECT_EQ(0, config_->pid_); |
Darin Petkov | 92c4390 | 2011-06-09 20:46:06 -0700 | [diff] [blame] | 313 | } |
Darin Petkov | f7897bc | 2011-06-08 17:13:36 -0700 | [diff] [blame] | 314 | |
Paul Stewart | 75a68b9 | 2013-10-24 10:50:27 -0700 | [diff] [blame] | 315 | MATCHER_P4(IsDHCPCDArgs, has_hostname, has_arp_gateway, has_lease_suffix, |
| 316 | has_minimal_config, "") { |
Paul Stewart | d32f484 | 2012-01-11 16:08:13 -0800 | [diff] [blame] | 317 | if (string(arg[0]) != "/sbin/dhcpcd" || |
Paul Stewart | 75a68b9 | 2013-10-24 10:50:27 -0700 | [diff] [blame] | 318 | string(arg[1]) != "-B" || |
| 319 | string(arg[2]) != "-q") { |
Paul Stewart | d32f484 | 2012-01-11 16:08:13 -0800 | [diff] [blame] | 320 | return false; |
| 321 | } |
| 322 | |
Paul Stewart | 75a68b9 | 2013-10-24 10:50:27 -0700 | [diff] [blame] | 323 | int end_offset = 3; |
Paul Stewart | d32f484 | 2012-01-11 16:08:13 -0800 | [diff] [blame] | 324 | if (has_hostname) { |
Paul Stewart | d408fdf | 2012-05-07 17:15:57 -0700 | [diff] [blame] | 325 | if (string(arg[end_offset]) != "-h" || |
| 326 | string(arg[end_offset + 1]) != kHostName) { |
Paul Stewart | d32f484 | 2012-01-11 16:08:13 -0800 | [diff] [blame] | 327 | return false; |
| 328 | } |
Paul Stewart | d408fdf | 2012-05-07 17:15:57 -0700 | [diff] [blame] | 329 | end_offset += 2; |
Paul Stewart | d32f484 | 2012-01-11 16:08:13 -0800 | [diff] [blame] | 330 | } |
| 331 | |
Paul Stewart | d408fdf | 2012-05-07 17:15:57 -0700 | [diff] [blame] | 332 | if (has_arp_gateway) { |
Paul Stewart | 75a68b9 | 2013-10-24 10:50:27 -0700 | [diff] [blame] | 333 | if (string(arg[end_offset]) != "-R" || |
| 334 | string(arg[end_offset + 1]) != "-U") { |
Paul Stewart | d408fdf | 2012-05-07 17:15:57 -0700 | [diff] [blame] | 335 | return false; |
Paul Stewart | 75a68b9 | 2013-10-24 10:50:27 -0700 | [diff] [blame] | 336 | } |
| 337 | end_offset += 2; |
| 338 | } |
| 339 | |
| 340 | if (has_minimal_config) { |
| 341 | if (string(arg[end_offset]) != "-f" || |
| 342 | string(arg[end_offset + 1]) != "/etc/dhcpcd-minimal.conf") { |
| 343 | return false; |
| 344 | } |
| 345 | end_offset += 2; |
Paul Stewart | d408fdf | 2012-05-07 17:15:57 -0700 | [diff] [blame] | 346 | } |
| 347 | |
| 348 | string device_arg = has_lease_suffix ? |
| 349 | string(kDeviceName) + "=" + string(kLeaseFileSuffix) : kDeviceName; |
| 350 | return string(arg[end_offset]) == device_arg && arg[end_offset + 1] == NULL; |
Paul Stewart | d32f484 | 2012-01-11 16:08:13 -0800 | [diff] [blame] | 351 | } |
| 352 | |
| 353 | TEST_F(DHCPConfigTest, StartWithHostname) { |
Paul Stewart | 75a68b9 | 2013-10-24 10:50:27 -0700 | [diff] [blame] | 354 | EXPECT_CALL(*minijail_, RunAndDestroy(_, IsDHCPCDArgs(kHasHostname, |
| 355 | kArpGateway, |
| 356 | kHasLeaseSuffix, |
| 357 | !kMinimalConfig), _)) |
| 358 | .WillOnce(Return(false)); |
Paul Stewart | d32f484 | 2012-01-11 16:08:13 -0800 | [diff] [blame] | 359 | EXPECT_FALSE(config_->Start()); |
| 360 | } |
| 361 | |
| 362 | TEST_F(DHCPConfigTest, StartWithoutHostname) { |
Jorge Lucangeli Obes | ad43cc6 | 2012-04-11 16:25:43 -0700 | [diff] [blame] | 363 | DHCPConfigRefPtr config = CreateMockMinijailConfig("", |
| 364 | kLeaseFileSuffix, |
Paul Stewart | 75a68b9 | 2013-10-24 10:50:27 -0700 | [diff] [blame] | 365 | kArpGateway, |
| 366 | !kMinimalConfig); |
| 367 | EXPECT_CALL(*minijail_, RunAndDestroy(_, IsDHCPCDArgs(!kHasHostname, |
| 368 | kArpGateway, |
| 369 | kHasLeaseSuffix, |
| 370 | !kMinimalConfig), _)) |
| 371 | .WillOnce(Return(false)); |
Paul Stewart | d408fdf | 2012-05-07 17:15:57 -0700 | [diff] [blame] | 372 | EXPECT_FALSE(config->Start()); |
| 373 | } |
| 374 | |
| 375 | TEST_F(DHCPConfigTest, StartWithoutArpGateway) { |
Jorge Lucangeli Obes | ad43cc6 | 2012-04-11 16:25:43 -0700 | [diff] [blame] | 376 | DHCPConfigRefPtr config = CreateMockMinijailConfig(kHostName, |
| 377 | kLeaseFileSuffix, |
Paul Stewart | 75a68b9 | 2013-10-24 10:50:27 -0700 | [diff] [blame] | 378 | !kArpGateway, |
| 379 | !kMinimalConfig); |
| 380 | EXPECT_CALL(*minijail_, RunAndDestroy(_, IsDHCPCDArgs(kHasHostname, |
| 381 | !kArpGateway, |
| 382 | kHasLeaseSuffix, |
| 383 | !kMinimalConfig), _)) |
| 384 | .WillOnce(Return(false)); |
Paul Stewart | d408fdf | 2012-05-07 17:15:57 -0700 | [diff] [blame] | 385 | EXPECT_FALSE(config->Start()); |
| 386 | } |
| 387 | |
| 388 | TEST_F(DHCPConfigTest, StartWithoutLeaseSuffix) { |
Jorge Lucangeli Obes | ad43cc6 | 2012-04-11 16:25:43 -0700 | [diff] [blame] | 389 | DHCPConfigRefPtr config = CreateMockMinijailConfig(kHostName, |
| 390 | kDeviceName, |
Paul Stewart | 75a68b9 | 2013-10-24 10:50:27 -0700 | [diff] [blame] | 391 | kArpGateway, |
| 392 | !kMinimalConfig); |
| 393 | EXPECT_CALL(*minijail_, RunAndDestroy(_, IsDHCPCDArgs(kHasHostname, |
| 394 | kArpGateway, |
| 395 | !kHasLeaseSuffix, |
| 396 | !kMinimalConfig), _)) |
| 397 | .WillOnce(Return(false)); |
| 398 | EXPECT_FALSE(config->Start()); |
| 399 | } |
| 400 | |
| 401 | TEST_F(DHCPConfigTest, StartWithMinimalConfig) { |
| 402 | DHCPConfigRefPtr config = CreateMockMinijailConfig(kHostName, |
| 403 | kLeaseFileSuffix, |
| 404 | kArpGateway, |
| 405 | kMinimalConfig); |
| 406 | EXPECT_CALL(*minijail_, RunAndDestroy(_, IsDHCPCDArgs(kHasHostname, |
| 407 | kArpGateway, |
| 408 | kHasLeaseSuffix, |
| 409 | kMinimalConfig), _)) |
| 410 | .WillOnce(Return(false)); |
Paul Stewart | d32f484 | 2012-01-11 16:08:13 -0800 | [diff] [blame] | 411 | EXPECT_FALSE(config->Start()); |
| 412 | } |
| 413 | |
Darin Petkov | f9b0ca8 | 2011-06-20 12:10:23 -0700 | [diff] [blame] | 414 | namespace { |
| 415 | |
Paul Stewart | c509953 | 2013-12-12 07:53:15 -0800 | [diff] [blame] | 416 | class DHCPConfigCallbackTest : public DHCPConfigTest { |
Darin Petkov | f9b0ca8 | 2011-06-20 12:10:23 -0700 | [diff] [blame] | 417 | public: |
Paul Stewart | c509953 | 2013-12-12 07:53:15 -0800 | [diff] [blame] | 418 | virtual void SetUp() { |
| 419 | DHCPConfigTest::SetUp(); |
| 420 | config_->RegisterUpdateCallback( |
| 421 | Bind(&DHCPConfigCallbackTest::SuccessCallback, Unretained(this))); |
| 422 | config_->RegisterFailureCallback( |
| 423 | Bind(&DHCPConfigCallbackTest::FailureCallback, Unretained(this))); |
| 424 | ip_config_ = config_; |
Darin Petkov | f9b0ca8 | 2011-06-20 12:10:23 -0700 | [diff] [blame] | 425 | } |
| 426 | |
Paul Stewart | c509953 | 2013-12-12 07:53:15 -0800 | [diff] [blame] | 427 | MOCK_METHOD1(SuccessCallback, void(const IPConfigRefPtr &ipconfig)); |
| 428 | MOCK_METHOD1(FailureCallback, void(const IPConfigRefPtr &ipconfig)); |
| 429 | |
| 430 | // The mock methods above take IPConfigRefPtr because this is the type |
| 431 | // that the registered callbacks take. This conversion of the DHCP |
| 432 | // config ref pointer eases our work in setting up expectations. |
| 433 | const IPConfigRefPtr &ConfigRef() { return ip_config_; } |
Darin Petkov | f9b0ca8 | 2011-06-20 12:10:23 -0700 | [diff] [blame] | 434 | |
| 435 | private: |
Paul Stewart | c509953 | 2013-12-12 07:53:15 -0800 | [diff] [blame] | 436 | IPConfigRefPtr ip_config_; |
Darin Petkov | f9b0ca8 | 2011-06-20 12:10:23 -0700 | [diff] [blame] | 437 | }; |
| 438 | |
mukesh agrawal | cc0fded | 2012-05-09 13:40:58 -0700 | [diff] [blame] | 439 | void DoNothing() {} |
| 440 | |
Alex Vakulenko | 8a53229 | 2014-06-16 17:18:44 -0700 | [diff] [blame^] | 441 | } // namespace |
Darin Petkov | f9b0ca8 | 2011-06-20 12:10:23 -0700 | [diff] [blame] | 442 | |
Paul Stewart | c509953 | 2013-12-12 07:53:15 -0800 | [diff] [blame] | 443 | TEST_F(DHCPConfigCallbackTest, ProcessEventSignalFail) { |
Darin Petkov | f9b0ca8 | 2011-06-20 12:10:23 -0700 | [diff] [blame] | 444 | DHCPConfig::Configuration conf; |
| 445 | conf[DHCPConfig::kConfigurationKeyIPAddress].writer().append_uint32( |
| 446 | 0x01020304); |
Paul Stewart | c509953 | 2013-12-12 07:53:15 -0800 | [diff] [blame] | 447 | EXPECT_CALL(*this, SuccessCallback(_)).Times(0); |
| 448 | EXPECT_CALL(*this, FailureCallback(ConfigRef())); |
mukesh agrawal | cc0fded | 2012-05-09 13:40:58 -0700 | [diff] [blame] | 449 | config_->lease_acquisition_timeout_callback_.Reset(base::Bind(&DoNothing)); |
Paul Stewart | 1f916e4 | 2013-12-23 09:52:54 -0800 | [diff] [blame] | 450 | config_->lease_expiration_callback_.Reset(base::Bind(&DoNothing)); |
Darin Petkov | f9b0ca8 | 2011-06-20 12:10:23 -0700 | [diff] [blame] | 451 | config_->ProcessEventSignal(DHCPConfig::kReasonFail, conf); |
Paul Stewart | c509953 | 2013-12-12 07:53:15 -0800 | [diff] [blame] | 452 | Mock::VerifyAndClearExpectations(this); |
Darin Petkov | f9b0ca8 | 2011-06-20 12:10:23 -0700 | [diff] [blame] | 453 | EXPECT_TRUE(config_->properties().address.empty()); |
mukesh agrawal | cc0fded | 2012-05-09 13:40:58 -0700 | [diff] [blame] | 454 | EXPECT_TRUE(config_->lease_acquisition_timeout_callback_.IsCancelled()); |
Paul Stewart | 1f916e4 | 2013-12-23 09:52:54 -0800 | [diff] [blame] | 455 | EXPECT_TRUE(config_->lease_expiration_callback_.IsCancelled()); |
Darin Petkov | f9b0ca8 | 2011-06-20 12:10:23 -0700 | [diff] [blame] | 456 | } |
| 457 | |
Paul Stewart | c509953 | 2013-12-12 07:53:15 -0800 | [diff] [blame] | 458 | TEST_F(DHCPConfigCallbackTest, ProcessEventSignalSuccess) { |
Paul Stewart | 1f916e4 | 2013-12-23 09:52:54 -0800 | [diff] [blame] | 459 | for (const auto &reason : { DHCPConfig::kReasonBound, |
| 460 | DHCPConfig::kReasonRebind, |
| 461 | DHCPConfig::kReasonReboot, |
| 462 | DHCPConfig::kReasonRenew }) { |
| 463 | int address_octet = 0; |
| 464 | for (const auto lease_time_given : { false, true }) { |
| 465 | DHCPConfig::Configuration conf; |
| 466 | conf[DHCPConfig::kConfigurationKeyIPAddress].writer().append_uint32( |
| 467 | ++address_octet); |
| 468 | if (lease_time_given) { |
| 469 | const uint32 kLeaseTime = 1; |
| 470 | conf[DHCPConfig::kConfigurationKeyLeaseTime].writer().append_uint32( |
| 471 | kLeaseTime); |
| 472 | config_->lease_expiration_callback_.Cancel(); |
| 473 | } else { |
| 474 | config_->lease_expiration_callback_.Reset(base::Bind(&DoNothing)); |
| 475 | } |
| 476 | config_->lease_acquisition_timeout_callback_.Reset( |
| 477 | base::Bind(&DoNothing)); |
| 478 | EXPECT_CALL(*this, SuccessCallback(ConfigRef())); |
| 479 | EXPECT_CALL(*this, FailureCallback(_)).Times(0); |
| 480 | config_->ProcessEventSignal(reason, conf); |
| 481 | string failure_message = string(reason) + " failed with lease time " + |
| 482 | (lease_time_given ? "given" : "not given"); |
| 483 | EXPECT_TRUE(Mock::VerifyAndClearExpectations(this)) << failure_message; |
| 484 | EXPECT_EQ(base::StringPrintf("%d.0.0.0", address_octet), |
| 485 | config_->properties().address) << failure_message; |
| 486 | EXPECT_TRUE(config_->lease_acquisition_timeout_callback_.IsCancelled()) |
| 487 | << failure_message; |
| 488 | // With no lease time given, the expiration callback will be cancelled. |
| 489 | // With a lease time given, the expiration callback should be started. |
| 490 | EXPECT_EQ(!lease_time_given, |
| 491 | config_->lease_expiration_callback_.IsCancelled()) |
| 492 | << failure_message; |
| 493 | } |
Darin Petkov | f9b0ca8 | 2011-06-20 12:10:23 -0700 | [diff] [blame] | 494 | } |
| 495 | } |
| 496 | |
Paul Stewart | 475c072 | 2014-04-18 08:52:00 -0700 | [diff] [blame] | 497 | TEST_F(DHCPConfigCallbackTest, StoppedDuringFailureCallback) { |
| 498 | DHCPConfig::Configuration conf; |
| 499 | conf[DHCPConfig::kConfigurationKeyIPAddress].writer().append_uint32( |
| 500 | 0x01020304); |
| 501 | // Stop the DHCP config while it is calling the failure callback. We |
| 502 | // need to ensure that no callbacks are left running inadvertently as |
| 503 | // a result. |
| 504 | EXPECT_CALL(*this, FailureCallback(ConfigRef())) |
| 505 | .WillOnce(InvokeWithoutArgs(this, &DHCPConfigTest::StopInstance)); |
| 506 | config_->ProcessEventSignal(DHCPConfig::kReasonFail, conf); |
| 507 | EXPECT_TRUE(Mock::VerifyAndClearExpectations(this)); |
| 508 | EXPECT_TRUE(config_->lease_acquisition_timeout_callback_.IsCancelled()); |
| 509 | EXPECT_TRUE(config_->lease_expiration_callback_.IsCancelled()); |
| 510 | } |
| 511 | |
| 512 | TEST_F(DHCPConfigCallbackTest, StoppedDuringSuccessCallback) { |
| 513 | DHCPConfig::Configuration conf; |
| 514 | conf[DHCPConfig::kConfigurationKeyIPAddress].writer().append_uint32( |
| 515 | 0x01020304); |
| 516 | const uint32 kLeaseTime = 1; |
| 517 | conf[DHCPConfig::kConfigurationKeyLeaseTime].writer().append_uint32( |
| 518 | kLeaseTime); |
| 519 | // Stop the DHCP config while it is calling the success callback. This |
| 520 | // can happen if the device has a static IP configuration and releases |
| 521 | // the lease after accepting other network parameters from the DHCP |
| 522 | // IPConfig properties. We need to ensure that no callbacks are left |
| 523 | // running inadvertently as a result. |
| 524 | EXPECT_CALL(*this, SuccessCallback(ConfigRef())) |
| 525 | .WillOnce(InvokeWithoutArgs(this, &DHCPConfigTest::StopInstance)); |
| 526 | config_->ProcessEventSignal(DHCPConfig::kReasonBound, conf); |
| 527 | EXPECT_TRUE(Mock::VerifyAndClearExpectations(this)); |
| 528 | EXPECT_TRUE(config_->lease_acquisition_timeout_callback_.IsCancelled()); |
| 529 | EXPECT_TRUE(config_->lease_expiration_callback_.IsCancelled()); |
| 530 | } |
| 531 | |
Paul Stewart | c509953 | 2013-12-12 07:53:15 -0800 | [diff] [blame] | 532 | TEST_F(DHCPConfigCallbackTest, ProcessEventSignalUnknown) { |
Darin Petkov | f9b0ca8 | 2011-06-20 12:10:23 -0700 | [diff] [blame] | 533 | DHCPConfig::Configuration conf; |
| 534 | conf[DHCPConfig::kConfigurationKeyIPAddress].writer().append_uint32( |
| 535 | 0x01020304); |
| 536 | static const char kReasonUnknown[] = "UNKNOWN_REASON"; |
Paul Stewart | c509953 | 2013-12-12 07:53:15 -0800 | [diff] [blame] | 537 | EXPECT_CALL(*this, SuccessCallback(_)).Times(0); |
| 538 | EXPECT_CALL(*this, FailureCallback(_)).Times(0); |
mukesh agrawal | cc0fded | 2012-05-09 13:40:58 -0700 | [diff] [blame] | 539 | config_->lease_acquisition_timeout_callback_.Reset(base::Bind(&DoNothing)); |
Darin Petkov | f9b0ca8 | 2011-06-20 12:10:23 -0700 | [diff] [blame] | 540 | config_->ProcessEventSignal(kReasonUnknown, conf); |
Paul Stewart | c509953 | 2013-12-12 07:53:15 -0800 | [diff] [blame] | 541 | Mock::VerifyAndClearExpectations(this); |
Darin Petkov | f9b0ca8 | 2011-06-20 12:10:23 -0700 | [diff] [blame] | 542 | EXPECT_TRUE(config_->properties().address.empty()); |
mukesh agrawal | cc0fded | 2012-05-09 13:40:58 -0700 | [diff] [blame] | 543 | EXPECT_FALSE(config_->lease_acquisition_timeout_callback_.IsCancelled()); |
Darin Petkov | f9b0ca8 | 2011-06-20 12:10:23 -0700 | [diff] [blame] | 544 | } |
| 545 | |
Paul Stewart | c509953 | 2013-12-12 07:53:15 -0800 | [diff] [blame] | 546 | TEST_F(DHCPConfigCallbackTest, ProcessEventSignalGatewayArp) { |
Paul Stewart | 94571f1 | 2013-09-10 17:26:07 -0700 | [diff] [blame] | 547 | DHCPConfig::Configuration conf; |
| 548 | conf[DHCPConfig::kConfigurationKeyIPAddress].writer().append_uint32( |
| 549 | 0x01020304); |
Paul Stewart | c509953 | 2013-12-12 07:53:15 -0800 | [diff] [blame] | 550 | EXPECT_CALL(*this, SuccessCallback(ConfigRef())); |
| 551 | EXPECT_CALL(*this, FailureCallback(_)).Times(0); |
Paul Stewart | 94571f1 | 2013-09-10 17:26:07 -0700 | [diff] [blame] | 552 | EXPECT_CALL(*minijail_, RunAndDestroy(_, _, _)).WillOnce(Return(true)); |
| 553 | config_->Start(); |
| 554 | config_->ProcessEventSignal(DHCPConfig::kReasonGatewayArp, conf); |
Paul Stewart | c509953 | 2013-12-12 07:53:15 -0800 | [diff] [blame] | 555 | Mock::VerifyAndClearExpectations(this); |
Paul Stewart | 94571f1 | 2013-09-10 17:26:07 -0700 | [diff] [blame] | 556 | EXPECT_EQ("4.3.2.1", config_->properties().address); |
| 557 | EXPECT_FALSE(config_->lease_acquisition_timeout_callback_.IsCancelled()); |
| 558 | EXPECT_TRUE(config_->is_gateway_arp_active_); |
| 559 | |
| 560 | // If the timeout gets called, we shouldn't lose the lease since GatewayArp |
| 561 | // is active. |
| 562 | ScopedMockLog log; |
| 563 | EXPECT_CALL(log, Log(_, _, _)).Times(AnyNumber()); |
| 564 | EXPECT_CALL(log, Log(_, _, ::testing::EndsWith( |
| 565 | "Continuing to use our previous lease, due to gateway-ARP."))); |
Paul Stewart | c509953 | 2013-12-12 07:53:15 -0800 | [diff] [blame] | 566 | EXPECT_CALL(*this, SuccessCallback(_)).Times(0); |
| 567 | EXPECT_CALL(*this, FailureCallback(_)).Times(0); |
Paul Stewart | 94571f1 | 2013-09-10 17:26:07 -0700 | [diff] [blame] | 568 | config_->lease_acquisition_timeout_callback_.callback().Run(); |
Paul Stewart | c509953 | 2013-12-12 07:53:15 -0800 | [diff] [blame] | 569 | Mock::VerifyAndClearExpectations(this); |
Paul Stewart | 94571f1 | 2013-09-10 17:26:07 -0700 | [diff] [blame] | 570 | EXPECT_TRUE(config_->is_gateway_arp_active_); |
| 571 | |
| 572 | // An official reply from a DHCP server should reset our GatewayArp state. |
Paul Stewart | c509953 | 2013-12-12 07:53:15 -0800 | [diff] [blame] | 573 | EXPECT_CALL(*this, SuccessCallback(ConfigRef())); |
| 574 | EXPECT_CALL(*this, FailureCallback(_)).Times(0); |
Paul Stewart | 94571f1 | 2013-09-10 17:26:07 -0700 | [diff] [blame] | 575 | config_->ProcessEventSignal(DHCPConfig::kReasonRenew, conf); |
Paul Stewart | c509953 | 2013-12-12 07:53:15 -0800 | [diff] [blame] | 576 | Mock::VerifyAndClearExpectations(this); |
Paul Stewart | 94571f1 | 2013-09-10 17:26:07 -0700 | [diff] [blame] | 577 | EXPECT_FALSE(config_->is_gateway_arp_active_); |
| 578 | } |
| 579 | |
Paul Stewart | c509953 | 2013-12-12 07:53:15 -0800 | [diff] [blame] | 580 | TEST_F(DHCPConfigCallbackTest, ProcessEventSignalGatewayArpNak) { |
Paul Stewart | 94571f1 | 2013-09-10 17:26:07 -0700 | [diff] [blame] | 581 | DHCPConfig::Configuration conf; |
| 582 | conf[DHCPConfig::kConfigurationKeyIPAddress].writer().append_uint32( |
| 583 | 0x01020304); |
Paul Stewart | 94571f1 | 2013-09-10 17:26:07 -0700 | [diff] [blame] | 584 | EXPECT_CALL(*minijail_, RunAndDestroy(_, _, _)).WillOnce(Return(true)); |
| 585 | config_->Start(); |
| 586 | config_->ProcessEventSignal(DHCPConfig::kReasonGatewayArp, conf); |
| 587 | EXPECT_TRUE(config_->is_gateway_arp_active_); |
| 588 | |
| 589 | // Sending a NAK should clear is_gateway_arp_active_. |
| 590 | config_->ProcessEventSignal(DHCPConfig::kReasonNak, conf); |
| 591 | EXPECT_FALSE(config_->is_gateway_arp_active_); |
Paul Stewart | c509953 | 2013-12-12 07:53:15 -0800 | [diff] [blame] | 592 | Mock::VerifyAndClearExpectations(this); |
Paul Stewart | 94571f1 | 2013-09-10 17:26:07 -0700 | [diff] [blame] | 593 | |
| 594 | // If the timeout gets called, we should lose the lease since GatewayArp |
| 595 | // is not active any more. |
Paul Stewart | c509953 | 2013-12-12 07:53:15 -0800 | [diff] [blame] | 596 | EXPECT_CALL(*this, SuccessCallback(_)).Times(0); |
| 597 | EXPECT_CALL(*this, FailureCallback(ConfigRef())); |
Paul Stewart | 94571f1 | 2013-09-10 17:26:07 -0700 | [diff] [blame] | 598 | config_->lease_acquisition_timeout_callback_.callback().Run(); |
Paul Stewart | c509953 | 2013-12-12 07:53:15 -0800 | [diff] [blame] | 599 | Mock::VerifyAndClearExpectations(this); |
Paul Stewart | 94571f1 | 2013-09-10 17:26:07 -0700 | [diff] [blame] | 600 | } |
Darin Petkov | f9b0ca8 | 2011-06-20 12:10:23 -0700 | [diff] [blame] | 601 | |
Darin Petkov | 98dd6a0 | 2011-06-10 15:12:57 -0700 | [diff] [blame] | 602 | TEST_F(DHCPConfigTest, ReleaseIP) { |
| 603 | config_->pid_ = 1 << 18; // Ensure unknown positive PID. |
Paul Stewart | a02ee49 | 2012-05-16 10:04:53 -0700 | [diff] [blame] | 604 | config_->arp_gateway_ = false; |
Darin Petkov | aceede3 | 2011-07-18 15:32:38 -0700 | [diff] [blame] | 605 | EXPECT_CALL(*proxy_, Release(kDeviceName)).Times(1); |
Darin Petkov | a7b8949 | 2011-07-27 12:48:17 -0700 | [diff] [blame] | 606 | config_->proxy_.reset(proxy_.release()); |
Paul Stewart | 217c61d | 2013-06-13 15:12:02 -0700 | [diff] [blame] | 607 | EXPECT_TRUE(config_->ReleaseIP(IPConfig::kReleaseReasonDisconnect)); |
Darin Petkov | 98dd6a0 | 2011-06-10 15:12:57 -0700 | [diff] [blame] | 608 | config_->pid_ = 0; |
| 609 | } |
| 610 | |
Paul Stewart | a02ee49 | 2012-05-16 10:04:53 -0700 | [diff] [blame] | 611 | TEST_F(DHCPConfigTest, ReleaseIPArpGW) { |
| 612 | config_->pid_ = 1 << 18; // Ensure unknown positive PID. |
| 613 | config_->arp_gateway_ = true; |
| 614 | EXPECT_CALL(*proxy_, Release(kDeviceName)).Times(0); |
| 615 | config_->proxy_.reset(proxy_.release()); |
Paul Stewart | 217c61d | 2013-06-13 15:12:02 -0700 | [diff] [blame] | 616 | EXPECT_TRUE(config_->ReleaseIP(IPConfig::kReleaseReasonDisconnect)); |
| 617 | config_->pid_ = 0; |
| 618 | } |
| 619 | |
| 620 | TEST_F(DHCPConfigTest, ReleaseIPStaticIPWithLease) { |
| 621 | config_->pid_ = 1 << 18; // Ensure unknown positive PID. |
| 622 | config_->arp_gateway_ = true; |
| 623 | config_->is_lease_active_ = true; |
| 624 | EXPECT_CALL(*proxy_, Release(kDeviceName)); |
| 625 | config_->proxy_.reset(proxy_.release()); |
| 626 | EXPECT_TRUE(config_->ReleaseIP(IPConfig::kReleaseReasonStaticIP)); |
| 627 | EXPECT_EQ(NULL, config_->proxy_.get()); |
| 628 | config_->pid_ = 0; |
| 629 | } |
| 630 | |
| 631 | TEST_F(DHCPConfigTest, ReleaseIPStaticIPWithoutLease) { |
| 632 | config_->pid_ = 1 << 18; // Ensure unknown positive PID. |
| 633 | config_->arp_gateway_ = true; |
| 634 | config_->is_lease_active_ = false; |
| 635 | EXPECT_CALL(*proxy_, Release(kDeviceName)).Times(0); |
| 636 | MockDHCPProxy *proxy_pointer = proxy_.get(); |
| 637 | config_->proxy_.reset(proxy_.release()); |
| 638 | EXPECT_TRUE(config_->ReleaseIP(IPConfig::kReleaseReasonStaticIP)); |
| 639 | // Expect that proxy has not been released. |
| 640 | EXPECT_EQ(proxy_pointer, config_->proxy_.get()); |
Paul Stewart | a02ee49 | 2012-05-16 10:04:53 -0700 | [diff] [blame] | 641 | config_->pid_ = 0; |
| 642 | } |
| 643 | |
Darin Petkov | 98dd6a0 | 2011-06-10 15:12:57 -0700 | [diff] [blame] | 644 | TEST_F(DHCPConfigTest, RenewIP) { |
Paul Stewart | 21f7b34 | 2013-11-19 10:15:58 -0800 | [diff] [blame] | 645 | EXPECT_CALL(*minijail_, RunAndDestroy(_, _, _)).WillOnce(Return(false)); |
| 646 | config_->pid_ = 0; |
| 647 | EXPECT_FALSE(config_->RenewIP()); // Expect a call to Start() if pid_ is 0. |
| 648 | Mock::VerifyAndClearExpectations(minijail_.get()); |
| 649 | EXPECT_CALL(*minijail_, RunAndDestroy(_, _, _)).Times(0); |
mukesh agrawal | cc0fded | 2012-05-09 13:40:58 -0700 | [diff] [blame] | 650 | EXPECT_TRUE(config_->lease_acquisition_timeout_callback_.IsCancelled()); |
Paul Stewart | 1f916e4 | 2013-12-23 09:52:54 -0800 | [diff] [blame] | 651 | config_->lease_expiration_callback_.Reset(base::Bind(&DoNothing)); |
Darin Petkov | 98dd6a0 | 2011-06-10 15:12:57 -0700 | [diff] [blame] | 652 | config_->pid_ = 456; |
Paul Stewart | c02344a | 2012-08-17 16:57:37 -0700 | [diff] [blame] | 653 | EXPECT_FALSE(config_->RenewIP()); // Expect no crash with NULL proxy. |
Darin Petkov | aceede3 | 2011-07-18 15:32:38 -0700 | [diff] [blame] | 654 | EXPECT_CALL(*proxy_, Rebind(kDeviceName)).Times(1); |
Darin Petkov | a7b8949 | 2011-07-27 12:48:17 -0700 | [diff] [blame] | 655 | config_->proxy_.reset(proxy_.release()); |
Darin Petkov | 98dd6a0 | 2011-06-10 15:12:57 -0700 | [diff] [blame] | 656 | EXPECT_TRUE(config_->RenewIP()); |
mukesh agrawal | cc0fded | 2012-05-09 13:40:58 -0700 | [diff] [blame] | 657 | EXPECT_FALSE(config_->lease_acquisition_timeout_callback_.IsCancelled()); |
Paul Stewart | 1f916e4 | 2013-12-23 09:52:54 -0800 | [diff] [blame] | 658 | EXPECT_TRUE(config_->lease_expiration_callback_.IsCancelled()); |
Darin Petkov | 98dd6a0 | 2011-06-10 15:12:57 -0700 | [diff] [blame] | 659 | config_->pid_ = 0; |
| 660 | } |
| 661 | |
| 662 | TEST_F(DHCPConfigTest, RequestIP) { |
mukesh agrawal | cc0fded | 2012-05-09 13:40:58 -0700 | [diff] [blame] | 663 | EXPECT_TRUE(config_->lease_acquisition_timeout_callback_.IsCancelled()); |
Darin Petkov | 98dd6a0 | 2011-06-10 15:12:57 -0700 | [diff] [blame] | 664 | config_->pid_ = 567; |
Darin Petkov | aceede3 | 2011-07-18 15:32:38 -0700 | [diff] [blame] | 665 | EXPECT_CALL(*proxy_, Rebind(kDeviceName)).Times(1); |
Darin Petkov | a7b8949 | 2011-07-27 12:48:17 -0700 | [diff] [blame] | 666 | config_->proxy_.reset(proxy_.release()); |
Darin Petkov | 98dd6a0 | 2011-06-10 15:12:57 -0700 | [diff] [blame] | 667 | EXPECT_TRUE(config_->RenewIP()); |
mukesh agrawal | cc0fded | 2012-05-09 13:40:58 -0700 | [diff] [blame] | 668 | EXPECT_FALSE(config_->lease_acquisition_timeout_callback_.IsCancelled()); |
| 669 | config_->pid_ = 0; |
| 670 | } |
| 671 | |
Paul Stewart | c509953 | 2013-12-12 07:53:15 -0800 | [diff] [blame] | 672 | TEST_F(DHCPConfigCallbackTest, RequestIPTimeout) { |
| 673 | EXPECT_CALL(*this, SuccessCallback(_)).Times(0); |
| 674 | EXPECT_CALL(*this, FailureCallback(ConfigRef())); |
mukesh agrawal | cc0fded | 2012-05-09 13:40:58 -0700 | [diff] [blame] | 675 | config_->lease_acquisition_timeout_seconds_ = 0; |
| 676 | config_->pid_ = 567; |
| 677 | EXPECT_CALL(*proxy_, Rebind(kDeviceName)).Times(1); |
| 678 | config_->proxy_.reset(proxy_.release()); |
| 679 | config_->RenewIP(); |
| 680 | config_->dispatcher_->DispatchPendingEvents(); |
Paul Stewart | c509953 | 2013-12-12 07:53:15 -0800 | [diff] [blame] | 681 | Mock::VerifyAndClearExpectations(this); |
Darin Petkov | 98dd6a0 | 2011-06-10 15:12:57 -0700 | [diff] [blame] | 682 | config_->pid_ = 0; |
| 683 | } |
| 684 | |
| 685 | TEST_F(DHCPConfigTest, Restart) { |
| 686 | const int kPID1 = 1 << 17; // Ensure unknown positive PID. |
| 687 | const int kPID2 = 987; |
| 688 | const unsigned int kTag1 = 11; |
| 689 | const unsigned int kTag2 = 22; |
| 690 | config_->pid_ = kPID1; |
| 691 | config_->child_watch_tag_ = kTag1; |
| 692 | DHCPProvider::GetInstance()->BindPID(kPID1, config_); |
Chris Masone | 2176a88 | 2011-09-14 22:29:15 -0700 | [diff] [blame] | 693 | EXPECT_CALL(*glib(), SourceRemove(kTag1)).WillOnce(Return(true)); |
Jorge Lucangeli Obes | ad43cc6 | 2012-04-11 16:25:43 -0700 | [diff] [blame] | 694 | EXPECT_CALL(*minijail_, RunAndDestroy(_, _, _)).WillOnce( |
| 695 | DoAll(SetArgumentPointee<2>(kPID2), Return(true))); |
Chris Masone | 2176a88 | 2011-09-14 22:29:15 -0700 | [diff] [blame] | 696 | EXPECT_CALL(*glib(), ChildWatchAdd(kPID2, _, _)).WillOnce(Return(kTag2)); |
Darin Petkov | 98dd6a0 | 2011-06-10 15:12:57 -0700 | [diff] [blame] | 697 | EXPECT_TRUE(config_->Restart()); |
| 698 | EXPECT_EQ(kPID2, config_->pid_); |
| 699 | EXPECT_EQ(config_.get(), DHCPProvider::GetInstance()->GetConfig(kPID2).get()); |
| 700 | EXPECT_EQ(kTag2, config_->child_watch_tag_); |
| 701 | DHCPProvider::GetInstance()->UnbindPID(kPID2); |
| 702 | config_->pid_ = 0; |
| 703 | config_->child_watch_tag_ = 0; |
| 704 | } |
| 705 | |
| 706 | TEST_F(DHCPConfigTest, RestartNoClient) { |
| 707 | const int kPID = 777; |
| 708 | const unsigned int kTag = 66; |
Chris Masone | 2176a88 | 2011-09-14 22:29:15 -0700 | [diff] [blame] | 709 | EXPECT_CALL(*glib(), SourceRemove(_)).Times(0); |
Jorge Lucangeli Obes | ad43cc6 | 2012-04-11 16:25:43 -0700 | [diff] [blame] | 710 | EXPECT_CALL(*minijail_, RunAndDestroy(_, _, _)).WillOnce( |
| 711 | DoAll(SetArgumentPointee<2>(kPID), Return(true))); |
Chris Masone | 2176a88 | 2011-09-14 22:29:15 -0700 | [diff] [blame] | 712 | EXPECT_CALL(*glib(), ChildWatchAdd(kPID, _, _)).WillOnce(Return(kTag)); |
Darin Petkov | 98dd6a0 | 2011-06-10 15:12:57 -0700 | [diff] [blame] | 713 | EXPECT_TRUE(config_->Restart()); |
| 714 | EXPECT_EQ(kPID, config_->pid_); |
| 715 | EXPECT_EQ(config_.get(), DHCPProvider::GetInstance()->GetConfig(kPID).get()); |
| 716 | EXPECT_EQ(kTag, config_->child_watch_tag_); |
| 717 | DHCPProvider::GetInstance()->UnbindPID(kPID); |
| 718 | config_->pid_ = 0; |
| 719 | config_->child_watch_tag_ = 0; |
| 720 | } |
| 721 | |
Paul Stewart | d408fdf | 2012-05-07 17:15:57 -0700 | [diff] [blame] | 722 | TEST_F(DHCPConfigTest, StartSuccessEphemeral) { |
| 723 | DHCPConfigRefPtr config = |
Paul Stewart | 75a68b9 | 2013-10-24 10:50:27 -0700 | [diff] [blame] | 724 | CreateRunningConfig(kHostName, kDeviceName, kArpGateway, !kMinimalConfig); |
Paul Stewart | d408fdf | 2012-05-07 17:15:57 -0700 | [diff] [blame] | 725 | StopRunningConfigAndExpect(config, false); |
| 726 | } |
Darin Petkov | 92c4390 | 2011-06-09 20:46:06 -0700 | [diff] [blame] | 727 | |
Paul Stewart | d408fdf | 2012-05-07 17:15:57 -0700 | [diff] [blame] | 728 | TEST_F(DHCPConfigTest, StartSuccessPersistent) { |
| 729 | DHCPConfigRefPtr config = |
Paul Stewart | 75a68b9 | 2013-10-24 10:50:27 -0700 | [diff] [blame] | 730 | CreateRunningConfig(kHostName, kLeaseFileSuffix, kArpGateway, |
| 731 | !kMinimalConfig); |
Paul Stewart | d408fdf | 2012-05-07 17:15:57 -0700 | [diff] [blame] | 732 | StopRunningConfigAndExpect(config, true); |
Darin Petkov | f7897bc | 2011-06-08 17:13:36 -0700 | [diff] [blame] | 733 | } |
| 734 | |
Paul Stewart | c509953 | 2013-12-12 07:53:15 -0800 | [diff] [blame] | 735 | TEST_F(DHCPConfigCallbackTest, StartTimeout) { |
| 736 | EXPECT_CALL(*this, SuccessCallback(_)).Times(0); |
| 737 | EXPECT_CALL(*this, FailureCallback(ConfigRef())); |
mukesh agrawal | cc0fded | 2012-05-09 13:40:58 -0700 | [diff] [blame] | 738 | config_->lease_acquisition_timeout_seconds_ = 0; |
| 739 | config_->proxy_.reset(proxy_.release()); |
Jorge Lucangeli Obes | ad43cc6 | 2012-04-11 16:25:43 -0700 | [diff] [blame] | 740 | EXPECT_CALL(*minijail_, RunAndDestroy(_, _, _)).WillOnce(Return(true)); |
mukesh agrawal | cc0fded | 2012-05-09 13:40:58 -0700 | [diff] [blame] | 741 | config_->Start(); |
| 742 | config_->dispatcher_->DispatchPendingEvents(); |
Paul Stewart | c509953 | 2013-12-12 07:53:15 -0800 | [diff] [blame] | 743 | Mock::VerifyAndClearExpectations(this); |
mukesh agrawal | cc0fded | 2012-05-09 13:40:58 -0700 | [diff] [blame] | 744 | } |
| 745 | |
Darin Petkov | 98dd6a0 | 2011-06-10 15:12:57 -0700 | [diff] [blame] | 746 | TEST_F(DHCPConfigTest, Stop) { |
Darin Petkov | 98dd6a0 | 2011-06-10 15:12:57 -0700 | [diff] [blame] | 747 | const int kPID = 1 << 17; // Ensure unknown positive PID. |
mukesh agrawal | 1835e77 | 2013-01-15 18:35:03 -0800 | [diff] [blame] | 748 | ScopedMockLog log; |
| 749 | EXPECT_CALL(log, Log(_, _, _)).Times(AnyNumber()); |
| 750 | EXPECT_CALL(log, Log(_, _, ContainsRegex( |
Darin Petkov | 3fe1766 | 2013-02-04 14:19:08 +0100 | [diff] [blame] | 751 | base::StringPrintf("Stopping.+%s", __func__)))); |
Darin Petkov | 98dd6a0 | 2011-06-10 15:12:57 -0700 | [diff] [blame] | 752 | config_->pid_ = kPID; |
Darin Petkov | 3fe1766 | 2013-02-04 14:19:08 +0100 | [diff] [blame] | 753 | DHCPProvider::GetInstance()->BindPID(kPID, config_); |
Paul Stewart | 1f916e4 | 2013-12-23 09:52:54 -0800 | [diff] [blame] | 754 | config_->lease_acquisition_timeout_callback_.Reset(base::Bind(&DoNothing)); |
| 755 | config_->lease_expiration_callback_.Reset(base::Bind(&DoNothing)); |
mukesh agrawal | 1835e77 | 2013-01-15 18:35:03 -0800 | [diff] [blame] | 756 | config_->Stop(__func__); |
mukesh agrawal | cc0fded | 2012-05-09 13:40:58 -0700 | [diff] [blame] | 757 | EXPECT_TRUE(config_->lease_acquisition_timeout_callback_.IsCancelled()); |
Paul Stewart | 1f916e4 | 2013-12-23 09:52:54 -0800 | [diff] [blame] | 758 | EXPECT_TRUE(config_->lease_expiration_callback_.IsCancelled()); |
Darin Petkov | 3fe1766 | 2013-02-04 14:19:08 +0100 | [diff] [blame] | 759 | EXPECT_FALSE(DHCPProvider::GetInstance()->GetConfig(kPID)); |
| 760 | EXPECT_FALSE(config_->pid_); |
mukesh agrawal | cc0fded | 2012-05-09 13:40:58 -0700 | [diff] [blame] | 761 | } |
| 762 | |
| 763 | TEST_F(DHCPConfigTest, StopDuringRequestIP) { |
| 764 | config_->pid_ = 567; |
| 765 | EXPECT_CALL(*proxy_, Rebind(kDeviceName)).Times(1); |
| 766 | config_->proxy_.reset(proxy_.release()); |
| 767 | EXPECT_TRUE(config_->RenewIP()); |
| 768 | EXPECT_FALSE(config_->lease_acquisition_timeout_callback_.IsCancelled()); |
| 769 | config_->pid_ = 0; // Keep Stop from killing a real process. |
mukesh agrawal | 1835e77 | 2013-01-15 18:35:03 -0800 | [diff] [blame] | 770 | config_->Stop(__func__); |
mukesh agrawal | cc0fded | 2012-05-09 13:40:58 -0700 | [diff] [blame] | 771 | EXPECT_TRUE(config_->lease_acquisition_timeout_callback_.IsCancelled()); |
Darin Petkov | 98dd6a0 | 2011-06-10 15:12:57 -0700 | [diff] [blame] | 772 | } |
| 773 | |
mukesh agrawal | 6bb9e7c | 2012-01-30 14:57:54 -0800 | [diff] [blame] | 774 | TEST_F(DHCPConfigTest, SetProperty) { |
Chris Masone | 43b48a1 | 2011-07-01 13:37:07 -0700 | [diff] [blame] | 775 | ::DBus::Error error; |
| 776 | // Ensure that an attempt to write a R/O property returns InvalidArgs error. |
mukesh agrawal | 6bb9e7c | 2012-01-30 14:57:54 -0800 | [diff] [blame] | 777 | EXPECT_FALSE(DBusAdaptor::SetProperty(config_->mutable_store(), |
Ben Chan | 0295e0f | 2013-09-20 13:47:29 -0700 | [diff] [blame] | 778 | kAddressProperty, |
mukesh agrawal | 6bb9e7c | 2012-01-30 14:57:54 -0800 | [diff] [blame] | 779 | PropertyStoreTest::kStringV, |
| 780 | &error)); |
mukesh agrawal | bebf1b8 | 2013-04-23 15:06:33 -0700 | [diff] [blame] | 781 | ASSERT_TRUE(error.is_set()); // name() may be invalid otherwise |
Chris Masone | 9d77993 | 2011-08-25 16:33:41 -0700 | [diff] [blame] | 782 | EXPECT_EQ(invalid_args(), error.name()); |
Chris Masone | 43b48a1 | 2011-07-01 13:37:07 -0700 | [diff] [blame] | 783 | } |
| 784 | |
Darin Petkov | e7cb7f8 | 2011-06-03 13:21:51 -0700 | [diff] [blame] | 785 | } // namespace shill |