update_engine: UM: More permissive use of P2P.
The logic we had in ChromeOSPolicy so far was not as permissive as the
original in P2PManagerImpl::IsP2PEnabled(). Specifically, we want to
allow P2P even if a device policy does not have this value set, but
otherwise indicates that the device is enterprise-enrolled.
This also renames the owner variable name so it is consistent with the
rest of the variable names (no get_ prefix).
BUG=chromium:384087
TEST=Unit tests.
Change-Id: I184ebaebc168352510ea3ed0277ea74167edf666
Reviewed-on: https://chromium-review.googlesource.com/221476
Reviewed-by: Alex Vakulenko <avakulenko@chromium.org>
Reviewed-by: David Zeuthen <zeuthen@chromium.org>
Tested-by: Gilad Arnold <garnold@chromium.org>
Reviewed-by: Alex Deymo <deymo@chromium.org>
Commit-Queue: Gilad Arnold <garnold@chromium.org>
diff --git a/update_manager/chromeos_policy_unittest.cc b/update_manager/chromeos_policy_unittest.cc
index e3f7acf..ae741e7 100644
--- a/update_manager/chromeos_policy_unittest.cc
+++ b/update_manager/chromeos_policy_unittest.cc
@@ -1193,6 +1193,36 @@
EXPECT_FALSE(result.do_increment_failures);
}
+TEST_F(UmChromeOSPolicyTest,
+ UpdateCanStartAllowedNoUsableUrlsButEnterpriseEnrolled) {
+ // The UpdateCanStart policy returns true; there's a single HTTP URL but its
+ // use is forbidden by policy, and P2P is unset on the policy, however the
+ // device is enterprise-enrolled so P2P is allowed. The result indicates that
+ // no URL can be used.
+ //
+ // Note: The number of failed attempts should not increase in this case (see
+ // above test).
+
+ SetUpdateCheckAllowed(false);
+
+ // Override specific device policy attributes.
+ fake_state_.device_policy_provider()->var_au_p2p_enabled()->reset(nullptr);
+ fake_state_.device_policy_provider()->var_owner()->reset(nullptr);
+ fake_state_.device_policy_provider()->var_http_downloads_enabled()->reset(
+ new bool(false));
+
+ // Check that the UpdateCanStart returns true.
+ UpdateState update_state = GetDefaultUpdateState(TimeDelta::FromMinutes(10));
+ UpdateDownloadParams result;
+ ExpectPolicyStatus(EvalStatus::kSucceeded, &Policy::UpdateCanStart, &result,
+ update_state);
+ EXPECT_TRUE(result.update_can_start);
+ EXPECT_TRUE(result.p2p_allowed);
+ EXPECT_GT(0, result.download_url_idx);
+ EXPECT_EQ(0, result.download_url_num_errors);
+ EXPECT_FALSE(result.do_increment_failures);
+}
+
TEST_F(UmChromeOSPolicyTest, UpdateDownloadAllowedEthernetDefault) {
// Ethernet is always allowed.