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 | |
Alex Deymo | 8427b4a | 2014-11-05 14:00:32 -0800 | [diff] [blame] | 5 | #include "update_engine/connection_manager.h" |
| 6 | |
Alex Vakulenko | d2779df | 2014-06-16 13:19:00 -0700 | [diff] [blame] | 7 | #include <set> |
| 8 | #include <string> |
| 9 | |
Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 10 | #include <base/logging.h> |
Alex Deymo | 3053450 | 2015-07-20 15:06:33 -0700 | [diff] [blame] | 11 | #include <chromeos/any.h> |
Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 12 | #include <chromeos/dbus/service_constants.h> |
Alex Deymo | 3053450 | 2015-07-20 15:06:33 -0700 | [diff] [blame] | 13 | #include <chromeos/make_unique_ptr.h> |
| 14 | #include <chromeos/message_loops/fake_message_loop.h> |
| 15 | #include <chromeos/variant_dictionary.h> |
Alex Deymo | 5665d0c | 2014-05-28 17:45:43 -0700 | [diff] [blame] | 16 | #include <gmock/gmock.h> |
Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 17 | #include <gtest/gtest.h> |
Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 18 | |
Alex Deymo | 3053450 | 2015-07-20 15:06:33 -0700 | [diff] [blame] | 19 | #include "update_engine/fake_shill_proxy.h" |
Gilad Arnold | 5bb4c90 | 2014-04-10 12:32:13 -0700 | [diff] [blame] | 20 | #include "update_engine/fake_system_state.h" |
Alex Deymo | 5665d0c | 2014-05-28 17:45:43 -0700 | [diff] [blame] | 21 | #include "update_engine/test_utils.h" |
Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 22 | |
Alex Deymo | 3053450 | 2015-07-20 15:06:33 -0700 | [diff] [blame] | 23 | using org::chromium::flimflam::ManagerProxyMock; |
| 24 | using org::chromium::flimflam::ServiceProxyMock; |
Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 25 | using std::set; |
| 26 | using std::string; |
Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 27 | using testing::Return; |
Alex Deymo | 3053450 | 2015-07-20 15:06:33 -0700 | [diff] [blame] | 28 | using testing::SetArgPointee; |
Alex Deymo | f329b93 | 2014-10-30 01:37:48 -0700 | [diff] [blame] | 29 | using testing::_; |
Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 30 | |
| 31 | namespace chromeos_update_engine { |
| 32 | |
| 33 | class ConnectionManagerTest : public ::testing::Test { |
| 34 | public: |
Alex Deymo | 3053450 | 2015-07-20 15:06:33 -0700 | [diff] [blame] | 35 | void SetUp() override { |
| 36 | loop_.SetAsCurrent(); |
Gilad Arnold | 5bb4c90 | 2014-04-10 12:32:13 -0700 | [diff] [blame] | 37 | fake_system_state_.set_connection_manager(&cmut_); |
Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 38 | } |
| 39 | |
Alex Deymo | 3053450 | 2015-07-20 15:06:33 -0700 | [diff] [blame] | 40 | void TearDown() override { EXPECT_FALSE(loop_.PendingTasks()); } |
Alex Deymo | 1c4e638 | 2013-07-15 12:09:51 -0700 | [diff] [blame] | 41 | |
Alex Deymo | 3053450 | 2015-07-20 15:06:33 -0700 | [diff] [blame] | 42 | protected: |
| 43 | // Sets the default_service object path in the response from the |
| 44 | // ManagerProxyMock instance. |
| 45 | void SetManagerReply(const char* default_service, bool reply_succeeds); |
| 46 | |
| 47 | // Sets the |service_type|, |physical_technology| and |service_tethering| |
| 48 | // properties in the mocked service |service_path|. If any of the three |
| 49 | // const char* is a nullptr, the corresponding property will not be included |
| 50 | // in the response. |
| 51 | void SetServiceReply(const string& service_path, |
| 52 | const char* service_type, |
Alex Deymo | 6ae9120 | 2014-03-10 19:21:25 -0700 | [diff] [blame] | 53 | const char* physical_technology, |
| 54 | const char* service_tethering); |
Alex Deymo | 3053450 | 2015-07-20 15:06:33 -0700 | [diff] [blame] | 55 | |
Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 56 | void TestWithServiceType( |
Alex Deymo | 1c4e638 | 2013-07-15 12:09:51 -0700 | [diff] [blame] | 57 | const char* service_type, |
| 58 | const char* physical_technology, |
| 59 | NetworkConnectionType expected_type); |
Alex Deymo | 6ae9120 | 2014-03-10 19:21:25 -0700 | [diff] [blame] | 60 | void TestWithServiceTethering( |
| 61 | const char* service_tethering, |
| 62 | NetworkTethering expected_tethering); |
Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 63 | |
Alex Deymo | 3053450 | 2015-07-20 15:06:33 -0700 | [diff] [blame] | 64 | chromeos::FakeMessageLoop loop_{nullptr}; |
Gilad Arnold | 5bb4c90 | 2014-04-10 12:32:13 -0700 | [diff] [blame] | 65 | FakeSystemState fake_system_state_; |
Alex Deymo | 3053450 | 2015-07-20 15:06:33 -0700 | [diff] [blame] | 66 | FakeShillProxy fake_shill_proxy_; |
| 67 | |
| 68 | // ConnectionManager under test. |
| 69 | ConnectionManager cmut_{&fake_shill_proxy_, &fake_system_state_}; |
Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 70 | }; |
| 71 | |
Alex Deymo | 3053450 | 2015-07-20 15:06:33 -0700 | [diff] [blame] | 72 | void ConnectionManagerTest::SetManagerReply(const char* default_service, |
| 73 | bool reply_succeeds) { |
| 74 | ManagerProxyMock* manager_proxy_mock = fake_shill_proxy_.GetManagerProxy(); |
| 75 | if (!reply_succeeds) { |
| 76 | EXPECT_CALL(*manager_proxy_mock, GetProperties(_, _, _)) |
| 77 | .WillOnce(Return(false)); |
| 78 | return; |
| 79 | } |
Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 80 | |
Alex Deymo | 3053450 | 2015-07-20 15:06:33 -0700 | [diff] [blame] | 81 | // Create a dictionary of properties and optionally include the default |
| 82 | // service. |
| 83 | chromeos::VariantDictionary reply_dict; |
| 84 | reply_dict["SomeOtherProperty"] = 0xC0FFEE; |
Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 85 | |
Alex Deymo | 3053450 | 2015-07-20 15:06:33 -0700 | [diff] [blame] | 86 | if (default_service) { |
| 87 | reply_dict[shill::kDefaultServiceProperty] = |
| 88 | dbus::ObjectPath(default_service); |
| 89 | } |
| 90 | EXPECT_CALL(*manager_proxy_mock, GetProperties(_, _, _)) |
| 91 | .WillOnce(DoAll(SetArgPointee<0>(reply_dict), Return(true))); |
Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 92 | } |
| 93 | |
Alex Deymo | 3053450 | 2015-07-20 15:06:33 -0700 | [diff] [blame] | 94 | void ConnectionManagerTest::SetServiceReply(const string& service_path, |
| 95 | const char* service_type, |
Alex Deymo | 6ae9120 | 2014-03-10 19:21:25 -0700 | [diff] [blame] | 96 | const char* physical_technology, |
| 97 | const char* service_tethering) { |
Alex Deymo | 3053450 | 2015-07-20 15:06:33 -0700 | [diff] [blame] | 98 | chromeos::VariantDictionary reply_dict; |
| 99 | reply_dict["SomeOtherProperty"] = 0xC0FFEE; |
| 100 | |
| 101 | if (service_type) |
| 102 | reply_dict[shill::kTypeProperty] = string(service_type); |
Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 103 | |
Alex Vakulenko | 88b591f | 2014-08-28 16:48:57 -0700 | [diff] [blame] | 104 | if (physical_technology) { |
Alex Deymo | 3053450 | 2015-07-20 15:06:33 -0700 | [diff] [blame] | 105 | reply_dict[shill::kPhysicalTechnologyProperty] = |
| 106 | string(physical_technology); |
Alex Deymo | 1c4e638 | 2013-07-15 12:09:51 -0700 | [diff] [blame] | 107 | } |
| 108 | |
Alex Deymo | 3053450 | 2015-07-20 15:06:33 -0700 | [diff] [blame] | 109 | if (service_tethering) |
| 110 | reply_dict[shill::kTetheringProperty] = string(service_tethering); |
| 111 | |
| 112 | std::unique_ptr<ServiceProxyMock> service_proxy_mock(new ServiceProxyMock()); |
Alex Deymo | 6ae9120 | 2014-03-10 19:21:25 -0700 | [diff] [blame] | 113 | |
Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 114 | // Plumb return value into mock object. |
Alex Deymo | 3053450 | 2015-07-20 15:06:33 -0700 | [diff] [blame] | 115 | EXPECT_CALL(*service_proxy_mock.get(), GetProperties(_, _, _)) |
| 116 | .WillOnce(DoAll(SetArgPointee<0>(reply_dict), Return(true))); |
Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 117 | |
Alex Deymo | 3053450 | 2015-07-20 15:06:33 -0700 | [diff] [blame] | 118 | fake_shill_proxy_.SetServiceForPath(service_path, |
| 119 | std::move(service_proxy_mock)); |
Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 120 | } |
| 121 | |
| 122 | void ConnectionManagerTest::TestWithServiceType( |
| 123 | const char* service_type, |
Alex Deymo | 1c4e638 | 2013-07-15 12:09:51 -0700 | [diff] [blame] | 124 | const char* physical_technology, |
Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 125 | NetworkConnectionType expected_type) { |
Alex Deymo | 3053450 | 2015-07-20 15:06:33 -0700 | [diff] [blame] | 126 | SetManagerReply("/service/guest-network", true); |
| 127 | SetServiceReply("/service/guest-network", |
| 128 | service_type, |
| 129 | physical_technology, |
Alex Deymo | 6ae9120 | 2014-03-10 19:21:25 -0700 | [diff] [blame] | 130 | shill::kTetheringNotDetectedState); |
Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 131 | |
| 132 | NetworkConnectionType type; |
Alex Deymo | 6ae9120 | 2014-03-10 19:21:25 -0700 | [diff] [blame] | 133 | NetworkTethering tethering; |
Alex Deymo | 3053450 | 2015-07-20 15:06:33 -0700 | [diff] [blame] | 134 | EXPECT_TRUE(cmut_.GetConnectionProperties(&type, &tethering)); |
Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 135 | EXPECT_EQ(expected_type, type); |
Alex Deymo | 3053450 | 2015-07-20 15:06:33 -0700 | [diff] [blame] | 136 | testing::Mock::VerifyAndClearExpectations( |
| 137 | fake_shill_proxy_.GetManagerProxy()); |
Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 138 | } |
| 139 | |
Alex Deymo | 6ae9120 | 2014-03-10 19:21:25 -0700 | [diff] [blame] | 140 | void ConnectionManagerTest::TestWithServiceTethering( |
| 141 | const char* service_tethering, |
| 142 | NetworkTethering expected_tethering) { |
Alex Deymo | 3053450 | 2015-07-20 15:06:33 -0700 | [diff] [blame] | 143 | SetManagerReply("/service/guest-network", true); |
| 144 | SetServiceReply( |
| 145 | "/service/guest-network", shill::kTypeWifi, nullptr, service_tethering); |
Alex Deymo | 6ae9120 | 2014-03-10 19:21:25 -0700 | [diff] [blame] | 146 | |
| 147 | NetworkConnectionType type; |
| 148 | NetworkTethering tethering; |
Alex Deymo | 3053450 | 2015-07-20 15:06:33 -0700 | [diff] [blame] | 149 | EXPECT_TRUE(cmut_.GetConnectionProperties(&type, &tethering)); |
Alex Deymo | 6ae9120 | 2014-03-10 19:21:25 -0700 | [diff] [blame] | 150 | EXPECT_EQ(expected_tethering, tethering); |
Alex Deymo | 3053450 | 2015-07-20 15:06:33 -0700 | [diff] [blame] | 151 | testing::Mock::VerifyAndClearExpectations( |
| 152 | fake_shill_proxy_.GetManagerProxy()); |
Alex Deymo | 6ae9120 | 2014-03-10 19:21:25 -0700 | [diff] [blame] | 153 | } |
| 154 | |
Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 155 | TEST_F(ConnectionManagerTest, SimpleTest) { |
Alex Deymo | 75eac7e | 2015-07-29 13:39:14 -0700 | [diff] [blame] | 156 | TestWithServiceType(shill::kTypeEthernet, nullptr, |
| 157 | NetworkConnectionType::kEthernet); |
| 158 | TestWithServiceType(shill::kTypeWifi, nullptr, |
| 159 | NetworkConnectionType::kWifi); |
| 160 | TestWithServiceType(shill::kTypeWimax, nullptr, |
| 161 | NetworkConnectionType::kWimax); |
| 162 | TestWithServiceType(shill::kTypeBluetooth, nullptr, |
| 163 | NetworkConnectionType::kBluetooth); |
| 164 | TestWithServiceType(shill::kTypeCellular, nullptr, |
| 165 | NetworkConnectionType::kCellular); |
Alex Deymo | 1c4e638 | 2013-07-15 12:09:51 -0700 | [diff] [blame] | 166 | } |
| 167 | |
| 168 | TEST_F(ConnectionManagerTest, PhysicalTechnologyTest) { |
Alex Deymo | 75eac7e | 2015-07-29 13:39:14 -0700 | [diff] [blame] | 169 | TestWithServiceType(shill::kTypeVPN, nullptr, |
| 170 | NetworkConnectionType::kUnknown); |
| 171 | TestWithServiceType(shill::kTypeVPN, shill::kTypeVPN, |
| 172 | NetworkConnectionType::kUnknown); |
| 173 | TestWithServiceType(shill::kTypeVPN, shill::kTypeWifi, |
| 174 | NetworkConnectionType::kWifi); |
| 175 | TestWithServiceType(shill::kTypeVPN, shill::kTypeWimax, |
| 176 | NetworkConnectionType::kWimax); |
Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 177 | } |
| 178 | |
Alex Deymo | 6ae9120 | 2014-03-10 19:21:25 -0700 | [diff] [blame] | 179 | TEST_F(ConnectionManagerTest, TetheringTest) { |
| 180 | TestWithServiceTethering(shill::kTetheringConfirmedState, |
| 181 | NetworkTethering::kConfirmed); |
| 182 | TestWithServiceTethering(shill::kTetheringNotDetectedState, |
| 183 | NetworkTethering::kNotDetected); |
| 184 | TestWithServiceTethering(shill::kTetheringSuspectedState, |
| 185 | NetworkTethering::kSuspected); |
| 186 | TestWithServiceTethering("I'm not a valid property value =)", |
| 187 | NetworkTethering::kUnknown); |
| 188 | } |
| 189 | |
Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 190 | TEST_F(ConnectionManagerTest, UnknownTest) { |
Alex Deymo | 75eac7e | 2015-07-29 13:39:14 -0700 | [diff] [blame] | 191 | TestWithServiceType("foo", nullptr, NetworkConnectionType::kUnknown); |
Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 192 | } |
| 193 | |
| 194 | TEST_F(ConnectionManagerTest, AllowUpdatesOverEthernetTest) { |
Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 195 | // Updates over Ethernet are allowed even if there's no policy. |
Alex Deymo | 75eac7e | 2015-07-29 13:39:14 -0700 | [diff] [blame] | 196 | EXPECT_TRUE(cmut_.IsUpdateAllowedOver(NetworkConnectionType::kEthernet, |
Alex Deymo | 6ae9120 | 2014-03-10 19:21:25 -0700 | [diff] [blame] | 197 | NetworkTethering::kUnknown)); |
Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 198 | } |
| 199 | |
| 200 | TEST_F(ConnectionManagerTest, AllowUpdatesOverWifiTest) { |
Alex Deymo | 75eac7e | 2015-07-29 13:39:14 -0700 | [diff] [blame] | 201 | EXPECT_TRUE(cmut_.IsUpdateAllowedOver(NetworkConnectionType::kWifi, |
| 202 | NetworkTethering::kUnknown)); |
Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 203 | } |
| 204 | |
| 205 | TEST_F(ConnectionManagerTest, AllowUpdatesOverWimaxTest) { |
Alex Deymo | 75eac7e | 2015-07-29 13:39:14 -0700 | [diff] [blame] | 206 | EXPECT_TRUE(cmut_.IsUpdateAllowedOver(NetworkConnectionType::kWimax, |
Alex Deymo | 6ae9120 | 2014-03-10 19:21:25 -0700 | [diff] [blame] | 207 | NetworkTethering::kUnknown)); |
Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 208 | } |
| 209 | |
| 210 | TEST_F(ConnectionManagerTest, BlockUpdatesOverBluetoothTest) { |
Alex Deymo | 75eac7e | 2015-07-29 13:39:14 -0700 | [diff] [blame] | 211 | EXPECT_FALSE(cmut_.IsUpdateAllowedOver(NetworkConnectionType::kBluetooth, |
Alex Deymo | 6ae9120 | 2014-03-10 19:21:25 -0700 | [diff] [blame] | 212 | NetworkTethering::kUnknown)); |
Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 213 | } |
| 214 | |
| 215 | TEST_F(ConnectionManagerTest, AllowUpdatesOnlyOver3GPerPolicyTest) { |
| 216 | policy::MockDevicePolicy allow_3g_policy; |
| 217 | |
Gilad Arnold | 5bb4c90 | 2014-04-10 12:32:13 -0700 | [diff] [blame] | 218 | fake_system_state_.set_device_policy(&allow_3g_policy); |
Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 219 | |
Alex Deymo | f4867c4 | 2013-06-28 14:41:39 -0700 | [diff] [blame] | 220 | // This test tests cellular (3G) being the only connection type being allowed. |
Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 221 | set<string> allowed_set; |
Alex Deymo | 75eac7e | 2015-07-29 13:39:14 -0700 | [diff] [blame] | 222 | allowed_set.insert( |
| 223 | cmut_.StringForConnectionType(NetworkConnectionType::kCellular)); |
Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 224 | |
| 225 | EXPECT_CALL(allow_3g_policy, GetAllowedConnectionTypesForUpdate(_)) |
| 226 | .Times(1) |
Alex Deymo | 3053450 | 2015-07-20 15:06:33 -0700 | [diff] [blame] | 227 | .WillOnce(DoAll(SetArgPointee<0>(allowed_set), Return(true))); |
Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 228 | |
Alex Deymo | 75eac7e | 2015-07-29 13:39:14 -0700 | [diff] [blame] | 229 | EXPECT_TRUE(cmut_.IsUpdateAllowedOver(NetworkConnectionType::kCellular, |
Alex Deymo | 6ae9120 | 2014-03-10 19:21:25 -0700 | [diff] [blame] | 230 | NetworkTethering::kUnknown)); |
Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 231 | } |
| 232 | |
| 233 | TEST_F(ConnectionManagerTest, AllowUpdatesOver3GAndOtherTypesPerPolicyTest) { |
| 234 | policy::MockDevicePolicy allow_3g_policy; |
| 235 | |
Gilad Arnold | 5bb4c90 | 2014-04-10 12:32:13 -0700 | [diff] [blame] | 236 | fake_system_state_.set_device_policy(&allow_3g_policy); |
Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 237 | |
| 238 | // This test tests multiple connection types being allowed, with |
Alex Deymo | f4867c4 | 2013-06-28 14:41:39 -0700 | [diff] [blame] | 239 | // 3G one among them. Only Cellular is currently enforced by the policy |
| 240 | // setting, the others are ignored (see Bluetooth for example). |
Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 241 | set<string> allowed_set; |
Alex Deymo | 75eac7e | 2015-07-29 13:39:14 -0700 | [diff] [blame] | 242 | allowed_set.insert( |
| 243 | cmut_.StringForConnectionType(NetworkConnectionType::kCellular)); |
| 244 | allowed_set.insert( |
| 245 | cmut_.StringForConnectionType(NetworkConnectionType::kBluetooth)); |
Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 246 | |
| 247 | EXPECT_CALL(allow_3g_policy, GetAllowedConnectionTypesForUpdate(_)) |
Alex Deymo | 6ae9120 | 2014-03-10 19:21:25 -0700 | [diff] [blame] | 248 | .Times(3) |
Alex Deymo | 3053450 | 2015-07-20 15:06:33 -0700 | [diff] [blame] | 249 | .WillRepeatedly(DoAll(SetArgPointee<0>(allowed_set), Return(true))); |
Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 250 | |
Alex Deymo | 75eac7e | 2015-07-29 13:39:14 -0700 | [diff] [blame] | 251 | EXPECT_TRUE(cmut_.IsUpdateAllowedOver(NetworkConnectionType::kEthernet, |
Alex Deymo | 6ae9120 | 2014-03-10 19:21:25 -0700 | [diff] [blame] | 252 | NetworkTethering::kUnknown)); |
Alex Deymo | 75eac7e | 2015-07-29 13:39:14 -0700 | [diff] [blame] | 253 | EXPECT_TRUE(cmut_.IsUpdateAllowedOver(NetworkConnectionType::kEthernet, |
Alex Deymo | 6ae9120 | 2014-03-10 19:21:25 -0700 | [diff] [blame] | 254 | NetworkTethering::kNotDetected)); |
Alex Deymo | 75eac7e | 2015-07-29 13:39:14 -0700 | [diff] [blame] | 255 | EXPECT_TRUE(cmut_.IsUpdateAllowedOver(NetworkConnectionType::kCellular, |
Alex Deymo | 6ae9120 | 2014-03-10 19:21:25 -0700 | [diff] [blame] | 256 | NetworkTethering::kUnknown)); |
Alex Deymo | 75eac7e | 2015-07-29 13:39:14 -0700 | [diff] [blame] | 257 | EXPECT_TRUE(cmut_.IsUpdateAllowedOver(NetworkConnectionType::kWifi, |
| 258 | NetworkTethering::kUnknown)); |
| 259 | EXPECT_TRUE(cmut_.IsUpdateAllowedOver(NetworkConnectionType::kWimax, |
| 260 | NetworkTethering::kUnknown)); |
| 261 | EXPECT_FALSE(cmut_.IsUpdateAllowedOver(NetworkConnectionType::kBluetooth, |
Alex Deymo | 6ae9120 | 2014-03-10 19:21:25 -0700 | [diff] [blame] | 262 | NetworkTethering::kUnknown)); |
| 263 | |
| 264 | // Tethered networks are treated in the same way as Cellular networks and |
| 265 | // thus allowed. |
Alex Deymo | 75eac7e | 2015-07-29 13:39:14 -0700 | [diff] [blame] | 266 | EXPECT_TRUE(cmut_.IsUpdateAllowedOver(NetworkConnectionType::kEthernet, |
Alex Deymo | 6ae9120 | 2014-03-10 19:21:25 -0700 | [diff] [blame] | 267 | NetworkTethering::kConfirmed)); |
Alex Deymo | 75eac7e | 2015-07-29 13:39:14 -0700 | [diff] [blame] | 268 | EXPECT_TRUE(cmut_.IsUpdateAllowedOver(NetworkConnectionType::kWifi, |
Alex Deymo | 6ae9120 | 2014-03-10 19:21:25 -0700 | [diff] [blame] | 269 | NetworkTethering::kConfirmed)); |
Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 270 | } |
| 271 | |
Alex Deymo | f4867c4 | 2013-06-28 14:41:39 -0700 | [diff] [blame] | 272 | TEST_F(ConnectionManagerTest, BlockUpdatesOverCellularByDefaultTest) { |
Alex Deymo | 75eac7e | 2015-07-29 13:39:14 -0700 | [diff] [blame] | 273 | EXPECT_FALSE(cmut_.IsUpdateAllowedOver(NetworkConnectionType::kCellular, |
Alex Deymo | 6ae9120 | 2014-03-10 19:21:25 -0700 | [diff] [blame] | 274 | NetworkTethering::kUnknown)); |
| 275 | } |
| 276 | |
| 277 | TEST_F(ConnectionManagerTest, BlockUpdatesOverTetheredNetworkByDefaultTest) { |
Alex Deymo | 75eac7e | 2015-07-29 13:39:14 -0700 | [diff] [blame] | 278 | EXPECT_FALSE(cmut_.IsUpdateAllowedOver(NetworkConnectionType::kWifi, |
Alex Deymo | 6ae9120 | 2014-03-10 19:21:25 -0700 | [diff] [blame] | 279 | NetworkTethering::kConfirmed)); |
Alex Deymo | 75eac7e | 2015-07-29 13:39:14 -0700 | [diff] [blame] | 280 | EXPECT_FALSE(cmut_.IsUpdateAllowedOver(NetworkConnectionType::kEthernet, |
Alex Deymo | 6ae9120 | 2014-03-10 19:21:25 -0700 | [diff] [blame] | 281 | NetworkTethering::kConfirmed)); |
Alex Deymo | 75eac7e | 2015-07-29 13:39:14 -0700 | [diff] [blame] | 282 | EXPECT_TRUE(cmut_.IsUpdateAllowedOver(NetworkConnectionType::kWifi, |
Alex Deymo | 6ae9120 | 2014-03-10 19:21:25 -0700 | [diff] [blame] | 283 | NetworkTethering::kSuspected)); |
Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 284 | } |
| 285 | |
| 286 | TEST_F(ConnectionManagerTest, BlockUpdatesOver3GPerPolicyTest) { |
| 287 | policy::MockDevicePolicy block_3g_policy; |
| 288 | |
Gilad Arnold | 5bb4c90 | 2014-04-10 12:32:13 -0700 | [diff] [blame] | 289 | fake_system_state_.set_device_policy(&block_3g_policy); |
Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 290 | |
| 291 | // Test that updates for 3G are blocked while updates are allowed |
| 292 | // over several other types. |
| 293 | set<string> allowed_set; |
Alex Deymo | 75eac7e | 2015-07-29 13:39:14 -0700 | [diff] [blame] | 294 | allowed_set.insert( |
| 295 | cmut_.StringForConnectionType(NetworkConnectionType::kEthernet)); |
| 296 | allowed_set.insert( |
| 297 | cmut_.StringForConnectionType(NetworkConnectionType::kWifi)); |
| 298 | allowed_set.insert( |
| 299 | cmut_.StringForConnectionType(NetworkConnectionType::kWimax)); |
Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 300 | |
| 301 | EXPECT_CALL(block_3g_policy, GetAllowedConnectionTypesForUpdate(_)) |
| 302 | .Times(1) |
Alex Deymo | 3053450 | 2015-07-20 15:06:33 -0700 | [diff] [blame] | 303 | .WillOnce(DoAll(SetArgPointee<0>(allowed_set), Return(true))); |
Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 304 | |
Alex Deymo | 75eac7e | 2015-07-29 13:39:14 -0700 | [diff] [blame] | 305 | EXPECT_FALSE(cmut_.IsUpdateAllowedOver(NetworkConnectionType::kCellular, |
Alex Deymo | 6ae9120 | 2014-03-10 19:21:25 -0700 | [diff] [blame] | 306 | NetworkTethering::kUnknown)); |
Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 307 | } |
| 308 | |
| 309 | TEST_F(ConnectionManagerTest, BlockUpdatesOver3GIfErrorInPolicyFetchTest) { |
| 310 | policy::MockDevicePolicy allow_3g_policy; |
| 311 | |
Gilad Arnold | 5bb4c90 | 2014-04-10 12:32:13 -0700 | [diff] [blame] | 312 | fake_system_state_.set_device_policy(&allow_3g_policy); |
Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 313 | |
| 314 | set<string> allowed_set; |
Alex Deymo | 75eac7e | 2015-07-29 13:39:14 -0700 | [diff] [blame] | 315 | allowed_set.insert( |
| 316 | cmut_.StringForConnectionType(NetworkConnectionType::kCellular)); |
Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 317 | |
| 318 | // Return false for GetAllowedConnectionTypesForUpdate and see |
| 319 | // that updates are still blocked for 3G despite the value being in |
| 320 | // the string set above. |
| 321 | EXPECT_CALL(allow_3g_policy, GetAllowedConnectionTypesForUpdate(_)) |
| 322 | .Times(1) |
Alex Deymo | 3053450 | 2015-07-20 15:06:33 -0700 | [diff] [blame] | 323 | .WillOnce(DoAll(SetArgPointee<0>(allowed_set), Return(false))); |
Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 324 | |
Alex Deymo | 75eac7e | 2015-07-29 13:39:14 -0700 | [diff] [blame] | 325 | EXPECT_FALSE(cmut_.IsUpdateAllowedOver(NetworkConnectionType::kCellular, |
Alex Deymo | 6ae9120 | 2014-03-10 19:21:25 -0700 | [diff] [blame] | 326 | NetworkTethering::kUnknown)); |
Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 327 | } |
| 328 | |
Alex Deymo | f4867c4 | 2013-06-28 14:41:39 -0700 | [diff] [blame] | 329 | TEST_F(ConnectionManagerTest, UseUserPrefForUpdatesOverCellularIfNoPolicyTest) { |
| 330 | policy::MockDevicePolicy no_policy; |
Alex Deymo | 8427b4a | 2014-11-05 14:00:32 -0800 | [diff] [blame] | 331 | testing::NiceMock<MockPrefs>* prefs = fake_system_state_.mock_prefs(); |
Alex Deymo | f4867c4 | 2013-06-28 14:41:39 -0700 | [diff] [blame] | 332 | |
Gilad Arnold | 5bb4c90 | 2014-04-10 12:32:13 -0700 | [diff] [blame] | 333 | fake_system_state_.set_device_policy(&no_policy); |
Alex Deymo | f4867c4 | 2013-06-28 14:41:39 -0700 | [diff] [blame] | 334 | |
| 335 | // No setting enforced by the device policy, user prefs should be used. |
| 336 | EXPECT_CALL(no_policy, GetAllowedConnectionTypesForUpdate(_)) |
| 337 | .Times(3) |
| 338 | .WillRepeatedly(Return(false)); |
| 339 | |
| 340 | // No user pref: block. |
| 341 | EXPECT_CALL(*prefs, Exists(kPrefsUpdateOverCellularPermission)) |
| 342 | .Times(1) |
| 343 | .WillOnce(Return(false)); |
Alex Deymo | 75eac7e | 2015-07-29 13:39:14 -0700 | [diff] [blame] | 344 | EXPECT_FALSE(cmut_.IsUpdateAllowedOver(NetworkConnectionType::kCellular, |
Alex Deymo | 6ae9120 | 2014-03-10 19:21:25 -0700 | [diff] [blame] | 345 | NetworkTethering::kUnknown)); |
Alex Deymo | f4867c4 | 2013-06-28 14:41:39 -0700 | [diff] [blame] | 346 | |
| 347 | // Allow per user pref. |
| 348 | EXPECT_CALL(*prefs, Exists(kPrefsUpdateOverCellularPermission)) |
| 349 | .Times(1) |
| 350 | .WillOnce(Return(true)); |
Alex Deymo | efb7c4c | 2013-07-09 14:34:00 -0700 | [diff] [blame] | 351 | EXPECT_CALL(*prefs, GetBoolean(kPrefsUpdateOverCellularPermission, _)) |
Alex Deymo | f4867c4 | 2013-06-28 14:41:39 -0700 | [diff] [blame] | 352 | .Times(1) |
Alex Deymo | 3053450 | 2015-07-20 15:06:33 -0700 | [diff] [blame] | 353 | .WillOnce(DoAll(SetArgPointee<1>(true), Return(true))); |
Alex Deymo | 75eac7e | 2015-07-29 13:39:14 -0700 | [diff] [blame] | 354 | EXPECT_TRUE(cmut_.IsUpdateAllowedOver(NetworkConnectionType::kCellular, |
Alex Deymo | 6ae9120 | 2014-03-10 19:21:25 -0700 | [diff] [blame] | 355 | NetworkTethering::kUnknown)); |
Alex Deymo | f4867c4 | 2013-06-28 14:41:39 -0700 | [diff] [blame] | 356 | |
| 357 | // Block per user pref. |
| 358 | EXPECT_CALL(*prefs, Exists(kPrefsUpdateOverCellularPermission)) |
| 359 | .Times(1) |
| 360 | .WillOnce(Return(true)); |
Alex Deymo | efb7c4c | 2013-07-09 14:34:00 -0700 | [diff] [blame] | 361 | EXPECT_CALL(*prefs, GetBoolean(kPrefsUpdateOverCellularPermission, _)) |
Alex Deymo | f4867c4 | 2013-06-28 14:41:39 -0700 | [diff] [blame] | 362 | .Times(1) |
Alex Deymo | 3053450 | 2015-07-20 15:06:33 -0700 | [diff] [blame] | 363 | .WillOnce(DoAll(SetArgPointee<1>(false), Return(true))); |
Alex Deymo | 75eac7e | 2015-07-29 13:39:14 -0700 | [diff] [blame] | 364 | EXPECT_FALSE(cmut_.IsUpdateAllowedOver(NetworkConnectionType::kCellular, |
Alex Deymo | 6ae9120 | 2014-03-10 19:21:25 -0700 | [diff] [blame] | 365 | NetworkTethering::kUnknown)); |
Alex Deymo | f4867c4 | 2013-06-28 14:41:39 -0700 | [diff] [blame] | 366 | } |
| 367 | |
Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 368 | TEST_F(ConnectionManagerTest, StringForConnectionTypeTest) { |
Ben Chan | c6007e4 | 2013-09-19 23:49:22 -0700 | [diff] [blame] | 369 | EXPECT_STREQ(shill::kTypeEthernet, |
Alex Deymo | 75eac7e | 2015-07-29 13:39:14 -0700 | [diff] [blame] | 370 | cmut_.StringForConnectionType(NetworkConnectionType::kEthernet)); |
Ben Chan | c6007e4 | 2013-09-19 23:49:22 -0700 | [diff] [blame] | 371 | EXPECT_STREQ(shill::kTypeWifi, |
Alex Deymo | 75eac7e | 2015-07-29 13:39:14 -0700 | [diff] [blame] | 372 | cmut_.StringForConnectionType(NetworkConnectionType::kWifi)); |
Ben Chan | c6007e4 | 2013-09-19 23:49:22 -0700 | [diff] [blame] | 373 | EXPECT_STREQ(shill::kTypeWimax, |
Alex Deymo | 75eac7e | 2015-07-29 13:39:14 -0700 | [diff] [blame] | 374 | cmut_.StringForConnectionType(NetworkConnectionType::kWimax)); |
Ben Chan | c6007e4 | 2013-09-19 23:49:22 -0700 | [diff] [blame] | 375 | EXPECT_STREQ(shill::kTypeBluetooth, |
Alex Deymo | 75eac7e | 2015-07-29 13:39:14 -0700 | [diff] [blame] | 376 | cmut_.StringForConnectionType( |
| 377 | NetworkConnectionType::kBluetooth)); |
Ben Chan | c6007e4 | 2013-09-19 23:49:22 -0700 | [diff] [blame] | 378 | EXPECT_STREQ(shill::kTypeCellular, |
Alex Deymo | 75eac7e | 2015-07-29 13:39:14 -0700 | [diff] [blame] | 379 | cmut_.StringForConnectionType(NetworkConnectionType::kCellular)); |
Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 380 | EXPECT_STREQ("Unknown", |
Alex Deymo | 75eac7e | 2015-07-29 13:39:14 -0700 | [diff] [blame] | 381 | cmut_.StringForConnectionType(NetworkConnectionType::kUnknown)); |
Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 382 | EXPECT_STREQ("Unknown", |
| 383 | cmut_.StringForConnectionType( |
| 384 | static_cast<NetworkConnectionType>(999999))); |
| 385 | } |
| 386 | |
| 387 | TEST_F(ConnectionManagerTest, MalformedServiceList) { |
Alex Deymo | 3053450 | 2015-07-20 15:06:33 -0700 | [diff] [blame] | 388 | SetManagerReply("/service/guest-network", false); |
Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 389 | |
| 390 | NetworkConnectionType type; |
Alex Deymo | 6ae9120 | 2014-03-10 19:21:25 -0700 | [diff] [blame] | 391 | NetworkTethering tethering; |
Alex Deymo | 3053450 | 2015-07-20 15:06:33 -0700 | [diff] [blame] | 392 | EXPECT_FALSE(cmut_.GetConnectionProperties(&type, &tethering)); |
Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 393 | } |
| 394 | |
| 395 | } // namespace chromeos_update_engine |