Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium OS Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include <base/logging.h> |
| 6 | #include <chromeos/dbus/service_constants.h> |
| 7 | #include <gtest/gtest.h> |
| 8 | #include <string> |
| 9 | |
| 10 | #include "update_engine/connection_manager.h" |
Gilad Arnold | 5bb4c90 | 2014-04-10 12:32:13 -0700 | [diff] [blame] | 11 | #include "update_engine/fake_system_state.h" |
Gilad Arnold | 1b9d6ae | 2014-03-03 13:46:07 -0800 | [diff] [blame] | 12 | #include "update_engine/mock_dbus_wrapper.h" |
Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 13 | |
| 14 | using std::set; |
| 15 | using std::string; |
| 16 | using testing::_; |
| 17 | using testing::AnyNumber; |
| 18 | using testing::Return; |
| 19 | using testing::SetArgumentPointee; |
| 20 | using testing::StrEq; |
| 21 | |
| 22 | namespace chromeos_update_engine { |
| 23 | |
| 24 | class ConnectionManagerTest : public ::testing::Test { |
| 25 | public: |
| 26 | ConnectionManagerTest() |
| 27 | : kMockFlimFlamManagerProxy_(NULL), |
| 28 | kMockFlimFlamServiceProxy_(NULL), |
| 29 | kServicePath_(NULL), |
Gilad Arnold | 5bb4c90 | 2014-04-10 12:32:13 -0700 | [diff] [blame] | 30 | cmut_(&fake_system_state_) { |
| 31 | fake_system_state_.set_connection_manager(&cmut_); |
Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 32 | } |
| 33 | |
| 34 | protected: |
| 35 | void SetupMocks(const char* service_path); |
| 36 | void SetManagerReply(gconstpointer value, const GType& type); |
Alex Deymo | 1c4e638 | 2013-07-15 12:09:51 -0700 | [diff] [blame] | 37 | |
| 38 | // Sets the |service_type| Type and the |physical_technology| |
| 39 | // PhysicalTechnology properties in the mocked service. If a NULL |
| 40 | // |physical_technology| is passed, the property is not set (not present). |
| 41 | void SetServiceReply(const char* service_type, |
Alex Deymo | 6ae9120 | 2014-03-10 19:21:25 -0700 | [diff] [blame] | 42 | const char* physical_technology, |
| 43 | const char* service_tethering); |
Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 44 | void TestWithServiceType( |
Alex Deymo | 1c4e638 | 2013-07-15 12:09:51 -0700 | [diff] [blame] | 45 | const char* service_type, |
| 46 | const char* physical_technology, |
| 47 | NetworkConnectionType expected_type); |
Alex Deymo | 6ae9120 | 2014-03-10 19:21:25 -0700 | [diff] [blame] | 48 | void TestWithServiceTethering( |
| 49 | const char* service_tethering, |
| 50 | NetworkTethering expected_tethering); |
Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 51 | |
| 52 | static const char* kGetPropertiesMethod; |
| 53 | DBusGProxy* kMockFlimFlamManagerProxy_; |
| 54 | DBusGProxy* kMockFlimFlamServiceProxy_; |
| 55 | DBusGConnection* kMockSystemBus_; |
| 56 | const char* kServicePath_; |
Gilad Arnold | 1b9d6ae | 2014-03-03 13:46:07 -0800 | [diff] [blame] | 57 | MockDBusWrapper dbus_iface_; |
Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 58 | ConnectionManager cmut_; // ConnectionManager under test. |
Gilad Arnold | 5bb4c90 | 2014-04-10 12:32:13 -0700 | [diff] [blame] | 59 | FakeSystemState fake_system_state_; |
Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 60 | }; |
| 61 | |
| 62 | // static |
| 63 | const char* ConnectionManagerTest::kGetPropertiesMethod = "GetProperties"; |
| 64 | |
| 65 | void ConnectionManagerTest::SetupMocks(const char* service_path) { |
| 66 | int number = 1; |
| 67 | kMockSystemBus_ = reinterpret_cast<DBusGConnection*>(number++); |
| 68 | kMockFlimFlamManagerProxy_ = reinterpret_cast<DBusGProxy*>(number++); |
| 69 | kMockFlimFlamServiceProxy_ = reinterpret_cast<DBusGProxy*>(number++); |
| 70 | ASSERT_NE(kMockSystemBus_, reinterpret_cast<DBusGConnection*>(NULL)); |
| 71 | |
| 72 | kServicePath_ = service_path; |
| 73 | |
| 74 | ON_CALL(dbus_iface_, BusGet(DBUS_BUS_SYSTEM, _)) |
| 75 | .WillByDefault(Return(kMockSystemBus_)); |
| 76 | EXPECT_CALL(dbus_iface_, BusGet(DBUS_BUS_SYSTEM, _)) |
| 77 | .Times(AnyNumber()); |
| 78 | } |
| 79 | |
| 80 | void ConnectionManagerTest::SetManagerReply(gconstpointer reply_value, |
| 81 | const GType& reply_type) { |
| 82 | // Initialize return value for D-Bus call to Manager object. |
| 83 | // TODO (jaysri): Free the objects allocated here. |
| 84 | GHashTable* manager_hash_table = g_hash_table_new(g_str_hash, g_str_equal); |
| 85 | |
| 86 | GArray* array = g_array_new(FALSE, FALSE, sizeof(const char*)); |
| 87 | ASSERT_TRUE(array != NULL); |
| 88 | |
| 89 | EXPECT_EQ(array, g_array_append_val(array, reply_value)); |
| 90 | GValue* array_as_value = g_new0(GValue, 1); |
| 91 | EXPECT_EQ(array_as_value, g_value_init(array_as_value, reply_type)); |
| 92 | g_value_take_boxed(array_as_value, array); |
| 93 | g_hash_table_insert(manager_hash_table, |
| 94 | const_cast<char*>("Services"), |
| 95 | array_as_value); |
| 96 | |
| 97 | // Plumb return value into mock object. |
Gilad Arnold | b752fb3 | 2014-03-03 12:23:39 -0800 | [diff] [blame] | 98 | EXPECT_CALL(dbus_iface_, ProxyCall_0_1(kMockFlimFlamManagerProxy_, |
| 99 | StrEq(kGetPropertiesMethod), |
| 100 | _, _)) |
| 101 | .WillOnce(DoAll(SetArgumentPointee<3>(manager_hash_table), Return(TRUE))); |
Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 102 | |
| 103 | // Set other expectations. |
| 104 | EXPECT_CALL(dbus_iface_, |
Gilad Arnold | b752fb3 | 2014-03-03 12:23:39 -0800 | [diff] [blame] | 105 | ProxyNewForName(kMockSystemBus_, |
| 106 | StrEq(shill::kFlimflamServiceName), |
| 107 | StrEq(shill::kFlimflamServicePath), |
| 108 | StrEq(shill::kFlimflamManagerInterface))) |
Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 109 | .WillOnce(Return(kMockFlimFlamManagerProxy_)); |
| 110 | EXPECT_CALL(dbus_iface_, ProxyUnref(kMockFlimFlamManagerProxy_)); |
| 111 | EXPECT_CALL(dbus_iface_, BusGet(DBUS_BUS_SYSTEM, _)) |
| 112 | .RetiresOnSaturation(); |
| 113 | } |
| 114 | |
Alex Deymo | 1c4e638 | 2013-07-15 12:09:51 -0700 | [diff] [blame] | 115 | void ConnectionManagerTest::SetServiceReply(const char* service_type, |
Alex Deymo | 6ae9120 | 2014-03-10 19:21:25 -0700 | [diff] [blame] | 116 | const char* physical_technology, |
| 117 | const char* service_tethering) { |
Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 118 | // Initialize return value for D-Bus call to Service object. |
| 119 | // TODO (jaysri): Free the objects allocated here. |
| 120 | GHashTable* service_hash_table = g_hash_table_new(g_str_hash, g_str_equal); |
| 121 | |
| 122 | GValue* service_type_value = g_new0(GValue, 1); |
| 123 | EXPECT_EQ(service_type_value, |
| 124 | g_value_init(service_type_value, G_TYPE_STRING)); |
| 125 | g_value_set_static_string(service_type_value, service_type); |
| 126 | |
| 127 | g_hash_table_insert(service_hash_table, |
| 128 | const_cast<char*>("Type"), |
| 129 | service_type_value); |
| 130 | |
Alex Deymo | 1c4e638 | 2013-07-15 12:09:51 -0700 | [diff] [blame] | 131 | if (physical_technology != NULL) { |
| 132 | GValue* physical_technology_value = g_new0(GValue, 1); |
| 133 | EXPECT_EQ(physical_technology_value, |
| 134 | g_value_init(physical_technology_value, G_TYPE_STRING)); |
| 135 | g_value_set_static_string(physical_technology_value, physical_technology); |
| 136 | |
| 137 | g_hash_table_insert(service_hash_table, |
| 138 | const_cast<char*>("PhysicalTechnology"), |
| 139 | physical_technology_value); |
| 140 | } |
| 141 | |
Alex Deymo | 6ae9120 | 2014-03-10 19:21:25 -0700 | [diff] [blame] | 142 | if (service_tethering != NULL) { |
| 143 | GValue* service_tethering_value = g_new0(GValue, 1); |
| 144 | EXPECT_EQ(service_tethering_value, |
| 145 | g_value_init(service_tethering_value, G_TYPE_STRING)); |
| 146 | g_value_set_static_string(service_tethering_value, service_tethering); |
| 147 | |
| 148 | g_hash_table_insert(service_hash_table, |
| 149 | const_cast<char*>("Tethering"), |
| 150 | service_tethering_value); |
| 151 | } |
| 152 | |
Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 153 | // Plumb return value into mock object. |
Gilad Arnold | b752fb3 | 2014-03-03 12:23:39 -0800 | [diff] [blame] | 154 | EXPECT_CALL(dbus_iface_, ProxyCall_0_1(kMockFlimFlamServiceProxy_, |
| 155 | StrEq(kGetPropertiesMethod), |
| 156 | _, _)) |
| 157 | .WillOnce(DoAll(SetArgumentPointee<3>(service_hash_table), Return(TRUE))); |
Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 158 | |
| 159 | // Set other expectations. |
| 160 | EXPECT_CALL(dbus_iface_, |
Gilad Arnold | b752fb3 | 2014-03-03 12:23:39 -0800 | [diff] [blame] | 161 | ProxyNewForName(kMockSystemBus_, |
| 162 | StrEq(shill::kFlimflamServiceName), |
| 163 | StrEq(kServicePath_), |
| 164 | StrEq(shill::kFlimflamServiceInterface))) |
Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 165 | .WillOnce(Return(kMockFlimFlamServiceProxy_)); |
| 166 | EXPECT_CALL(dbus_iface_, ProxyUnref(kMockFlimFlamServiceProxy_)); |
| 167 | EXPECT_CALL(dbus_iface_, BusGet(DBUS_BUS_SYSTEM, _)) |
| 168 | .RetiresOnSaturation(); |
| 169 | } |
| 170 | |
| 171 | void ConnectionManagerTest::TestWithServiceType( |
| 172 | const char* service_type, |
Alex Deymo | 1c4e638 | 2013-07-15 12:09:51 -0700 | [diff] [blame] | 173 | const char* physical_technology, |
Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 174 | NetworkConnectionType expected_type) { |
| 175 | |
| 176 | SetupMocks("/service/guest-network"); |
| 177 | SetManagerReply(kServicePath_, DBUS_TYPE_G_OBJECT_PATH_ARRAY); |
Alex Deymo | 6ae9120 | 2014-03-10 19:21:25 -0700 | [diff] [blame] | 178 | SetServiceReply(service_type, physical_technology, |
| 179 | shill::kTetheringNotDetectedState); |
Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 180 | |
| 181 | NetworkConnectionType type; |
Alex Deymo | 6ae9120 | 2014-03-10 19:21:25 -0700 | [diff] [blame] | 182 | NetworkTethering tethering; |
| 183 | EXPECT_TRUE(cmut_.GetConnectionProperties(&dbus_iface_, &type, &tethering)); |
Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 184 | EXPECT_EQ(expected_type, type); |
| 185 | } |
| 186 | |
Alex Deymo | 6ae9120 | 2014-03-10 19:21:25 -0700 | [diff] [blame] | 187 | void ConnectionManagerTest::TestWithServiceTethering( |
| 188 | const char* service_tethering, |
| 189 | NetworkTethering expected_tethering) { |
| 190 | |
| 191 | SetupMocks("/service/guest-network"); |
| 192 | SetManagerReply(kServicePath_, DBUS_TYPE_G_OBJECT_PATH_ARRAY); |
| 193 | SetServiceReply(shill::kTypeWifi, NULL, service_tethering); |
| 194 | |
| 195 | NetworkConnectionType type; |
| 196 | NetworkTethering tethering; |
| 197 | EXPECT_TRUE(cmut_.GetConnectionProperties(&dbus_iface_, &type, &tethering)); |
| 198 | EXPECT_EQ(expected_tethering, tethering); |
| 199 | } |
| 200 | |
Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 201 | TEST_F(ConnectionManagerTest, SimpleTest) { |
Ben Chan | c6007e4 | 2013-09-19 23:49:22 -0700 | [diff] [blame] | 202 | TestWithServiceType(shill::kTypeEthernet, NULL, kNetEthernet); |
| 203 | TestWithServiceType(shill::kTypeWifi, NULL, kNetWifi); |
| 204 | TestWithServiceType(shill::kTypeWimax, NULL, kNetWimax); |
| 205 | TestWithServiceType(shill::kTypeBluetooth, NULL, kNetBluetooth); |
| 206 | TestWithServiceType(shill::kTypeCellular, NULL, kNetCellular); |
Alex Deymo | 1c4e638 | 2013-07-15 12:09:51 -0700 | [diff] [blame] | 207 | } |
| 208 | |
| 209 | TEST_F(ConnectionManagerTest, PhysicalTechnologyTest) { |
Ben Chan | c6007e4 | 2013-09-19 23:49:22 -0700 | [diff] [blame] | 210 | TestWithServiceType(shill::kTypeVPN, NULL, kNetUnknown); |
| 211 | TestWithServiceType(shill::kTypeVPN, shill::kTypeVPN, kNetUnknown); |
| 212 | TestWithServiceType(shill::kTypeVPN, shill::kTypeWifi, kNetWifi); |
| 213 | TestWithServiceType(shill::kTypeVPN, shill::kTypeWimax, kNetWimax); |
Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 214 | } |
| 215 | |
Alex Deymo | 6ae9120 | 2014-03-10 19:21:25 -0700 | [diff] [blame] | 216 | TEST_F(ConnectionManagerTest, TetheringTest) { |
| 217 | TestWithServiceTethering(shill::kTetheringConfirmedState, |
| 218 | NetworkTethering::kConfirmed); |
| 219 | TestWithServiceTethering(shill::kTetheringNotDetectedState, |
| 220 | NetworkTethering::kNotDetected); |
| 221 | TestWithServiceTethering(shill::kTetheringSuspectedState, |
| 222 | NetworkTethering::kSuspected); |
| 223 | TestWithServiceTethering("I'm not a valid property value =)", |
| 224 | NetworkTethering::kUnknown); |
| 225 | } |
| 226 | |
Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 227 | TEST_F(ConnectionManagerTest, UnknownTest) { |
Alex Deymo | 1c4e638 | 2013-07-15 12:09:51 -0700 | [diff] [blame] | 228 | TestWithServiceType("foo", NULL, kNetUnknown); |
Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 229 | } |
| 230 | |
| 231 | TEST_F(ConnectionManagerTest, AllowUpdatesOverEthernetTest) { |
Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 232 | // Updates over Ethernet are allowed even if there's no policy. |
Alex Deymo | 6ae9120 | 2014-03-10 19:21:25 -0700 | [diff] [blame] | 233 | EXPECT_TRUE(cmut_.IsUpdateAllowedOver(kNetEthernet, |
| 234 | NetworkTethering::kUnknown)); |
Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 235 | } |
| 236 | |
| 237 | TEST_F(ConnectionManagerTest, AllowUpdatesOverWifiTest) { |
Alex Deymo | 6ae9120 | 2014-03-10 19:21:25 -0700 | [diff] [blame] | 238 | EXPECT_TRUE(cmut_.IsUpdateAllowedOver(kNetWifi, NetworkTethering::kUnknown)); |
Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 239 | } |
| 240 | |
| 241 | TEST_F(ConnectionManagerTest, AllowUpdatesOverWimaxTest) { |
Alex Deymo | 6ae9120 | 2014-03-10 19:21:25 -0700 | [diff] [blame] | 242 | EXPECT_TRUE(cmut_.IsUpdateAllowedOver(kNetWimax, |
| 243 | NetworkTethering::kUnknown)); |
Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 244 | } |
| 245 | |
| 246 | TEST_F(ConnectionManagerTest, BlockUpdatesOverBluetoothTest) { |
Alex Deymo | 6ae9120 | 2014-03-10 19:21:25 -0700 | [diff] [blame] | 247 | EXPECT_FALSE(cmut_.IsUpdateAllowedOver(kNetBluetooth, |
| 248 | NetworkTethering::kUnknown)); |
Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 249 | } |
| 250 | |
| 251 | TEST_F(ConnectionManagerTest, AllowUpdatesOnlyOver3GPerPolicyTest) { |
| 252 | policy::MockDevicePolicy allow_3g_policy; |
| 253 | |
Gilad Arnold | 5bb4c90 | 2014-04-10 12:32:13 -0700 | [diff] [blame] | 254 | fake_system_state_.set_device_policy(&allow_3g_policy); |
Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 255 | |
Alex Deymo | f4867c4 | 2013-06-28 14:41:39 -0700 | [diff] [blame] | 256 | // This test tests cellular (3G) being the only connection type being allowed. |
Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 257 | set<string> allowed_set; |
| 258 | allowed_set.insert(cmut_.StringForConnectionType(kNetCellular)); |
| 259 | |
| 260 | EXPECT_CALL(allow_3g_policy, GetAllowedConnectionTypesForUpdate(_)) |
| 261 | .Times(1) |
| 262 | .WillOnce(DoAll(SetArgumentPointee<0>(allowed_set), Return(true))); |
| 263 | |
Alex Deymo | 6ae9120 | 2014-03-10 19:21:25 -0700 | [diff] [blame] | 264 | EXPECT_TRUE(cmut_.IsUpdateAllowedOver(kNetCellular, |
| 265 | NetworkTethering::kUnknown)); |
Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 266 | } |
| 267 | |
| 268 | TEST_F(ConnectionManagerTest, AllowUpdatesOver3GAndOtherTypesPerPolicyTest) { |
| 269 | policy::MockDevicePolicy allow_3g_policy; |
| 270 | |
Gilad Arnold | 5bb4c90 | 2014-04-10 12:32:13 -0700 | [diff] [blame] | 271 | fake_system_state_.set_device_policy(&allow_3g_policy); |
Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 272 | |
| 273 | // This test tests multiple connection types being allowed, with |
Alex Deymo | f4867c4 | 2013-06-28 14:41:39 -0700 | [diff] [blame] | 274 | // 3G one among them. Only Cellular is currently enforced by the policy |
| 275 | // setting, the others are ignored (see Bluetooth for example). |
Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 276 | set<string> allowed_set; |
Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 277 | allowed_set.insert(cmut_.StringForConnectionType(kNetCellular)); |
Alex Deymo | f4867c4 | 2013-06-28 14:41:39 -0700 | [diff] [blame] | 278 | allowed_set.insert(cmut_.StringForConnectionType(kNetBluetooth)); |
Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 279 | |
| 280 | EXPECT_CALL(allow_3g_policy, GetAllowedConnectionTypesForUpdate(_)) |
Alex Deymo | 6ae9120 | 2014-03-10 19:21:25 -0700 | [diff] [blame] | 281 | .Times(3) |
| 282 | .WillRepeatedly(DoAll(SetArgumentPointee<0>(allowed_set), Return(true))); |
Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 283 | |
Alex Deymo | 6ae9120 | 2014-03-10 19:21:25 -0700 | [diff] [blame] | 284 | EXPECT_TRUE(cmut_.IsUpdateAllowedOver(kNetEthernet, |
| 285 | NetworkTethering::kUnknown)); |
| 286 | EXPECT_TRUE(cmut_.IsUpdateAllowedOver(kNetEthernet, |
| 287 | NetworkTethering::kNotDetected)); |
| 288 | EXPECT_TRUE(cmut_.IsUpdateAllowedOver(kNetCellular, |
| 289 | NetworkTethering::kUnknown)); |
| 290 | EXPECT_TRUE(cmut_.IsUpdateAllowedOver(kNetWifi, NetworkTethering::kUnknown)); |
| 291 | EXPECT_TRUE(cmut_.IsUpdateAllowedOver(kNetWimax, NetworkTethering::kUnknown)); |
| 292 | EXPECT_FALSE(cmut_.IsUpdateAllowedOver(kNetBluetooth, |
| 293 | NetworkTethering::kUnknown)); |
| 294 | |
| 295 | // Tethered networks are treated in the same way as Cellular networks and |
| 296 | // thus allowed. |
| 297 | EXPECT_TRUE(cmut_.IsUpdateAllowedOver(kNetEthernet, |
| 298 | NetworkTethering::kConfirmed)); |
| 299 | EXPECT_TRUE(cmut_.IsUpdateAllowedOver(kNetWifi, |
| 300 | NetworkTethering::kConfirmed)); |
Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 301 | } |
| 302 | |
Alex Deymo | f4867c4 | 2013-06-28 14:41:39 -0700 | [diff] [blame] | 303 | TEST_F(ConnectionManagerTest, BlockUpdatesOverCellularByDefaultTest) { |
Alex Deymo | 6ae9120 | 2014-03-10 19:21:25 -0700 | [diff] [blame] | 304 | EXPECT_FALSE(cmut_.IsUpdateAllowedOver(kNetCellular, |
| 305 | NetworkTethering::kUnknown)); |
| 306 | } |
| 307 | |
| 308 | TEST_F(ConnectionManagerTest, BlockUpdatesOverTetheredNetworkByDefaultTest) { |
Alex Deymo | 6ae9120 | 2014-03-10 19:21:25 -0700 | [diff] [blame] | 309 | EXPECT_FALSE(cmut_.IsUpdateAllowedOver(kNetWifi, |
| 310 | NetworkTethering::kConfirmed)); |
| 311 | EXPECT_FALSE(cmut_.IsUpdateAllowedOver(kNetEthernet, |
| 312 | NetworkTethering::kConfirmed)); |
| 313 | EXPECT_TRUE(cmut_.IsUpdateAllowedOver(kNetWifi, |
| 314 | NetworkTethering::kSuspected)); |
Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 315 | } |
| 316 | |
| 317 | TEST_F(ConnectionManagerTest, BlockUpdatesOver3GPerPolicyTest) { |
| 318 | policy::MockDevicePolicy block_3g_policy; |
| 319 | |
Gilad Arnold | 5bb4c90 | 2014-04-10 12:32:13 -0700 | [diff] [blame] | 320 | fake_system_state_.set_device_policy(&block_3g_policy); |
Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 321 | |
| 322 | // Test that updates for 3G are blocked while updates are allowed |
| 323 | // over several other types. |
| 324 | set<string> allowed_set; |
| 325 | allowed_set.insert(cmut_.StringForConnectionType(kNetEthernet)); |
| 326 | allowed_set.insert(cmut_.StringForConnectionType(kNetWifi)); |
| 327 | allowed_set.insert(cmut_.StringForConnectionType(kNetWimax)); |
| 328 | |
| 329 | EXPECT_CALL(block_3g_policy, GetAllowedConnectionTypesForUpdate(_)) |
| 330 | .Times(1) |
| 331 | .WillOnce(DoAll(SetArgumentPointee<0>(allowed_set), Return(true))); |
| 332 | |
Alex Deymo | 6ae9120 | 2014-03-10 19:21:25 -0700 | [diff] [blame] | 333 | EXPECT_FALSE(cmut_.IsUpdateAllowedOver(kNetCellular, |
| 334 | NetworkTethering::kUnknown)); |
Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 335 | } |
| 336 | |
| 337 | TEST_F(ConnectionManagerTest, BlockUpdatesOver3GIfErrorInPolicyFetchTest) { |
| 338 | policy::MockDevicePolicy allow_3g_policy; |
| 339 | |
Gilad Arnold | 5bb4c90 | 2014-04-10 12:32:13 -0700 | [diff] [blame] | 340 | fake_system_state_.set_device_policy(&allow_3g_policy); |
Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 341 | |
| 342 | set<string> allowed_set; |
| 343 | allowed_set.insert(cmut_.StringForConnectionType(kNetCellular)); |
| 344 | |
| 345 | // Return false for GetAllowedConnectionTypesForUpdate and see |
| 346 | // that updates are still blocked for 3G despite the value being in |
| 347 | // the string set above. |
| 348 | EXPECT_CALL(allow_3g_policy, GetAllowedConnectionTypesForUpdate(_)) |
| 349 | .Times(1) |
| 350 | .WillOnce(DoAll(SetArgumentPointee<0>(allowed_set), Return(false))); |
| 351 | |
Alex Deymo | 6ae9120 | 2014-03-10 19:21:25 -0700 | [diff] [blame] | 352 | EXPECT_FALSE(cmut_.IsUpdateAllowedOver(kNetCellular, |
| 353 | NetworkTethering::kUnknown)); |
Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 354 | } |
| 355 | |
Alex Deymo | f4867c4 | 2013-06-28 14:41:39 -0700 | [diff] [blame] | 356 | TEST_F(ConnectionManagerTest, UseUserPrefForUpdatesOverCellularIfNoPolicyTest) { |
| 357 | policy::MockDevicePolicy no_policy; |
Gilad Arnold | 5bb4c90 | 2014-04-10 12:32:13 -0700 | [diff] [blame] | 358 | testing::NiceMock<PrefsMock>* prefs = fake_system_state_.mock_prefs(); |
Alex Deymo | f4867c4 | 2013-06-28 14:41:39 -0700 | [diff] [blame] | 359 | |
Gilad Arnold | 5bb4c90 | 2014-04-10 12:32:13 -0700 | [diff] [blame] | 360 | fake_system_state_.set_device_policy(&no_policy); |
Alex Deymo | f4867c4 | 2013-06-28 14:41:39 -0700 | [diff] [blame] | 361 | |
| 362 | // No setting enforced by the device policy, user prefs should be used. |
| 363 | EXPECT_CALL(no_policy, GetAllowedConnectionTypesForUpdate(_)) |
| 364 | .Times(3) |
| 365 | .WillRepeatedly(Return(false)); |
| 366 | |
| 367 | // No user pref: block. |
| 368 | EXPECT_CALL(*prefs, Exists(kPrefsUpdateOverCellularPermission)) |
| 369 | .Times(1) |
| 370 | .WillOnce(Return(false)); |
Alex Deymo | 6ae9120 | 2014-03-10 19:21:25 -0700 | [diff] [blame] | 371 | EXPECT_FALSE(cmut_.IsUpdateAllowedOver(kNetCellular, |
| 372 | NetworkTethering::kUnknown)); |
Alex Deymo | f4867c4 | 2013-06-28 14:41:39 -0700 | [diff] [blame] | 373 | |
| 374 | // Allow per user pref. |
| 375 | EXPECT_CALL(*prefs, Exists(kPrefsUpdateOverCellularPermission)) |
| 376 | .Times(1) |
| 377 | .WillOnce(Return(true)); |
Alex Deymo | efb7c4c | 2013-07-09 14:34:00 -0700 | [diff] [blame] | 378 | EXPECT_CALL(*prefs, GetBoolean(kPrefsUpdateOverCellularPermission, _)) |
Alex Deymo | f4867c4 | 2013-06-28 14:41:39 -0700 | [diff] [blame] | 379 | .Times(1) |
Alex Deymo | efb7c4c | 2013-07-09 14:34:00 -0700 | [diff] [blame] | 380 | .WillOnce(DoAll(SetArgumentPointee<1>(true), Return(true))); |
Alex Deymo | 6ae9120 | 2014-03-10 19:21:25 -0700 | [diff] [blame] | 381 | EXPECT_TRUE(cmut_.IsUpdateAllowedOver(kNetCellular, |
| 382 | NetworkTethering::kUnknown)); |
Alex Deymo | f4867c4 | 2013-06-28 14:41:39 -0700 | [diff] [blame] | 383 | |
| 384 | // Block per user pref. |
| 385 | EXPECT_CALL(*prefs, Exists(kPrefsUpdateOverCellularPermission)) |
| 386 | .Times(1) |
| 387 | .WillOnce(Return(true)); |
Alex Deymo | efb7c4c | 2013-07-09 14:34:00 -0700 | [diff] [blame] | 388 | EXPECT_CALL(*prefs, GetBoolean(kPrefsUpdateOverCellularPermission, _)) |
Alex Deymo | f4867c4 | 2013-06-28 14:41:39 -0700 | [diff] [blame] | 389 | .Times(1) |
Alex Deymo | efb7c4c | 2013-07-09 14:34:00 -0700 | [diff] [blame] | 390 | .WillOnce(DoAll(SetArgumentPointee<1>(false), Return(true))); |
Alex Deymo | 6ae9120 | 2014-03-10 19:21:25 -0700 | [diff] [blame] | 391 | EXPECT_FALSE(cmut_.IsUpdateAllowedOver(kNetCellular, |
| 392 | NetworkTethering::kUnknown)); |
Alex Deymo | f4867c4 | 2013-06-28 14:41:39 -0700 | [diff] [blame] | 393 | } |
| 394 | |
Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 395 | TEST_F(ConnectionManagerTest, StringForConnectionTypeTest) { |
Ben Chan | c6007e4 | 2013-09-19 23:49:22 -0700 | [diff] [blame] | 396 | EXPECT_STREQ(shill::kTypeEthernet, |
Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 397 | cmut_.StringForConnectionType(kNetEthernet)); |
Ben Chan | c6007e4 | 2013-09-19 23:49:22 -0700 | [diff] [blame] | 398 | EXPECT_STREQ(shill::kTypeWifi, |
Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 399 | cmut_.StringForConnectionType(kNetWifi)); |
Ben Chan | c6007e4 | 2013-09-19 23:49:22 -0700 | [diff] [blame] | 400 | EXPECT_STREQ(shill::kTypeWimax, |
Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 401 | cmut_.StringForConnectionType(kNetWimax)); |
Ben Chan | c6007e4 | 2013-09-19 23:49:22 -0700 | [diff] [blame] | 402 | EXPECT_STREQ(shill::kTypeBluetooth, |
Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 403 | cmut_.StringForConnectionType(kNetBluetooth)); |
Ben Chan | c6007e4 | 2013-09-19 23:49:22 -0700 | [diff] [blame] | 404 | EXPECT_STREQ(shill::kTypeCellular, |
Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 405 | cmut_.StringForConnectionType(kNetCellular)); |
| 406 | EXPECT_STREQ("Unknown", |
| 407 | cmut_.StringForConnectionType(kNetUnknown)); |
| 408 | EXPECT_STREQ("Unknown", |
| 409 | cmut_.StringForConnectionType( |
| 410 | static_cast<NetworkConnectionType>(999999))); |
| 411 | } |
| 412 | |
| 413 | TEST_F(ConnectionManagerTest, MalformedServiceList) { |
| 414 | SetupMocks("/service/guest-network"); |
| 415 | string service_name(kServicePath_); |
| 416 | SetManagerReply(&service_name, DBUS_TYPE_G_STRING_ARRAY); |
| 417 | |
| 418 | NetworkConnectionType type; |
Alex Deymo | 6ae9120 | 2014-03-10 19:21:25 -0700 | [diff] [blame] | 419 | NetworkTethering tethering; |
| 420 | EXPECT_FALSE(cmut_.GetConnectionProperties(&dbus_iface_, &type, &tethering)); |
Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 421 | } |
| 422 | |
| 423 | } // namespace chromeos_update_engine |