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