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