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