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