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; |
Amin Hassani | 7cc8bb0 | 2019-01-14 16:29:47 -0800 | [diff] [blame] | 43 | using testing::_; |
Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 44 | using testing::Return; |
Alex Deymo | 3053450 | 2015-07-20 15:06:33 -0700 | [diff] [blame] | 45 | using testing::SetArgPointee; |
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 | |
Amin Hassani | 7cc8bb0 | 2019-01-14 16:29:47 -0800 | [diff] [blame] | 74 | void TestWithServiceType(const char* service_type, |
| 75 | const char* physical_technology, |
| 76 | ConnectionType expected_type); |
Colin Howes | c9e98d6 | 2018-09-18 10:35:20 -0700 | [diff] [blame] | 77 | |
| 78 | void TestWithServiceDisconnected(ConnectionType expected_type); |
| 79 | |
Amin Hassani | 7cc8bb0 | 2019-01-14 16:29:47 -0800 | [diff] [blame] | 80 | void TestWithServiceTethering(const char* service_tethering, |
| 81 | ConnectionTethering expected_tethering); |
Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 82 | |
Alex Vakulenko | 3f39d5c | 2015-10-13 09:27:13 -0700 | [diff] [blame] | 83 | brillo::FakeMessageLoop loop_{nullptr}; |
Gilad Arnold | 5bb4c90 | 2014-04-10 12:32:13 -0700 | [diff] [blame] | 84 | FakeSystemState fake_system_state_; |
Sen Jiang | f5bebae | 2016-06-03 15:36:54 -0700 | [diff] [blame] | 85 | FakeShillProxy* fake_shill_proxy_; |
Alex Deymo | 3053450 | 2015-07-20 15:06:33 -0700 | [diff] [blame] | 86 | |
| 87 | // ConnectionManager under test. |
Sen Jiang | f5bebae | 2016-06-03 15:36:54 -0700 | [diff] [blame] | 88 | ConnectionManager cmut_{fake_shill_proxy_, &fake_system_state_}; |
Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 89 | }; |
| 90 | |
Alex Deymo | 3053450 | 2015-07-20 15:06:33 -0700 | [diff] [blame] | 91 | void ConnectionManagerTest::SetManagerReply(const char* default_service, |
| 92 | bool reply_succeeds) { |
Sen Jiang | f5bebae | 2016-06-03 15:36:54 -0700 | [diff] [blame] | 93 | ManagerProxyMock* manager_proxy_mock = fake_shill_proxy_->GetManagerProxy(); |
Alex Deymo | 3053450 | 2015-07-20 15:06:33 -0700 | [diff] [blame] | 94 | if (!reply_succeeds) { |
| 95 | EXPECT_CALL(*manager_proxy_mock, GetProperties(_, _, _)) |
| 96 | .WillOnce(Return(false)); |
| 97 | return; |
| 98 | } |
Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 99 | |
Alex Deymo | 3053450 | 2015-07-20 15:06:33 -0700 | [diff] [blame] | 100 | // Create a dictionary of properties and optionally include the default |
| 101 | // service. |
Alex Vakulenko | 3f39d5c | 2015-10-13 09:27:13 -0700 | [diff] [blame] | 102 | brillo::VariantDictionary reply_dict; |
Alex Deymo | 3053450 | 2015-07-20 15:06:33 -0700 | [diff] [blame] | 103 | reply_dict["SomeOtherProperty"] = 0xC0FFEE; |
Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 104 | |
Alex Deymo | 3053450 | 2015-07-20 15:06:33 -0700 | [diff] [blame] | 105 | if (default_service) { |
| 106 | reply_dict[shill::kDefaultServiceProperty] = |
| 107 | dbus::ObjectPath(default_service); |
| 108 | } |
| 109 | EXPECT_CALL(*manager_proxy_mock, GetProperties(_, _, _)) |
| 110 | .WillOnce(DoAll(SetArgPointee<0>(reply_dict), Return(true))); |
Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 111 | } |
| 112 | |
Alex Deymo | 3053450 | 2015-07-20 15:06:33 -0700 | [diff] [blame] | 113 | void ConnectionManagerTest::SetServiceReply(const string& service_path, |
| 114 | const char* service_type, |
Alex Deymo | 6ae9120 | 2014-03-10 19:21:25 -0700 | [diff] [blame] | 115 | const char* physical_technology, |
| 116 | const char* service_tethering) { |
Alex Vakulenko | 3f39d5c | 2015-10-13 09:27:13 -0700 | [diff] [blame] | 117 | brillo::VariantDictionary reply_dict; |
Alex Deymo | 3053450 | 2015-07-20 15:06:33 -0700 | [diff] [blame] | 118 | reply_dict["SomeOtherProperty"] = 0xC0FFEE; |
| 119 | |
| 120 | if (service_type) |
| 121 | reply_dict[shill::kTypeProperty] = string(service_type); |
Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 122 | |
Alex Vakulenko | 88b591f | 2014-08-28 16:48:57 -0700 | [diff] [blame] | 123 | if (physical_technology) { |
Alex Deymo | 3053450 | 2015-07-20 15:06:33 -0700 | [diff] [blame] | 124 | reply_dict[shill::kPhysicalTechnologyProperty] = |
| 125 | string(physical_technology); |
Alex Deymo | 1c4e638 | 2013-07-15 12:09:51 -0700 | [diff] [blame] | 126 | } |
| 127 | |
Alex Deymo | 3053450 | 2015-07-20 15:06:33 -0700 | [diff] [blame] | 128 | if (service_tethering) |
| 129 | reply_dict[shill::kTetheringProperty] = string(service_tethering); |
| 130 | |
| 131 | std::unique_ptr<ServiceProxyMock> service_proxy_mock(new ServiceProxyMock()); |
Alex Deymo | 6ae9120 | 2014-03-10 19:21:25 -0700 | [diff] [blame] | 132 | |
Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 133 | // Plumb return value into mock object. |
Alex Deymo | 3053450 | 2015-07-20 15:06:33 -0700 | [diff] [blame] | 134 | EXPECT_CALL(*service_proxy_mock.get(), GetProperties(_, _, _)) |
| 135 | .WillOnce(DoAll(SetArgPointee<0>(reply_dict), Return(true))); |
Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 136 | |
Sen Jiang | f5bebae | 2016-06-03 15:36:54 -0700 | [diff] [blame] | 137 | fake_shill_proxy_->SetServiceForPath(dbus::ObjectPath(service_path), |
| 138 | std::move(service_proxy_mock)); |
Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 139 | } |
| 140 | |
Amin Hassani | 7cc8bb0 | 2019-01-14 16:29:47 -0800 | [diff] [blame] | 141 | void ConnectionManagerTest::TestWithServiceType(const char* service_type, |
| 142 | const char* physical_technology, |
| 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( |
Amin Hassani | 7cc8bb0 | 2019-01-14 16:29:47 -0800 | [diff] [blame] | 159 | const char* service_tethering, ConnectionTethering expected_tethering) { |
Alex Deymo | 758dd53 | 2015-09-09 15:21:22 -0700 | [diff] [blame] | 160 | SetManagerReply("/service/guest/network", true); |
Alex Deymo | 3053450 | 2015-07-20 15:06:33 -0700 | [diff] [blame] | 161 | SetServiceReply( |
Alex Deymo | 758dd53 | 2015-09-09 15:21:22 -0700 | [diff] [blame] | 162 | "/service/guest/network", shill::kTypeWifi, nullptr, service_tethering); |
Alex Deymo | 6ae9120 | 2014-03-10 19:21:25 -0700 | [diff] [blame] | 163 | |
Sen Jiang | 255e22b | 2016-05-20 16:15:29 -0700 | [diff] [blame] | 164 | ConnectionType type; |
| 165 | ConnectionTethering tethering; |
Alex Deymo | 3053450 | 2015-07-20 15:06:33 -0700 | [diff] [blame] | 166 | EXPECT_TRUE(cmut_.GetConnectionProperties(&type, &tethering)); |
Alex Deymo | 6ae9120 | 2014-03-10 19:21:25 -0700 | [diff] [blame] | 167 | EXPECT_EQ(expected_tethering, tethering); |
Alex Deymo | 3053450 | 2015-07-20 15:06:33 -0700 | [diff] [blame] | 168 | testing::Mock::VerifyAndClearExpectations( |
Sen Jiang | f5bebae | 2016-06-03 15:36:54 -0700 | [diff] [blame] | 169 | fake_shill_proxy_->GetManagerProxy()); |
Alex Deymo | 6ae9120 | 2014-03-10 19:21:25 -0700 | [diff] [blame] | 170 | } |
| 171 | |
Colin Howes | c9e98d6 | 2018-09-18 10:35:20 -0700 | [diff] [blame] | 172 | void ConnectionManagerTest::TestWithServiceDisconnected( |
| 173 | ConnectionType expected_type) { |
| 174 | SetManagerReply("/", true); |
| 175 | |
| 176 | ConnectionType type; |
| 177 | ConnectionTethering tethering; |
| 178 | EXPECT_TRUE(cmut_.GetConnectionProperties(&type, &tethering)); |
| 179 | EXPECT_EQ(expected_type, type); |
| 180 | testing::Mock::VerifyAndClearExpectations( |
| 181 | fake_shill_proxy_->GetManagerProxy()); |
| 182 | } |
| 183 | |
Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 184 | TEST_F(ConnectionManagerTest, SimpleTest) { |
Sen Jiang | 255e22b | 2016-05-20 16:15:29 -0700 | [diff] [blame] | 185 | TestWithServiceType(shill::kTypeEthernet, nullptr, ConnectionType::kEthernet); |
| 186 | TestWithServiceType(shill::kTypeWifi, nullptr, ConnectionType::kWifi); |
Sen Jiang | 255e22b | 2016-05-20 16:15:29 -0700 | [diff] [blame] | 187 | TestWithServiceType(shill::kTypeCellular, nullptr, ConnectionType::kCellular); |
Alex Deymo | 1c4e638 | 2013-07-15 12:09:51 -0700 | [diff] [blame] | 188 | } |
| 189 | |
| 190 | TEST_F(ConnectionManagerTest, PhysicalTechnologyTest) { |
Sen Jiang | 255e22b | 2016-05-20 16:15:29 -0700 | [diff] [blame] | 191 | TestWithServiceType(shill::kTypeVPN, nullptr, ConnectionType::kUnknown); |
| 192 | TestWithServiceType( |
| 193 | shill::kTypeVPN, shill::kTypeVPN, ConnectionType::kUnknown); |
| 194 | TestWithServiceType(shill::kTypeVPN, shill::kTypeWifi, ConnectionType::kWifi); |
Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 195 | } |
| 196 | |
Alex Deymo | 6ae9120 | 2014-03-10 19:21:25 -0700 | [diff] [blame] | 197 | TEST_F(ConnectionManagerTest, TetheringTest) { |
| 198 | TestWithServiceTethering(shill::kTetheringConfirmedState, |
Sen Jiang | 255e22b | 2016-05-20 16:15:29 -0700 | [diff] [blame] | 199 | ConnectionTethering::kConfirmed); |
Alex Deymo | 6ae9120 | 2014-03-10 19:21:25 -0700 | [diff] [blame] | 200 | TestWithServiceTethering(shill::kTetheringNotDetectedState, |
Sen Jiang | 255e22b | 2016-05-20 16:15:29 -0700 | [diff] [blame] | 201 | ConnectionTethering::kNotDetected); |
Alex Deymo | 6ae9120 | 2014-03-10 19:21:25 -0700 | [diff] [blame] | 202 | TestWithServiceTethering(shill::kTetheringSuspectedState, |
Sen Jiang | 255e22b | 2016-05-20 16:15:29 -0700 | [diff] [blame] | 203 | ConnectionTethering::kSuspected); |
Alex Deymo | 6ae9120 | 2014-03-10 19:21:25 -0700 | [diff] [blame] | 204 | TestWithServiceTethering("I'm not a valid property value =)", |
Sen Jiang | 255e22b | 2016-05-20 16:15:29 -0700 | [diff] [blame] | 205 | ConnectionTethering::kUnknown); |
Alex Deymo | 6ae9120 | 2014-03-10 19:21:25 -0700 | [diff] [blame] | 206 | } |
| 207 | |
Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 208 | TEST_F(ConnectionManagerTest, UnknownTest) { |
Sen Jiang | 255e22b | 2016-05-20 16:15:29 -0700 | [diff] [blame] | 209 | TestWithServiceType("foo", nullptr, ConnectionType::kUnknown); |
Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 210 | } |
| 211 | |
Colin Howes | c9e98d6 | 2018-09-18 10:35:20 -0700 | [diff] [blame] | 212 | TEST_F(ConnectionManagerTest, DisconnectTest) { |
| 213 | TestWithServiceDisconnected(ConnectionType::kDisconnected); |
| 214 | } |
| 215 | |
Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 216 | TEST_F(ConnectionManagerTest, AllowUpdatesOverEthernetTest) { |
Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 217 | // Updates over Ethernet are allowed even if there's no policy. |
Sen Jiang | 255e22b | 2016-05-20 16:15:29 -0700 | [diff] [blame] | 218 | EXPECT_TRUE(cmut_.IsUpdateAllowedOver(ConnectionType::kEthernet, |
| 219 | ConnectionTethering::kUnknown)); |
Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 220 | } |
| 221 | |
| 222 | TEST_F(ConnectionManagerTest, AllowUpdatesOverWifiTest) { |
Sen Jiang | 255e22b | 2016-05-20 16:15:29 -0700 | [diff] [blame] | 223 | EXPECT_TRUE(cmut_.IsUpdateAllowedOver(ConnectionType::kWifi, |
| 224 | ConnectionTethering::kUnknown)); |
Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 225 | } |
| 226 | |
Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 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 |
Alex Khouderchah | bfa8226 | 2019-08-13 15:00:34 -0700 | [diff] [blame] | 251 | // setting. |
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)); |
Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 254 | |
| 255 | EXPECT_CALL(allow_3g_policy, GetAllowedConnectionTypesForUpdate(_)) |
Alex Deymo | 6ae9120 | 2014-03-10 19:21:25 -0700 | [diff] [blame] | 256 | .Times(3) |
Alex Deymo | 3053450 | 2015-07-20 15:06:33 -0700 | [diff] [blame] | 257 | .WillRepeatedly(DoAll(SetArgPointee<0>(allowed_set), Return(true))); |
Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 258 | |
Sen Jiang | 255e22b | 2016-05-20 16:15:29 -0700 | [diff] [blame] | 259 | EXPECT_TRUE(cmut_.IsUpdateAllowedOver(ConnectionType::kEthernet, |
| 260 | ConnectionTethering::kUnknown)); |
| 261 | EXPECT_TRUE(cmut_.IsUpdateAllowedOver(ConnectionType::kEthernet, |
| 262 | ConnectionTethering::kNotDetected)); |
| 263 | EXPECT_TRUE(cmut_.IsUpdateAllowedOver(ConnectionType::kCellular, |
| 264 | ConnectionTethering::kUnknown)); |
| 265 | EXPECT_TRUE(cmut_.IsUpdateAllowedOver(ConnectionType::kWifi, |
| 266 | ConnectionTethering::kUnknown)); |
Alex Deymo | 6ae9120 | 2014-03-10 19:21:25 -0700 | [diff] [blame] | 267 | |
| 268 | // Tethered networks are treated in the same way as Cellular networks and |
| 269 | // thus allowed. |
Sen Jiang | 255e22b | 2016-05-20 16:15:29 -0700 | [diff] [blame] | 270 | EXPECT_TRUE(cmut_.IsUpdateAllowedOver(ConnectionType::kEthernet, |
| 271 | ConnectionTethering::kConfirmed)); |
| 272 | EXPECT_TRUE(cmut_.IsUpdateAllowedOver(ConnectionType::kWifi, |
| 273 | ConnectionTethering::kConfirmed)); |
Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 274 | } |
| 275 | |
Weidong Guo | 421ff33 | 2017-04-17 10:08:38 -0700 | [diff] [blame] | 276 | TEST_F(ConnectionManagerTest, AllowUpdatesOverCellularByDefaultTest) { |
| 277 | policy::MockDevicePolicy device_policy; |
| 278 | // Set an empty device policy. |
| 279 | fake_system_state_.set_device_policy(&device_policy); |
| 280 | |
| 281 | EXPECT_TRUE(cmut_.IsUpdateAllowedOver(ConnectionType::kCellular, |
| 282 | ConnectionTethering::kUnknown)); |
Alex Deymo | 6ae9120 | 2014-03-10 19:21:25 -0700 | [diff] [blame] | 283 | } |
| 284 | |
Weidong Guo | 421ff33 | 2017-04-17 10:08:38 -0700 | [diff] [blame] | 285 | TEST_F(ConnectionManagerTest, AllowUpdatesOverTetheredNetworkByDefaultTest) { |
| 286 | policy::MockDevicePolicy device_policy; |
| 287 | // Set an empty device policy. |
| 288 | fake_system_state_.set_device_policy(&device_policy); |
| 289 | |
| 290 | EXPECT_TRUE(cmut_.IsUpdateAllowedOver(ConnectionType::kWifi, |
| 291 | ConnectionTethering::kConfirmed)); |
| 292 | EXPECT_TRUE(cmut_.IsUpdateAllowedOver(ConnectionType::kEthernet, |
| 293 | ConnectionTethering::kConfirmed)); |
Sen Jiang | 255e22b | 2016-05-20 16:15:29 -0700 | [diff] [blame] | 294 | EXPECT_TRUE(cmut_.IsUpdateAllowedOver(ConnectionType::kWifi, |
| 295 | ConnectionTethering::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; |
Sen Jiang | 255e22b | 2016-05-20 16:15:29 -0700 | [diff] [blame] | 306 | allowed_set.insert(StringForConnectionType(ConnectionType::kEthernet)); |
| 307 | allowed_set.insert(StringForConnectionType(ConnectionType::kWifi)); |
Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 308 | |
| 309 | EXPECT_CALL(block_3g_policy, GetAllowedConnectionTypesForUpdate(_)) |
| 310 | .Times(1) |
Alex Deymo | 3053450 | 2015-07-20 15:06:33 -0700 | [diff] [blame] | 311 | .WillOnce(DoAll(SetArgPointee<0>(allowed_set), Return(true))); |
Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 312 | |
Sen Jiang | 255e22b | 2016-05-20 16:15:29 -0700 | [diff] [blame] | 313 | EXPECT_FALSE(cmut_.IsUpdateAllowedOver(ConnectionType::kCellular, |
| 314 | ConnectionTethering::kUnknown)); |
Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 315 | } |
| 316 | |
Weidong Guo | 421ff33 | 2017-04-17 10:08:38 -0700 | [diff] [blame] | 317 | TEST_F(ConnectionManagerTest, AllowUpdatesOver3GIfPolicyIsNotSet) { |
| 318 | policy::MockDevicePolicy device_policy; |
Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 319 | |
Weidong Guo | 421ff33 | 2017-04-17 10:08:38 -0700 | [diff] [blame] | 320 | fake_system_state_.set_device_policy(&device_policy); |
Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 321 | |
| 322 | // Return false for GetAllowedConnectionTypesForUpdate and see |
Weidong Guo | 421ff33 | 2017-04-17 10:08:38 -0700 | [diff] [blame] | 323 | // that updates are allowed as device policy is not set. Further |
| 324 | // check is left to |OmahaRequestAction|. |
| 325 | EXPECT_CALL(device_policy, GetAllowedConnectionTypesForUpdate(_)) |
Alex Deymo | f4867c4 | 2013-06-28 14:41:39 -0700 | [diff] [blame] | 326 | .Times(1) |
| 327 | .WillOnce(Return(false)); |
Alex Deymo | f4867c4 | 2013-06-28 14:41:39 -0700 | [diff] [blame] | 328 | |
Sen Jiang | 255e22b | 2016-05-20 16:15:29 -0700 | [diff] [blame] | 329 | EXPECT_TRUE(cmut_.IsUpdateAllowedOver(ConnectionType::kCellular, |
| 330 | ConnectionTethering::kUnknown)); |
Weidong Guo | 421ff33 | 2017-04-17 10:08:38 -0700 | [diff] [blame] | 331 | } |
Tao Bao | 5688d16 | 2017-06-06 13:09:06 -0700 | [diff] [blame] | 332 | |
Weidong Guo | 421ff33 | 2017-04-17 10:08:38 -0700 | [diff] [blame] | 333 | TEST_F(ConnectionManagerTest, AllowUpdatesOverCellularIfPolicyFailsToBeLoaded) { |
| 334 | fake_system_state_.set_device_policy(nullptr); |
| 335 | |
| 336 | EXPECT_TRUE(cmut_.IsUpdateAllowedOver(ConnectionType::kCellular, |
| 337 | ConnectionTethering::kUnknown)); |
Alex Deymo | f4867c4 | 2013-06-28 14:41:39 -0700 | [diff] [blame] | 338 | } |
| 339 | |
Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 340 | TEST_F(ConnectionManagerTest, StringForConnectionTypeTest) { |
Ben Chan | c6007e4 | 2013-09-19 23:49:22 -0700 | [diff] [blame] | 341 | EXPECT_STREQ(shill::kTypeEthernet, |
Sen Jiang | 255e22b | 2016-05-20 16:15:29 -0700 | [diff] [blame] | 342 | StringForConnectionType(ConnectionType::kEthernet)); |
Ben Chan | c6007e4 | 2013-09-19 23:49:22 -0700 | [diff] [blame] | 343 | EXPECT_STREQ(shill::kTypeWifi, |
Sen Jiang | 255e22b | 2016-05-20 16:15:29 -0700 | [diff] [blame] | 344 | StringForConnectionType(ConnectionType::kWifi)); |
Ben Chan | c6007e4 | 2013-09-19 23:49:22 -0700 | [diff] [blame] | 345 | EXPECT_STREQ(shill::kTypeCellular, |
Sen Jiang | 255e22b | 2016-05-20 16:15:29 -0700 | [diff] [blame] | 346 | StringForConnectionType(ConnectionType::kCellular)); |
| 347 | EXPECT_STREQ("Unknown", StringForConnectionType(ConnectionType::kUnknown)); |
Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 348 | EXPECT_STREQ("Unknown", |
Sen Jiang | 255e22b | 2016-05-20 16:15:29 -0700 | [diff] [blame] | 349 | StringForConnectionType(static_cast<ConnectionType>(999999))); |
Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 350 | } |
| 351 | |
| 352 | TEST_F(ConnectionManagerTest, MalformedServiceList) { |
Alex Deymo | 758dd53 | 2015-09-09 15:21:22 -0700 | [diff] [blame] | 353 | SetManagerReply("/service/guest/network", false); |
Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 354 | |
Sen Jiang | 255e22b | 2016-05-20 16:15:29 -0700 | [diff] [blame] | 355 | ConnectionType type; |
| 356 | ConnectionTethering tethering; |
Alex Deymo | 3053450 | 2015-07-20 15:06:33 -0700 | [diff] [blame] | 357 | EXPECT_FALSE(cmut_.GetConnectionProperties(&type, &tethering)); |
Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 358 | } |
| 359 | |
| 360 | } // namespace chromeos_update_engine |