Alex Deymo | 0d11c60 | 2014-04-23 20:12:20 -0700 | [diff] [blame] | 1 | // Copyright (c) 2014 The Chromium OS Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
Alex Deymo | 63784a5 | 2014-05-28 10:46:14 -0700 | [diff] [blame] | 5 | #include "update_engine/update_manager/chromeos_policy.h" |
Alex Deymo | 0d11c60 | 2014-04-23 20:12:20 -0700 | [diff] [blame] | 6 | |
Gilad Arnold | 0adbc94 | 2014-05-12 10:35:43 -0700 | [diff] [blame] | 7 | #include <set> |
Alex Deymo | 0d11c60 | 2014-04-23 20:12:20 -0700 | [diff] [blame] | 8 | #include <string> |
Gilad Arnold | b3b0544 | 2014-05-30 14:25:05 -0700 | [diff] [blame] | 9 | #include <vector> |
Alex Deymo | 0d11c60 | 2014-04-23 20:12:20 -0700 | [diff] [blame] | 10 | |
| 11 | #include <base/time/time.h> |
| 12 | #include <gtest/gtest.h> |
| 13 | |
| 14 | #include "update_engine/fake_clock.h" |
Alex Deymo | 63784a5 | 2014-05-28 10:46:14 -0700 | [diff] [blame] | 15 | #include "update_engine/update_manager/evaluation_context.h" |
| 16 | #include "update_engine/update_manager/fake_state.h" |
| 17 | #include "update_engine/update_manager/umtest_utils.h" |
Alex Deymo | 0d11c60 | 2014-04-23 20:12:20 -0700 | [diff] [blame] | 18 | |
| 19 | using base::Time; |
| 20 | using base::TimeDelta; |
Gilad Arnold | b3b0544 | 2014-05-30 14:25:05 -0700 | [diff] [blame] | 21 | using chromeos_update_engine::ErrorCode; |
Alex Deymo | 0d11c60 | 2014-04-23 20:12:20 -0700 | [diff] [blame] | 22 | using chromeos_update_engine::FakeClock; |
Gilad Arnold | 0adbc94 | 2014-05-12 10:35:43 -0700 | [diff] [blame] | 23 | using std::set; |
Alex Deymo | 0d11c60 | 2014-04-23 20:12:20 -0700 | [diff] [blame] | 24 | using std::string; |
Gilad Arnold | b3b0544 | 2014-05-30 14:25:05 -0700 | [diff] [blame] | 25 | using std::vector; |
Alex Deymo | 0d11c60 | 2014-04-23 20:12:20 -0700 | [diff] [blame] | 26 | |
Alex Deymo | 63784a5 | 2014-05-28 10:46:14 -0700 | [diff] [blame] | 27 | namespace chromeos_update_manager { |
Alex Deymo | 0d11c60 | 2014-04-23 20:12:20 -0700 | [diff] [blame] | 28 | |
Alex Deymo | 63784a5 | 2014-05-28 10:46:14 -0700 | [diff] [blame] | 29 | class UmChromeOSPolicyTest : public ::testing::Test { |
Alex Deymo | 0d11c60 | 2014-04-23 20:12:20 -0700 | [diff] [blame] | 30 | protected: |
| 31 | virtual void SetUp() { |
| 32 | SetUpDefaultClock(); |
Gilad Arnold | b227199 | 2014-06-19 12:35:24 -0700 | [diff] [blame] | 33 | eval_ctx_ = new EvaluationContext(&fake_clock_, TimeDelta::FromSeconds(5)); |
Gilad Arnold | f62a4b8 | 2014-05-01 07:41:07 -0700 | [diff] [blame] | 34 | SetUpDefaultState(); |
| 35 | SetUpDefaultDevicePolicy(); |
Alex Deymo | 0d11c60 | 2014-04-23 20:12:20 -0700 | [diff] [blame] | 36 | } |
| 37 | |
| 38 | // Sets the clock to fixed values. |
| 39 | void SetUpDefaultClock() { |
| 40 | fake_clock_.SetMonotonicTime(Time::FromInternalValue(12345678L)); |
| 41 | fake_clock_.SetWallclockTime(Time::FromInternalValue(12345678901234L)); |
| 42 | } |
| 43 | |
| 44 | void SetUpDefaultState() { |
| 45 | fake_state_.updater_provider()->var_updater_started_time()->reset( |
| 46 | new Time(fake_clock_.GetWallclockTime())); |
| 47 | fake_state_.updater_provider()->var_last_checked_time()->reset( |
| 48 | new Time(fake_clock_.GetWallclockTime())); |
| 49 | fake_state_.updater_provider()->var_consecutive_failed_update_checks()-> |
Gilad Arnold | 684219d | 2014-07-07 14:54:57 -0700 | [diff] [blame] | 50 | reset(new unsigned int(0)); // NOLINT(readability/casting) |
Alex Deymo | 0d11c60 | 2014-04-23 20:12:20 -0700 | [diff] [blame] | 51 | |
| 52 | fake_state_.random_provider()->var_seed()->reset( |
| 53 | new uint64_t(4)); // chosen by fair dice roll. |
| 54 | // guaranteed to be random. |
Gilad Arnold | f62a4b8 | 2014-05-01 07:41:07 -0700 | [diff] [blame] | 55 | |
| 56 | // No device policy loaded by default. |
| 57 | fake_state_.device_policy_provider()->var_device_policy_is_loaded()->reset( |
| 58 | new bool(false)); |
| 59 | |
Gilad Arnold | 76a11f6 | 2014-05-20 09:02:12 -0700 | [diff] [blame] | 60 | // For the purpose of the tests, this is an official build and OOBE was |
| 61 | // completed. |
Gilad Arnold | f62a4b8 | 2014-05-01 07:41:07 -0700 | [diff] [blame] | 62 | fake_state_.system_provider()->var_is_official_build()->reset( |
| 63 | new bool(true)); |
Gilad Arnold | 76a11f6 | 2014-05-20 09:02:12 -0700 | [diff] [blame] | 64 | fake_state_.system_provider()->var_is_oobe_complete()->reset( |
| 65 | new bool(true)); |
Gilad Arnold | 0adbc94 | 2014-05-12 10:35:43 -0700 | [diff] [blame] | 66 | |
| 67 | // Connection is wifi, untethered. |
| 68 | fake_state_.shill_provider()->var_conn_type()-> |
| 69 | reset(new ConnectionType(ConnectionType::kWifi)); |
| 70 | fake_state_.shill_provider()->var_conn_tethering()-> |
| 71 | reset(new ConnectionTethering(ConnectionTethering::kNotDetected)); |
Gilad Arnold | f62a4b8 | 2014-05-01 07:41:07 -0700 | [diff] [blame] | 72 | } |
| 73 | |
Gilad Arnold | b3b0544 | 2014-05-30 14:25:05 -0700 | [diff] [blame] | 74 | // Sets up a default device policy that does not impose any restrictions |
| 75 | // (HTTP) nor enables any features (P2P). |
Gilad Arnold | f62a4b8 | 2014-05-01 07:41:07 -0700 | [diff] [blame] | 76 | void SetUpDefaultDevicePolicy() { |
| 77 | fake_state_.device_policy_provider()->var_device_policy_is_loaded()->reset( |
| 78 | new bool(true)); |
| 79 | fake_state_.device_policy_provider()->var_update_disabled()->reset( |
| 80 | new bool(false)); |
| 81 | fake_state_.device_policy_provider()-> |
| 82 | var_allowed_connection_types_for_update()->reset(nullptr); |
| 83 | fake_state_.device_policy_provider()->var_scatter_factor()->reset( |
| 84 | new TimeDelta()); |
| 85 | fake_state_.device_policy_provider()->var_http_downloads_enabled()->reset( |
Gilad Arnold | b3b0544 | 2014-05-30 14:25:05 -0700 | [diff] [blame] | 86 | new bool(true)); |
Gilad Arnold | f62a4b8 | 2014-05-01 07:41:07 -0700 | [diff] [blame] | 87 | fake_state_.device_policy_provider()->var_au_p2p_enabled()->reset( |
| 88 | new bool(false)); |
| 89 | fake_state_.device_policy_provider()->var_release_channel_delegated()-> |
| 90 | reset(new bool(true)); |
| 91 | } |
| 92 | |
| 93 | // Configures the UpdateCheckAllowed policy to return a desired value by |
| 94 | // faking the current wall clock time as needed. Restores the default state. |
| 95 | // This is used when testing policies that depend on this one. |
| 96 | void SetUpdateCheckAllowed(bool allow_check) { |
| 97 | Time next_update_check; |
| 98 | ExpectPolicyStatus(EvalStatus::kSucceeded, |
| 99 | &ChromeOSPolicy::NextUpdateCheckTime, |
| 100 | &next_update_check); |
| 101 | SetUpDefaultState(); |
| 102 | SetUpDefaultDevicePolicy(); |
| 103 | Time curr_time = next_update_check; |
| 104 | if (allow_check) |
| 105 | curr_time += TimeDelta::FromSeconds(1); |
| 106 | else |
| 107 | curr_time -= TimeDelta::FromSeconds(1); |
| 108 | fake_clock_.SetWallclockTime(curr_time); |
| 109 | } |
| 110 | |
| 111 | // Returns a default UpdateState structure: first seen time is calculated |
Gilad Arnold | b3b0544 | 2014-05-30 14:25:05 -0700 | [diff] [blame] | 112 | // backward from the current wall clock time, update was seen just once; |
| 113 | // there's a single HTTP download URL with a maximum of 10 allowed failures; |
| 114 | // there is no scattering wait period and the max allowed is 7 days, there is |
| 115 | // no check threshold and none is allowed. |
Gilad Arnold | f62a4b8 | 2014-05-01 07:41:07 -0700 | [diff] [blame] | 116 | UpdateState GetDefaultUpdateState(TimeDelta update_first_seen_period) { |
| 117 | UpdateState update_state = { |
| 118 | fake_clock_.GetWallclockTime() - update_first_seen_period, 1, |
Gilad Arnold | b3b0544 | 2014-05-30 14:25:05 -0700 | [diff] [blame] | 119 | vector<string>(1, "http://fake/url/"), 10, 0, 0, vector<ErrorCode>(), |
Gilad Arnold | f62a4b8 | 2014-05-01 07:41:07 -0700 | [diff] [blame] | 120 | TimeDelta(), TimeDelta::FromDays(7), 0, 0, 0 |
| 121 | }; |
| 122 | return update_state; |
Alex Deymo | 0d11c60 | 2014-04-23 20:12:20 -0700 | [diff] [blame] | 123 | } |
| 124 | |
| 125 | // Runs the passed |policy_method| policy and expects it to return the |
| 126 | // |expected| return value. |
| 127 | template<typename T, typename R, typename... Args> |
| 128 | void ExpectPolicyStatus( |
| 129 | EvalStatus expected, |
| 130 | T policy_method, |
| 131 | R* result, Args... args) { |
| 132 | string error = "<None>"; |
| 133 | eval_ctx_->ResetEvaluation(); |
| 134 | EXPECT_EQ(expected, |
Gilad Arnold | f62a4b8 | 2014-05-01 07:41:07 -0700 | [diff] [blame] | 135 | (policy_.*policy_method)(eval_ctx_, &fake_state_, &error, result, |
| 136 | args...)) |
Alex Deymo | c850b4f | 2014-05-19 11:06:41 -0700 | [diff] [blame] | 137 | << "Returned error: " << error |
| 138 | << "\nEvaluation context: " << eval_ctx_->DumpContext(); |
Alex Deymo | 0d11c60 | 2014-04-23 20:12:20 -0700 | [diff] [blame] | 139 | } |
| 140 | |
| 141 | FakeClock fake_clock_; |
| 142 | FakeState fake_state_; |
| 143 | scoped_refptr<EvaluationContext> eval_ctx_; |
| 144 | ChromeOSPolicy policy_; // ChromeOSPolicy under test. |
| 145 | }; |
| 146 | |
Alex Deymo | 63784a5 | 2014-05-28 10:46:14 -0700 | [diff] [blame] | 147 | TEST_F(UmChromeOSPolicyTest, FirstCheckIsAtMostInitialIntervalAfterStart) { |
Alex Deymo | 0d11c60 | 2014-04-23 20:12:20 -0700 | [diff] [blame] | 148 | Time next_update_check; |
| 149 | |
Gilad Arnold | 38b1402 | 2014-07-09 12:45:56 -0700 | [diff] [blame] | 150 | // Set the last update time so it'll appear as if this is a first update check |
| 151 | // in the lifetime of the current updater. |
| 152 | fake_state_.updater_provider()->var_last_checked_time()->reset( |
| 153 | new Time(fake_clock_.GetWallclockTime() - TimeDelta::FromMinutes(10))); |
| 154 | |
Alex Deymo | 0d11c60 | 2014-04-23 20:12:20 -0700 | [diff] [blame] | 155 | ExpectPolicyStatus(EvalStatus::kSucceeded, |
| 156 | &ChromeOSPolicy::NextUpdateCheckTime, &next_update_check); |
| 157 | |
| 158 | EXPECT_LE(fake_clock_.GetWallclockTime(), next_update_check); |
Gilad Arnold | 38b1402 | 2014-07-09 12:45:56 -0700 | [diff] [blame] | 159 | EXPECT_GE( |
| 160 | fake_clock_.GetWallclockTime() + TimeDelta::FromSeconds( |
| 161 | ChromeOSPolicy::kTimeoutInitialInterval + |
| 162 | ChromeOSPolicy::kTimeoutRegularFuzz / 2), |
| 163 | next_update_check); |
| 164 | } |
| 165 | |
| 166 | TEST_F(UmChromeOSPolicyTest, RecurringCheckBaseIntervalAndFuzz) { |
| 167 | // Ensure that we're using the correct interval (kPeriodicInterval) and fuzz |
| 168 | // (kTimeoutRegularFuzz) as base values for period updates. |
| 169 | Time next_update_check; |
| 170 | |
| 171 | ExpectPolicyStatus(EvalStatus::kSucceeded, |
| 172 | &ChromeOSPolicy::NextUpdateCheckTime, &next_update_check); |
| 173 | |
| 174 | EXPECT_LE( |
| 175 | fake_clock_.GetWallclockTime() + TimeDelta::FromSeconds( |
| 176 | ChromeOSPolicy::kTimeoutPeriodicInterval - |
| 177 | ChromeOSPolicy::kTimeoutRegularFuzz / 2), |
| 178 | next_update_check); |
| 179 | EXPECT_GE( |
| 180 | fake_clock_.GetWallclockTime() + TimeDelta::FromSeconds( |
| 181 | ChromeOSPolicy::kTimeoutPeriodicInterval + |
| 182 | ChromeOSPolicy::kTimeoutRegularFuzz / 2), |
| 183 | next_update_check); |
| 184 | } |
| 185 | |
| 186 | TEST_F(UmChromeOSPolicyTest, RecurringCheckBackoffIntervalAndFuzz) { |
| 187 | // Ensure that we're properly backing off and fuzzing in the presence of |
| 188 | // failed updates attempts. |
| 189 | Time next_update_check; |
| 190 | |
| 191 | fake_state_.updater_provider()->var_consecutive_failed_update_checks()-> |
| 192 | reset(new unsigned int(2)); // NOLINT(readability/casting) |
| 193 | |
| 194 | ExpectPolicyStatus(EvalStatus::kSucceeded, |
| 195 | &ChromeOSPolicy::NextUpdateCheckTime, &next_update_check); |
| 196 | |
| 197 | int expected_interval = ChromeOSPolicy::kTimeoutPeriodicInterval * 4; |
| 198 | EXPECT_LE( |
| 199 | fake_clock_.GetWallclockTime() + TimeDelta::FromSeconds( |
| 200 | expected_interval - expected_interval / 2), |
| 201 | next_update_check); |
| 202 | EXPECT_GE( |
| 203 | fake_clock_.GetWallclockTime() + TimeDelta::FromSeconds( |
| 204 | expected_interval + expected_interval / 2), |
| 205 | next_update_check); |
Alex Deymo | 0d11c60 | 2014-04-23 20:12:20 -0700 | [diff] [blame] | 206 | } |
| 207 | |
Alex Deymo | 63784a5 | 2014-05-28 10:46:14 -0700 | [diff] [blame] | 208 | TEST_F(UmChromeOSPolicyTest, ExponentialBackoffIsCapped) { |
Alex Deymo | 0d11c60 | 2014-04-23 20:12:20 -0700 | [diff] [blame] | 209 | Time next_update_check; |
| 210 | |
Alex Deymo | 0d11c60 | 2014-04-23 20:12:20 -0700 | [diff] [blame] | 211 | fake_state_.updater_provider()->var_consecutive_failed_update_checks()-> |
Gilad Arnold | 684219d | 2014-07-07 14:54:57 -0700 | [diff] [blame] | 212 | reset(new unsigned int(100)); // NOLINT(readability/casting) |
Gilad Arnold | 38b1402 | 2014-07-09 12:45:56 -0700 | [diff] [blame] | 213 | |
Alex Deymo | 0d11c60 | 2014-04-23 20:12:20 -0700 | [diff] [blame] | 214 | ExpectPolicyStatus(EvalStatus::kSucceeded, |
| 215 | &ChromeOSPolicy::NextUpdateCheckTime, &next_update_check); |
| 216 | |
Gilad Arnold | 38b1402 | 2014-07-09 12:45:56 -0700 | [diff] [blame] | 217 | EXPECT_LE( |
| 218 | fake_clock_.GetWallclockTime() + TimeDelta::FromSeconds( |
| 219 | ChromeOSPolicy::kTimeoutMaxBackoffInterval - |
| 220 | ChromeOSPolicy::kTimeoutMaxBackoffInterval / 2), |
| 221 | next_update_check); |
| 222 | EXPECT_GE( |
| 223 | fake_clock_.GetWallclockTime() + TimeDelta::FromSeconds( |
| 224 | ChromeOSPolicy::kTimeoutMaxBackoffInterval + |
| 225 | ChromeOSPolicy::kTimeoutMaxBackoffInterval /2), |
| 226 | next_update_check); |
Alex Deymo | 0d11c60 | 2014-04-23 20:12:20 -0700 | [diff] [blame] | 227 | } |
| 228 | |
Alex Deymo | 63784a5 | 2014-05-28 10:46:14 -0700 | [diff] [blame] | 229 | TEST_F(UmChromeOSPolicyTest, UpdateCheckAllowedWaitsForTheTimeout) { |
Alex Deymo | 0d11c60 | 2014-04-23 20:12:20 -0700 | [diff] [blame] | 230 | // We get the next update_check timestamp from the policy's private method |
| 231 | // and then we check the public method respects that value on the normal |
| 232 | // case. |
| 233 | Time next_update_check; |
| 234 | Time last_checked_time = |
| 235 | fake_clock_.GetWallclockTime() + TimeDelta::FromMinutes(1234); |
| 236 | |
Alex Deymo | 0d11c60 | 2014-04-23 20:12:20 -0700 | [diff] [blame] | 237 | fake_state_.updater_provider()->var_last_checked_time()->reset( |
| 238 | new Time(last_checked_time)); |
| 239 | ExpectPolicyStatus(EvalStatus::kSucceeded, |
| 240 | &ChromeOSPolicy::NextUpdateCheckTime, &next_update_check); |
| 241 | |
| 242 | UpdateCheckParams result; |
| 243 | |
| 244 | // Check that the policy blocks until the next_update_check is reached. |
| 245 | SetUpDefaultClock(); |
| 246 | SetUpDefaultState(); |
| 247 | fake_state_.updater_provider()->var_last_checked_time()->reset( |
| 248 | new Time(last_checked_time)); |
| 249 | fake_clock_.SetWallclockTime(next_update_check - TimeDelta::FromSeconds(1)); |
| 250 | ExpectPolicyStatus(EvalStatus::kAskMeAgainLater, |
| 251 | &Policy::UpdateCheckAllowed, &result); |
| 252 | |
| 253 | SetUpDefaultClock(); |
| 254 | SetUpDefaultState(); |
| 255 | fake_state_.updater_provider()->var_last_checked_time()->reset( |
| 256 | new Time(last_checked_time)); |
| 257 | fake_clock_.SetWallclockTime(next_update_check + TimeDelta::FromSeconds(1)); |
| 258 | ExpectPolicyStatus(EvalStatus::kSucceeded, |
| 259 | &Policy::UpdateCheckAllowed, &result); |
| 260 | } |
| 261 | |
Gilad Arnold | 42f253b | 2014-06-25 12:39:17 -0700 | [diff] [blame] | 262 | TEST_F(UmChromeOSPolicyTest, UpdateCheckAllowedWithAttributes) { |
| 263 | // Update check is allowed, reponse includes attributes for use in the |
| 264 | // request. |
| 265 | SetUpdateCheckAllowed(true); |
| 266 | |
| 267 | // Override specific device policy attributes. |
| 268 | fake_state_.device_policy_provider()->var_release_channel_delegated()-> |
| 269 | reset(new bool(false)); |
| 270 | fake_state_.device_policy_provider()->var_release_channel()-> |
| 271 | reset(new string("foo-channel")); |
| 272 | |
| 273 | UpdateCheckParams result; |
| 274 | ExpectPolicyStatus(EvalStatus::kSucceeded, |
| 275 | &Policy::UpdateCheckAllowed, &result); |
| 276 | EXPECT_TRUE(result.updates_enabled); |
| 277 | EXPECT_EQ("foo-channel", result.target_channel); |
| 278 | } |
| 279 | |
Gilad Arnold | fe12a0f | 2014-07-09 14:26:57 -0700 | [diff] [blame^] | 280 | TEST_F(UmChromeOSPolicyTest, |
| 281 | UpdateCheckAllowedUpdatesDisabledForUnofficialBuilds) { |
| 282 | // UpdateCheckAllowed should return false (kSucceeded) if this is an |
| 283 | // unofficial build; we don't want periodic update checks on developer images. |
| 284 | |
| 285 | fake_state_.system_provider()->var_is_official_build()->reset( |
| 286 | new bool(false)); |
| 287 | |
| 288 | UpdateCheckParams result; |
| 289 | ExpectPolicyStatus(EvalStatus::kSucceeded, |
| 290 | &Policy::UpdateCheckAllowed, &result); |
| 291 | EXPECT_FALSE(result.updates_enabled); |
| 292 | } |
| 293 | |
| 294 | TEST_F(UmChromeOSPolicyTest, UpdateCheckAllowedUpdatesDisabledByPolicy) { |
Gilad Arnold | 42f253b | 2014-06-25 12:39:17 -0700 | [diff] [blame] | 295 | // UpdateCheckAllowed should return kAskMeAgainLater because a device policy |
| 296 | // is loaded and prohibits updates. |
| 297 | |
| 298 | SetUpdateCheckAllowed(false); |
| 299 | fake_state_.device_policy_provider()->var_update_disabled()->reset( |
| 300 | new bool(true)); |
| 301 | |
Gilad Arnold | 42f253b | 2014-06-25 12:39:17 -0700 | [diff] [blame] | 302 | UpdateCheckParams result; |
| 303 | ExpectPolicyStatus(EvalStatus::kAskMeAgainLater, |
| 304 | &Policy::UpdateCheckAllowed, &result); |
| 305 | } |
| 306 | |
Alex Deymo | 63784a5 | 2014-05-28 10:46:14 -0700 | [diff] [blame] | 307 | TEST_F(UmChromeOSPolicyTest, UpdateCanStartFailsCheckAllowedError) { |
Gilad Arnold | f62a4b8 | 2014-05-01 07:41:07 -0700 | [diff] [blame] | 308 | // The UpdateCanStart policy fails, not being able to query |
| 309 | // UpdateCheckAllowed. |
| 310 | |
| 311 | // Configure the UpdateCheckAllowed policy to fail. |
| 312 | fake_state_.updater_provider()->var_updater_started_time()->reset(nullptr); |
| 313 | |
| 314 | // Check that the UpdateCanStart fails. |
| 315 | UpdateState update_state = GetDefaultUpdateState(TimeDelta::FromMinutes(10)); |
Gilad Arnold | 42f253b | 2014-06-25 12:39:17 -0700 | [diff] [blame] | 316 | UpdateDownloadParams result; |
Gilad Arnold | f62a4b8 | 2014-05-01 07:41:07 -0700 | [diff] [blame] | 317 | ExpectPolicyStatus(EvalStatus::kFailed, |
| 318 | &Policy::UpdateCanStart, &result, false, update_state); |
| 319 | } |
| 320 | |
Alex Deymo | 63784a5 | 2014-05-28 10:46:14 -0700 | [diff] [blame] | 321 | TEST_F(UmChromeOSPolicyTest, UpdateCanStartNotAllowedCheckDue) { |
Gilad Arnold | f62a4b8 | 2014-05-01 07:41:07 -0700 | [diff] [blame] | 322 | // The UpdateCanStart policy returns false because we are due for another |
| 323 | // update check. |
| 324 | |
| 325 | SetUpdateCheckAllowed(true); |
| 326 | |
| 327 | // Check that the UpdateCanStart returns false. |
| 328 | UpdateState update_state = GetDefaultUpdateState(TimeDelta::FromMinutes(10)); |
Gilad Arnold | 42f253b | 2014-06-25 12:39:17 -0700 | [diff] [blame] | 329 | UpdateDownloadParams result; |
Gilad Arnold | f62a4b8 | 2014-05-01 07:41:07 -0700 | [diff] [blame] | 330 | ExpectPolicyStatus(EvalStatus::kSucceeded, |
| 331 | &Policy::UpdateCanStart, &result, false, update_state); |
| 332 | EXPECT_FALSE(result.update_can_start); |
| 333 | EXPECT_EQ(UpdateCannotStartReason::kCheckDue, result.cannot_start_reason); |
| 334 | } |
| 335 | |
Alex Deymo | 63784a5 | 2014-05-28 10:46:14 -0700 | [diff] [blame] | 336 | TEST_F(UmChromeOSPolicyTest, UpdateCanStartAllowedNoDevicePolicy) { |
Gilad Arnold | f62a4b8 | 2014-05-01 07:41:07 -0700 | [diff] [blame] | 337 | // The UpdateCanStart policy returns true; no device policy is loaded. |
| 338 | |
| 339 | SetUpdateCheckAllowed(false); |
| 340 | fake_state_.device_policy_provider()->var_device_policy_is_loaded()->reset( |
| 341 | new bool(false)); |
| 342 | |
| 343 | // Check that the UpdateCanStart returns true with no further attributes. |
| 344 | UpdateState update_state = GetDefaultUpdateState(TimeDelta::FromMinutes(10)); |
Gilad Arnold | 42f253b | 2014-06-25 12:39:17 -0700 | [diff] [blame] | 345 | UpdateDownloadParams result; |
Gilad Arnold | f62a4b8 | 2014-05-01 07:41:07 -0700 | [diff] [blame] | 346 | ExpectPolicyStatus(EvalStatus::kSucceeded, |
| 347 | &Policy::UpdateCanStart, &result, false, update_state); |
| 348 | EXPECT_TRUE(result.update_can_start); |
Gilad Arnold | f62a4b8 | 2014-05-01 07:41:07 -0700 | [diff] [blame] | 349 | EXPECT_FALSE(result.p2p_allowed); |
Gilad Arnold | b3b0544 | 2014-05-30 14:25:05 -0700 | [diff] [blame] | 350 | EXPECT_EQ(0, result.download_url_idx); |
| 351 | EXPECT_EQ(0, result.download_url_num_failures); |
Gilad Arnold | f62a4b8 | 2014-05-01 07:41:07 -0700 | [diff] [blame] | 352 | } |
| 353 | |
Alex Deymo | 63784a5 | 2014-05-28 10:46:14 -0700 | [diff] [blame] | 354 | TEST_F(UmChromeOSPolicyTest, UpdateCanStartAllowedBlankPolicy) { |
Gilad Arnold | f62a4b8 | 2014-05-01 07:41:07 -0700 | [diff] [blame] | 355 | // The UpdateCanStart policy returns true; device policy is loaded but imposes |
| 356 | // no restrictions on updating. |
| 357 | |
| 358 | SetUpdateCheckAllowed(false); |
| 359 | |
| 360 | // Check that the UpdateCanStart returns true. |
| 361 | UpdateState update_state = GetDefaultUpdateState(TimeDelta::FromMinutes(10)); |
Gilad Arnold | 42f253b | 2014-06-25 12:39:17 -0700 | [diff] [blame] | 362 | UpdateDownloadParams result; |
Gilad Arnold | f62a4b8 | 2014-05-01 07:41:07 -0700 | [diff] [blame] | 363 | ExpectPolicyStatus(EvalStatus::kSucceeded, |
| 364 | &Policy::UpdateCanStart, &result, false, update_state); |
| 365 | EXPECT_TRUE(result.update_can_start); |
Gilad Arnold | f62a4b8 | 2014-05-01 07:41:07 -0700 | [diff] [blame] | 366 | EXPECT_FALSE(result.p2p_allowed); |
Gilad Arnold | b3b0544 | 2014-05-30 14:25:05 -0700 | [diff] [blame] | 367 | EXPECT_EQ(0, result.download_url_idx); |
| 368 | EXPECT_EQ(0, result.download_url_num_failures); |
Gilad Arnold | f62a4b8 | 2014-05-01 07:41:07 -0700 | [diff] [blame] | 369 | } |
| 370 | |
Alex Deymo | 63784a5 | 2014-05-28 10:46:14 -0700 | [diff] [blame] | 371 | TEST_F(UmChromeOSPolicyTest, UpdateCanStartFailsScatteringFailed) { |
Gilad Arnold | f62a4b8 | 2014-05-01 07:41:07 -0700 | [diff] [blame] | 372 | // The UpdateCanStart policy fails because the UpdateScattering policy it |
| 373 | // depends on fails (unset variable). |
| 374 | |
| 375 | SetUpdateCheckAllowed(false); |
| 376 | |
| 377 | // Override the default seed variable with a null value so that the policy |
| 378 | // request would fail. |
| 379 | fake_state_.random_provider()->var_seed()->reset(nullptr); |
| 380 | |
| 381 | // Check that the UpdateCanStart fails. |
| 382 | UpdateState update_state = GetDefaultUpdateState(TimeDelta::FromSeconds(1)); |
Gilad Arnold | 42f253b | 2014-06-25 12:39:17 -0700 | [diff] [blame] | 383 | UpdateDownloadParams result; |
Gilad Arnold | f62a4b8 | 2014-05-01 07:41:07 -0700 | [diff] [blame] | 384 | ExpectPolicyStatus(EvalStatus::kFailed, |
| 385 | &Policy::UpdateCanStart, &result, false, update_state); |
| 386 | } |
| 387 | |
Alex Deymo | 63784a5 | 2014-05-28 10:46:14 -0700 | [diff] [blame] | 388 | TEST_F(UmChromeOSPolicyTest, |
Gilad Arnold | f62a4b8 | 2014-05-01 07:41:07 -0700 | [diff] [blame] | 389 | UpdateCanStartNotAllowedScatteringNewWaitPeriodApplies) { |
| 390 | // The UpdateCanStart policy returns false; device policy is loaded and |
| 391 | // scattering applies due to an unsatisfied wait period, which was newly |
| 392 | // generated. |
| 393 | |
| 394 | SetUpdateCheckAllowed(false); |
| 395 | fake_state_.device_policy_provider()->var_scatter_factor()->reset( |
| 396 | new TimeDelta(TimeDelta::FromMinutes(2))); |
| 397 | |
| 398 | |
| 399 | UpdateState update_state = GetDefaultUpdateState(TimeDelta::FromSeconds(1)); |
| 400 | |
| 401 | // Check that the UpdateCanStart returns false and a new wait period |
| 402 | // generated. |
Gilad Arnold | 42f253b | 2014-06-25 12:39:17 -0700 | [diff] [blame] | 403 | UpdateDownloadParams result; |
Gilad Arnold | f62a4b8 | 2014-05-01 07:41:07 -0700 | [diff] [blame] | 404 | ExpectPolicyStatus(EvalStatus::kSucceeded, &Policy::UpdateCanStart, &result, |
| 405 | false, update_state); |
| 406 | EXPECT_FALSE(result.update_can_start); |
| 407 | EXPECT_EQ(UpdateCannotStartReason::kScattering, result.cannot_start_reason); |
| 408 | EXPECT_LT(TimeDelta(), result.scatter_wait_period); |
| 409 | EXPECT_EQ(0, result.scatter_check_threshold); |
| 410 | } |
| 411 | |
Alex Deymo | 63784a5 | 2014-05-28 10:46:14 -0700 | [diff] [blame] | 412 | TEST_F(UmChromeOSPolicyTest, |
Gilad Arnold | f62a4b8 | 2014-05-01 07:41:07 -0700 | [diff] [blame] | 413 | UpdateCanStartNotAllowedScatteringPrevWaitPeriodStillApplies) { |
| 414 | // The UpdateCanStart policy returns false w/ kAskMeAgainLater; device policy |
| 415 | // is loaded and a previously generated scattering period still applies, none |
| 416 | // of the scattering values has changed. |
| 417 | |
| 418 | SetUpdateCheckAllowed(false); |
| 419 | fake_state_.device_policy_provider()->var_scatter_factor()->reset( |
| 420 | new TimeDelta(TimeDelta::FromMinutes(2))); |
| 421 | |
| 422 | UpdateState update_state = GetDefaultUpdateState(TimeDelta::FromSeconds(1)); |
| 423 | update_state.scatter_wait_period = TimeDelta::FromSeconds(35); |
| 424 | |
| 425 | // Check that the UpdateCanStart returns false and a new wait period |
| 426 | // generated. |
Gilad Arnold | 42f253b | 2014-06-25 12:39:17 -0700 | [diff] [blame] | 427 | UpdateDownloadParams result; |
Gilad Arnold | f62a4b8 | 2014-05-01 07:41:07 -0700 | [diff] [blame] | 428 | ExpectPolicyStatus(EvalStatus::kAskMeAgainLater, &Policy::UpdateCanStart, |
| 429 | &result, false, update_state); |
| 430 | EXPECT_FALSE(result.update_can_start); |
| 431 | EXPECT_EQ(UpdateCannotStartReason::kScattering, result.cannot_start_reason); |
| 432 | EXPECT_EQ(TimeDelta::FromSeconds(35), result.scatter_wait_period); |
| 433 | EXPECT_EQ(0, result.scatter_check_threshold); |
| 434 | } |
| 435 | |
Alex Deymo | 63784a5 | 2014-05-28 10:46:14 -0700 | [diff] [blame] | 436 | TEST_F(UmChromeOSPolicyTest, |
Gilad Arnold | f62a4b8 | 2014-05-01 07:41:07 -0700 | [diff] [blame] | 437 | UpdateCanStartNotAllowedScatteringNewCountThresholdApplies) { |
| 438 | // The UpdateCanStart policy returns false; device policy is loaded and |
| 439 | // scattering applies due to an unsatisfied update check count threshold. |
| 440 | // |
| 441 | // This ensures a non-zero check threshold, which may or may not be combined |
| 442 | // with a non-zero wait period (for which we cannot reliably control). |
| 443 | |
| 444 | SetUpdateCheckAllowed(false); |
| 445 | fake_state_.device_policy_provider()->var_scatter_factor()->reset( |
| 446 | new TimeDelta(TimeDelta::FromSeconds(1))); |
| 447 | |
| 448 | UpdateState update_state = GetDefaultUpdateState(TimeDelta::FromSeconds(1)); |
| 449 | update_state.scatter_check_threshold_min = 2; |
| 450 | update_state.scatter_check_threshold_max = 5; |
| 451 | |
| 452 | // Check that the UpdateCanStart returns false. |
Gilad Arnold | 42f253b | 2014-06-25 12:39:17 -0700 | [diff] [blame] | 453 | UpdateDownloadParams result; |
Gilad Arnold | f62a4b8 | 2014-05-01 07:41:07 -0700 | [diff] [blame] | 454 | ExpectPolicyStatus(EvalStatus::kSucceeded, &Policy::UpdateCanStart, &result, |
| 455 | false, update_state); |
| 456 | EXPECT_FALSE(result.update_can_start); |
| 457 | EXPECT_EQ(UpdateCannotStartReason::kScattering, result.cannot_start_reason); |
| 458 | EXPECT_LE(2, result.scatter_check_threshold); |
| 459 | EXPECT_GE(5, result.scatter_check_threshold); |
| 460 | } |
| 461 | |
Alex Deymo | 63784a5 | 2014-05-28 10:46:14 -0700 | [diff] [blame] | 462 | TEST_F(UmChromeOSPolicyTest, |
Gilad Arnold | f62a4b8 | 2014-05-01 07:41:07 -0700 | [diff] [blame] | 463 | UpdateCanStartNotAllowedScatteringPrevCountThresholdStillApplies) { |
| 464 | // The UpdateCanStart policy returns false; device policy is loaded and |
| 465 | // scattering due to a previously generated count threshold still applies. |
| 466 | |
| 467 | SetUpdateCheckAllowed(false); |
| 468 | fake_state_.device_policy_provider()->var_scatter_factor()->reset( |
| 469 | new TimeDelta(TimeDelta::FromSeconds(1))); |
| 470 | |
| 471 | UpdateState update_state = GetDefaultUpdateState(TimeDelta::FromSeconds(1)); |
| 472 | update_state.scatter_check_threshold = 3; |
| 473 | update_state.scatter_check_threshold_min = 2; |
| 474 | update_state.scatter_check_threshold_max = 5; |
| 475 | |
| 476 | // Check that the UpdateCanStart returns false. |
Gilad Arnold | 42f253b | 2014-06-25 12:39:17 -0700 | [diff] [blame] | 477 | UpdateDownloadParams result; |
Gilad Arnold | f62a4b8 | 2014-05-01 07:41:07 -0700 | [diff] [blame] | 478 | ExpectPolicyStatus(EvalStatus::kSucceeded, &Policy::UpdateCanStart, &result, |
| 479 | false, update_state); |
| 480 | EXPECT_FALSE(result.update_can_start); |
| 481 | EXPECT_EQ(UpdateCannotStartReason::kScattering, result.cannot_start_reason); |
| 482 | EXPECT_EQ(3, result.scatter_check_threshold); |
| 483 | } |
| 484 | |
Alex Deymo | 63784a5 | 2014-05-28 10:46:14 -0700 | [diff] [blame] | 485 | TEST_F(UmChromeOSPolicyTest, UpdateCanStartAllowedScatteringSatisfied) { |
Gilad Arnold | f62a4b8 | 2014-05-01 07:41:07 -0700 | [diff] [blame] | 486 | // The UpdateCanStart policy returns true; device policy is loaded and |
| 487 | // scattering is enabled, but both wait period and check threshold are |
| 488 | // satisfied. |
| 489 | |
| 490 | SetUpdateCheckAllowed(false); |
| 491 | fake_state_.device_policy_provider()->var_scatter_factor()->reset( |
| 492 | new TimeDelta(TimeDelta::FromSeconds(120))); |
| 493 | |
| 494 | UpdateState update_state = GetDefaultUpdateState(TimeDelta::FromSeconds(75)); |
| 495 | update_state.num_checks = 4; |
| 496 | update_state.scatter_wait_period = TimeDelta::FromSeconds(60); |
| 497 | update_state.scatter_check_threshold = 3; |
| 498 | update_state.scatter_check_threshold_min = 2; |
| 499 | update_state.scatter_check_threshold_max = 5; |
| 500 | |
| 501 | // Check that the UpdateCanStart returns true. |
Gilad Arnold | 42f253b | 2014-06-25 12:39:17 -0700 | [diff] [blame] | 502 | UpdateDownloadParams result; |
Gilad Arnold | f62a4b8 | 2014-05-01 07:41:07 -0700 | [diff] [blame] | 503 | ExpectPolicyStatus(EvalStatus::kSucceeded, &Policy::UpdateCanStart, &result, |
| 504 | false, update_state); |
| 505 | EXPECT_TRUE(result.update_can_start); |
| 506 | EXPECT_EQ(TimeDelta(), result.scatter_wait_period); |
| 507 | EXPECT_EQ(0, result.scatter_check_threshold); |
Gilad Arnold | b3b0544 | 2014-05-30 14:25:05 -0700 | [diff] [blame] | 508 | EXPECT_EQ(0, result.download_url_idx); |
| 509 | EXPECT_EQ(0, result.download_url_num_failures); |
Gilad Arnold | f62a4b8 | 2014-05-01 07:41:07 -0700 | [diff] [blame] | 510 | } |
| 511 | |
Alex Deymo | 63784a5 | 2014-05-28 10:46:14 -0700 | [diff] [blame] | 512 | TEST_F(UmChromeOSPolicyTest, |
Gilad Arnold | f62a4b8 | 2014-05-01 07:41:07 -0700 | [diff] [blame] | 513 | UpdateCanStartAllowedInteractivePreventsScattering) { |
| 514 | // The UpdateCanStart policy returns true; device policy is loaded and |
| 515 | // scattering would have applied, except that the update check is interactive |
| 516 | // and so it is suppressed. |
| 517 | |
| 518 | SetUpdateCheckAllowed(false); |
| 519 | fake_state_.device_policy_provider()->var_scatter_factor()->reset( |
| 520 | new TimeDelta(TimeDelta::FromSeconds(1))); |
| 521 | |
| 522 | UpdateState update_state = GetDefaultUpdateState(TimeDelta::FromSeconds(1)); |
| 523 | update_state.scatter_check_threshold = 0; |
| 524 | update_state.scatter_check_threshold_min = 2; |
| 525 | update_state.scatter_check_threshold_max = 5; |
| 526 | |
| 527 | // Check that the UpdateCanStart returns true. |
Gilad Arnold | 42f253b | 2014-06-25 12:39:17 -0700 | [diff] [blame] | 528 | UpdateDownloadParams result; |
Gilad Arnold | f62a4b8 | 2014-05-01 07:41:07 -0700 | [diff] [blame] | 529 | ExpectPolicyStatus(EvalStatus::kSucceeded, &Policy::UpdateCanStart, &result, |
| 530 | true, update_state); |
| 531 | EXPECT_TRUE(result.update_can_start); |
| 532 | EXPECT_EQ(TimeDelta(), result.scatter_wait_period); |
| 533 | EXPECT_EQ(0, result.scatter_check_threshold); |
Gilad Arnold | b3b0544 | 2014-05-30 14:25:05 -0700 | [diff] [blame] | 534 | EXPECT_EQ(0, result.download_url_idx); |
| 535 | EXPECT_EQ(0, result.download_url_num_failures); |
Gilad Arnold | f62a4b8 | 2014-05-01 07:41:07 -0700 | [diff] [blame] | 536 | } |
| 537 | |
Alex Deymo | 63784a5 | 2014-05-28 10:46:14 -0700 | [diff] [blame] | 538 | TEST_F(UmChromeOSPolicyTest, |
Gilad Arnold | 76a11f6 | 2014-05-20 09:02:12 -0700 | [diff] [blame] | 539 | UpdateCanStartAllowedOobePreventsScattering) { |
| 540 | // The UpdateCanStart policy returns true; device policy is loaded and |
| 541 | // scattering would have applied, except that OOBE was not completed and so it |
| 542 | // is suppressed. |
| 543 | |
| 544 | SetUpdateCheckAllowed(false); |
| 545 | fake_state_.device_policy_provider()->var_scatter_factor()->reset( |
| 546 | new TimeDelta(TimeDelta::FromSeconds(1))); |
| 547 | fake_state_.system_provider()->var_is_oobe_complete()->reset(new bool(false)); |
| 548 | |
| 549 | UpdateState update_state = GetDefaultUpdateState(TimeDelta::FromSeconds(1)); |
| 550 | update_state.scatter_check_threshold = 0; |
| 551 | update_state.scatter_check_threshold_min = 2; |
| 552 | update_state.scatter_check_threshold_max = 5; |
| 553 | |
| 554 | // Check that the UpdateCanStart returns true. |
Gilad Arnold | 42f253b | 2014-06-25 12:39:17 -0700 | [diff] [blame] | 555 | UpdateDownloadParams result; |
Gilad Arnold | 76a11f6 | 2014-05-20 09:02:12 -0700 | [diff] [blame] | 556 | ExpectPolicyStatus(EvalStatus::kSucceeded, &Policy::UpdateCanStart, &result, |
| 557 | true, update_state); |
| 558 | EXPECT_TRUE(result.update_can_start); |
| 559 | EXPECT_EQ(TimeDelta(), result.scatter_wait_period); |
| 560 | EXPECT_EQ(0, result.scatter_check_threshold); |
Gilad Arnold | b3b0544 | 2014-05-30 14:25:05 -0700 | [diff] [blame] | 561 | EXPECT_EQ(0, result.download_url_idx); |
| 562 | EXPECT_EQ(0, result.download_url_num_failures); |
Gilad Arnold | 76a11f6 | 2014-05-20 09:02:12 -0700 | [diff] [blame] | 563 | } |
| 564 | |
Alex Deymo | 63784a5 | 2014-05-28 10:46:14 -0700 | [diff] [blame] | 565 | TEST_F(UmChromeOSPolicyTest, UpdateCanStartAllowedWithAttributes) { |
Gilad Arnold | f62a4b8 | 2014-05-01 07:41:07 -0700 | [diff] [blame] | 566 | // The UpdateCanStart policy returns true; device policy permits both HTTP and |
| 567 | // P2P updates, as well as a non-empty target channel string. |
| 568 | |
| 569 | SetUpdateCheckAllowed(false); |
| 570 | |
| 571 | // Override specific device policy attributes. |
| 572 | fake_state_.device_policy_provider()->var_http_downloads_enabled()->reset( |
| 573 | new bool(true)); |
| 574 | fake_state_.device_policy_provider()->var_au_p2p_enabled()->reset( |
| 575 | new bool(true)); |
Gilad Arnold | f62a4b8 | 2014-05-01 07:41:07 -0700 | [diff] [blame] | 576 | |
| 577 | // Check that the UpdateCanStart returns true. |
| 578 | UpdateState update_state = GetDefaultUpdateState(TimeDelta::FromMinutes(10)); |
Gilad Arnold | 42f253b | 2014-06-25 12:39:17 -0700 | [diff] [blame] | 579 | UpdateDownloadParams result; |
Gilad Arnold | f62a4b8 | 2014-05-01 07:41:07 -0700 | [diff] [blame] | 580 | ExpectPolicyStatus(EvalStatus::kSucceeded, &Policy::UpdateCanStart, &result, |
| 581 | false, update_state); |
| 582 | EXPECT_TRUE(result.update_can_start); |
Gilad Arnold | f62a4b8 | 2014-05-01 07:41:07 -0700 | [diff] [blame] | 583 | EXPECT_TRUE(result.p2p_allowed); |
Gilad Arnold | b3b0544 | 2014-05-30 14:25:05 -0700 | [diff] [blame] | 584 | EXPECT_EQ(0, result.download_url_idx); |
| 585 | EXPECT_EQ(0, result.download_url_num_failures); |
Gilad Arnold | f62a4b8 | 2014-05-01 07:41:07 -0700 | [diff] [blame] | 586 | } |
| 587 | |
Alex Deymo | 63784a5 | 2014-05-28 10:46:14 -0700 | [diff] [blame] | 588 | TEST_F(UmChromeOSPolicyTest, UpdateCanStartAllowedWithP2PFromUpdater) { |
Gilad Arnold | f62a4b8 | 2014-05-01 07:41:07 -0700 | [diff] [blame] | 589 | // The UpdateCanStart policy returns true; device policy forbids both HTTP and |
| 590 | // P2P updates, but the updater is configured to allow P2P and overrules the |
| 591 | // setting. |
| 592 | |
| 593 | SetUpdateCheckAllowed(false); |
| 594 | |
| 595 | // Override specific device policy attributes. |
Gilad Arnold | f62a4b8 | 2014-05-01 07:41:07 -0700 | [diff] [blame] | 596 | fake_state_.updater_provider()->var_p2p_enabled()->reset(new bool(true)); |
| 597 | |
| 598 | // Check that the UpdateCanStart returns true. |
| 599 | UpdateState update_state = GetDefaultUpdateState(TimeDelta::FromMinutes(10)); |
Gilad Arnold | 42f253b | 2014-06-25 12:39:17 -0700 | [diff] [blame] | 600 | UpdateDownloadParams result; |
Gilad Arnold | f62a4b8 | 2014-05-01 07:41:07 -0700 | [diff] [blame] | 601 | ExpectPolicyStatus(EvalStatus::kSucceeded, &Policy::UpdateCanStart, &result, |
| 602 | false, update_state); |
| 603 | EXPECT_TRUE(result.update_can_start); |
Gilad Arnold | f62a4b8 | 2014-05-01 07:41:07 -0700 | [diff] [blame] | 604 | EXPECT_TRUE(result.p2p_allowed); |
Gilad Arnold | b3b0544 | 2014-05-30 14:25:05 -0700 | [diff] [blame] | 605 | EXPECT_EQ(0, result.download_url_idx); |
| 606 | EXPECT_EQ(0, result.download_url_num_failures); |
Gilad Arnold | f62a4b8 | 2014-05-01 07:41:07 -0700 | [diff] [blame] | 607 | } |
| 608 | |
Gilad Arnold | b3b0544 | 2014-05-30 14:25:05 -0700 | [diff] [blame] | 609 | TEST_F(UmChromeOSPolicyTest, |
| 610 | UpdateCanStartAllowedWithHttpUrlForUnofficialBuild) { |
Gilad Arnold | f62a4b8 | 2014-05-01 07:41:07 -0700 | [diff] [blame] | 611 | // The UpdateCanStart policy returns true; device policy forbids both HTTP and |
| 612 | // P2P updates, but marking this an unofficial build overrules the HTTP |
| 613 | // setting. |
| 614 | |
| 615 | SetUpdateCheckAllowed(false); |
| 616 | |
| 617 | // Override specific device policy attributes. |
Gilad Arnold | b3b0544 | 2014-05-30 14:25:05 -0700 | [diff] [blame] | 618 | fake_state_.device_policy_provider()->var_http_downloads_enabled()->reset( |
| 619 | new bool(false)); |
Gilad Arnold | f62a4b8 | 2014-05-01 07:41:07 -0700 | [diff] [blame] | 620 | fake_state_.system_provider()->var_is_official_build()-> |
| 621 | reset(new bool(false)); |
| 622 | |
| 623 | // Check that the UpdateCanStart returns true. |
| 624 | UpdateState update_state = GetDefaultUpdateState(TimeDelta::FromMinutes(10)); |
Gilad Arnold | 42f253b | 2014-06-25 12:39:17 -0700 | [diff] [blame] | 625 | UpdateDownloadParams result; |
Gilad Arnold | f62a4b8 | 2014-05-01 07:41:07 -0700 | [diff] [blame] | 626 | ExpectPolicyStatus(EvalStatus::kSucceeded, &Policy::UpdateCanStart, &result, |
| 627 | false, update_state); |
| 628 | EXPECT_TRUE(result.update_can_start); |
Gilad Arnold | f62a4b8 | 2014-05-01 07:41:07 -0700 | [diff] [blame] | 629 | EXPECT_FALSE(result.p2p_allowed); |
Gilad Arnold | b3b0544 | 2014-05-30 14:25:05 -0700 | [diff] [blame] | 630 | EXPECT_EQ(0, result.download_url_idx); |
| 631 | EXPECT_EQ(0, result.download_url_num_failures); |
| 632 | } |
| 633 | |
| 634 | TEST_F(UmChromeOSPolicyTest, UpdateCanStartAllowedWithHttpsUrl) { |
| 635 | // The UpdateCanStart policy returns true; device policy forbids both HTTP and |
| 636 | // P2P updates, but an HTTPS URL is provided and selected for download. |
| 637 | |
| 638 | SetUpdateCheckAllowed(false); |
| 639 | |
| 640 | // Override specific device policy attributes. |
| 641 | fake_state_.device_policy_provider()->var_http_downloads_enabled()->reset( |
| 642 | new bool(false)); |
| 643 | |
| 644 | // Add an HTTPS URL. |
| 645 | UpdateState update_state = GetDefaultUpdateState(TimeDelta::FromMinutes(10)); |
| 646 | update_state.download_urls.push_back("https://secure/url/"); |
| 647 | |
| 648 | // Check that the UpdateCanStart returns true. |
Gilad Arnold | 42f253b | 2014-06-25 12:39:17 -0700 | [diff] [blame] | 649 | UpdateDownloadParams result; |
Gilad Arnold | b3b0544 | 2014-05-30 14:25:05 -0700 | [diff] [blame] | 650 | ExpectPolicyStatus(EvalStatus::kSucceeded, &Policy::UpdateCanStart, &result, |
| 651 | false, update_state); |
| 652 | EXPECT_TRUE(result.update_can_start); |
| 653 | EXPECT_FALSE(result.p2p_allowed); |
| 654 | EXPECT_EQ(1, result.download_url_idx); |
| 655 | EXPECT_EQ(0, result.download_url_num_failures); |
| 656 | } |
| 657 | |
| 658 | TEST_F(UmChromeOSPolicyTest, UpdateCanStartAllowedWithSecondUrlMaxExceeded) { |
| 659 | // The UpdateCanStart policy returns true; the first URL exceeded the maximum |
| 660 | // allowed number of failures, but a second URL is available. |
| 661 | |
| 662 | SetUpdateCheckAllowed(false); |
| 663 | |
| 664 | // Add a second URL; update with this URL attempted and failed enough times to |
| 665 | // disqualify the current (first) URL. This tests both the previously |
| 666 | // accounted failures (download_url_num_failures) as well as those occurring |
| 667 | // since the last call (download_url_error_codes). |
| 668 | UpdateState update_state = GetDefaultUpdateState(TimeDelta::FromMinutes(10)); |
| 669 | update_state.num_checks = 10; |
| 670 | update_state.download_urls.push_back("http://another/fake/url/"); |
| 671 | update_state.download_url_num_failures = 9; |
| 672 | update_state.download_url_error_codes.push_back( |
| 673 | ErrorCode::kDownloadTransferError); |
| 674 | update_state.download_url_error_codes.push_back( |
| 675 | ErrorCode::kDownloadWriteError); |
| 676 | |
| 677 | // Check that the UpdateCanStart returns true. |
Gilad Arnold | 42f253b | 2014-06-25 12:39:17 -0700 | [diff] [blame] | 678 | UpdateDownloadParams result; |
Gilad Arnold | b3b0544 | 2014-05-30 14:25:05 -0700 | [diff] [blame] | 679 | ExpectPolicyStatus(EvalStatus::kSucceeded, &Policy::UpdateCanStart, &result, |
| 680 | false, update_state); |
| 681 | EXPECT_TRUE(result.update_can_start); |
| 682 | EXPECT_FALSE(result.p2p_allowed); |
| 683 | EXPECT_EQ(1, result.download_url_idx); |
| 684 | EXPECT_EQ(0, result.download_url_num_failures); |
| 685 | } |
| 686 | |
| 687 | TEST_F(UmChromeOSPolicyTest, UpdateCanStartAllowedWithSecondUrlHardError) { |
| 688 | // The UpdateCanStart policy returns true; the first URL fails with a hard |
| 689 | // error, but a second URL is available. |
| 690 | |
| 691 | SetUpdateCheckAllowed(false); |
| 692 | |
| 693 | // Add a second URL; update with this URL attempted and failed in a way that |
| 694 | // causes it to switch directly to the next URL. |
| 695 | UpdateState update_state = GetDefaultUpdateState(TimeDelta::FromMinutes(10)); |
| 696 | update_state.num_checks = 10; |
| 697 | update_state.download_urls.push_back("http://another/fake/url/"); |
| 698 | update_state.download_url_error_codes.push_back( |
| 699 | ErrorCode::kPayloadHashMismatchError); |
| 700 | |
| 701 | // Check that the UpdateCanStart returns true. |
Gilad Arnold | 42f253b | 2014-06-25 12:39:17 -0700 | [diff] [blame] | 702 | UpdateDownloadParams result; |
Gilad Arnold | b3b0544 | 2014-05-30 14:25:05 -0700 | [diff] [blame] | 703 | ExpectPolicyStatus(EvalStatus::kSucceeded, &Policy::UpdateCanStart, &result, |
| 704 | false, update_state); |
| 705 | EXPECT_TRUE(result.update_can_start); |
| 706 | EXPECT_FALSE(result.p2p_allowed); |
| 707 | EXPECT_EQ(1, result.download_url_idx); |
| 708 | EXPECT_EQ(0, result.download_url_num_failures); |
| 709 | } |
| 710 | |
| 711 | TEST_F(UmChromeOSPolicyTest, UpdateCanStartAllowedUrlWrapsAround) { |
| 712 | // The UpdateCanStart policy returns true; URL search properly wraps around |
| 713 | // the last one on the list. |
| 714 | |
| 715 | SetUpdateCheckAllowed(false); |
| 716 | |
| 717 | // Add a second URL; update with this URL attempted and failed in a way that |
| 718 | // causes it to switch directly to the next URL. |
| 719 | UpdateState update_state = GetDefaultUpdateState(TimeDelta::FromMinutes(10)); |
| 720 | update_state.num_checks = 10; |
| 721 | update_state.download_urls.push_back("http://another/fake/url/"); |
| 722 | update_state.download_url_idx = 1; |
| 723 | update_state.download_url_error_codes.push_back( |
| 724 | ErrorCode::kPayloadHashMismatchError); |
| 725 | |
| 726 | // Check that the UpdateCanStart returns true. |
Gilad Arnold | 42f253b | 2014-06-25 12:39:17 -0700 | [diff] [blame] | 727 | UpdateDownloadParams result; |
Gilad Arnold | b3b0544 | 2014-05-30 14:25:05 -0700 | [diff] [blame] | 728 | ExpectPolicyStatus(EvalStatus::kSucceeded, &Policy::UpdateCanStart, &result, |
| 729 | false, update_state); |
| 730 | EXPECT_TRUE(result.update_can_start); |
| 731 | EXPECT_FALSE(result.p2p_allowed); |
| 732 | EXPECT_EQ(0, result.download_url_idx); |
| 733 | EXPECT_EQ(0, result.download_url_num_failures); |
| 734 | } |
| 735 | |
| 736 | TEST_F(UmChromeOSPolicyTest, UpdateCanStartNotAllowedNoUsableUrls) { |
| 737 | // The UpdateCanStart policy returns false; there's a single HTTP URL but its |
| 738 | // use is forbidden by policy. |
| 739 | |
| 740 | SetUpdateCheckAllowed(false); |
| 741 | |
| 742 | // Override specific device policy attributes. |
| 743 | fake_state_.device_policy_provider()->var_http_downloads_enabled()->reset( |
| 744 | new bool(false)); |
| 745 | |
| 746 | // Check that the UpdateCanStart returns false. |
| 747 | UpdateState update_state = GetDefaultUpdateState(TimeDelta::FromMinutes(10)); |
Gilad Arnold | 42f253b | 2014-06-25 12:39:17 -0700 | [diff] [blame] | 748 | UpdateDownloadParams result; |
Gilad Arnold | b3b0544 | 2014-05-30 14:25:05 -0700 | [diff] [blame] | 749 | ExpectPolicyStatus(EvalStatus::kFailed, &Policy::UpdateCanStart, &result, |
| 750 | false, update_state); |
| 751 | } |
| 752 | |
| 753 | TEST_F(UmChromeOSPolicyTest, UpdateCanStartAllowedNoUsableUrlsButP2PEnabled) { |
| 754 | // The UpdateCanStart policy returns true; there's a single HTTP URL but its |
| 755 | // use is forbidden by policy, however P2P is enabled. The result indicates |
| 756 | // that no URL can be used. |
| 757 | |
| 758 | SetUpdateCheckAllowed(false); |
| 759 | |
| 760 | // Override specific device policy attributes. |
| 761 | fake_state_.device_policy_provider()->var_au_p2p_enabled()->reset( |
| 762 | new bool(true)); |
| 763 | fake_state_.device_policy_provider()->var_http_downloads_enabled()->reset( |
| 764 | new bool(false)); |
| 765 | |
| 766 | // Check that the UpdateCanStart returns true. |
| 767 | UpdateState update_state = GetDefaultUpdateState(TimeDelta::FromMinutes(10)); |
Gilad Arnold | 42f253b | 2014-06-25 12:39:17 -0700 | [diff] [blame] | 768 | UpdateDownloadParams result; |
Gilad Arnold | b3b0544 | 2014-05-30 14:25:05 -0700 | [diff] [blame] | 769 | ExpectPolicyStatus(EvalStatus::kSucceeded, &Policy::UpdateCanStart, &result, |
| 770 | false, update_state); |
| 771 | EXPECT_TRUE(result.update_can_start); |
| 772 | EXPECT_TRUE(result.p2p_allowed); |
| 773 | EXPECT_GT(0, result.download_url_idx); |
| 774 | EXPECT_EQ(0, result.download_url_num_failures); |
Gilad Arnold | f62a4b8 | 2014-05-01 07:41:07 -0700 | [diff] [blame] | 775 | } |
| 776 | |
Gilad Arnold | 684219d | 2014-07-07 14:54:57 -0700 | [diff] [blame] | 777 | TEST_F(UmChromeOSPolicyTest, UpdateDownloadAllowedEthernetDefault) { |
Gilad Arnold | 0adbc94 | 2014-05-12 10:35:43 -0700 | [diff] [blame] | 778 | // Ethernet is always allowed. |
| 779 | |
| 780 | fake_state_.shill_provider()->var_conn_type()-> |
| 781 | reset(new ConnectionType(ConnectionType::kEthernet)); |
| 782 | |
| 783 | bool result; |
| 784 | ExpectPolicyStatus(EvalStatus::kSucceeded, |
Gilad Arnold | 684219d | 2014-07-07 14:54:57 -0700 | [diff] [blame] | 785 | &Policy::UpdateDownloadAllowed, &result); |
Gilad Arnold | 0adbc94 | 2014-05-12 10:35:43 -0700 | [diff] [blame] | 786 | EXPECT_TRUE(result); |
| 787 | } |
| 788 | |
Gilad Arnold | 684219d | 2014-07-07 14:54:57 -0700 | [diff] [blame] | 789 | TEST_F(UmChromeOSPolicyTest, UpdateDownloadAllowedWifiDefault) { |
Gilad Arnold | 0adbc94 | 2014-05-12 10:35:43 -0700 | [diff] [blame] | 790 | // Wifi is allowed if not tethered. |
| 791 | |
| 792 | fake_state_.shill_provider()->var_conn_type()-> |
| 793 | reset(new ConnectionType(ConnectionType::kWifi)); |
| 794 | |
| 795 | bool result; |
| 796 | ExpectPolicyStatus(EvalStatus::kSucceeded, |
Gilad Arnold | 684219d | 2014-07-07 14:54:57 -0700 | [diff] [blame] | 797 | &Policy::UpdateDownloadAllowed, &result); |
Gilad Arnold | 0adbc94 | 2014-05-12 10:35:43 -0700 | [diff] [blame] | 798 | EXPECT_TRUE(result); |
| 799 | } |
| 800 | |
Alex Deymo | 63784a5 | 2014-05-28 10:46:14 -0700 | [diff] [blame] | 801 | TEST_F(UmChromeOSPolicyTest, |
Gilad Arnold | 0adbc94 | 2014-05-12 10:35:43 -0700 | [diff] [blame] | 802 | UpdateCurrentConnectionNotAllowedWifiTetheredDefault) { |
| 803 | // Tethered wifi is not allowed by default. |
| 804 | |
| 805 | fake_state_.shill_provider()->var_conn_type()-> |
| 806 | reset(new ConnectionType(ConnectionType::kWifi)); |
| 807 | fake_state_.shill_provider()->var_conn_tethering()-> |
| 808 | reset(new ConnectionTethering(ConnectionTethering::kConfirmed)); |
| 809 | |
| 810 | bool result; |
Gilad Arnold | 28d6be6 | 2014-06-30 14:04:04 -0700 | [diff] [blame] | 811 | ExpectPolicyStatus(EvalStatus::kAskMeAgainLater, |
Gilad Arnold | 684219d | 2014-07-07 14:54:57 -0700 | [diff] [blame] | 812 | &Policy::UpdateDownloadAllowed, &result); |
Gilad Arnold | 0adbc94 | 2014-05-12 10:35:43 -0700 | [diff] [blame] | 813 | } |
| 814 | |
Alex Deymo | 63784a5 | 2014-05-28 10:46:14 -0700 | [diff] [blame] | 815 | TEST_F(UmChromeOSPolicyTest, |
Gilad Arnold | 684219d | 2014-07-07 14:54:57 -0700 | [diff] [blame] | 816 | UpdateDownloadAllowedWifiTetheredPolicyOverride) { |
Gilad Arnold | 0adbc94 | 2014-05-12 10:35:43 -0700 | [diff] [blame] | 817 | // Tethered wifi can be allowed by policy. |
| 818 | |
| 819 | fake_state_.shill_provider()->var_conn_type()-> |
| 820 | reset(new ConnectionType(ConnectionType::kWifi)); |
| 821 | fake_state_.shill_provider()->var_conn_tethering()-> |
| 822 | reset(new ConnectionTethering(ConnectionTethering::kConfirmed)); |
| 823 | set<ConnectionType> allowed_connections; |
| 824 | allowed_connections.insert(ConnectionType::kCellular); |
| 825 | fake_state_.device_policy_provider()-> |
| 826 | var_allowed_connection_types_for_update()-> |
| 827 | reset(new set<ConnectionType>(allowed_connections)); |
| 828 | |
| 829 | bool result; |
| 830 | ExpectPolicyStatus(EvalStatus::kSucceeded, |
Gilad Arnold | 684219d | 2014-07-07 14:54:57 -0700 | [diff] [blame] | 831 | &Policy::UpdateDownloadAllowed, &result); |
Gilad Arnold | 0adbc94 | 2014-05-12 10:35:43 -0700 | [diff] [blame] | 832 | EXPECT_TRUE(result); |
| 833 | } |
| 834 | |
Gilad Arnold | 684219d | 2014-07-07 14:54:57 -0700 | [diff] [blame] | 835 | TEST_F(UmChromeOSPolicyTest, UpdateDownloadAllowedWimaxDefault) { |
Gilad Arnold | 0adbc94 | 2014-05-12 10:35:43 -0700 | [diff] [blame] | 836 | // Wimax is always allowed. |
| 837 | |
| 838 | fake_state_.shill_provider()->var_conn_type()-> |
| 839 | reset(new ConnectionType(ConnectionType::kWifi)); |
| 840 | |
| 841 | bool result; |
| 842 | ExpectPolicyStatus(EvalStatus::kSucceeded, |
Gilad Arnold | 684219d | 2014-07-07 14:54:57 -0700 | [diff] [blame] | 843 | &Policy::UpdateDownloadAllowed, &result); |
Gilad Arnold | 0adbc94 | 2014-05-12 10:35:43 -0700 | [diff] [blame] | 844 | EXPECT_TRUE(result); |
| 845 | } |
| 846 | |
Alex Deymo | 63784a5 | 2014-05-28 10:46:14 -0700 | [diff] [blame] | 847 | TEST_F(UmChromeOSPolicyTest, |
Gilad Arnold | 0adbc94 | 2014-05-12 10:35:43 -0700 | [diff] [blame] | 848 | UpdateCurrentConnectionNotAllowedBluetoothDefault) { |
| 849 | // Bluetooth is never allowed. |
| 850 | |
| 851 | fake_state_.shill_provider()->var_conn_type()-> |
| 852 | reset(new ConnectionType(ConnectionType::kBluetooth)); |
| 853 | |
| 854 | bool result; |
Gilad Arnold | 28d6be6 | 2014-06-30 14:04:04 -0700 | [diff] [blame] | 855 | ExpectPolicyStatus(EvalStatus::kAskMeAgainLater, |
Gilad Arnold | 684219d | 2014-07-07 14:54:57 -0700 | [diff] [blame] | 856 | &Policy::UpdateDownloadAllowed, &result); |
Gilad Arnold | 0adbc94 | 2014-05-12 10:35:43 -0700 | [diff] [blame] | 857 | } |
| 858 | |
Alex Deymo | 63784a5 | 2014-05-28 10:46:14 -0700 | [diff] [blame] | 859 | TEST_F(UmChromeOSPolicyTest, |
Gilad Arnold | 0adbc94 | 2014-05-12 10:35:43 -0700 | [diff] [blame] | 860 | UpdateCurrentConnectionNotAllowedBluetoothPolicyCannotOverride) { |
| 861 | // Bluetooth cannot be allowed even by policy. |
| 862 | |
| 863 | fake_state_.shill_provider()->var_conn_type()-> |
| 864 | reset(new ConnectionType(ConnectionType::kBluetooth)); |
| 865 | set<ConnectionType> allowed_connections; |
| 866 | allowed_connections.insert(ConnectionType::kBluetooth); |
| 867 | fake_state_.device_policy_provider()-> |
| 868 | var_allowed_connection_types_for_update()-> |
| 869 | reset(new set<ConnectionType>(allowed_connections)); |
| 870 | |
| 871 | bool result; |
Gilad Arnold | 28d6be6 | 2014-06-30 14:04:04 -0700 | [diff] [blame] | 872 | ExpectPolicyStatus(EvalStatus::kAskMeAgainLater, |
Gilad Arnold | 684219d | 2014-07-07 14:54:57 -0700 | [diff] [blame] | 873 | &Policy::UpdateDownloadAllowed, &result); |
Gilad Arnold | 0adbc94 | 2014-05-12 10:35:43 -0700 | [diff] [blame] | 874 | } |
| 875 | |
Alex Deymo | 63784a5 | 2014-05-28 10:46:14 -0700 | [diff] [blame] | 876 | TEST_F(UmChromeOSPolicyTest, UpdateCurrentConnectionNotAllowedCellularDefault) { |
Gilad Arnold | 0adbc94 | 2014-05-12 10:35:43 -0700 | [diff] [blame] | 877 | // Cellular is not allowed by default. |
| 878 | |
| 879 | fake_state_.shill_provider()->var_conn_type()-> |
| 880 | reset(new ConnectionType(ConnectionType::kCellular)); |
| 881 | |
| 882 | bool result; |
Gilad Arnold | 28d6be6 | 2014-06-30 14:04:04 -0700 | [diff] [blame] | 883 | ExpectPolicyStatus(EvalStatus::kAskMeAgainLater, |
Gilad Arnold | 684219d | 2014-07-07 14:54:57 -0700 | [diff] [blame] | 884 | &Policy::UpdateDownloadAllowed, &result); |
Gilad Arnold | 0adbc94 | 2014-05-12 10:35:43 -0700 | [diff] [blame] | 885 | } |
| 886 | |
Alex Deymo | 63784a5 | 2014-05-28 10:46:14 -0700 | [diff] [blame] | 887 | TEST_F(UmChromeOSPolicyTest, |
Gilad Arnold | 684219d | 2014-07-07 14:54:57 -0700 | [diff] [blame] | 888 | UpdateDownloadAllowedCellularPolicyOverride) { |
Gilad Arnold | 0adbc94 | 2014-05-12 10:35:43 -0700 | [diff] [blame] | 889 | // Update over cellular can be enabled by policy. |
| 890 | |
| 891 | fake_state_.shill_provider()->var_conn_type()-> |
| 892 | reset(new ConnectionType(ConnectionType::kCellular)); |
| 893 | set<ConnectionType> allowed_connections; |
| 894 | allowed_connections.insert(ConnectionType::kCellular); |
| 895 | fake_state_.device_policy_provider()-> |
| 896 | var_allowed_connection_types_for_update()-> |
| 897 | reset(new set<ConnectionType>(allowed_connections)); |
| 898 | |
| 899 | bool result; |
| 900 | ExpectPolicyStatus(EvalStatus::kSucceeded, |
Gilad Arnold | 684219d | 2014-07-07 14:54:57 -0700 | [diff] [blame] | 901 | &Policy::UpdateDownloadAllowed, &result); |
Gilad Arnold | 0adbc94 | 2014-05-12 10:35:43 -0700 | [diff] [blame] | 902 | EXPECT_TRUE(result); |
| 903 | } |
| 904 | |
Alex Deymo | 63784a5 | 2014-05-28 10:46:14 -0700 | [diff] [blame] | 905 | TEST_F(UmChromeOSPolicyTest, |
Gilad Arnold | 684219d | 2014-07-07 14:54:57 -0700 | [diff] [blame] | 906 | UpdateDownloadAllowedCellularUserOverride) { |
Gilad Arnold | 0adbc94 | 2014-05-12 10:35:43 -0700 | [diff] [blame] | 907 | // Update over cellular can be enabled by user settings, but only if policy |
| 908 | // is present and does not determine allowed connections. |
| 909 | |
| 910 | fake_state_.shill_provider()->var_conn_type()-> |
| 911 | reset(new ConnectionType(ConnectionType::kCellular)); |
| 912 | set<ConnectionType> allowed_connections; |
| 913 | allowed_connections.insert(ConnectionType::kCellular); |
| 914 | fake_state_.updater_provider()->var_cellular_enabled()-> |
| 915 | reset(new bool(true)); |
| 916 | |
| 917 | bool result; |
| 918 | ExpectPolicyStatus(EvalStatus::kSucceeded, |
Gilad Arnold | 684219d | 2014-07-07 14:54:57 -0700 | [diff] [blame] | 919 | &Policy::UpdateDownloadAllowed, &result); |
Gilad Arnold | 0adbc94 | 2014-05-12 10:35:43 -0700 | [diff] [blame] | 920 | EXPECT_TRUE(result); |
| 921 | } |
| 922 | |
Alex Deymo | 63784a5 | 2014-05-28 10:46:14 -0700 | [diff] [blame] | 923 | } // namespace chromeos_update_manager |