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 | |
Alex Deymo | 0d11c60 | 2014-04-23 20:12:20 -0700 | [diff] [blame] | 150 | ExpectPolicyStatus(EvalStatus::kSucceeded, |
| 151 | &ChromeOSPolicy::NextUpdateCheckTime, &next_update_check); |
| 152 | |
| 153 | EXPECT_LE(fake_clock_.GetWallclockTime(), next_update_check); |
| 154 | EXPECT_GE(fake_clock_.GetWallclockTime() + TimeDelta::FromSeconds( |
| 155 | ChromeOSPolicy::kTimeoutInitialInterval + |
| 156 | ChromeOSPolicy::kTimeoutRegularFuzz), next_update_check); |
| 157 | } |
| 158 | |
Alex Deymo | 63784a5 | 2014-05-28 10:46:14 -0700 | [diff] [blame] | 159 | TEST_F(UmChromeOSPolicyTest, ExponentialBackoffIsCapped) { |
Alex Deymo | 0d11c60 | 2014-04-23 20:12:20 -0700 | [diff] [blame] | 160 | Time next_update_check; |
| 161 | |
Alex Deymo | 0d11c60 | 2014-04-23 20:12:20 -0700 | [diff] [blame] | 162 | fake_state_.updater_provider()->var_consecutive_failed_update_checks()-> |
Gilad Arnold | 684219d | 2014-07-07 14:54:57 -0700 | [diff] [blame] | 163 | reset(new unsigned int(100)); // NOLINT(readability/casting) |
Alex Deymo | 0d11c60 | 2014-04-23 20:12:20 -0700 | [diff] [blame] | 164 | ExpectPolicyStatus(EvalStatus::kSucceeded, |
| 165 | &ChromeOSPolicy::NextUpdateCheckTime, &next_update_check); |
| 166 | |
| 167 | EXPECT_LE(fake_clock_.GetWallclockTime() + TimeDelta::FromSeconds( |
| 168 | ChromeOSPolicy::kTimeoutMaxBackoffInterval - |
| 169 | ChromeOSPolicy::kTimeoutRegularFuzz - 1), next_update_check); |
| 170 | EXPECT_GE(fake_clock_.GetWallclockTime() + TimeDelta::FromSeconds( |
| 171 | ChromeOSPolicy::kTimeoutMaxBackoffInterval + |
| 172 | ChromeOSPolicy::kTimeoutRegularFuzz), next_update_check); |
| 173 | } |
| 174 | |
Alex Deymo | 63784a5 | 2014-05-28 10:46:14 -0700 | [diff] [blame] | 175 | TEST_F(UmChromeOSPolicyTest, UpdateCheckAllowedWaitsForTheTimeout) { |
Alex Deymo | 0d11c60 | 2014-04-23 20:12:20 -0700 | [diff] [blame] | 176 | // We get the next update_check timestamp from the policy's private method |
| 177 | // and then we check the public method respects that value on the normal |
| 178 | // case. |
| 179 | Time next_update_check; |
| 180 | Time last_checked_time = |
| 181 | fake_clock_.GetWallclockTime() + TimeDelta::FromMinutes(1234); |
| 182 | |
Alex Deymo | 0d11c60 | 2014-04-23 20:12:20 -0700 | [diff] [blame] | 183 | fake_state_.updater_provider()->var_last_checked_time()->reset( |
| 184 | new Time(last_checked_time)); |
| 185 | ExpectPolicyStatus(EvalStatus::kSucceeded, |
| 186 | &ChromeOSPolicy::NextUpdateCheckTime, &next_update_check); |
| 187 | |
| 188 | UpdateCheckParams result; |
| 189 | |
| 190 | // Check that the policy blocks until the next_update_check is reached. |
| 191 | SetUpDefaultClock(); |
| 192 | SetUpDefaultState(); |
| 193 | fake_state_.updater_provider()->var_last_checked_time()->reset( |
| 194 | new Time(last_checked_time)); |
| 195 | fake_clock_.SetWallclockTime(next_update_check - TimeDelta::FromSeconds(1)); |
| 196 | ExpectPolicyStatus(EvalStatus::kAskMeAgainLater, |
| 197 | &Policy::UpdateCheckAllowed, &result); |
| 198 | |
| 199 | SetUpDefaultClock(); |
| 200 | SetUpDefaultState(); |
| 201 | fake_state_.updater_provider()->var_last_checked_time()->reset( |
| 202 | new Time(last_checked_time)); |
| 203 | fake_clock_.SetWallclockTime(next_update_check + TimeDelta::FromSeconds(1)); |
| 204 | ExpectPolicyStatus(EvalStatus::kSucceeded, |
| 205 | &Policy::UpdateCheckAllowed, &result); |
| 206 | } |
| 207 | |
Gilad Arnold | 42f253b | 2014-06-25 12:39:17 -0700 | [diff] [blame^] | 208 | TEST_F(UmChromeOSPolicyTest, UpdateCheckAllowedWithAttributes) { |
| 209 | // Update check is allowed, reponse includes attributes for use in the |
| 210 | // request. |
| 211 | SetUpdateCheckAllowed(true); |
| 212 | |
| 213 | // Override specific device policy attributes. |
| 214 | fake_state_.device_policy_provider()->var_release_channel_delegated()-> |
| 215 | reset(new bool(false)); |
| 216 | fake_state_.device_policy_provider()->var_release_channel()-> |
| 217 | reset(new string("foo-channel")); |
| 218 | |
| 219 | UpdateCheckParams result; |
| 220 | ExpectPolicyStatus(EvalStatus::kSucceeded, |
| 221 | &Policy::UpdateCheckAllowed, &result); |
| 222 | EXPECT_TRUE(result.updates_enabled); |
| 223 | EXPECT_EQ("foo-channel", result.target_channel); |
| 224 | } |
| 225 | |
| 226 | TEST_F(UmChromeOSPolicyTest, UpdateCheckAllowedUpdatesDisabled) { |
| 227 | // UpdateCheckAllowed should return kAskMeAgainLater because a device policy |
| 228 | // is loaded and prohibits updates. |
| 229 | |
| 230 | SetUpdateCheckAllowed(false); |
| 231 | fake_state_.device_policy_provider()->var_update_disabled()->reset( |
| 232 | new bool(true)); |
| 233 | |
| 234 | // Check that the UpdateCanStart returns false. |
| 235 | UpdateCheckParams result; |
| 236 | ExpectPolicyStatus(EvalStatus::kAskMeAgainLater, |
| 237 | &Policy::UpdateCheckAllowed, &result); |
| 238 | } |
| 239 | |
Alex Deymo | 63784a5 | 2014-05-28 10:46:14 -0700 | [diff] [blame] | 240 | TEST_F(UmChromeOSPolicyTest, UpdateCanStartFailsCheckAllowedError) { |
Gilad Arnold | f62a4b8 | 2014-05-01 07:41:07 -0700 | [diff] [blame] | 241 | // The UpdateCanStart policy fails, not being able to query |
| 242 | // UpdateCheckAllowed. |
| 243 | |
| 244 | // Configure the UpdateCheckAllowed policy to fail. |
| 245 | fake_state_.updater_provider()->var_updater_started_time()->reset(nullptr); |
| 246 | |
| 247 | // Check that the UpdateCanStart fails. |
| 248 | UpdateState update_state = GetDefaultUpdateState(TimeDelta::FromMinutes(10)); |
Gilad Arnold | 42f253b | 2014-06-25 12:39:17 -0700 | [diff] [blame^] | 249 | UpdateDownloadParams result; |
Gilad Arnold | f62a4b8 | 2014-05-01 07:41:07 -0700 | [diff] [blame] | 250 | ExpectPolicyStatus(EvalStatus::kFailed, |
| 251 | &Policy::UpdateCanStart, &result, false, update_state); |
| 252 | } |
| 253 | |
Alex Deymo | 63784a5 | 2014-05-28 10:46:14 -0700 | [diff] [blame] | 254 | TEST_F(UmChromeOSPolicyTest, UpdateCanStartNotAllowedCheckDue) { |
Gilad Arnold | f62a4b8 | 2014-05-01 07:41:07 -0700 | [diff] [blame] | 255 | // The UpdateCanStart policy returns false because we are due for another |
| 256 | // update check. |
| 257 | |
| 258 | SetUpdateCheckAllowed(true); |
| 259 | |
| 260 | // Check that the UpdateCanStart returns false. |
| 261 | UpdateState update_state = GetDefaultUpdateState(TimeDelta::FromMinutes(10)); |
Gilad Arnold | 42f253b | 2014-06-25 12:39:17 -0700 | [diff] [blame^] | 262 | UpdateDownloadParams result; |
Gilad Arnold | f62a4b8 | 2014-05-01 07:41:07 -0700 | [diff] [blame] | 263 | ExpectPolicyStatus(EvalStatus::kSucceeded, |
| 264 | &Policy::UpdateCanStart, &result, false, update_state); |
| 265 | EXPECT_FALSE(result.update_can_start); |
| 266 | EXPECT_EQ(UpdateCannotStartReason::kCheckDue, result.cannot_start_reason); |
| 267 | } |
| 268 | |
Alex Deymo | 63784a5 | 2014-05-28 10:46:14 -0700 | [diff] [blame] | 269 | TEST_F(UmChromeOSPolicyTest, UpdateCanStartAllowedNoDevicePolicy) { |
Gilad Arnold | f62a4b8 | 2014-05-01 07:41:07 -0700 | [diff] [blame] | 270 | // The UpdateCanStart policy returns true; no device policy is loaded. |
| 271 | |
| 272 | SetUpdateCheckAllowed(false); |
| 273 | fake_state_.device_policy_provider()->var_device_policy_is_loaded()->reset( |
| 274 | new bool(false)); |
| 275 | |
| 276 | // Check that the UpdateCanStart returns true with no further attributes. |
| 277 | UpdateState update_state = GetDefaultUpdateState(TimeDelta::FromMinutes(10)); |
Gilad Arnold | 42f253b | 2014-06-25 12:39:17 -0700 | [diff] [blame^] | 278 | UpdateDownloadParams result; |
Gilad Arnold | f62a4b8 | 2014-05-01 07:41:07 -0700 | [diff] [blame] | 279 | ExpectPolicyStatus(EvalStatus::kSucceeded, |
| 280 | &Policy::UpdateCanStart, &result, false, update_state); |
| 281 | EXPECT_TRUE(result.update_can_start); |
Gilad Arnold | f62a4b8 | 2014-05-01 07:41:07 -0700 | [diff] [blame] | 282 | EXPECT_FALSE(result.p2p_allowed); |
Gilad Arnold | b3b0544 | 2014-05-30 14:25:05 -0700 | [diff] [blame] | 283 | EXPECT_EQ(0, result.download_url_idx); |
| 284 | EXPECT_EQ(0, result.download_url_num_failures); |
Gilad Arnold | f62a4b8 | 2014-05-01 07:41:07 -0700 | [diff] [blame] | 285 | } |
| 286 | |
Alex Deymo | 63784a5 | 2014-05-28 10:46:14 -0700 | [diff] [blame] | 287 | TEST_F(UmChromeOSPolicyTest, UpdateCanStartAllowedBlankPolicy) { |
Gilad Arnold | f62a4b8 | 2014-05-01 07:41:07 -0700 | [diff] [blame] | 288 | // The UpdateCanStart policy returns true; device policy is loaded but imposes |
| 289 | // no restrictions on updating. |
| 290 | |
| 291 | SetUpdateCheckAllowed(false); |
| 292 | |
| 293 | // Check that the UpdateCanStart returns true. |
| 294 | UpdateState update_state = GetDefaultUpdateState(TimeDelta::FromMinutes(10)); |
Gilad Arnold | 42f253b | 2014-06-25 12:39:17 -0700 | [diff] [blame^] | 295 | UpdateDownloadParams result; |
Gilad Arnold | f62a4b8 | 2014-05-01 07:41:07 -0700 | [diff] [blame] | 296 | ExpectPolicyStatus(EvalStatus::kSucceeded, |
| 297 | &Policy::UpdateCanStart, &result, false, update_state); |
| 298 | EXPECT_TRUE(result.update_can_start); |
Gilad Arnold | f62a4b8 | 2014-05-01 07:41:07 -0700 | [diff] [blame] | 299 | EXPECT_FALSE(result.p2p_allowed); |
Gilad Arnold | b3b0544 | 2014-05-30 14:25:05 -0700 | [diff] [blame] | 300 | EXPECT_EQ(0, result.download_url_idx); |
| 301 | EXPECT_EQ(0, result.download_url_num_failures); |
Gilad Arnold | f62a4b8 | 2014-05-01 07:41:07 -0700 | [diff] [blame] | 302 | } |
| 303 | |
Alex Deymo | 63784a5 | 2014-05-28 10:46:14 -0700 | [diff] [blame] | 304 | TEST_F(UmChromeOSPolicyTest, UpdateCanStartFailsScatteringFailed) { |
Gilad Arnold | f62a4b8 | 2014-05-01 07:41:07 -0700 | [diff] [blame] | 305 | // The UpdateCanStart policy fails because the UpdateScattering policy it |
| 306 | // depends on fails (unset variable). |
| 307 | |
| 308 | SetUpdateCheckAllowed(false); |
| 309 | |
| 310 | // Override the default seed variable with a null value so that the policy |
| 311 | // request would fail. |
| 312 | fake_state_.random_provider()->var_seed()->reset(nullptr); |
| 313 | |
| 314 | // Check that the UpdateCanStart fails. |
| 315 | UpdateState update_state = GetDefaultUpdateState(TimeDelta::FromSeconds(1)); |
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, |
Gilad Arnold | f62a4b8 | 2014-05-01 07:41:07 -0700 | [diff] [blame] | 322 | UpdateCanStartNotAllowedScatteringNewWaitPeriodApplies) { |
| 323 | // The UpdateCanStart policy returns false; device policy is loaded and |
| 324 | // scattering applies due to an unsatisfied wait period, which was newly |
| 325 | // generated. |
| 326 | |
| 327 | SetUpdateCheckAllowed(false); |
| 328 | fake_state_.device_policy_provider()->var_scatter_factor()->reset( |
| 329 | new TimeDelta(TimeDelta::FromMinutes(2))); |
| 330 | |
| 331 | |
| 332 | UpdateState update_state = GetDefaultUpdateState(TimeDelta::FromSeconds(1)); |
| 333 | |
| 334 | // Check that the UpdateCanStart returns false and a new wait period |
| 335 | // generated. |
Gilad Arnold | 42f253b | 2014-06-25 12:39:17 -0700 | [diff] [blame^] | 336 | UpdateDownloadParams result; |
Gilad Arnold | f62a4b8 | 2014-05-01 07:41:07 -0700 | [diff] [blame] | 337 | ExpectPolicyStatus(EvalStatus::kSucceeded, &Policy::UpdateCanStart, &result, |
| 338 | false, update_state); |
| 339 | EXPECT_FALSE(result.update_can_start); |
| 340 | EXPECT_EQ(UpdateCannotStartReason::kScattering, result.cannot_start_reason); |
| 341 | EXPECT_LT(TimeDelta(), result.scatter_wait_period); |
| 342 | EXPECT_EQ(0, result.scatter_check_threshold); |
| 343 | } |
| 344 | |
Alex Deymo | 63784a5 | 2014-05-28 10:46:14 -0700 | [diff] [blame] | 345 | TEST_F(UmChromeOSPolicyTest, |
Gilad Arnold | f62a4b8 | 2014-05-01 07:41:07 -0700 | [diff] [blame] | 346 | UpdateCanStartNotAllowedScatteringPrevWaitPeriodStillApplies) { |
| 347 | // The UpdateCanStart policy returns false w/ kAskMeAgainLater; device policy |
| 348 | // is loaded and a previously generated scattering period still applies, none |
| 349 | // of the scattering values has changed. |
| 350 | |
| 351 | SetUpdateCheckAllowed(false); |
| 352 | fake_state_.device_policy_provider()->var_scatter_factor()->reset( |
| 353 | new TimeDelta(TimeDelta::FromMinutes(2))); |
| 354 | |
| 355 | UpdateState update_state = GetDefaultUpdateState(TimeDelta::FromSeconds(1)); |
| 356 | update_state.scatter_wait_period = TimeDelta::FromSeconds(35); |
| 357 | |
| 358 | // Check that the UpdateCanStart returns false and a new wait period |
| 359 | // generated. |
Gilad Arnold | 42f253b | 2014-06-25 12:39:17 -0700 | [diff] [blame^] | 360 | UpdateDownloadParams result; |
Gilad Arnold | f62a4b8 | 2014-05-01 07:41:07 -0700 | [diff] [blame] | 361 | ExpectPolicyStatus(EvalStatus::kAskMeAgainLater, &Policy::UpdateCanStart, |
| 362 | &result, false, update_state); |
| 363 | EXPECT_FALSE(result.update_can_start); |
| 364 | EXPECT_EQ(UpdateCannotStartReason::kScattering, result.cannot_start_reason); |
| 365 | EXPECT_EQ(TimeDelta::FromSeconds(35), result.scatter_wait_period); |
| 366 | EXPECT_EQ(0, result.scatter_check_threshold); |
| 367 | } |
| 368 | |
Alex Deymo | 63784a5 | 2014-05-28 10:46:14 -0700 | [diff] [blame] | 369 | TEST_F(UmChromeOSPolicyTest, |
Gilad Arnold | f62a4b8 | 2014-05-01 07:41:07 -0700 | [diff] [blame] | 370 | UpdateCanStartNotAllowedScatteringNewCountThresholdApplies) { |
| 371 | // The UpdateCanStart policy returns false; device policy is loaded and |
| 372 | // scattering applies due to an unsatisfied update check count threshold. |
| 373 | // |
| 374 | // This ensures a non-zero check threshold, which may or may not be combined |
| 375 | // with a non-zero wait period (for which we cannot reliably control). |
| 376 | |
| 377 | SetUpdateCheckAllowed(false); |
| 378 | fake_state_.device_policy_provider()->var_scatter_factor()->reset( |
| 379 | new TimeDelta(TimeDelta::FromSeconds(1))); |
| 380 | |
| 381 | UpdateState update_state = GetDefaultUpdateState(TimeDelta::FromSeconds(1)); |
| 382 | update_state.scatter_check_threshold_min = 2; |
| 383 | update_state.scatter_check_threshold_max = 5; |
| 384 | |
| 385 | // Check that the UpdateCanStart returns false. |
Gilad Arnold | 42f253b | 2014-06-25 12:39:17 -0700 | [diff] [blame^] | 386 | UpdateDownloadParams result; |
Gilad Arnold | f62a4b8 | 2014-05-01 07:41:07 -0700 | [diff] [blame] | 387 | ExpectPolicyStatus(EvalStatus::kSucceeded, &Policy::UpdateCanStart, &result, |
| 388 | false, update_state); |
| 389 | EXPECT_FALSE(result.update_can_start); |
| 390 | EXPECT_EQ(UpdateCannotStartReason::kScattering, result.cannot_start_reason); |
| 391 | EXPECT_LE(2, result.scatter_check_threshold); |
| 392 | EXPECT_GE(5, result.scatter_check_threshold); |
| 393 | } |
| 394 | |
Alex Deymo | 63784a5 | 2014-05-28 10:46:14 -0700 | [diff] [blame] | 395 | TEST_F(UmChromeOSPolicyTest, |
Gilad Arnold | f62a4b8 | 2014-05-01 07:41:07 -0700 | [diff] [blame] | 396 | UpdateCanStartNotAllowedScatteringPrevCountThresholdStillApplies) { |
| 397 | // The UpdateCanStart policy returns false; device policy is loaded and |
| 398 | // scattering due to a previously generated count threshold still applies. |
| 399 | |
| 400 | SetUpdateCheckAllowed(false); |
| 401 | fake_state_.device_policy_provider()->var_scatter_factor()->reset( |
| 402 | new TimeDelta(TimeDelta::FromSeconds(1))); |
| 403 | |
| 404 | UpdateState update_state = GetDefaultUpdateState(TimeDelta::FromSeconds(1)); |
| 405 | update_state.scatter_check_threshold = 3; |
| 406 | update_state.scatter_check_threshold_min = 2; |
| 407 | update_state.scatter_check_threshold_max = 5; |
| 408 | |
| 409 | // Check that the UpdateCanStart returns false. |
Gilad Arnold | 42f253b | 2014-06-25 12:39:17 -0700 | [diff] [blame^] | 410 | UpdateDownloadParams result; |
Gilad Arnold | f62a4b8 | 2014-05-01 07:41:07 -0700 | [diff] [blame] | 411 | ExpectPolicyStatus(EvalStatus::kSucceeded, &Policy::UpdateCanStart, &result, |
| 412 | false, update_state); |
| 413 | EXPECT_FALSE(result.update_can_start); |
| 414 | EXPECT_EQ(UpdateCannotStartReason::kScattering, result.cannot_start_reason); |
| 415 | EXPECT_EQ(3, result.scatter_check_threshold); |
| 416 | } |
| 417 | |
Alex Deymo | 63784a5 | 2014-05-28 10:46:14 -0700 | [diff] [blame] | 418 | TEST_F(UmChromeOSPolicyTest, UpdateCanStartAllowedScatteringSatisfied) { |
Gilad Arnold | f62a4b8 | 2014-05-01 07:41:07 -0700 | [diff] [blame] | 419 | // The UpdateCanStart policy returns true; device policy is loaded and |
| 420 | // scattering is enabled, but both wait period and check threshold are |
| 421 | // satisfied. |
| 422 | |
| 423 | SetUpdateCheckAllowed(false); |
| 424 | fake_state_.device_policy_provider()->var_scatter_factor()->reset( |
| 425 | new TimeDelta(TimeDelta::FromSeconds(120))); |
| 426 | |
| 427 | UpdateState update_state = GetDefaultUpdateState(TimeDelta::FromSeconds(75)); |
| 428 | update_state.num_checks = 4; |
| 429 | update_state.scatter_wait_period = TimeDelta::FromSeconds(60); |
| 430 | update_state.scatter_check_threshold = 3; |
| 431 | update_state.scatter_check_threshold_min = 2; |
| 432 | update_state.scatter_check_threshold_max = 5; |
| 433 | |
| 434 | // Check that the UpdateCanStart returns true. |
Gilad Arnold | 42f253b | 2014-06-25 12:39:17 -0700 | [diff] [blame^] | 435 | UpdateDownloadParams result; |
Gilad Arnold | f62a4b8 | 2014-05-01 07:41:07 -0700 | [diff] [blame] | 436 | ExpectPolicyStatus(EvalStatus::kSucceeded, &Policy::UpdateCanStart, &result, |
| 437 | false, update_state); |
| 438 | EXPECT_TRUE(result.update_can_start); |
| 439 | EXPECT_EQ(TimeDelta(), result.scatter_wait_period); |
| 440 | EXPECT_EQ(0, result.scatter_check_threshold); |
Gilad Arnold | b3b0544 | 2014-05-30 14:25:05 -0700 | [diff] [blame] | 441 | EXPECT_EQ(0, result.download_url_idx); |
| 442 | EXPECT_EQ(0, result.download_url_num_failures); |
Gilad Arnold | f62a4b8 | 2014-05-01 07:41:07 -0700 | [diff] [blame] | 443 | } |
| 444 | |
Alex Deymo | 63784a5 | 2014-05-28 10:46:14 -0700 | [diff] [blame] | 445 | TEST_F(UmChromeOSPolicyTest, |
Gilad Arnold | f62a4b8 | 2014-05-01 07:41:07 -0700 | [diff] [blame] | 446 | UpdateCanStartAllowedInteractivePreventsScattering) { |
| 447 | // The UpdateCanStart policy returns true; device policy is loaded and |
| 448 | // scattering would have applied, except that the update check is interactive |
| 449 | // and so it is suppressed. |
| 450 | |
| 451 | SetUpdateCheckAllowed(false); |
| 452 | fake_state_.device_policy_provider()->var_scatter_factor()->reset( |
| 453 | new TimeDelta(TimeDelta::FromSeconds(1))); |
| 454 | |
| 455 | UpdateState update_state = GetDefaultUpdateState(TimeDelta::FromSeconds(1)); |
| 456 | update_state.scatter_check_threshold = 0; |
| 457 | update_state.scatter_check_threshold_min = 2; |
| 458 | update_state.scatter_check_threshold_max = 5; |
| 459 | |
| 460 | // Check that the UpdateCanStart returns true. |
Gilad Arnold | 42f253b | 2014-06-25 12:39:17 -0700 | [diff] [blame^] | 461 | UpdateDownloadParams result; |
Gilad Arnold | f62a4b8 | 2014-05-01 07:41:07 -0700 | [diff] [blame] | 462 | ExpectPolicyStatus(EvalStatus::kSucceeded, &Policy::UpdateCanStart, &result, |
| 463 | true, update_state); |
| 464 | EXPECT_TRUE(result.update_can_start); |
| 465 | EXPECT_EQ(TimeDelta(), result.scatter_wait_period); |
| 466 | EXPECT_EQ(0, result.scatter_check_threshold); |
Gilad Arnold | b3b0544 | 2014-05-30 14:25:05 -0700 | [diff] [blame] | 467 | EXPECT_EQ(0, result.download_url_idx); |
| 468 | EXPECT_EQ(0, result.download_url_num_failures); |
Gilad Arnold | f62a4b8 | 2014-05-01 07:41:07 -0700 | [diff] [blame] | 469 | } |
| 470 | |
Alex Deymo | 63784a5 | 2014-05-28 10:46:14 -0700 | [diff] [blame] | 471 | TEST_F(UmChromeOSPolicyTest, |
Gilad Arnold | 76a11f6 | 2014-05-20 09:02:12 -0700 | [diff] [blame] | 472 | UpdateCanStartAllowedOobePreventsScattering) { |
| 473 | // The UpdateCanStart policy returns true; device policy is loaded and |
| 474 | // scattering would have applied, except that OOBE was not completed and so it |
| 475 | // is suppressed. |
| 476 | |
| 477 | SetUpdateCheckAllowed(false); |
| 478 | fake_state_.device_policy_provider()->var_scatter_factor()->reset( |
| 479 | new TimeDelta(TimeDelta::FromSeconds(1))); |
| 480 | fake_state_.system_provider()->var_is_oobe_complete()->reset(new bool(false)); |
| 481 | |
| 482 | UpdateState update_state = GetDefaultUpdateState(TimeDelta::FromSeconds(1)); |
| 483 | update_state.scatter_check_threshold = 0; |
| 484 | update_state.scatter_check_threshold_min = 2; |
| 485 | update_state.scatter_check_threshold_max = 5; |
| 486 | |
| 487 | // Check that the UpdateCanStart returns true. |
Gilad Arnold | 42f253b | 2014-06-25 12:39:17 -0700 | [diff] [blame^] | 488 | UpdateDownloadParams result; |
Gilad Arnold | 76a11f6 | 2014-05-20 09:02:12 -0700 | [diff] [blame] | 489 | ExpectPolicyStatus(EvalStatus::kSucceeded, &Policy::UpdateCanStart, &result, |
| 490 | true, update_state); |
| 491 | EXPECT_TRUE(result.update_can_start); |
| 492 | EXPECT_EQ(TimeDelta(), result.scatter_wait_period); |
| 493 | EXPECT_EQ(0, result.scatter_check_threshold); |
Gilad Arnold | b3b0544 | 2014-05-30 14:25:05 -0700 | [diff] [blame] | 494 | EXPECT_EQ(0, result.download_url_idx); |
| 495 | EXPECT_EQ(0, result.download_url_num_failures); |
Gilad Arnold | 76a11f6 | 2014-05-20 09:02:12 -0700 | [diff] [blame] | 496 | } |
| 497 | |
Alex Deymo | 63784a5 | 2014-05-28 10:46:14 -0700 | [diff] [blame] | 498 | TEST_F(UmChromeOSPolicyTest, UpdateCanStartAllowedWithAttributes) { |
Gilad Arnold | f62a4b8 | 2014-05-01 07:41:07 -0700 | [diff] [blame] | 499 | // The UpdateCanStart policy returns true; device policy permits both HTTP and |
| 500 | // P2P updates, as well as a non-empty target channel string. |
| 501 | |
| 502 | SetUpdateCheckAllowed(false); |
| 503 | |
| 504 | // Override specific device policy attributes. |
| 505 | fake_state_.device_policy_provider()->var_http_downloads_enabled()->reset( |
| 506 | new bool(true)); |
| 507 | fake_state_.device_policy_provider()->var_au_p2p_enabled()->reset( |
| 508 | new bool(true)); |
Gilad Arnold | f62a4b8 | 2014-05-01 07:41:07 -0700 | [diff] [blame] | 509 | |
| 510 | // Check that the UpdateCanStart returns true. |
| 511 | UpdateState update_state = GetDefaultUpdateState(TimeDelta::FromMinutes(10)); |
Gilad Arnold | 42f253b | 2014-06-25 12:39:17 -0700 | [diff] [blame^] | 512 | UpdateDownloadParams result; |
Gilad Arnold | f62a4b8 | 2014-05-01 07:41:07 -0700 | [diff] [blame] | 513 | ExpectPolicyStatus(EvalStatus::kSucceeded, &Policy::UpdateCanStart, &result, |
| 514 | false, update_state); |
| 515 | EXPECT_TRUE(result.update_can_start); |
Gilad Arnold | f62a4b8 | 2014-05-01 07:41:07 -0700 | [diff] [blame] | 516 | EXPECT_TRUE(result.p2p_allowed); |
Gilad Arnold | b3b0544 | 2014-05-30 14:25:05 -0700 | [diff] [blame] | 517 | EXPECT_EQ(0, result.download_url_idx); |
| 518 | EXPECT_EQ(0, result.download_url_num_failures); |
Gilad Arnold | f62a4b8 | 2014-05-01 07:41:07 -0700 | [diff] [blame] | 519 | } |
| 520 | |
Alex Deymo | 63784a5 | 2014-05-28 10:46:14 -0700 | [diff] [blame] | 521 | TEST_F(UmChromeOSPolicyTest, UpdateCanStartAllowedWithP2PFromUpdater) { |
Gilad Arnold | f62a4b8 | 2014-05-01 07:41:07 -0700 | [diff] [blame] | 522 | // The UpdateCanStart policy returns true; device policy forbids both HTTP and |
| 523 | // P2P updates, but the updater is configured to allow P2P and overrules the |
| 524 | // setting. |
| 525 | |
| 526 | SetUpdateCheckAllowed(false); |
| 527 | |
| 528 | // Override specific device policy attributes. |
Gilad Arnold | f62a4b8 | 2014-05-01 07:41:07 -0700 | [diff] [blame] | 529 | fake_state_.updater_provider()->var_p2p_enabled()->reset(new bool(true)); |
| 530 | |
| 531 | // Check that the UpdateCanStart returns true. |
| 532 | UpdateState update_state = GetDefaultUpdateState(TimeDelta::FromMinutes(10)); |
Gilad Arnold | 42f253b | 2014-06-25 12:39:17 -0700 | [diff] [blame^] | 533 | UpdateDownloadParams result; |
Gilad Arnold | f62a4b8 | 2014-05-01 07:41:07 -0700 | [diff] [blame] | 534 | ExpectPolicyStatus(EvalStatus::kSucceeded, &Policy::UpdateCanStart, &result, |
| 535 | false, update_state); |
| 536 | EXPECT_TRUE(result.update_can_start); |
Gilad Arnold | f62a4b8 | 2014-05-01 07:41:07 -0700 | [diff] [blame] | 537 | EXPECT_TRUE(result.p2p_allowed); |
Gilad Arnold | b3b0544 | 2014-05-30 14:25:05 -0700 | [diff] [blame] | 538 | EXPECT_EQ(0, result.download_url_idx); |
| 539 | EXPECT_EQ(0, result.download_url_num_failures); |
Gilad Arnold | f62a4b8 | 2014-05-01 07:41:07 -0700 | [diff] [blame] | 540 | } |
| 541 | |
Gilad Arnold | b3b0544 | 2014-05-30 14:25:05 -0700 | [diff] [blame] | 542 | TEST_F(UmChromeOSPolicyTest, |
| 543 | UpdateCanStartAllowedWithHttpUrlForUnofficialBuild) { |
Gilad Arnold | f62a4b8 | 2014-05-01 07:41:07 -0700 | [diff] [blame] | 544 | // The UpdateCanStart policy returns true; device policy forbids both HTTP and |
| 545 | // P2P updates, but marking this an unofficial build overrules the HTTP |
| 546 | // setting. |
| 547 | |
| 548 | SetUpdateCheckAllowed(false); |
| 549 | |
| 550 | // Override specific device policy attributes. |
Gilad Arnold | b3b0544 | 2014-05-30 14:25:05 -0700 | [diff] [blame] | 551 | fake_state_.device_policy_provider()->var_http_downloads_enabled()->reset( |
| 552 | new bool(false)); |
Gilad Arnold | f62a4b8 | 2014-05-01 07:41:07 -0700 | [diff] [blame] | 553 | fake_state_.system_provider()->var_is_official_build()-> |
| 554 | reset(new bool(false)); |
| 555 | |
| 556 | // Check that the UpdateCanStart returns true. |
| 557 | UpdateState update_state = GetDefaultUpdateState(TimeDelta::FromMinutes(10)); |
Gilad Arnold | 42f253b | 2014-06-25 12:39:17 -0700 | [diff] [blame^] | 558 | UpdateDownloadParams result; |
Gilad Arnold | f62a4b8 | 2014-05-01 07:41:07 -0700 | [diff] [blame] | 559 | ExpectPolicyStatus(EvalStatus::kSucceeded, &Policy::UpdateCanStart, &result, |
| 560 | false, update_state); |
| 561 | EXPECT_TRUE(result.update_can_start); |
Gilad Arnold | f62a4b8 | 2014-05-01 07:41:07 -0700 | [diff] [blame] | 562 | EXPECT_FALSE(result.p2p_allowed); |
Gilad Arnold | b3b0544 | 2014-05-30 14:25:05 -0700 | [diff] [blame] | 563 | EXPECT_EQ(0, result.download_url_idx); |
| 564 | EXPECT_EQ(0, result.download_url_num_failures); |
| 565 | } |
| 566 | |
| 567 | TEST_F(UmChromeOSPolicyTest, UpdateCanStartAllowedWithHttpsUrl) { |
| 568 | // The UpdateCanStart policy returns true; device policy forbids both HTTP and |
| 569 | // P2P updates, but an HTTPS URL is provided and selected for download. |
| 570 | |
| 571 | SetUpdateCheckAllowed(false); |
| 572 | |
| 573 | // Override specific device policy attributes. |
| 574 | fake_state_.device_policy_provider()->var_http_downloads_enabled()->reset( |
| 575 | new bool(false)); |
| 576 | |
| 577 | // Add an HTTPS URL. |
| 578 | UpdateState update_state = GetDefaultUpdateState(TimeDelta::FromMinutes(10)); |
| 579 | update_state.download_urls.push_back("https://secure/url/"); |
| 580 | |
| 581 | // Check that the UpdateCanStart returns true. |
Gilad Arnold | 42f253b | 2014-06-25 12:39:17 -0700 | [diff] [blame^] | 582 | UpdateDownloadParams result; |
Gilad Arnold | b3b0544 | 2014-05-30 14:25:05 -0700 | [diff] [blame] | 583 | ExpectPolicyStatus(EvalStatus::kSucceeded, &Policy::UpdateCanStart, &result, |
| 584 | false, update_state); |
| 585 | EXPECT_TRUE(result.update_can_start); |
| 586 | EXPECT_FALSE(result.p2p_allowed); |
| 587 | EXPECT_EQ(1, result.download_url_idx); |
| 588 | EXPECT_EQ(0, result.download_url_num_failures); |
| 589 | } |
| 590 | |
| 591 | TEST_F(UmChromeOSPolicyTest, UpdateCanStartAllowedWithSecondUrlMaxExceeded) { |
| 592 | // The UpdateCanStart policy returns true; the first URL exceeded the maximum |
| 593 | // allowed number of failures, but a second URL is available. |
| 594 | |
| 595 | SetUpdateCheckAllowed(false); |
| 596 | |
| 597 | // Add a second URL; update with this URL attempted and failed enough times to |
| 598 | // disqualify the current (first) URL. This tests both the previously |
| 599 | // accounted failures (download_url_num_failures) as well as those occurring |
| 600 | // since the last call (download_url_error_codes). |
| 601 | UpdateState update_state = GetDefaultUpdateState(TimeDelta::FromMinutes(10)); |
| 602 | update_state.num_checks = 10; |
| 603 | update_state.download_urls.push_back("http://another/fake/url/"); |
| 604 | update_state.download_url_num_failures = 9; |
| 605 | update_state.download_url_error_codes.push_back( |
| 606 | ErrorCode::kDownloadTransferError); |
| 607 | update_state.download_url_error_codes.push_back( |
| 608 | ErrorCode::kDownloadWriteError); |
| 609 | |
| 610 | // Check that the UpdateCanStart returns true. |
Gilad Arnold | 42f253b | 2014-06-25 12:39:17 -0700 | [diff] [blame^] | 611 | UpdateDownloadParams result; |
Gilad Arnold | b3b0544 | 2014-05-30 14:25:05 -0700 | [diff] [blame] | 612 | ExpectPolicyStatus(EvalStatus::kSucceeded, &Policy::UpdateCanStart, &result, |
| 613 | false, update_state); |
| 614 | EXPECT_TRUE(result.update_can_start); |
| 615 | EXPECT_FALSE(result.p2p_allowed); |
| 616 | EXPECT_EQ(1, result.download_url_idx); |
| 617 | EXPECT_EQ(0, result.download_url_num_failures); |
| 618 | } |
| 619 | |
| 620 | TEST_F(UmChromeOSPolicyTest, UpdateCanStartAllowedWithSecondUrlHardError) { |
| 621 | // The UpdateCanStart policy returns true; the first URL fails with a hard |
| 622 | // error, but a second URL is available. |
| 623 | |
| 624 | SetUpdateCheckAllowed(false); |
| 625 | |
| 626 | // Add a second URL; update with this URL attempted and failed in a way that |
| 627 | // causes it to switch directly to the next URL. |
| 628 | UpdateState update_state = GetDefaultUpdateState(TimeDelta::FromMinutes(10)); |
| 629 | update_state.num_checks = 10; |
| 630 | update_state.download_urls.push_back("http://another/fake/url/"); |
| 631 | update_state.download_url_error_codes.push_back( |
| 632 | ErrorCode::kPayloadHashMismatchError); |
| 633 | |
| 634 | // Check that the UpdateCanStart returns true. |
Gilad Arnold | 42f253b | 2014-06-25 12:39:17 -0700 | [diff] [blame^] | 635 | UpdateDownloadParams result; |
Gilad Arnold | b3b0544 | 2014-05-30 14:25:05 -0700 | [diff] [blame] | 636 | ExpectPolicyStatus(EvalStatus::kSucceeded, &Policy::UpdateCanStart, &result, |
| 637 | false, update_state); |
| 638 | EXPECT_TRUE(result.update_can_start); |
| 639 | EXPECT_FALSE(result.p2p_allowed); |
| 640 | EXPECT_EQ(1, result.download_url_idx); |
| 641 | EXPECT_EQ(0, result.download_url_num_failures); |
| 642 | } |
| 643 | |
| 644 | TEST_F(UmChromeOSPolicyTest, UpdateCanStartAllowedUrlWrapsAround) { |
| 645 | // The UpdateCanStart policy returns true; URL search properly wraps around |
| 646 | // the last one on the list. |
| 647 | |
| 648 | SetUpdateCheckAllowed(false); |
| 649 | |
| 650 | // Add a second URL; update with this URL attempted and failed in a way that |
| 651 | // causes it to switch directly to the next URL. |
| 652 | UpdateState update_state = GetDefaultUpdateState(TimeDelta::FromMinutes(10)); |
| 653 | update_state.num_checks = 10; |
| 654 | update_state.download_urls.push_back("http://another/fake/url/"); |
| 655 | update_state.download_url_idx = 1; |
| 656 | update_state.download_url_error_codes.push_back( |
| 657 | ErrorCode::kPayloadHashMismatchError); |
| 658 | |
| 659 | // Check that the UpdateCanStart returns true. |
Gilad Arnold | 42f253b | 2014-06-25 12:39:17 -0700 | [diff] [blame^] | 660 | UpdateDownloadParams result; |
Gilad Arnold | b3b0544 | 2014-05-30 14:25:05 -0700 | [diff] [blame] | 661 | ExpectPolicyStatus(EvalStatus::kSucceeded, &Policy::UpdateCanStart, &result, |
| 662 | false, update_state); |
| 663 | EXPECT_TRUE(result.update_can_start); |
| 664 | EXPECT_FALSE(result.p2p_allowed); |
| 665 | EXPECT_EQ(0, result.download_url_idx); |
| 666 | EXPECT_EQ(0, result.download_url_num_failures); |
| 667 | } |
| 668 | |
| 669 | TEST_F(UmChromeOSPolicyTest, UpdateCanStartNotAllowedNoUsableUrls) { |
| 670 | // The UpdateCanStart policy returns false; there's a single HTTP URL but its |
| 671 | // use is forbidden by policy. |
| 672 | |
| 673 | SetUpdateCheckAllowed(false); |
| 674 | |
| 675 | // Override specific device policy attributes. |
| 676 | fake_state_.device_policy_provider()->var_http_downloads_enabled()->reset( |
| 677 | new bool(false)); |
| 678 | |
| 679 | // Check that the UpdateCanStart returns false. |
| 680 | UpdateState update_state = GetDefaultUpdateState(TimeDelta::FromMinutes(10)); |
Gilad Arnold | 42f253b | 2014-06-25 12:39:17 -0700 | [diff] [blame^] | 681 | UpdateDownloadParams result; |
Gilad Arnold | b3b0544 | 2014-05-30 14:25:05 -0700 | [diff] [blame] | 682 | ExpectPolicyStatus(EvalStatus::kFailed, &Policy::UpdateCanStart, &result, |
| 683 | false, update_state); |
| 684 | } |
| 685 | |
| 686 | TEST_F(UmChromeOSPolicyTest, UpdateCanStartAllowedNoUsableUrlsButP2PEnabled) { |
| 687 | // The UpdateCanStart policy returns true; there's a single HTTP URL but its |
| 688 | // use is forbidden by policy, however P2P is enabled. The result indicates |
| 689 | // that no URL can be used. |
| 690 | |
| 691 | SetUpdateCheckAllowed(false); |
| 692 | |
| 693 | // Override specific device policy attributes. |
| 694 | fake_state_.device_policy_provider()->var_au_p2p_enabled()->reset( |
| 695 | new bool(true)); |
| 696 | fake_state_.device_policy_provider()->var_http_downloads_enabled()->reset( |
| 697 | new bool(false)); |
| 698 | |
| 699 | // Check that the UpdateCanStart returns true. |
| 700 | UpdateState update_state = GetDefaultUpdateState(TimeDelta::FromMinutes(10)); |
Gilad Arnold | 42f253b | 2014-06-25 12:39:17 -0700 | [diff] [blame^] | 701 | UpdateDownloadParams result; |
Gilad Arnold | b3b0544 | 2014-05-30 14:25:05 -0700 | [diff] [blame] | 702 | ExpectPolicyStatus(EvalStatus::kSucceeded, &Policy::UpdateCanStart, &result, |
| 703 | false, update_state); |
| 704 | EXPECT_TRUE(result.update_can_start); |
| 705 | EXPECT_TRUE(result.p2p_allowed); |
| 706 | EXPECT_GT(0, result.download_url_idx); |
| 707 | EXPECT_EQ(0, result.download_url_num_failures); |
Gilad Arnold | f62a4b8 | 2014-05-01 07:41:07 -0700 | [diff] [blame] | 708 | } |
| 709 | |
Gilad Arnold | 684219d | 2014-07-07 14:54:57 -0700 | [diff] [blame] | 710 | TEST_F(UmChromeOSPolicyTest, UpdateDownloadAllowedEthernetDefault) { |
Gilad Arnold | 0adbc94 | 2014-05-12 10:35:43 -0700 | [diff] [blame] | 711 | // Ethernet is always allowed. |
| 712 | |
| 713 | fake_state_.shill_provider()->var_conn_type()-> |
| 714 | reset(new ConnectionType(ConnectionType::kEthernet)); |
| 715 | |
| 716 | bool result; |
| 717 | ExpectPolicyStatus(EvalStatus::kSucceeded, |
Gilad Arnold | 684219d | 2014-07-07 14:54:57 -0700 | [diff] [blame] | 718 | &Policy::UpdateDownloadAllowed, &result); |
Gilad Arnold | 0adbc94 | 2014-05-12 10:35:43 -0700 | [diff] [blame] | 719 | EXPECT_TRUE(result); |
| 720 | } |
| 721 | |
Gilad Arnold | 684219d | 2014-07-07 14:54:57 -0700 | [diff] [blame] | 722 | TEST_F(UmChromeOSPolicyTest, UpdateDownloadAllowedWifiDefault) { |
Gilad Arnold | 0adbc94 | 2014-05-12 10:35:43 -0700 | [diff] [blame] | 723 | // Wifi is allowed if not tethered. |
| 724 | |
| 725 | fake_state_.shill_provider()->var_conn_type()-> |
| 726 | reset(new ConnectionType(ConnectionType::kWifi)); |
| 727 | |
| 728 | bool result; |
| 729 | ExpectPolicyStatus(EvalStatus::kSucceeded, |
Gilad Arnold | 684219d | 2014-07-07 14:54:57 -0700 | [diff] [blame] | 730 | &Policy::UpdateDownloadAllowed, &result); |
Gilad Arnold | 0adbc94 | 2014-05-12 10:35:43 -0700 | [diff] [blame] | 731 | EXPECT_TRUE(result); |
| 732 | } |
| 733 | |
Alex Deymo | 63784a5 | 2014-05-28 10:46:14 -0700 | [diff] [blame] | 734 | TEST_F(UmChromeOSPolicyTest, |
Gilad Arnold | 0adbc94 | 2014-05-12 10:35:43 -0700 | [diff] [blame] | 735 | UpdateCurrentConnectionNotAllowedWifiTetheredDefault) { |
| 736 | // Tethered wifi is not allowed by default. |
| 737 | |
| 738 | fake_state_.shill_provider()->var_conn_type()-> |
| 739 | reset(new ConnectionType(ConnectionType::kWifi)); |
| 740 | fake_state_.shill_provider()->var_conn_tethering()-> |
| 741 | reset(new ConnectionTethering(ConnectionTethering::kConfirmed)); |
| 742 | |
| 743 | bool result; |
| 744 | ExpectPolicyStatus(EvalStatus::kSucceeded, |
Gilad Arnold | 684219d | 2014-07-07 14:54:57 -0700 | [diff] [blame] | 745 | &Policy::UpdateDownloadAllowed, &result); |
Gilad Arnold | 0adbc94 | 2014-05-12 10:35:43 -0700 | [diff] [blame] | 746 | EXPECT_FALSE(result); |
| 747 | } |
| 748 | |
Alex Deymo | 63784a5 | 2014-05-28 10:46:14 -0700 | [diff] [blame] | 749 | TEST_F(UmChromeOSPolicyTest, |
Gilad Arnold | 684219d | 2014-07-07 14:54:57 -0700 | [diff] [blame] | 750 | UpdateDownloadAllowedWifiTetheredPolicyOverride) { |
Gilad Arnold | 0adbc94 | 2014-05-12 10:35:43 -0700 | [diff] [blame] | 751 | // Tethered wifi can be allowed by policy. |
| 752 | |
| 753 | fake_state_.shill_provider()->var_conn_type()-> |
| 754 | reset(new ConnectionType(ConnectionType::kWifi)); |
| 755 | fake_state_.shill_provider()->var_conn_tethering()-> |
| 756 | reset(new ConnectionTethering(ConnectionTethering::kConfirmed)); |
| 757 | set<ConnectionType> allowed_connections; |
| 758 | allowed_connections.insert(ConnectionType::kCellular); |
| 759 | fake_state_.device_policy_provider()-> |
| 760 | var_allowed_connection_types_for_update()-> |
| 761 | reset(new set<ConnectionType>(allowed_connections)); |
| 762 | |
| 763 | bool result; |
| 764 | ExpectPolicyStatus(EvalStatus::kSucceeded, |
Gilad Arnold | 684219d | 2014-07-07 14:54:57 -0700 | [diff] [blame] | 765 | &Policy::UpdateDownloadAllowed, &result); |
Gilad Arnold | 0adbc94 | 2014-05-12 10:35:43 -0700 | [diff] [blame] | 766 | EXPECT_TRUE(result); |
| 767 | } |
| 768 | |
Gilad Arnold | 684219d | 2014-07-07 14:54:57 -0700 | [diff] [blame] | 769 | TEST_F(UmChromeOSPolicyTest, UpdateDownloadAllowedWimaxDefault) { |
Gilad Arnold | 0adbc94 | 2014-05-12 10:35:43 -0700 | [diff] [blame] | 770 | // Wimax is always allowed. |
| 771 | |
| 772 | fake_state_.shill_provider()->var_conn_type()-> |
| 773 | reset(new ConnectionType(ConnectionType::kWifi)); |
| 774 | |
| 775 | bool result; |
| 776 | ExpectPolicyStatus(EvalStatus::kSucceeded, |
Gilad Arnold | 684219d | 2014-07-07 14:54:57 -0700 | [diff] [blame] | 777 | &Policy::UpdateDownloadAllowed, &result); |
Gilad Arnold | 0adbc94 | 2014-05-12 10:35:43 -0700 | [diff] [blame] | 778 | EXPECT_TRUE(result); |
| 779 | } |
| 780 | |
Alex Deymo | 63784a5 | 2014-05-28 10:46:14 -0700 | [diff] [blame] | 781 | TEST_F(UmChromeOSPolicyTest, |
Gilad Arnold | 0adbc94 | 2014-05-12 10:35:43 -0700 | [diff] [blame] | 782 | UpdateCurrentConnectionNotAllowedBluetoothDefault) { |
| 783 | // Bluetooth is never allowed. |
| 784 | |
| 785 | fake_state_.shill_provider()->var_conn_type()-> |
| 786 | reset(new ConnectionType(ConnectionType::kBluetooth)); |
| 787 | |
| 788 | bool result; |
| 789 | ExpectPolicyStatus(EvalStatus::kSucceeded, |
Gilad Arnold | 684219d | 2014-07-07 14:54:57 -0700 | [diff] [blame] | 790 | &Policy::UpdateDownloadAllowed, &result); |
Gilad Arnold | 0adbc94 | 2014-05-12 10:35:43 -0700 | [diff] [blame] | 791 | EXPECT_FALSE(result); |
| 792 | } |
| 793 | |
Alex Deymo | 63784a5 | 2014-05-28 10:46:14 -0700 | [diff] [blame] | 794 | TEST_F(UmChromeOSPolicyTest, |
Gilad Arnold | 0adbc94 | 2014-05-12 10:35:43 -0700 | [diff] [blame] | 795 | UpdateCurrentConnectionNotAllowedBluetoothPolicyCannotOverride) { |
| 796 | // Bluetooth cannot be allowed even by policy. |
| 797 | |
| 798 | fake_state_.shill_provider()->var_conn_type()-> |
| 799 | reset(new ConnectionType(ConnectionType::kBluetooth)); |
| 800 | set<ConnectionType> allowed_connections; |
| 801 | allowed_connections.insert(ConnectionType::kBluetooth); |
| 802 | fake_state_.device_policy_provider()-> |
| 803 | var_allowed_connection_types_for_update()-> |
| 804 | reset(new set<ConnectionType>(allowed_connections)); |
| 805 | |
| 806 | bool result; |
| 807 | ExpectPolicyStatus(EvalStatus::kSucceeded, |
Gilad Arnold | 684219d | 2014-07-07 14:54:57 -0700 | [diff] [blame] | 808 | &Policy::UpdateDownloadAllowed, &result); |
Gilad Arnold | 0adbc94 | 2014-05-12 10:35:43 -0700 | [diff] [blame] | 809 | EXPECT_FALSE(result); |
| 810 | } |
| 811 | |
Alex Deymo | 63784a5 | 2014-05-28 10:46:14 -0700 | [diff] [blame] | 812 | TEST_F(UmChromeOSPolicyTest, UpdateCurrentConnectionNotAllowedCellularDefault) { |
Gilad Arnold | 0adbc94 | 2014-05-12 10:35:43 -0700 | [diff] [blame] | 813 | // Cellular is not allowed by default. |
| 814 | |
| 815 | fake_state_.shill_provider()->var_conn_type()-> |
| 816 | reset(new ConnectionType(ConnectionType::kCellular)); |
| 817 | |
| 818 | bool result; |
| 819 | ExpectPolicyStatus(EvalStatus::kSucceeded, |
Gilad Arnold | 684219d | 2014-07-07 14:54:57 -0700 | [diff] [blame] | 820 | &Policy::UpdateDownloadAllowed, &result); |
Gilad Arnold | 0adbc94 | 2014-05-12 10:35:43 -0700 | [diff] [blame] | 821 | EXPECT_FALSE(result); |
| 822 | } |
| 823 | |
Alex Deymo | 63784a5 | 2014-05-28 10:46:14 -0700 | [diff] [blame] | 824 | TEST_F(UmChromeOSPolicyTest, |
Gilad Arnold | 684219d | 2014-07-07 14:54:57 -0700 | [diff] [blame] | 825 | UpdateDownloadAllowedCellularPolicyOverride) { |
Gilad Arnold | 0adbc94 | 2014-05-12 10:35:43 -0700 | [diff] [blame] | 826 | // Update over cellular can be enabled by policy. |
| 827 | |
| 828 | fake_state_.shill_provider()->var_conn_type()-> |
| 829 | reset(new ConnectionType(ConnectionType::kCellular)); |
| 830 | set<ConnectionType> allowed_connections; |
| 831 | allowed_connections.insert(ConnectionType::kCellular); |
| 832 | fake_state_.device_policy_provider()-> |
| 833 | var_allowed_connection_types_for_update()-> |
| 834 | reset(new set<ConnectionType>(allowed_connections)); |
| 835 | |
| 836 | bool result; |
| 837 | ExpectPolicyStatus(EvalStatus::kSucceeded, |
Gilad Arnold | 684219d | 2014-07-07 14:54:57 -0700 | [diff] [blame] | 838 | &Policy::UpdateDownloadAllowed, &result); |
Gilad Arnold | 0adbc94 | 2014-05-12 10:35:43 -0700 | [diff] [blame] | 839 | EXPECT_TRUE(result); |
| 840 | } |
| 841 | |
Alex Deymo | 63784a5 | 2014-05-28 10:46:14 -0700 | [diff] [blame] | 842 | TEST_F(UmChromeOSPolicyTest, |
Gilad Arnold | 684219d | 2014-07-07 14:54:57 -0700 | [diff] [blame] | 843 | UpdateDownloadAllowedCellularUserOverride) { |
Gilad Arnold | 0adbc94 | 2014-05-12 10:35:43 -0700 | [diff] [blame] | 844 | // Update over cellular can be enabled by user settings, but only if policy |
| 845 | // is present and does not determine allowed connections. |
| 846 | |
| 847 | fake_state_.shill_provider()->var_conn_type()-> |
| 848 | reset(new ConnectionType(ConnectionType::kCellular)); |
| 849 | set<ConnectionType> allowed_connections; |
| 850 | allowed_connections.insert(ConnectionType::kCellular); |
| 851 | fake_state_.updater_provider()->var_cellular_enabled()-> |
| 852 | reset(new bool(true)); |
| 853 | |
| 854 | bool result; |
| 855 | ExpectPolicyStatus(EvalStatus::kSucceeded, |
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 | EXPECT_TRUE(result); |
| 858 | } |
| 859 | |
Alex Deymo | 63784a5 | 2014-05-28 10:46:14 -0700 | [diff] [blame] | 860 | } // namespace chromeos_update_manager |